-
Notifications
You must be signed in to change notification settings - Fork 1
Simulation
Quartz simulations are runned using a Quartz::Simulation instance.
Initializing a simulation requires a model as an argument:
model = model = QueuingSystem.new("queuing_system")
simulation = Simulation.new(model)Simulating the model now simply requires calling the #simulate method:
simulation.simulateAs we didn't configured the simulation with a maximum duration or a custom termination condition, our model will be simulated indefinitely. More precisely, it runs as long as the model keeps scheduling events. It may stop on its own if the model plans an infinite duration as an internal event.
When you models keep running indefinitely, you typically want to run a simulation until a certain point in virtual time. This can be done by initializing the simulation with the duration named argument, which expects a 'Duration' or a 'TimePoint':
simulation = Simulation.new(model, duration: 100.time_units)For more complex situations, you can set a custom termination condition via the #termination_condition method, which yields the virtual time as well as the root model. It expects a block returning true if the simulation should stop, false otherwise.
This is particularly useful if you want to stop a simulation once a model or an observer reached a given state.
Below is such an example :
model = QueuingSystem.new("queuing_system")
simulation = Simulation.new(model)
max = TimePoint.new(1, Scale::KILO)
simulation.termination_condition do |time, model|
return true if time > max
queuing_system.servers.any? { |s| s.processing_time / time >= 1 }
end
simulation.simulateNote that setting a custom termination condition overrides the duration parameter provided it was set during the simulation initialization.
TODO