Commit 30347bd1 authored by Björn Richerzhagen's avatar Björn Richerzhagen
Browse files

Merge branch 'tm/sumo-integration' into 'master'

Integrate RouteSensor/SpeedSensor

See merge request !5
parents 3628bb28 153af762
/*
* Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
*
* This file is part of Simonstrator.KOM.
*
* Simonstrator.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.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork;
public class RoadNetworkLane {
private String _laneID;
public RoadNetworkLane(String pLaneID) {
_laneID = pLaneID;
}
public RoadNetworkLane(SerializableRoadNetworkLane pLane) {
_laneID = pLane.getLaneID();
}
public String getLaneID() {
return _laneID;
}
public void setLaneID(String pLaneID) {
_laneID = pLaneID;
}
@Override
public boolean equals(Object pArg0) {
if (pArg0 instanceof RoadNetworkLane) {
return ((RoadNetworkLane) pArg0).getLaneID().equals(_laneID);
}
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.tudarmstadt.maki.simonstrator.api.component.vehicular.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();
}
public boolean containsEdges(List<RoadNetworkEdge> pBlocked) {
for (RoadNetworkEdge roadNetworkEdge : pBlocked) {
if (containsEdge(roadNetworkEdge)) {
return true;
}
}
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.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement
public class SerializableRoadNetwork implements Serializable {
/**
*
*/
private static final long serialVersionUID = -8523360385937842443L;
@XmlElement(name = "roadNetwork")
private Map<String, SerializableRoadNetworkEdge> _roadNetwork;
private SerializableRoadNetwork() {
}
public SerializableRoadNetwork(RoadNetwork pRoadNetwork) {
_roadNetwork = new HashMap<>();
for (RoadNetworkEdge edge : pRoadNetwork.getAvailableEdges()) {
_roadNetwork.put(edge.getEdgeID(), new SerializableRoadNetworkEdge(edge));
}
}
public List<SerializableRoadNetworkEdge> getAvailableEdges() {
return new ArrayList<>(_roadNetwork.values());
}
}
/*
* 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.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import javax.xml.bind.annotation.XmlElement;
public class SerializableRoadNetworkEdge implements Serializable {
/**
*
*/
private static final long serialVersionUID = -311466941428215723L;
@XmlElement(name = "edgeID")
private String _edgeID;
@XmlElement(name = "angle")
private double _angle;
@XmlElement(name = "lanes")
private List<SerializableRoadNetworkLane> _lanes = new ArrayList<>();
@XmlElement(name = "maxSpeed")
private double _maxSpeed = 0;
private List<String> _accessibleEdgeIDs = new ArrayList<>();
private SerializableRoadNetworkEdge() {
}
public SerializableRoadNetworkEdge(RoadNetworkEdge pEdge) {
_edgeID = pEdge.getEdgeID();
_angle = pEdge.getAngle();
for (RoadNetworkLane lane : pEdge.getLanes()) {
_lanes.add(new SerializableRoadNetworkLane(lane));
}
_maxSpeed = pEdge.getOriginalMaxSpeed();
for (RoadNetworkEdge edge : pEdge.getAccessibleEdges()) {
_accessibleEdgeIDs.add(edge.getEdgeID());
}
}
public String getEdgeID() {
return _edgeID;
}
public double getAngle() {
return _angle;
}
public double getMaxSpeed() {
return _maxSpeed;
}
public int getLaneAmount() {
return _lanes.size();
}
public void setMaxSpeed(double pMaxSpeed) {
if (pMaxSpeed > _maxSpeed) {
_maxSpeed = pMaxSpeed;
}
}
public List<String> getAccessibleEdges() {
return Collections.unmodifiableList(_accessibleEdgeIDs);
}
public String getDescription() {
return "id: " + _edgeID + ", lanes: " + _lanes.size() + ", speed limit: " + _maxSpeed;
}
@Override
public String toString() {
return _edgeID;
}
public boolean isInternal() {
return _edgeID.startsWith(":");
}
public List<SerializableRoadNetworkLane> getLanes() {
return _lanes;
}
}
/*
* Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
*
* This file is part of Simonstrator.KOM.
*
* Simonstrator.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.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork;
import java.io.Serializable;
import javax.xml.bind.annotation.XmlElement;
public class SerializableRoadNetworkLane implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1504425570955552005L;
@XmlElement(name = "laneID")
private String _laneID;
private SerializableRoadNetworkLane() {
}
public SerializableRoadNetworkLane(RoadNetworkLane pLane) {
_laneID = pLane.getLaneID();
}
public SerializableRoadNetworkLane(String pLaneID) {
_laneID = pLaneID;
}
public String getLaneID() {
return _laneID;
}
public void setLaneID(String pLaneID) {
_laneID = pLaneID;
}
}
/*
* 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.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.exception;
import java.util.List;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetworkEdge;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.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.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.exception;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.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.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.routing;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
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;
public class BreadthFirstSearchRoutingAlgorithm 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.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.routing;
import java.util.List;
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;
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);
}
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