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

Added functionality to reroute vehicles to VehicleInformationComponent

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