garro95 / desim Goto Github PK
View Code? Open in Web Editor NEWA discrete-time events simulation framework, written in rust, using the generator experimental feature
License: GNU General Public License v3.0
A discrete-time events simulation framework, written in rust, using the generator experimental feature
License: GNU General Public License v3.0
The link to the api docs on the repo landing page is dead.
Is it possible to add container feature in a similar way as in simpy container? https://simpy.readthedocs.io/en/latest/topical_guides/resources.html#res-type-container
pull request: #12
pub trait Resource<T> {
fn allocate_or_enqueue(&mut self, event: Event<T>) -> Vec<Event<T>>;
fn release_and_schedule_next(&mut self, event: Event<T>) -> Vec<Event<T>>;
}
instead of returning an optional value, the resource can now return zero or multiple events
Effect::Request(r) => {
let res = &mut self.resources[r];
let request_event = Event::new(self.time, event.process(), y);
for e in res.allocate_or_enqueue(request_event) {
self.future_events.push(Reverse(e))
}
}
Effect::Release(r) => {
let res = &mut self.resources[r];
let request_event = Event::new(self.time, event.process(), y);
let events = res.release_and_schedule_next(request_event);
for e in events {
self.future_events.push(Reverse(e));
}
}
now the scheduler always schedules all the events that the resource returned.
fn release_and_schedule_next(&mut self, event: Event<T>) -> Vec<Event<T>> {
match self.queue.pop_front() {
Some(mut request_event) => {
// some is waiting for the request, schedule it! and schedule the self
request_event.set_time(event.time());
vec![request_event, event]
}
None => {
// no one is waiting for the resorce, restore the availiable and return self
assert!(self.available < self.quantity);
self.available += 1;
vec![event]
}
}
}
Hi,
Using desim v0.2
results in some import errors in the examples or when using desim
as described in the examples.
For example, the carwash example does not compile with the following errors:
18 | use desim::prelude::*;
| ^^^^^^^ could not find `prelude` in `desim`
error[E0432]: unresolved import `desim::resources`
--> simulator/src/bin/carwash.rs:19:12
|
19 | use desim::resources::SimpleResource;
| ^^^^^^^^^ could not find `resources` in `desim`
In contrast, the example compiles successfully using the version on git , i.e. desim = {git = "https://github.com/garro95/desim"}
.
The crate has not been updated on crates.io which is evident when looking at the last update on crates.io vs the commit history here.
It would be nice if you would update the crate.
Is it possible to implement process interruption in a similar way as in simpy
?
Write a test to ensure that log trace is correct
I'm trying to asses the opportunity for one or more pull requests that add some features to desim. Most of those are the result of my own needs for discrete event simulation, but I would like to see if there is wider interest:
Currently already done but in need of polishing (marked below) or in my near-term pipeline:
Effect
+ arbitrary additional state)on_event_processed
, on_resource_acquire
, on_resource_enqueue
, on_resource_release
SimResource
trait that all Resources
implementProcesses
can be logically run in a time-sharing fashion (each being given a time slice). This is more disruptive to the code as simulation steps are no longer entirely driven by resuming generators.At the moment the new code lives in my own fork of desim in a "new_features" branch but that is just a messy experiment and separate pull requests would have to be teased from that. However, I don't plan on maintaining a separate fork if you are interested in the changes upstream.
Any idea how to access simulation time from within the process?
This code won't compile:
#![feature(generators, generator_trait)]
extern crate desim;
use desim::{Simulation, Effect, Event, EndCondition};
fn main() {
let mut s = Simulation::new();
let g = Box::new(|| {
let tik = 0.7;
loop{
println!("tik {}", s.time());
yield Effect::TimeOut(tik);
}
});
let p = s.create_process(g);
s.schedule_event(Event{time: 0.0, process: p});
let s = s.run(EndCondition::Time(10.0));
}
The problem is accessing s
from within the closure - it introduces immutable borrow of s
with conflicts with the need to use the mutable borrow later. Any idea how to solve this without using Rc
and RefCell
?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.