Initializes a new instance of the Simulation class.
Override the onStarting method to generate entities when the simulation starts running.
Object with parameters used to initialize the simulation (properties and event handlers).
Event that occurs after the simulation finishes executing.
Event that occurs before the simulation finishes executing.
Event that occurs after the simulation starts executing.
Event that occurs before the simulation starts executing.
Event that occurs after the simulation's state property changes.
For example:
sim.stateChanged.addEventListener(s => {
console.log('the simulation state changed to', SimulationState[s.state]);
});
Event that occurs before the simulation's state property changes.
Event that occurs after the simulation's timeNow property changes.
For example:
sim.timeChanged.addEventListener(s => {
console.log('the simulation time advanced to', s.timeNow);
});
Event that occurs before the simulation's timeNow property changes.
Gets or sets the duration, in milliseconds of each simulated time advance.
This property is useful to slow down animated simulations.
For example, if you set frameDelay to 100, each animation frame will be displayed for 100ms before being updated.
The default value for this property is 0, which means no frame delays should be applied and the animation will run as quickly as possible.
See also the maxTimeStep property.
Gets or sets the duration, in milliseconds of each simulated time advance.
This property is useful to slow down animated simulations.
For example, if you set frameDelay to 100, each animation frame will be displayed for 100ms before being updated.
The default value for this property is 0, which means no frame delays should be applied and the animation will run as quickly as possible.
See also the maxTimeStep property.
Gets or sets the maximum time step allowed by the simulation.
The default value for this property is 0, which allows the simulation to advance the time in steps of any size.
This property can be useful to slow down and set the pace for animated simulations. This will prevent animations from becoming too jerky and hard to follow.
See also the frameDelay property.
Gets or sets the maximum time step allowed by the simulation.
The default value for this property is 0, which allows the simulation to advance the time in steps of any size.
This property can be useful to slow down and set the pace for animated simulations. This will prevent animations from becoming too jerky and hard to follow.
See also the frameDelay property.
Gets or sets a string that represents the simulation name.
This value used by the getStatsTable method when creating output tables. It does not have any effect on the simulation results.
This property is set to an empty string by default, which causes the getStatsTable method to use the class name as the simulation name. This is adequate in most cases, except if the code is minified.
Gets or sets a string that represents the simulation name.
This value used by the getStatsTable method when creating output tables. It does not have any effect on the simulation results.
This property is set to an empty string by default, which causes the getStatsTable method to use the class name as the simulation name. This is adequate in most cases, except if the code is minified.
Gets an array with the Queue objects in use by this Simulation.
Gets the actual simulation time in milliseconds.
Gets or sets the simulation end time.
The default value for this property is null, which causes the simulation to run until the stop method is called or until it runs out of things to do.
Gets or sets the simulation end time.
The default value for this property is null, which causes the simulation to run until the stop method is called or until it runs out of things to do.
Gets the current simulated time in simulation time units.
Gets or sets a string that represents the simulation time unit.
This value used by the getStatsTable method when creating output tables. It does not have any effect on the simulation results.
This property is set to 'Sim Time' by default. Set it to a string such as 's', 'min', or 'hours' to get better looking output from the getStatsTable method.
Gets or sets a string that represents the simulation time unit.
This value used by the getStatsTable method when creating output tables. It does not have any effect on the simulation results.
This property is set to 'Sim Time' by default. Set it to a string such as 's', 'min', or 'hours' to get better looking output from the getStatsTable method.
Gets or sets a value that determines how often the Simulation will release control of the thread so the brower remains responsive.
The default value for this property is 100 ms, which is enough to keep the UI responsive. Use higher values to increase the simulation speed at the expense of UI responsiveness.
Gets or sets a value that determines how often the Simulation will release control of the thread so the brower remains responsive.
The default value for this property is 100 ms, which is enough to keep the UI responsive. Use higher values to increase the simulation speed at the expense of UI responsiveness.
Activates an Entity, causing it to enter the simulation and start executing its Entity.script method.
Entity to activate.
Generates and activates Entity objects of a given type according to a schedule.
For example, the code below shows a Simulation that overrides the onStarting method to generate entities of type Customer with inter-arrival times of 18+/-6 minutes:
export class BarberShop extends Simulation {
qJoe = new Queue('Joe', 1);
qWait = new Queue('Wait Area');
// generate Customer entities with inter-arrival times of 18+/-6 min
// for 8 hours * 7 days
onStarting() {
super.onStarting();
this.timeEnd = 60 * 8 * 7; // 8 hours * 7 days
this.generateEntities(Customer, new Uniform(18 - 6, 18 + 6));
}
}
class Customer extends Entity<BarberShop> {
async script() {
// do what the customers do...
}
}
Type of Entity to generate.
RandomVar that returns the inter-arrival time, or a number that represents a fixed interval, or null to generate a single entity.
Maximum number of entities to generate.
Time to start generating entities.
Time to stop generating entities.
Creates a table with the Simulation statistics.
For example, here is the table generated after running the BarberShop sample simulation:
BarberShop
Finish Time 3,380.37
Elapsed Time (s) 0.01
Populations
Queue Min Avg Max StDev Capy Utz
Joe 0.00 0.82 1.00 0.38 1 82%
Wait Area 0.00 0.03 1.00 0.17 *
Dwell Times
Queue Min Avg Max StDev Cnt
Joe 12.11 14.91 17.99 1.76 185
Wait Area 0.00 0.54 6.81 1.30 185
The table shows the simulated finish time, the actual elapsed time, and a list of the Queue objects used in the simulation, along with their population (number of entities in the queue) and dwell time (time they spent in the queue) statistics.
Whether to include net statistics (non-zero Queue dwell times and populations).
An HTML string defining a table with statistics for all Queue objects in the simulation.
Raises the starting event.
Classes that extend Simulation typically override this method to create the entities that will drive the simulation.
For example:
export class BarberShop extends Simulation {
qJoe = new Queue('Joe', 1);
qWait = new Queue('Wait Area');
// generate entities with inter-arrival times of 18 min for 8 hours
onStarting() {
this.qWait.grossDwell.binSize = 1;
this.generateEntities(Customer, new Uniform(18 - 6, 18 + 6));
}
}
Raises the stateChanged event.
Raises the stateChanging event.
Raises the timeNowChanged event.
Raises the timeNowChanging event.
Starts the Simulation or resumes the execution of a stopped simulation.
Whether to restart the simulation or resume execution from where it stopped.
Stops the Simulation.
Calling this method causes the SimulationState to change from Running to Paused.
Use the the start method to resume or re-start the simulation when it is paused.
Whether to reset the simulation state after stopping it.
Generated using TypeDoc
Abstract base class for simulations.
Simulation objects are basically schedulers. They act as a stage where the actors are Entity objects and have props represented by Queue objects.
Simulations keep a list of active entities and conditions these entities are waiting for within their Entity.script methods, which execute asynchronously. As these conditions are satisfied along the simulated time, the Entity objects resume executing their scripts. When the simulation runs out of active entities, that means all entities have finished their scripts and the simulation ends.
To create simulations follow these steps:
Create one or more classes that extend the Entity class and override the Entity.script method to describe the entity's actions within the simulation.
Create a class that extends Simulation to use the entities you defined in step 1.
Override the simulation's onStarting method to create and activate one or more of the entities you defined in step 1.
For example: