Visualization
Drawing and Controlling Visualization
To draw a line and control its visualization in the simulation, you can use the position keyword for objects and the visualize, realtime, and factor keywords for controlling the visualization behavior.
Using the position Keyword
The position keyword specifies the coordinates of objects (e.g., Source, Sink, Switch) in the simulation. These coordinates are used to draw the objects on the visualization screen. For example:
source = Source(
name='Source',
position=(100, 300), # X, Y coordinates
processing_time=5,
...
)
sink = Sink(
name='Sink_1',
position=(500, 200), # X, Y coordinates
processing_time=10,
...
)
position values determine where the objects appear on the screen. You can adjust the coordinates to arrange the layout of your line visually.
Controlling the Visualization with Keywords:
-
visualize:- Set this to
Truewhen calling the run method to enable the graphical visualization of the line. - Example:
- Set this to
-
realtime:- Set this to
Truewhen initializing the Line object to make the simulation run in real-time. This ensures that the simulation speed matches the wall-clock time. - Example:
- Set this to
-
factor:- This controls the speed of the visualization when
realtime=True. A factor of 1.0 means the simulation runs at normal speed, while a smaller value (e.g., 0.5) slows it down, and a larger value (e.g., 2.0) speeds it up. - Example:
- This controls the speed of the visualization when
Example Usage
Here’s how you can combine these keywords to visualize a line:
if __name__ == '__main__':
line = MultiSink(realtime=True, factor=1.0, n_sinks=3, alternate=True)
agent = make_greedy_policy(3)
line.run(simulation_end=300, agent=agent, visualize=True)
This will:
- Arrange the objects based on their position values.
- Run the simulation in real-time (
realtime=True). - Display the visualization (
visualize=True) at normal speed (factor=1.0).