The core of the simulation functionality which orchestrates the workflow of the simulation is fully implemented in DIVAs. The implementation of the “TrafficSimulation” class creates a “TrafficEnvironment” and binds it to the “TrafficSimulation”.
Implementation Steps
- Inside the package “edu.utdallas.mavs.traffic.simulation.sim” create a class named “TrafficSimulation” that extends the abstract class “Simulation” defined in the package “edu.utdallas.mavs.divas.core.sim”.
- The “TrafficSimulation” provides concrete implementations for the following abstract methods:
- “createEnvironment”: This method is responsible for creating the “TrafficEnvironment” at the simulation initialization and associating it to the “TrafficSimulation”.
- “tick”: This method is responsible for triggering the start of the simulation cycle. The full implementation of the class “TrafficSimulation” is provided in the following code.
package edu.utdallas.mavs.traffic.simulation.sim; import java.io.Serializable; import edu.utdallas.mavs.divas.core.msg.TickMsg; import edu.utdallas.mavs.divas.core.sim.Simulation; import edu.utdallas.mavs.divas.mts.MTSClient; import edu.utdallas.mavs.traffic.simulation.sim.env.TrafficEnvironment; /** * This class describes a simulation for evacuation scenarios. */ public class TrafficSimulation extends Simulation<TrafficEnvironment> implements Serializable { private static final long serialVersionUID = 1L; /** * Creates a new instance of the simulation for traffic scenarios. * * @param client * the MTS client */ public TrafficSimulation(MTSClient client) { super(client); } @Override protected void createEnvironment(MTSClient client) { environment = new TrafficEnvironment(client); } @Override public void tick(TickMsg tick) { super.tick(tick); } }