Class TrafficLightManager

java.lang.Object
real_time_traffic_simulation_with_java.wrapper.TrafficLightManager

public class TrafficLightManager extends Object
Wrapper class for TraaS to manage traffic lights in the simulation
  • Constructor Details

    • TrafficLightManager

      public TrafficLightManager(it.polito.appeal.traci.SumoTraciConnection connection)
      Wrapper class for TraaS to manage traffic lights in the simulation
      Parameters:
      connection - connection to Sumo
  • Method Details

    • getIDList

      public List<String> getIDList() throws Exception
      Get list of traffic light IDs
      Returns:
      a List type String of traffic light IDs
      Throws:
      Exception
    • getCount

      public int getCount()
      Get number of traffic light in the simulation
      Returns:
      a int number of traffic lights
    • getState

      public String getState(String tlId) throws Exception
      Get the current state of the traffic light ('r', 'y', 'g' sequence)
      Parameters:
      tlId - ID of the traffic light
      Returns:
      String of traffic light current state
      Throws:
      Exception
    • getNextSwitch

      public double getNextSwitch(String tlId)
      Get remaining time of the current phase of the traffic light (second)
      Parameters:
      tlId - ID of the traffic light
      Returns:
      double of remaining time in seconds
    • getDuration

      public double getDuration(String tlId)
      Get the duration of the current phase of the traffic light (second)
      Parameters:
      tlId - ID of the traffic light
      Returns:
      double of duration of the current phase in seconds
    • getPhaseID

      public int getPhaseID(String tlId)
      Get the current phase index of the traffic light
      Parameters:
      tlId - ID of the traffic light
      Returns:
      int of current phase index
    • getPhaseCount

      public int getPhaseCount(String tlId) throws Exception
      Get number of phases of the traffic light
      Parameters:
      tlId - ID of the traffic light
      Returns:
      int of number of phases
      Throws:
      Exception
    • getPhasesDuration

      public List<Integer> getPhasesDuration(String tlId) throws Exception
      Get initial list of durations for each phase of the traffic light set in net file
      Parameters:
      tlId - ID of the traffic light
      Returns:
      a List of Double type durations for each phase
      Throws:
      Exception
    • setPhaseDuration

      public void setPhaseDuration(String tlId, List<Integer> durations)
      Set new duration for each phase of the traffic light and update TrafficLightData phasesDuration
      Parameters:
      tlId - ID of the traffic light
      durations - List of durations for each phase
    • nextPhase

      public void nextPhase(String tlId)
      Toggle traffic light to next phase: get the current phase index and then add 1 to convert to next phase
      Parameters:
      tlId - ID of the traffic light
    • getLinksTraffic

      public List<de.tudresden.sumo.objects.SumoLink> getLinksTraffic(String tlID) throws Exception
      Method to get links controlled by the traffic light
      Parameters:
      tlID - ID of the traffic light
      Returns:
      a list type SumoLink objects controlled by the traffic light
      Throws:
      Exception
    • getTrafficLightDataList

      public List<TrafficLightData> getTrafficLightDataList() throws Exception
      Initiate a List of TrafficLightData for all traffic lights
      Returns:
      a List of TrafficLightData for all traffic lights
      Throws:
      Exception
    • updateTrafficLightDataList

      public void updateTrafficLightDataList() throws Exception
      Update mapping data of the TrafficLightData List with current states from simulation
      Throws:
      Exception