Commit 69aa8c41 authored by Tobias Meuser's avatar Tobias Meuser
Browse files

Moved RoadNetwork and dependencies to api

parent 93e07276
......@@ -13,4 +13,6 @@ public interface SimulationSetupExtractor {
double getScenarioWidth();
double getScenarioHeight();
// RoadNetwork getScenarioRoadNetwork();
}
/*
* 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 <http://www.gnu.org/licenses/>.
*
*/
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<String, RoadNetworkEdge> _roadNetwork;
public RoadNetwork(Map<String, RoadNetworkEdge> pRoadNetwork) {
_roadNetwork = pRoadNetwork;
}
public List<RoadNetworkEdge> getAvailableEdges() {
return new ArrayList<>(_roadNetwork.values());
}
public RoadNetworkEdge getEdge(String pRouteID) {
return _roadNetwork.get(pRouteID);
}
}
/*
* 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 <http://www.gnu.org/licenses/>.
*
*/
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<RoadNetworkEdge> _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<RoadNetworkEdge> getAccessibleEdges() {
return Collections.unmodifiableList(_accessibleEdges);
}
@Override
public String toString() {
return _edgeID;
}
}
/*
* 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 <http://www.gnu.org/licenses/>.
*
*/
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<RoadNetworkEdge> _route;
public RoadNetworkRoute(List<RoadNetworkEdge> pRoute) {
_route = pRoute;
}
public RoadNetworkRoute(List<String> pRoute, RoadNetwork pNetwork) {
_route = new ArrayList<>();
for (String pRouteID : pRoute) {
RoadNetworkEdge edge = pNetwork.getEdge(pRouteID);
_route.add(edge);
}
}
public List<RoadNetworkEdge> getRoute() {
return Collections.unmodifiableList(_route);
}
@Override
public boolean equals(Object pObj) {
if (pObj instanceof RoadNetworkRoute) {
List<RoadNetworkEdge> 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();
}
}
/*
* 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 <http://www.gnu.org/licenses/>.
*
*/
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<RoadNetworkRoute> 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<RoadNetworkRoute> pRoutes) {
StringBuffer stringBuffer = new StringBuffer();
for (RoadNetworkRoute roadNetworkRoute : pRoutes) {
stringBuffer.append("\n\t").append(roadNetworkRoute);
}
return stringBuffer.toString();
}
}
/*
* 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 <http://www.gnu.org/licenses/>.
*
*/
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());
}
}
/*
* 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 <http://www.gnu.org/licenses/>.
*
*/
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<RoadNetworkRoute> pKnownRoutes) {
return findRoute(pNetwork, pCurrentPosition, pDestination, pKnownRoutes, new ArrayList<>());
}
@Override
public RoadNetworkRoute findRoute(RoadNetwork pNetwork, RoadNetworkEdge pCurrentPosition, RoadNetworkEdge pDestination,
List<RoadNetworkRoute> pKnownRoutes, List<RoadNetworkEdge> pEdgesToAvoid) {
List<RoadNetworkEdge> visitedEdges = new ArrayList<>();
Queue<PathInformation> 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<RoadNetworkEdge> accessibleEdges = edge.getAccessibleEdges();
for (RoadNetworkEdge roadNetworkEdge : accessibleEdges) {
if (roadNetworkEdge.equals(pDestination)) {
List<RoadNetworkEdge> 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<RoadNetworkEdge> 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;
}
}
}
/*
* 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 <http://www.gnu.org/licenses/>.
*
*/
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<RoadNetworkRoute> pKnownRoutes);
RoadNetworkRoute findRoute(RoadNetwork pNetwork, RoadNetworkEdge pCurrentPosition, RoadNetworkEdge pDestination, List<RoadNetworkRoute> pKnownRoutes, List<RoadNetworkEdge> pEdgesToAvoid);
}
......@@ -10,13 +10,13 @@ import de.tud.kom.p2psim.impl.topology.movement.vehicular.information.LocationUt
import de.tud.kom.p2psim.impl.topology.movement.vehicular.information.Position;
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.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetwork;
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;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.routing.BreathFirstSearchRoutingAlgorithm;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.routing.RoutingAlgorithm;
import de.tudresden.sumo.cmd.Junction;
import de.tudresden.sumo.cmd.Lane;
import de.tudresden.sumo.cmd.Simulation;
......
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