Commit 46aee7f6 authored by Tobias Meuser's avatar Tobias Meuser
Browse files

Fixed bug preventing rerouting on internal edges

parent 58641b7b
......@@ -290,21 +290,42 @@ public class TraciSimulationController implements VehicleController, SimulationS
return new ArrayList<>(map.keySet());
}
public RoadNetworkEdge getCurrentEdge(String pVehicleID) {
obtainRoadNetwork();
SumoCommand roadIDCommand = Vehicle.getRoadID(pVehicleID);
String currentRoadID = (String) requestObject(roadIDCommand);
RoadNetworkEdge edge = _roadNetwork.getEdge(currentRoadID);
while (edge.isInternal()) {
if (edge.getAccessibleEdges().size() == 1) {
edge = edge.getAccessibleEdges().get(0);
} else {
break;
}
}
return edge;
}
@Override
public RoadNetworkRoute getCurrentRoute(String pVehicleID) {
obtainRoadNetwork();
SumoCommand routeCommand = Vehicle.getRoute(pVehicleID);
Object object = requestObject(routeCommand);
SumoStringList streetList = (SumoStringList) object;
SumoCommand roadIDCommand = Vehicle.getRoadID(pVehicleID);
String currentRoadID = (String) requestObject(roadIDCommand);
RoadNetworkEdge currentEdge = getCurrentEdge(pVehicleID);
obtainRoadNetwork();
if (currentEdge == null) {
return null;
}
List<RoadNetworkEdge> streets = new ArrayList<>();
boolean add = false;
for (String street : streetList) {
if (street.equals(currentRoadID)) {
if (street.equals(currentEdge.getEdgeID())) {
add = true;
}
if (add) {
......@@ -314,9 +335,7 @@ public class TraciSimulationController implements VehicleController, SimulationS
if (streets.size() == 0) {
for (String street : streetList) {
streets.add(_roadNetwork.getEdge(street));
}
return new RoadNetworkRoute(new ArrayList<>());
}
return new RoadNetworkRoute(streets);
......@@ -418,6 +437,11 @@ public class TraciSimulationController implements VehicleController, SimulationS
public RoadNetworkRoute findNewRoute(String pVehicle) throws NoAdditionalRouteAvailableException {
List<RoadNetworkRoute> routes = new ArrayList<>();
RoadNetworkRoute route = getCurrentRoute(pVehicle);
if (route.getRoute().isEmpty()) {
return null;
}
routes.add(route);
RoadNetworkRoute findRoute = _algorithm.findRoute(_roadNetwork, route.getStart(), route.getDestination(), routes);
if (findRoute == null) {
......@@ -431,6 +455,11 @@ public class TraciSimulationController implements VehicleController, SimulationS
if (pKeepDestination) {
List<RoadNetworkRoute> routes = new ArrayList<>();
RoadNetworkRoute route = getCurrentRoute(pVehicle);
if (route.getRoute().isEmpty()) {
return null;
}
routes.add(route);
RoadNetworkRoute findRoute = _algorithm.findRoute(_roadNetwork, route.getStart(), route.getDestination(), routes, pEdgesToAvoid);
......@@ -440,6 +469,11 @@ public class TraciSimulationController implements VehicleController, SimulationS
return findRoute;
} else {
RoadNetworkRoute route = getCurrentRoute(pVehicle);
if (route.getRoute().isEmpty()) {
return null;
}
List<RoadNetworkEdge> routeList = route.getRoute();
RoadNetworkEdge lastEdge = null;
......
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