diff --git a/src/de/tud/kom/p2psim/impl/topology/movement/vehicular/sumo/simulation/controller/roadnetwork/RoadNetwork.java b/src/de/tud/kom/p2psim/impl/topology/movement/vehicular/sumo/simulation/controller/roadnetwork/RoadNetwork.java new file mode 100755 index 0000000000000000000000000000000000000000..6b4a346e9353c3060ee2a8c2d73def3ca0a88211 --- /dev/null +++ b/src/de/tud/kom/p2psim/impl/topology/movement/vehicular/sumo/simulation/controller/roadnetwork/RoadNetwork.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2005-2010 KOM – Multimedia Communications Lab + * + * This file is part of PeerfactSim.KOM. + * + * PeerfactSim.KOM is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * PeerfactSim.KOM is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with PeerfactSim.KOM. If not, see . + * + */ + +package de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.roadnetwork; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +public class RoadNetwork { + private Map _roadNetwork; + + public RoadNetwork(Map pRoadNetwork) { + _roadNetwork = pRoadNetwork; + } + + public List getAvailableEdges() { + return new ArrayList<>(_roadNetwork.values()); + } + + public RoadNetworkEdge getEdge(String pRouteID) { + return _roadNetwork.get(pRouteID); + } +} diff --git a/src/de/tud/kom/p2psim/impl/topology/movement/vehicular/sumo/simulation/controller/roadnetwork/RoadNetworkEdge.java b/src/de/tud/kom/p2psim/impl/topology/movement/vehicular/sumo/simulation/controller/roadnetwork/RoadNetworkEdge.java new file mode 100755 index 0000000000000000000000000000000000000000..e969264c4fddc242ee0e28abaa76f01c7cdfc4f4 --- /dev/null +++ b/src/de/tud/kom/p2psim/impl/topology/movement/vehicular/sumo/simulation/controller/roadnetwork/RoadNetworkEdge.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2005-2010 KOM – Multimedia Communications Lab + * + * This file is part of PeerfactSim.KOM. + * + * PeerfactSim.KOM is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * PeerfactSim.KOM is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with PeerfactSim.KOM. If not, see . + * + */ + +package de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.roadnetwork; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +public class RoadNetworkEdge { + private String _edgeID; + private List _accessibleEdges = new ArrayList<>(); + + public RoadNetworkEdge(String pEdgeID) { + _edgeID = pEdgeID; + } + + public String getEdgeID() { + return _edgeID; + } + + public void addConnectedEdge(RoadNetworkEdge pEdge) { + if (!_accessibleEdges.contains(pEdge)) { + _accessibleEdges.add(pEdge); + } + } + + public List getAccessibleEdges() { + return Collections.unmodifiableList(_accessibleEdges); + } + + @Override + public String toString() { + return _edgeID; + } +} diff --git a/src/de/tud/kom/p2psim/impl/topology/movement/vehicular/sumo/simulation/controller/roadnetwork/RoadNetworkRoute.java b/src/de/tud/kom/p2psim/impl/topology/movement/vehicular/sumo/simulation/controller/roadnetwork/RoadNetworkRoute.java new file mode 100755 index 0000000000000000000000000000000000000000..02e55b09194bd929314f1cbba311287bdf8778c3 --- /dev/null +++ b/src/de/tud/kom/p2psim/impl/topology/movement/vehicular/sumo/simulation/controller/roadnetwork/RoadNetworkRoute.java @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2005-2010 KOM – Multimedia Communications Lab + * + * This file is part of PeerfactSim.KOM. + * + * PeerfactSim.KOM is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * PeerfactSim.KOM is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with PeerfactSim.KOM. If not, see . + * + */ + +package de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.roadnetwork; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +public class RoadNetworkRoute { + private List _route; + + public RoadNetworkRoute(List pRoute) { + _route = pRoute; + } + + public RoadNetworkRoute(List pRoute, RoadNetwork pNetwork) { + _route = new ArrayList<>(); + + for (String pRouteID : pRoute) { + RoadNetworkEdge edge = pNetwork.getEdge(pRouteID); + _route.add(edge); + } + } + + public List getRoute() { + return Collections.unmodifiableList(_route); + } + + @Override + public boolean equals(Object pObj) { + if (pObj instanceof RoadNetworkRoute) { + List route = ((RoadNetworkRoute) pObj).getRoute(); + + if (route.size() == _route.size()) { + for (int i = 0; i < route.size(); i++) { + if (!route.get(i).equals(_route.get(i))) { + return false; + } + } + return true; + } + } + return false; + } + + public boolean containsEdge(String pEdgeID) { + for (RoadNetworkEdge roadNetworkEdge : _route) { + if (roadNetworkEdge.getEdgeID().equals(pEdgeID)) { + return true; + } + } + return false; + } + + public boolean containsEdge(RoadNetworkEdge pEdge) { + return _route.contains(pEdge); + } + + public RoadNetworkEdge getStart() { + return _route.get(0); + } + + public RoadNetworkEdge getDestination() { + return _route.get(_route.size() - 1); + } + + @Override + public String toString() { + StringBuffer buffer = new StringBuffer(); + for (int i = 0; i < _route.size(); i++) { + if (i != 0) { + buffer.append(" --> "); + } + buffer.append(_route.get(i)); + } + return buffer.toString(); + } +} diff --git a/src/de/tud/kom/p2psim/impl/topology/movement/vehicular/sumo/simulation/controller/roadnetwork/exception/NoAdditionalRouteAvailableException.java b/src/de/tud/kom/p2psim/impl/topology/movement/vehicular/sumo/simulation/controller/roadnetwork/exception/NoAdditionalRouteAvailableException.java new file mode 100755 index 0000000000000000000000000000000000000000..d906bd8a292dbf09dbd31388fbc7c0cfb8929696 --- /dev/null +++ b/src/de/tud/kom/p2psim/impl/topology/movement/vehicular/sumo/simulation/controller/roadnetwork/exception/NoAdditionalRouteAvailableException.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2005-2010 KOM – Multimedia Communications Lab + * + * This file is part of PeerfactSim.KOM. + * + * PeerfactSim.KOM is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * PeerfactSim.KOM is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with PeerfactSim.KOM. If not, see . + * + */ + +package de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.roadnetwork.exception; + +import java.util.List; + +import de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.roadnetwork.RoadNetworkEdge; +import de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.roadnetwork.RoadNetworkRoute; + +public class NoAdditionalRouteAvailableException extends Exception { + public NoAdditionalRouteAvailableException(RoadNetworkEdge pStart, RoadNetworkEdge pDestination, List pRoutes) { + super("No " + (pRoutes.size() > 0?"additional ":"") + "route available between " + pStart.getEdgeID() + " and " + pDestination.getEdgeID() + (pRoutes.size()>0?" known routes are:" + printRoutes(pRoutes) + "\n":"")); + } + + private static String printRoutes(List pRoutes) { + StringBuffer stringBuffer = new StringBuffer(); + for (RoadNetworkRoute roadNetworkRoute : pRoutes) { + stringBuffer.append("\n\t").append(roadNetworkRoute); + } + return stringBuffer.toString(); + } +} diff --git a/src/de/tud/kom/p2psim/impl/topology/movement/vehicular/sumo/simulation/controller/roadnetwork/exception/NoExitAvailableException.java b/src/de/tud/kom/p2psim/impl/topology/movement/vehicular/sumo/simulation/controller/roadnetwork/exception/NoExitAvailableException.java new file mode 100755 index 0000000000000000000000000000000000000000..2d1a905ad59944951384497bf4e8b879b524f7f0 --- /dev/null +++ b/src/de/tud/kom/p2psim/impl/topology/movement/vehicular/sumo/simulation/controller/roadnetwork/exception/NoExitAvailableException.java @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2005-2010 KOM – Multimedia Communications Lab + * + * This file is part of PeerfactSim.KOM. + * + * PeerfactSim.KOM is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * PeerfactSim.KOM is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with PeerfactSim.KOM. If not, see . + * + */ + +package de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.roadnetwork.exception; + +import de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.roadnetwork.RoadNetworkEdge; + +public class NoExitAvailableException extends Exception { + public NoExitAvailableException(RoadNetworkEdge pStart, RoadNetworkEdge pDestination) { + super("No departure available between " + pStart.getEdgeID() + " and " + pDestination.getEdgeID()); + } +} diff --git a/src/de/tud/kom/p2psim/impl/topology/movement/vehicular/sumo/simulation/controller/roadnetwork/routing/BreathFirstSearchRoutingAlgorithm.java b/src/de/tud/kom/p2psim/impl/topology/movement/vehicular/sumo/simulation/controller/roadnetwork/routing/BreathFirstSearchRoutingAlgorithm.java new file mode 100755 index 0000000000000000000000000000000000000000..fc61479bbae842a3e739e4e28d57b3fcaa675852 --- /dev/null +++ b/src/de/tud/kom/p2psim/impl/topology/movement/vehicular/sumo/simulation/controller/roadnetwork/routing/BreathFirstSearchRoutingAlgorithm.java @@ -0,0 +1,120 @@ +/* + * Copyright (c) 2005-2010 KOM – Multimedia Communications Lab + * + * This file is part of PeerfactSim.KOM. + * + * PeerfactSim.KOM is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * PeerfactSim.KOM is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with PeerfactSim.KOM. If not, see . + * + */ + +package de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.roadnetwork.routing; + +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; +import java.util.Queue; + +import de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.roadnetwork.RoadNetwork; +import de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.roadnetwork.RoadNetworkEdge; +import de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.roadnetwork.RoadNetworkRoute; + +public class BreathFirstSearchRoutingAlgorithm implements RoutingAlgorithm { + + @Override + public RoadNetworkRoute findRoute(RoadNetwork pNetwork, RoadNetworkEdge pCurrentPosition, RoadNetworkEdge pDestination, + List pKnownRoutes) { + return findRoute(pNetwork, pCurrentPosition, pDestination, pKnownRoutes, new ArrayList<>()); + } + + @Override + public RoadNetworkRoute findRoute(RoadNetwork pNetwork, RoadNetworkEdge pCurrentPosition, RoadNetworkEdge pDestination, + List pKnownRoutes, List pEdgesToAvoid) { + List visitedEdges = new ArrayList<>(); + Queue buffer = new LinkedList<>(); + PathInformation rootPathInformation = new PathInformation(pCurrentPosition, null); + buffer.add(rootPathInformation); + visitedEdges.add(pCurrentPosition); + + outer:while (buffer.size() > 0) { + PathInformation pathInformation = buffer.poll(); + + RoadNetworkEdge edge = pathInformation.getEdge(); + + if (pEdgesToAvoid.contains(edge)) { + continue; + } + + List accessibleEdges = edge.getAccessibleEdges(); + + for (RoadNetworkEdge roadNetworkEdge : accessibleEdges) { + if (roadNetworkEdge.equals(pDestination)) { + List routeList = new ArrayList<>(); + extractRoute(routeList, new PathInformation(roadNetworkEdge, pathInformation)); + + RoadNetworkRoute route = new RoadNetworkRoute(routeList); + + for (RoadNetworkEdge edgeToAvoid : pEdgesToAvoid) { + if (route.containsEdge(edgeToAvoid)) { + continue outer; + } + } + + if (!pKnownRoutes.contains(route)) { + return route; + } + } else if (!visitedEdges.contains(roadNetworkEdge)) { + PathInformation childPathInformation = new PathInformation(roadNetworkEdge, pathInformation); + buffer.add(childPathInformation); + visitedEdges.add(roadNetworkEdge); + } + } + } + return null; + } + + private void extractRoute(List pEdges, PathInformation pPathInformation) { + if (pPathInformation.getPreviousEdge() != null) { + extractRoute(pEdges, pPathInformation.getPreviousEdge()); + } + pEdges.add(pPathInformation.getEdge()); + } + + private class PathInformation { + private final RoadNetworkEdge _edge; + private final PathInformation _previousEdge; + + public PathInformation(RoadNetworkEdge pEdge, + PathInformation pPreviousEdge) { + _edge = pEdge; + _previousEdge = pPreviousEdge; + } + + public RoadNetworkEdge getEdge() { + return _edge; + } + + public PathInformation getPreviousEdge() { + return _previousEdge; + } + + @Override + public boolean equals(Object pObj) { + if (pObj instanceof PathInformation) { + return ((PathInformation) pObj).getEdge().equals(_edge); + } + return false; + } + } + +} diff --git a/src/de/tud/kom/p2psim/impl/topology/movement/vehicular/sumo/simulation/controller/roadnetwork/routing/RoutingAlgorithm.java b/src/de/tud/kom/p2psim/impl/topology/movement/vehicular/sumo/simulation/controller/roadnetwork/routing/RoutingAlgorithm.java new file mode 100755 index 0000000000000000000000000000000000000000..43099cf63965e3116964ddf5322056e00bd35f8e --- /dev/null +++ b/src/de/tud/kom/p2psim/impl/topology/movement/vehicular/sumo/simulation/controller/roadnetwork/routing/RoutingAlgorithm.java @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2005-2010 KOM – Multimedia Communications Lab + * + * This file is part of PeerfactSim.KOM. + * + * PeerfactSim.KOM is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * PeerfactSim.KOM is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with PeerfactSim.KOM. If not, see . + * + */ + +package de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.roadnetwork.routing; + +import java.util.List; + +import de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.roadnetwork.RoadNetwork; +import de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.roadnetwork.RoadNetworkEdge; +import de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.roadnetwork.RoadNetworkRoute; + +public interface RoutingAlgorithm { + RoadNetworkRoute findRoute(RoadNetwork pNetwork, RoadNetworkEdge pCurrentPosition, RoadNetworkEdge pDestination, List pKnownRoutes); + RoadNetworkRoute findRoute(RoadNetwork pNetwork, RoadNetworkEdge pCurrentPosition, RoadNetworkEdge pDestination, List pKnownRoutes, List pEdgesToAvoid); +} diff --git a/src/de/tud/kom/p2psim/impl/topology/movement/vehicular/sumo/simulation/controller/traci/TraciSimulationController.java b/src/de/tud/kom/p2psim/impl/topology/movement/vehicular/sumo/simulation/controller/traci/TraciSimulationController.java index 59e154a51b44fc1b2af0054c14f75d8ff042d5c2..7bc8e6013bb422102f420adeb4e0597d1c47f487 100755 --- a/src/de/tud/kom/p2psim/impl/topology/movement/vehicular/sumo/simulation/controller/traci/TraciSimulationController.java +++ b/src/de/tud/kom/p2psim/impl/topology/movement/vehicular/sumo/simulation/controller/traci/TraciSimulationController.java @@ -8,15 +8,23 @@ import java.util.Map; import de.tud.kom.p2psim.impl.topology.movement.vehicular.information.LocationUtils; import de.tud.kom.p2psim.impl.topology.movement.vehicular.information.Position; -import de.tud.kom.p2psim.impl.topology.movement.vehicular.information.Route; -import de.tud.kom.p2psim.impl.topology.movement.vehicular.information.Street; 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.roadnetwork.RoadNetwork; +import de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.roadnetwork.RoadNetworkEdge; +import de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.roadnetwork.RoadNetworkRoute; +import de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.roadnetwork.exception.NoAdditionalRouteAvailableException; +import de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.roadnetwork.exception.NoExitAvailableException; +import de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.roadnetwork.routing.BreathFirstSearchRoutingAlgorithm; +import de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.roadnetwork.routing.RoutingAlgorithm; import de.tudresden.sumo.cmd.Junction; +import de.tudresden.sumo.cmd.Lane; import de.tudresden.sumo.cmd.Simulation; import de.tudresden.sumo.cmd.Vehicle; import de.tudresden.sumo.util.SumoCommand; import de.tudresden.ws.container.SumoBoundingBox; +import de.tudresden.ws.container.SumoLink; +import de.tudresden.ws.container.SumoLinkList; import de.tudresden.ws.container.SumoPosition2D; import de.tudresden.ws.container.SumoStringList; import it.polito.appeal.traci.SumoTraciConnection; @@ -41,7 +49,7 @@ public class TraciSimulationController implements VehicleController, SimulationS private double _endY; private Map> _positonsByTimestamp = new HashMap<>(); - private int _futureInformation = 10; + private int _futureInformation = 0; private boolean _initalized = false; @@ -49,6 +57,10 @@ public class TraciSimulationController implements VehicleController, SimulationS private Map _vehiclesOutOfRange = new HashMap<>(); + private RoadNetwork _roadNetwork; + + private RoutingAlgorithm _algorithm = new BreathFirstSearchRoutingAlgorithm(); + public static synchronized TraciSimulationController createSimulationController(String pSumoExe, String pConfigFile) { if (!CONTROLLER.containsKey(pConfigFile)) { CONTROLLER.put(pConfigFile, new TraciSimulationController(pSumoExe, pConfigFile)); @@ -276,18 +288,19 @@ public class TraciSimulationController implements VehicleController, SimulationS return new ArrayList<>(map.keySet()); } - public Route getRoute(String pVehicleID) { + public RoadNetworkRoute getRoute(String pVehicleID) { SumoCommand routeCommand = Vehicle.getRoute(pVehicleID); Object object = requestObject(routeCommand); SumoStringList streetList = (SumoStringList) object; - Route route = new Route(); - List streets = route.getStreets(); + obtainRoadNetwork(); + + List streets = new ArrayList<>(); for (String street : streetList) { - streets.add(new Street(street)); + streets.add(_roadNetwork.getEdge(street)); } - return route; + return new RoadNetworkRoute(streets); } public Object requestObject(SumoCommand routeCommand) { @@ -302,6 +315,16 @@ public class TraciSimulationController implements VehicleController, SimulationS return object; } + public void execute(SumoCommand routeCommand) { + try { + _connection.do_job_set(routeCommand); + } catch (RuntimeException e) { + throw e; + } catch (Exception e) { + e.printStackTrace(); + } + } + @Override public double getStep() { return _step; @@ -355,4 +378,126 @@ public class TraciSimulationController implements VehicleController, SimulationS return -1; } + public boolean providesRoadInformation() { + return true; + } + + public RoadNetworkEdge getVehicleDestination(String pVehicleID) { + RoadNetworkRoute roadNetworkRoute = getRoute(pVehicleID); + + return roadNetworkRoute.getDestination(); + } + + public RoadNetwork getRoadNetwork() { + obtainRoadNetwork(); + + return _roadNetwork; + } + + public RoadNetworkRoute findNewRoute(String pVehicle) throws NoAdditionalRouteAvailableException { + List routes = new ArrayList<>(); + RoadNetworkRoute route = getRoute(pVehicle); + routes.add(route); + RoadNetworkRoute findRoute = _algorithm.findRoute(_roadNetwork, route.getStart(), route.getDestination(), routes); + if (findRoute == null) { + throw new NoAdditionalRouteAvailableException(route.getStart(), route.getDestination(), routes); + } + return findRoute; + } + + public RoadNetworkRoute findNewRoute(String pVehicle, List pEdgesToAvoid, boolean pKeepDestination) throws NoAdditionalRouteAvailableException, NoExitAvailableException { + if (pKeepDestination) { + List routes = new ArrayList<>(); + RoadNetworkRoute route = getRoute(pVehicle); + routes.add(route); + + RoadNetworkRoute findRoute = _algorithm.findRoute(_roadNetwork, route.getStart(), route.getDestination(), routes, pEdgesToAvoid); + if (findRoute == null) { + throw new NoAdditionalRouteAvailableException(route.getStart(), route.getDestination(), routes); + } + return findRoute; + } else { + RoadNetworkRoute route = getRoute(pVehicle); + List routeList = route.getRoute(); + + RoadNetworkEdge lastEdge = null; + boolean search = false; + outer:for (int i = routeList.size() - 1; i >= 0; i--) { + if (search) { + List accessibleEdges = routeList.get(i).getAccessibleEdges(); + if (accessibleEdges.size() > 1) { + for (int j = 0; j < accessibleEdges.size(); j++) { + if (!accessibleEdges.get(j).equals(lastEdge)) { + List edges = new ArrayList<>(); + + for (int k = 0; k <= i; k++) { + edges.add(routeList.get(k)); + } + edges.add(accessibleEdges.get(j)); + + for (RoadNetworkEdge roadNetworkEdge : edges) { + if (pEdgesToAvoid.contains(roadNetworkEdge)) { + continue outer; + } + } + + return new RoadNetworkRoute(edges); + } + } + } + } + search = true; + lastEdge = routeList.get(i); + } + throw new NoExitAvailableException(route.getStart(), route.getDestination()); + } + } + + public void rerouteVehicle(String pVehicle, RoadNetworkRoute pRoute) { + SumoStringList routeEdges = new SumoStringList(); + for (RoadNetworkEdge edge : pRoute.getRoute()) { + routeEdges.add(edge.getEdgeID()); + } + execute(Vehicle.setRoute(pVehicle, routeEdges)); + } + + public void obtainRoadNetwork() { + if (_roadNetwork == null) { + SumoCommand laneIDCommand = Lane.getIDList(); + + Map roadNetwork = new HashMap<>(); + + SumoStringList laneIDStringList = (SumoStringList) requestObject(laneIDCommand); + for (String laneID : laneIDStringList) { + SumoCommand edgeIDCommand = Lane.getEdgeID(laneID); + + SumoLinkList linkStringList = (SumoLinkList) requestObject(Lane.getLinks(laneID)); + + if (linkStringList.size() > 0) { + String edgeID = (String) requestObject(edgeIDCommand); + + if (!roadNetwork.containsKey(edgeID)) { + roadNetwork.put(edgeID, new RoadNetworkEdge(edgeID)); + } + + RoadNetworkEdge edge = roadNetwork.get(edgeID); + + for (SumoLink link : linkStringList) { + String notInternalLane = link.notInternalLane; + String connectedEdge = (String) requestObject(Lane.getEdgeID(notInternalLane)); + + if (!roadNetwork.containsKey(connectedEdge)) { + roadNetwork.put(connectedEdge, new RoadNetworkEdge(connectedEdge)); + } + + edge.addConnectedEdge(roadNetwork.get(connectedEdge)); + } + } + + + } + _roadNetwork = new RoadNetwork(roadNetwork); + } + } + }