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

Working version for WoWMoM paper

parent 2b9f8ebc
/*
* 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.relevance;
import java.util.Set;
import de.tudarmstadt.maki.simonstrator.api.Host;
import de.tudarmstadt.maki.simonstrator.api.component.overlay.OverlayContact;
import de.tudarmstadt.maki.simonstrator.api.component.pubsub.Notification;
/**
* @author Tobias Meuser (tobias.meuser@kom.tu-darmstadt.de)
* @version 1.0 at 13.11.2017
*
*/
public class EmptyFilter implements SubscriberFilter {
private Host _host;
public EmptyFilter(Host pHost) {
_host = pHost;
}
@Override
public void startMechanism(Callback pCb) {
pCb.finished(true);
}
@Override
public void stopMechanism(Callback pCb) {
pCb.finished(true);
}
@Override
public void filterSubscribers(Set<OverlayContact> pContacts, Notification pNotification,
SubscriptionFilterResultCallback pCallback, Object... pParametersToStore) {
pCallback.onComplete(pContacts, pParametersToStore);
}
}
/*
* 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.relevance;
import java.util.Set;
import de.tudarmstadt.maki.simonstrator.api.component.overlay.OverlayContact;
import de.tudarmstadt.maki.simonstrator.api.component.pubsub.Notification;
import de.tudarmstadt.maki.simonstrator.api.component.transition.TransitionEnabled;
/**
* @author Tobias Meuser (tobias.meuser@kom.tu-darmstadt.de)
* @version 1.0 at 13.11.2017
*
*/
public interface SubscriberFilter extends TransitionEnabled {
/**
*
* @param pContacts
* @param pNotification
* @param pCloud
* @return
*/
void filterSubscribers(Set<OverlayContact> pContacts, Notification pNotification,
SubscriptionFilterResultCallback pCallback, Object... pParametersToStore);
}
/*
* 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.relevance;
import java.util.Set;
import de.tudarmstadt.maki.simonstrator.api.component.overlay.OverlayContact;
/**
* @author Tobias Meuser (tobias.meuser@kom.tu-darmstadt.de)
* @version 1.0 at 13.11.2017
*
*/
public interface SubscriptionFilterResultCallback {
/**
*
* @param pNotifiedSubscribers
* @param pParametersToStore
*/
void onComplete(Set<OverlayContact> pNotifiedSubscribers, Object... pStoredParameters);
}
...@@ -34,6 +34,11 @@ public class RoadNetworkEdge { ...@@ -34,6 +34,11 @@ public class RoadNetworkEdge {
private double _originalMaxSpeed = 0; private double _originalMaxSpeed = 0;
private double _maxSpeed = 0; private double _maxSpeed = 0;
private boolean _isUsableInit = false;
private boolean _isUsable = false;
private double _length = Double.NaN;
private List<RoadNetworkLane> _lanes = new ArrayList<>(); private List<RoadNetworkLane> _lanes = new ArrayList<>();
private List<RoadNetworkEdge> _accessibleEdges = new ArrayList<>(); private List<RoadNetworkEdge> _accessibleEdges = new ArrayList<>();
...@@ -150,7 +155,10 @@ public class RoadNetworkEdge { ...@@ -150,7 +155,10 @@ public class RoadNetworkEdge {
} }
public double getLength() { public double getLength() {
return _edgeController.getEdgeLength(_edgeID); if (Double.isNaN(_length)) {
_length = _edgeController.getEdgeLength(_edgeID);
}
return _length;
} }
public String getDescription() { public String getDescription() {
...@@ -172,7 +180,11 @@ public class RoadNetworkEdge { ...@@ -172,7 +180,11 @@ public class RoadNetworkEdge {
} }
public boolean isUsable() { public boolean isUsable() {
return _edgeController.isEdgeUsable(getEdgeID()); if (!_isUsableInit) {
_isUsableInit = true;
_isUsable = _edgeController.isEdgeUsable(getEdgeID());
}
return _isUsable;
} }
public List<List<Location>> getRoadShape() { public List<List<Location>> getRoadShape() {
......
...@@ -102,4 +102,39 @@ public class RoadNetworkRoute { ...@@ -102,4 +102,39 @@ public class RoadNetworkRoute {
} }
return false; return false;
} }
/**
* @return
*/
public double getTravelTime() {
double time = 0;
for (RoadNetworkEdge roadNetworkEdge : _route) {
time += roadNetworkEdge.getLength() / roadNetworkEdge.getMaxSpeed();
}
return time;
}
/**
* @param pEdge
* @param pEdge2
* @return
*/
public RoadNetworkRoute subRoute(RoadNetworkEdge pStart, RoadNetworkEdge pEnd) {
List<RoadNetworkEdge> edges = new ArrayList<>();
boolean startFound = false;
boolean endFound = false;
for (RoadNetworkEdge roadNetworkEdge : _route) {
if (roadNetworkEdge.equals(pStart)) {
startFound = true;
}
if (startFound ^ endFound) {
edges.add(roadNetworkEdge);
}
if (roadNetworkEdge.equals(pEnd)) {
endFound = true;
}
}
return new RoadNetworkRoute(edges);
}
} }
...@@ -41,10 +41,10 @@ public interface PathDetectionAlgorithm { ...@@ -41,10 +41,10 @@ public interface PathDetectionAlgorithm {
private final RoadNetworkRoute _route; private final RoadNetworkRoute _route;
private final double _length; private final double _length;
public ProbabilisticRoadNetworkRoute(double pProbability, RoadNetworkRoute pRoute, double pLength) { public ProbabilisticRoadNetworkRoute(double pProbability, RoadNetworkRoute pRoute) {
_probability = pProbability; _probability = pProbability;
_route = pRoute; _route = pRoute;
_length = pLength; _length = pRoute.getTravelTime();
} }
public double getProbability() { public double getProbability() {
...@@ -58,5 +58,10 @@ public interface PathDetectionAlgorithm { ...@@ -58,5 +58,10 @@ public interface PathDetectionAlgorithm {
public double getLength() { public double getLength() {
return _length; return _length;
} }
@Override
public String toString() {
return _route.toString() + " with probability of " + _probability;
}
} }
} }
...@@ -36,7 +36,7 @@ import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.Road ...@@ -36,7 +36,7 @@ import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.Road
* @version 1.0 at 28.11.2017 * @version 1.0 at 28.11.2017
* *
*/ */
public class DijkstraBasedPathDetectionAlgorithm implements PathDetectionAlgorithm { public class SimplePathDetectionAlgorithm implements PathDetectionAlgorithm {
private static final double ABORT_THRESHOLD = 0.001d; private static final double ABORT_THRESHOLD = 0.001d;
@Override @Override
...@@ -58,25 +58,33 @@ public class DijkstraBasedPathDetectionAlgorithm implements PathDetectionAlgorit ...@@ -58,25 +58,33 @@ public class DijkstraBasedPathDetectionAlgorithm implements PathDetectionAlgorit
List<RoadNetworkEdge> accessibleEdges = roadNetworkPath.getEdge().getAccessibleEdges(); List<RoadNetworkEdge> accessibleEdges = roadNetworkPath.getEdge().getAccessibleEdges();
for (RoadNetworkEdge accessibleEdge : accessibleEdges) { for (RoadNetworkEdge accessibleEdge : accessibleEdges) {
double travelTime = accessibleEdge.getLength() / accessibleEdge.getMaxSpeed(); if (accessibleEdge.isUsable()) {
double probability = VehiclePathTrackerFactory.getVehiclePathTracker() double travelTime = accessibleEdge.getLength() / accessibleEdge.getMaxSpeed();
.getTransitionProbability(roadNetworkPath.getEdge(), accessibleEdge); double probability = VehiclePathTrackerFactory.getVehiclePathTracker()
.getTransitionProbability(roadNetworkPath.getEdge(), accessibleEdge);
RoadNetworkPath newPath = roadNetworkPath.createPath(accessibleEdge, probability, travelTime); RoadNetworkPath newPath = roadNetworkPath.createPath(accessibleEdge, probability, travelTime);
if (newPath.getEdge() == pDestination) { if (newPath.getEdge() == pDestination) {
double totalTravelTime = newPath.getTravelTime(); double totalTravelTime = newPath.getTravelTime();
double totalProbability = newPath.getProbability(); double totalProbability = newPath.getProbability();
RoadNetworkRoute route = newPath.getRoute();
double temporalRelevance = 1; // TODO: To be done! double temporalRelevance = 1; // TODO: To be done!
routes.add( routes.add(new ProbabilisticRoadNetworkRoute(totalProbability, route));
new ProbabilisticRoadNetworkRoute(totalProbability, newPath.getRoute(), totalTravelTime)); } else {
} else { currentPaths.add(newPath);
currentPaths.add(newPath); }
} }
} }
} }
double sum = 0;
for (ProbabilisticRoadNetworkRoute probabilisticRoadNetworkRoute : routes) {
sum += probabilisticRoadNetworkRoute.getProbability();
}
return routes; return routes;
} }
...@@ -125,6 +133,7 @@ public class DijkstraBasedPathDetectionAlgorithm implements PathDetectionAlgorit ...@@ -125,6 +133,7 @@ public class DijkstraBasedPathDetectionAlgorithm implements PathDetectionAlgorit
public RoadNetworkRoute getRoute() { public RoadNetworkRoute getRoute() {
List<RoadNetworkEdge> edges = new ArrayList<>(); List<RoadNetworkEdge> edges = new ArrayList<>();
getRoute(edges);
return new RoadNetworkRoute(edges); return new RoadNetworkRoute(edges);
} }
......
...@@ -49,6 +49,12 @@ public class BreadthFirstSearch implements RoutingAlgorithm { ...@@ -49,6 +49,12 @@ public class BreadthFirstSearch implements RoutingAlgorithm {
@Override @Override
public RoadNetworkRoute findRoute(RoadNetwork pNetwork, RoadNetworkEdge pCurrentPosition, RoadNetworkEdge pDestination, public RoadNetworkRoute findRoute(RoadNetwork pNetwork, RoadNetworkEdge pCurrentPosition, RoadNetworkEdge pDestination,
List<RoadNetworkRoute> pKnownRoutes, List<RoadNetworkEdge> pEdgesToAvoid) { List<RoadNetworkRoute> pKnownRoutes, List<RoadNetworkEdge> pEdgesToAvoid) {
if (pCurrentPosition.equals(pDestination)) {
List<RoadNetworkEdge> segments = new ArrayList<>();
segments.add(pCurrentPosition);
return new RoadNetworkRoute(segments);
}
List<RoadNetworkEdge> visitedEdges = new ArrayList<>(); List<RoadNetworkEdge> visitedEdges = new ArrayList<>();
Queue<PathInformation> buffer = new PriorityQueue<>(new PathInformationComparator()); Queue<PathInformation> buffer = new PriorityQueue<>(new PathInformationComparator());
PathInformation rootPathInformation = new PathInformation(pCurrentPosition, null, 0, 0); PathInformation rootPathInformation = new PathInformation(pCurrentPosition, null, 0, 0);
...@@ -58,7 +64,7 @@ public class BreadthFirstSearch implements RoutingAlgorithm { ...@@ -58,7 +64,7 @@ public class BreadthFirstSearch implements RoutingAlgorithm {
double currentPathLength = Double.MAX_VALUE; double currentPathLength = Double.MAX_VALUE;
RoadNetworkRoute currentShortestRoute = null; RoadNetworkRoute currentShortestRoute = null;
double maxDepth = 10; double maxDepth = 12;
for (RoadNetworkRoute roadNetworkRoute : pKnownRoutes) { for (RoadNetworkRoute roadNetworkRoute : pKnownRoutes) {
if (roadNetworkRoute.getRoute().size() * MAX_DEPTH_RATIO > maxDepth) { if (roadNetworkRoute.getRoute().size() * MAX_DEPTH_RATIO > maxDepth) {
maxDepth = roadNetworkRoute.getRoute().size() * MAX_DEPTH_RATIO; maxDepth = roadNetworkRoute.getRoute().size() * MAX_DEPTH_RATIO;
...@@ -128,7 +134,11 @@ public class BreadthFirstSearch implements RoutingAlgorithm { ...@@ -128,7 +134,11 @@ public class BreadthFirstSearch implements RoutingAlgorithm {
@Override @Override
public int compare(PathInformation pO1, PathInformation pO2) { public int compare(PathInformation pO1, PathInformation pO2) {
return Double.compare(pO1.getLength(), pO2.getLength()); int compare = Double.compare(pO1.getLength(), pO2.getLength());
if (compare == 0) {
compare = Double.compare(pO1.getHops(), pO2.getHops());
}
return compare;
} }
} }
......
...@@ -49,6 +49,12 @@ public class DijkstraAlgorithm implements RoutingAlgorithm { ...@@ -49,6 +49,12 @@ public class DijkstraAlgorithm implements RoutingAlgorithm {
@Override @Override
public RoadNetworkRoute findRoute(RoadNetwork pNetwork, RoadNetworkEdge pCurrentPosition, RoadNetworkEdge pDestination, public RoadNetworkRoute findRoute(RoadNetwork pNetwork, RoadNetworkEdge pCurrentPosition, RoadNetworkEdge pDestination,
List<RoadNetworkRoute> pKnownRoutes, List<RoadNetworkEdge> pEdgesToAvoid) { List<RoadNetworkRoute> pKnownRoutes, List<RoadNetworkEdge> pEdgesToAvoid) {
if (pCurrentPosition.equals(pDestination)) {
List<RoadNetworkEdge> segments = new ArrayList<>();
segments.add(pCurrentPosition);
return new RoadNetworkRoute(segments);
}
List<RoadNetworkEdge> visitedEdges = new ArrayList<>(); List<RoadNetworkEdge> visitedEdges = new ArrayList<>();
Queue<PathInformation> buffer = new PriorityQueue<>(new PathInformationComparator()); Queue<PathInformation> buffer = new PriorityQueue<>(new PathInformationComparator());
PathInformation rootPathInformation = new PathInformation(pCurrentPosition, null, 0, 0); PathInformation rootPathInformation = new PathInformation(pCurrentPosition, null, 0, 0);
...@@ -58,7 +64,7 @@ public class DijkstraAlgorithm implements RoutingAlgorithm { ...@@ -58,7 +64,7 @@ public class DijkstraAlgorithm implements RoutingAlgorithm {
double currentPathLength = Double.MAX_VALUE; double currentPathLength = Double.MAX_VALUE;
RoadNetworkRoute currentShortestRoute = null; RoadNetworkRoute currentShortestRoute = null;
double maxDepth = 10; double maxDepth = 12;
for (RoadNetworkRoute roadNetworkRoute : pKnownRoutes) { for (RoadNetworkRoute roadNetworkRoute : pKnownRoutes) {
if (roadNetworkRoute.getRoute().size() * MAX_DEPTH_RATIO > maxDepth) { if (roadNetworkRoute.getRoute().size() * MAX_DEPTH_RATIO > maxDepth) {
maxDepth = roadNetworkRoute.getRoute().size() * MAX_DEPTH_RATIO; maxDepth = roadNetworkRoute.getRoute().size() * MAX_DEPTH_RATIO;
......
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