Class SimulationEngine

java.lang.Object
real_time_traffic_simulation_with_java.cores.SimulationEngine

public class SimulationEngine extends Object
Core to control the simulation, center of backend operations.
Manages all other manager classes.
  • Constructor Details

    • SimulationEngine

      public SimulationEngine() throws Exception
      Core to control the simulation, center of backend operations.
      Manages all other manager classes.
      Throws:
      Exception
  • Method Details

    • stepSimulation

      public void stepSimulation() throws IllegalStateException
      Control simulation: advance simulation by one step invalid input: '&' update edge congestion status and traffic light states
      Throws:
      IllegalStateException
    • stopSimulation

      public void stopSimulation()
      Control simulation: stop
    • getAllEdgeIDs

      public List<String> getAllEdgeIDs() throws IllegalStateException
      Get all IDs: edges
      Returns:
      List of String edge IDs
      Throws:
      Exception
      IllegalStateException
    • getAllVehicleIDs

      public List<String> getAllVehicleIDs() throws IllegalStateException
      Get all IDs: vehicles
      Returns:
      List of String vehicle IDs
      Throws:
      Exception
      IllegalStateException
    • getAllTrafficLightIDs

      public List<String> getAllTrafficLightIDs() throws IllegalStateException
      Get all IDs: traffic lights
      Returns:
      List of String traffic light IDs
      Throws:
      Exception
      IllegalStateException
    • injectVehicle

      public void injectVehicle(int numVehicles, String start_edge_ID, String end_edge_ID, String color, String speed)
      Inject vehicle: single and batch injection, create route first then create vehicles on that route.
      Route ID format: [currentTime]
      Vehicle ID format: [routeID]_[index]
      Parameters:
      numVehicles - Number of vehicles to inject
      start_edge_ID - Starting edge ID
      end_edge_ID - Ending edge ID
      color - Color of the vehicles
    • stressTest

      public void stressTest(int number_of_vehicles, String start_edge_ID)
      Inject vehicle: stress test tool, inject 100 vehicles on up to 10 different random routes. Create routes first then create vehicles on those routes.
      Route ID format: [currentTime]_[index]
      Vehicle ID format: [routeID]_[index_of_vehicle_in_this_stress_test]
      Parameters:
      number_of_vehicles - Number of vehicles to inject
      start_edge_ID - Edge ID to inject to
    • toggleAllTls

      public void toggleAllTls()
      Control traffic lights: toggle all traffic lights
    • toggleSingleTl

      public void toggleSingleTl(String tlID)
      Control traffic light: toggle single traffic light
      Parameters:
      tlID - Traffic light ID
    • setTlPhaseDurations

      public void setTlPhaseDurations(String tlID, List<Integer> durations)
      Control traffic light: set phase durations for a traffic light
      Parameters:
      tlID - Traffic light ID
      durations - List of durations for each phase
    • getMapEdges

      public List<EdgeData> getMapEdges()
      Get mapping data: edges
      Returns:
      List of EdgeData representing edges shape to be rendered
    • getMapJunctions

      public List<JunctionData> getMapJunctions()
      Get mapping data: junctions
      Returns:
      List of JunctionData representing junctions shape to be rendered
    • getMapVehicles

      public List<VehicleData> getMapVehicles()
      Get mapping data: vehicles
      Returns:
      List of VehicleData representing vehicles shape to be rendered
    • setVehicleFilter

      public void setVehicleFilter(String color, String edgeID)
      Set mapping data: filter vehicles by color and edge
    • getMapTls

      public List<TrafficLightData> getMapTls()
      Get mapping data: traffic lights
      Returns:
      List of TrafficLightData representing traffic lights shape to be rendered
    • getEdgeTooltip

      public String getEdgeTooltip(String edgeID)
      Get tooltip: edges
      Parameters:
      edgeID - ID of the edge
      Returns:
      Formatted tooltip string
    • getTlTooltip

      public String getTlTooltip(String tlID)
      Get tooltip: traffic lights
      Parameters:
      tlID - ID of the traffic light
      Returns:
      Formatted tooltip string
    • getCurrentTimeStep

      public String getCurrentTimeStep() throws IllegalStateException
      Get statistics: current time step
      Returns:
      Formatted statistic string for Dashboard
      Throws:
      IllegalStateException
    • getBasicInfo

      public String getBasicInfo()
      Get statistics: number of entities in the simulation
      Returns:
      Formatted statistic string for Dashboard
    • getCongestionHotspots

      public String getCongestionHotspots()
      Get statistics: congestion hotspots
      Returns:
      Formatted statistic string of congested edge IDs for Dashboard
    • getEdgeStats

      public double[] getEdgeStats(String edgeID) throws IllegalStateException
      Get statistics: chart values (average speed (km/h), density (veh/km), halting number (veh)) of a specific edge
      Parameters:
      vehicleID - ID of the vehicle
      Returns:
      Formatted statistic string for Dashboard
      Throws:
      IllegalStateException
    • dataForCSV

      public List<String[]> dataForCSV() throws IllegalStateException
      Prepare data for CSV logging: "Simulation step", "vehicle id","vehicle color", "vehicle speed", "vehicle is on edge", "edge congestion status", "edge average speed", "edge density"
      Returns:
      List of String arrays representing data rows
      Throws:
      IllegalStateException
    • dataForPDF

      public List<String[]> dataForPDF() throws IllegalStateException
      Prepare data for PDF summary: 1st element is {edgeCount, tlsCount}, 2nd element is {exportedSimulationStep}, following elements are {edgeID, laneCount, length}
      Returns:
      Throws:
      IllegalStateException