Commit 84e9b991 authored by Tobias Meuser's avatar Tobias Meuser Committed by Jose Ignacio Monreal Bailey
Browse files

Added option to block edges without failures in SUMO

parent ebdc2a8b
...@@ -44,6 +44,8 @@ import it.polito.appeal.traci.SumoTraciConnection; ...@@ -44,6 +44,8 @@ import it.polito.appeal.traci.SumoTraciConnection;
public class TraciSimulationController implements VehicleController, SimulationSetupExtractor, EdgeController { public class TraciSimulationController implements VehicleController, SimulationSetupExtractor, EdgeController {
private static final File TEMP_FILE = new File(new File(System.getProperty("java.io.tmpdir")), "road_network.tmp"); private static final File TEMP_FILE = new File(new File(System.getProperty("java.io.tmpdir")), "road_network.tmp");
private List<RoadNetworkEdge> modifiedEdges = new ArrayList<>();
private static final Map<String, TraciSimulationController> CONTROLLER = new HashMap<>(); private static final Map<String, TraciSimulationController> CONTROLLER = new HashMap<>();
private static final double CLUSTERING_DISTANCE = 50; private static final double CLUSTERING_DISTANCE = 50;
...@@ -182,6 +184,13 @@ public class TraciSimulationController implements VehicleController, SimulationS ...@@ -182,6 +184,13 @@ public class TraciSimulationController implements VehicleController, SimulationS
@Override @Override
public boolean nextStep() { public boolean nextStep() {
try { try {
for (RoadNetworkEdge roadNetworkEdge : modifiedEdges) {
SumoCommand setMaxSpeedCommand = Edge.setMaxSpeed(roadNetworkEdge.getEdgeID(), roadNetworkEdge.getOriginalMaxSpeed());
execute(setMaxSpeedCommand);
}
_connection.do_timestep(); _connection.do_timestep();
try { try {
...@@ -214,6 +223,12 @@ public class TraciSimulationController implements VehicleController, SimulationS ...@@ -214,6 +223,12 @@ public class TraciSimulationController implements VehicleController, SimulationS
e.printStackTrace(); e.printStackTrace();
} }
for (RoadNetworkEdge roadNetworkEdge : modifiedEdges) {
SumoCommand setMaxSpeedCommand = Edge.setMaxSpeed(roadNetworkEdge.getEdgeID(), roadNetworkEdge.getMaxSpeed());
execute(setMaxSpeedCommand);
}
return true; return true;
} catch (RuntimeException e) { } catch (RuntimeException e) {
throw e; throw e;
...@@ -672,6 +687,18 @@ public class TraciSimulationController implements VehicleController, SimulationS ...@@ -672,6 +687,18 @@ public class TraciSimulationController implements VehicleController, SimulationS
SumoCommand setMaxSpeedCommand = Edge.setMaxSpeed(pEdgeID, pMaxSpeed); SumoCommand setMaxSpeedCommand = Edge.setMaxSpeed(pEdgeID, pMaxSpeed);
execute(setMaxSpeedCommand); execute(setMaxSpeedCommand);
RoadNetworkEdge edge = _roadNetwork.getEdge(pEdgeID);
edge.setMaxSpeed(pMaxSpeed);
if (edge.getOriginalMaxSpeed() != pMaxSpeed) {
if (!modifiedEdges.contains(edge)) {
modifiedEdges.add(edge);
}
} else {
modifiedEdges.remove(edge);
}
} }
} }
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