Commit df3aa567 authored by Tobias Meuser's avatar Tobias Meuser
Browse files

Updated Breadth-First-Search

parent f6bcb0d0
......@@ -30,6 +30,7 @@ import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.Road
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetworkRoute;
public class BreadthFirstSearchRoutingAlgorithm implements RoutingAlgorithm {
private final int MAX_DEPTH = 10;
@Override
public RoadNetworkRoute findRoute(RoadNetwork pNetwork, RoadNetworkEdge pCurrentPosition, RoadNetworkEdge pDestination,
......@@ -42,13 +43,17 @@ public class BreadthFirstSearchRoutingAlgorithm implements RoutingAlgorithm {
List<RoadNetworkRoute> pKnownRoutes, List<RoadNetworkEdge> pEdgesToAvoid) {
List<RoadNetworkEdge> visitedEdges = new ArrayList<>();
Queue<PathInformation> buffer = new LinkedList<>();
PathInformation rootPathInformation = new PathInformation(pCurrentPosition, null);
PathInformation rootPathInformation = new PathInformation(pCurrentPosition, null, 0);
buffer.add(rootPathInformation);
visitedEdges.add(pCurrentPosition);
outer:while (buffer.size() > 0) {
PathInformation pathInformation = buffer.poll();
if (pathInformation.getLength() >= MAX_DEPTH) {
continue;
}
RoadNetworkEdge edge = pathInformation.getEdge();
if (pEdgesToAvoid.contains(edge)) {
......@@ -60,7 +65,8 @@ public class BreadthFirstSearchRoutingAlgorithm implements RoutingAlgorithm {
for (RoadNetworkEdge roadNetworkEdge : accessibleEdges) {
if (roadNetworkEdge.equals(pDestination)) {
List<RoadNetworkEdge> routeList = new ArrayList<>();
extractRoute(routeList, new PathInformation(roadNetworkEdge, pathInformation));
extractRoute(routeList,
new PathInformation(roadNetworkEdge, pathInformation, pathInformation.getLength() + 1));
RoadNetworkRoute route = new RoadNetworkRoute(routeList);
......@@ -74,7 +80,8 @@ public class BreadthFirstSearchRoutingAlgorithm implements RoutingAlgorithm {
return route;
}
} else if (!visitedEdges.contains(roadNetworkEdge)) {
PathInformation childPathInformation = new PathInformation(roadNetworkEdge, pathInformation);
PathInformation childPathInformation = new PathInformation(roadNetworkEdge, pathInformation,
pathInformation.getLength() + 1);
buffer.add(childPathInformation);
visitedEdges.add(roadNetworkEdge);
}
......@@ -91,13 +98,19 @@ public class BreadthFirstSearchRoutingAlgorithm implements RoutingAlgorithm {
}
private class PathInformation {
private final int _length;
private final RoadNetworkEdge _edge;
private final PathInformation _previousEdge;
public PathInformation(RoadNetworkEdge pEdge,
PathInformation pPreviousEdge) {
PathInformation pPreviousEdge, int pLenght) {
_edge = pEdge;
_previousEdge = pPreviousEdge;
_length = pLenght;
}
public int getLength() {
return _length;
}
public RoadNetworkEdge getEdge() {
......
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