Commit 11d4860c authored by Tobias Meuser's avatar Tobias Meuser
Browse files

Added functionality to reroute vehicles to VehicleInformationComponent

parent b44bd143
......@@ -3,7 +3,10 @@ package de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.contr
import java.util.List;
import de.tud.kom.p2psim.impl.topology.movement.vehicular.information.Position;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetworkEdge;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetworkRoute;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.exception.NoAdditionalRouteAvailableException;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.exception.NoExitAvailableException;
public interface VehicleController {
void setObservedArea(double pStartX, double pStartY, double pEndX, double pEndY);
......@@ -20,10 +23,16 @@ public interface VehicleController {
double getMaximumAvailablePrediction();
void rerouteVehicle(String pVehicle, RoadNetworkRoute pRoute);
RoadNetworkRoute findNewRoute(String pVehicle)
throws NoAdditionalRouteAvailableException;
RoadNetworkRoute findNewRoute(String pVehicle,
List<RoadNetworkEdge> pEdgesToAvoid, boolean pKeepDestination)
throws NoAdditionalRouteAvailableException,
NoExitAvailableException;
double getStep();
double getStart();
void init();
}
......@@ -414,6 +414,7 @@ public class TraciSimulationController implements VehicleController, SimulationS
return _roadNetwork;
}
@Override
public RoadNetworkRoute findNewRoute(String pVehicle) throws NoAdditionalRouteAvailableException {
List<RoadNetworkRoute> routes = new ArrayList<>();
RoadNetworkRoute route = getCurrentRoute(pVehicle);
......@@ -425,6 +426,7 @@ public class TraciSimulationController implements VehicleController, SimulationS
return findRoute;
}
@Override
public RoadNetworkRoute findNewRoute(String pVehicle, List<RoadNetworkEdge> pEdgesToAvoid, boolean pKeepDestination) throws NoAdditionalRouteAvailableException, NoExitAvailableException {
if (pKeepDestination) {
List<RoadNetworkRoute> routes = new ArrayList<>();
......@@ -473,6 +475,7 @@ public class TraciSimulationController implements VehicleController, SimulationS
}
}
@Override
public void rerouteVehicle(String pVehicle, RoadNetworkRoute pRoute) {
SumoStringList routeEdges = new SumoStringList();
for (RoadNetworkEdge edge : pRoute.getRoute()) {
......
......@@ -20,11 +20,16 @@
package de.tud.kom.p2psim.impl.vehicular;
import java.util.List;
import de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.SimulationSetupExtractor;
import de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.VehicleController;
import de.tudarmstadt.maki.simonstrator.api.Host;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.VehicleInformationComponent;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetworkEdge;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetworkRoute;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.exception.NoAdditionalRouteAvailableException;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.exception.NoExitAvailableException;
public class DefaultVehicleInformationComponent implements VehicleInformationComponent {
......@@ -74,4 +79,30 @@ public class DefaultVehicleInformationComponent implements VehicleInformationCom
return controller.getCurrentRoute(vehicleID);
}
@Override
public boolean changeCurrentRoute(RoadNetworkRoute pRoute) {
controller.rerouteVehicle(vehicleID, pRoute);
return true;
}
@Override
public RoadNetworkRoute findNewRoute() {
try {
return controller.findNewRoute(vehicleID);
} catch (NoAdditionalRouteAvailableException e) {
return null;
}
}
@Override
public RoadNetworkRoute findNewRoute(List<RoadNetworkEdge> pEdgesToAvoid,
boolean pKeepDestination) {
try {
return controller.findNewRoute(vehicleID, pEdgesToAvoid, pKeepDestination);
} catch (NoAdditionalRouteAvailableException
| NoExitAvailableException e) {
return 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