Commit 2d56973c authored by Tobias Meuser's avatar Tobias Meuser
Browse files

Extended vehicle route randomly after exit

parent 30a32f4c
...@@ -50,7 +50,7 @@ import it.polito.appeal.traci.SumoTraciConnection; ...@@ -50,7 +50,7 @@ import it.polito.appeal.traci.SumoTraciConnection;
public class TraciSimulationController implements VehicleController, SimulationSetupExtractor, EdgeController, SimulatorObserver { public class TraciSimulationController implements VehicleController, SimulationSetupExtractor, EdgeController, SimulatorObserver {
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 Random _random = Randoms.getRandom(getClass());
private static final Map<String, TraciSimulationController> CONTROLLER = new HashMap<>(); private static final Map<String, TraciSimulationController> CONTROLLER = new HashMap<>();
...@@ -200,6 +200,9 @@ public class TraciSimulationController implements VehicleController, SimulationS ...@@ -200,6 +200,9 @@ public class TraciSimulationController implements VehicleController, SimulationS
@Override @Override
public boolean nextStep() { public boolean nextStep() {
if (Simulator.getEndTime() == Simulator.getCurrentTime()) {
return false;
}
try { try {
// for (RoadNetworkEdge roadNetworkEdge : modifiedEdges) { // for (RoadNetworkEdge roadNetworkEdge : modifiedEdges) {
// SumoCommand setMaxSpeedCommand = Edge.setMaxSpeed(roadNetworkEdge.getEdgeID(), roadNetworkEdge.getOriginalMaxSpeed()); // SumoCommand setMaxSpeedCommand = Edge.setMaxSpeed(roadNetworkEdge.getEdgeID(), roadNetworkEdge.getOriginalMaxSpeed());
...@@ -534,6 +537,11 @@ public class TraciSimulationController implements VehicleController, SimulationS ...@@ -534,6 +537,11 @@ public class TraciSimulationController implements VehicleController, SimulationS
} }
edges.add(accessibleEdges.get(j)); edges.add(accessibleEdges.get(j));
List<RoadNetworkEdge> newPaths;
while ((newPaths = edges.get(edges.size() - 1).getAccessibleEdges()).size() > 0) {
edges.add(newPaths.get(_random.nextInt(newPaths.size())));
}
for (RoadNetworkEdge roadNetworkEdge : edges) { for (RoadNetworkEdge roadNetworkEdge : edges) {
if (pEdgesToAvoid.contains(roadNetworkEdge)) { if (pEdgesToAvoid.contains(roadNetworkEdge)) {
continue outer; continue outer;
...@@ -708,14 +716,6 @@ public class TraciSimulationController implements VehicleController, SimulationS ...@@ -708,14 +716,6 @@ public class TraciSimulationController implements VehicleController, SimulationS
RoadNetworkEdge edge = _roadNetwork.getEdge(pEdgeID); RoadNetworkEdge edge = _roadNetwork.getEdge(pEdgeID);
edge.setMaxSpeed(pMaxSpeed); 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