Commit 019d1168 authored by jimonreal's avatar jimonreal Committed by Jose Ignacio Monreal Bailey
Browse files

Adding functionality to discover edges controlled by traffic light

parent 43ef5b62
...@@ -6,12 +6,7 @@ import java.io.FileOutputStream; ...@@ -6,12 +6,7 @@ import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.ObjectInputStream; import java.io.ObjectInputStream;
import java.io.ObjectOutputStream; import java.io.ObjectOutputStream;
import java.util.ArrayList; import java.util.*;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Random;
import de.tud.kom.p2psim.api.simengine.SimulatorObserver; import de.tud.kom.p2psim.api.simengine.SimulatorObserver;
import de.tud.kom.p2psim.impl.simengine.Simulator; import de.tud.kom.p2psim.impl.simengine.Simulator;
...@@ -958,7 +953,29 @@ public class TraciSimulationController implements VehicleController, SimulationS ...@@ -958,7 +953,29 @@ public class TraciSimulationController implements VehicleController, SimulationS
return result; return result;
} }
@Override @Override
public List<String> getControlledEdges(String pTrafficLightID) {
List<String> controlledLanesList = getControlledLanes(pTrafficLightID);
Map<String, String> controlledEdgeHash = new HashMap<>();
List<String> controlledEdgeList = new ArrayList<>();
controlledLanesList.removeIf(lane -> lane.charAt(0) == ':');
for (String lane : controlledLanesList) {
String edge = lane.split("_")[0];
if (!controlledEdgeHash.containsKey(edge)) {
controlledEdgeHash.put(edge, "");
}
}
for (String edge : controlledEdgeHash.keySet()) {
controlledEdgeList.add(edge);
}
return controlledEdgeList;
}
@Override
public Map<RoadNetworkLink, TrafficLightState> getTrafficLightStateForEachLane(String pTrafficLightID) { public Map<RoadNetworkLink, TrafficLightState> getTrafficLightStateForEachLane(String pTrafficLightID) {
SumoCommand trafficLightCommand = Trafficlight.getRedYellowGreenState(pTrafficLightID); SumoCommand trafficLightCommand = Trafficlight.getRedYellowGreenState(pTrafficLightID);
Object trafficLightObject = requestObject(trafficLightCommand); Object trafficLightObject = requestObject(trafficLightCommand);
......
...@@ -115,6 +115,11 @@ public class XMLSimulationController implements VehicleController, SimulationSet ...@@ -115,6 +115,11 @@ public class XMLSimulationController implements VehicleController, SimulationSet
return null; return null;
} }
@Override
public List<String> getControlledEdges(String pTrafficLightID) {
return null;
}
@Override @Override
public Map<RoadNetworkLink, TrafficLightState> getTrafficLightStateForEachLane(String pTrafficLightID) { public Map<RoadNetworkLink, TrafficLightState> getTrafficLightStateForEachLane(String pTrafficLightID) {
return null; return null;
......
...@@ -59,6 +59,16 @@ public class DefaultTrafficLightInformationComponent implements TrafficLightInfo ...@@ -59,6 +59,16 @@ public class DefaultTrafficLightInformationComponent implements TrafficLightInfo
return trafficLightId; return trafficLightId;
} }
@Override
public List<String> getControlledLanes(String pTrafficLightID) {
return controller.getControlledLanes(pTrafficLightID);
}
@Override
public List<String> getControlledEdges(String pTrafficLightId) {
return controller.getControlledEdges(pTrafficLightId);
}
@Override @Override
public void initialize() { public void initialize() {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment