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

Update in vehicle decision-making

parent dc10deed
...@@ -20,8 +20,7 @@ ...@@ -20,8 +20,7 @@
package de.tud.kom.p2psim.impl.vehicular.decision; package de.tud.kom.p2psim.impl.vehicular.decision;
import java.util.List; import de.tud.kom.p2psim.impl.topology.movement.VehicleMovementModel;
import de.tudarmstadt.maki.simonstrator.api.Event; import de.tudarmstadt.maki.simonstrator.api.Event;
import de.tudarmstadt.maki.simonstrator.api.EventHandler; import de.tudarmstadt.maki.simonstrator.api.EventHandler;
import de.tudarmstadt.maki.simonstrator.api.Host; import de.tudarmstadt.maki.simonstrator.api.Host;
...@@ -30,11 +29,12 @@ import de.tudarmstadt.maki.simonstrator.api.Time; ...@@ -30,11 +29,12 @@ import de.tudarmstadt.maki.simonstrator.api.Time;
import de.tudarmstadt.maki.simonstrator.api.component.ComponentNotAvailableException; import de.tudarmstadt.maki.simonstrator.api.component.ComponentNotAvailableException;
import de.tudarmstadt.maki.simonstrator.api.component.core.MonitorComponent.AnalyzerNotAvailableException; import de.tudarmstadt.maki.simonstrator.api.component.core.MonitorComponent.AnalyzerNotAvailableException;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.EnvironmentSensor; import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.EnvironmentSensor;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.Environment;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.VehicleDecisionComponent; import de.tudarmstadt.maki.simonstrator.api.component.vehicular.VehicleDecisionComponent;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.VehicleInformationComponent; import de.tudarmstadt.maki.simonstrator.api.component.vehicular.VehicleInformationComponent;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.CachingComponent; import de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.CachingComponent;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.RoadInformation; import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.RoadInformation;
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.RoadNetworkRoute;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.VehicleRouteAnalyzer; import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.VehicleRouteAnalyzer;
...@@ -42,6 +42,8 @@ public abstract class AbstractVehicleDecisionComponent implements VehicleDecisio ...@@ -42,6 +42,8 @@ public abstract class AbstractVehicleDecisionComponent implements VehicleDecisio
private static final int EVENT_DECISION_MAKING_CYCLE = 0; private static final int EVENT_DECISION_MAKING_CYCLE = 0;
private static final long EVENT_DECISION_MAKING_FREQUENCY = Time.SECOND * VehicleMovementModel.TIMESTEP_RATIO;
private VehicleInformationComponent _vehicleInformation; private VehicleInformationComponent _vehicleInformation;
private Host _host; private Host _host;
private CachingComponent _cache; private CachingComponent _cache;
...@@ -88,7 +90,7 @@ public abstract class AbstractVehicleDecisionComponent implements VehicleDecisio ...@@ -88,7 +90,7 @@ public abstract class AbstractVehicleDecisionComponent implements VehicleDecisio
@Override @Override
public void startDecisionMaking() { public void startDecisionMaking() {
Event.scheduleImmediately(this, null, EVENT_DECISION_MAKING_CYCLE); Event.scheduleWithDelay(EVENT_DECISION_MAKING_FREQUENCY / 3 * 2, this, null, EVENT_DECISION_MAKING_CYCLE);
} }
@Override @Override
...@@ -98,20 +100,18 @@ public abstract class AbstractVehicleDecisionComponent implements VehicleDecisio ...@@ -98,20 +100,18 @@ public abstract class AbstractVehicleDecisionComponent implements VehicleDecisio
RoadNetworkRoute currentRoute = getVehicleInformation().getCurrentRoute(); RoadNetworkRoute currentRoute = getVehicleInformation().getCurrentRoute();
if (currentRoute != null) { if (currentRoute != null) {
boolean changed = false; boolean changed = false;
if (currentRoute.getRoute().size() > 2) { if (currentRoute.getRoute().size() > 2) {
BenefitBasedRoute optimalRouteWithBenefit = getOptimalRoute(currentRoute, BenefitBasedRoute optimalRouteWithBenefit = getOptimalRoute(currentRoute,
_cache.getDecidedCacheEntries(RoadInformation.class), _sensors.getEnvironment()); _cache.getDecidedCacheEntries(RoadInformation.class), _sensors.getEnvironment());
if (optimalRouteWithBenefit != null) { if (optimalRouteWithBenefit != null && optimalRouteWithBenefit.getBenefit() > 0) {
RoadNetworkRoute optimalRoute = optimalRouteWithBenefit.getRoute(); RoadNetworkRoute optimalRoute = optimalRouteWithBenefit.getRoute();
if (optimalRouteWithBenefit.getRoute().getRoute().size() > 1) { if (optimalRouteWithBenefit.getRoute().getRoute().size() > 1) {
if (currentRoute.getRoute().get(1) != optimalRoute.getRoute().get(1)) { if (hasRouteAnalyzer()) {
if (hasRouteAnalyzer()) { getRouteAnalyzer().routeChanged(getHost().getId(), currentRoute, optimalRoute);
getRouteAnalyzer().routeChanged(getHost().getId(), currentRoute, optimalRoute); }
} changed = true;
changed = true; getVehicleInformation().changeCurrentRoute(optimalRouteWithBenefit.getRoute());
getVehicleInformation().changeCurrentRoute(optimalRouteWithBenefit.getRoute());
}
} }
} }
} }
...@@ -120,7 +120,7 @@ public abstract class AbstractVehicleDecisionComponent implements VehicleDecisio ...@@ -120,7 +120,7 @@ public abstract class AbstractVehicleDecisionComponent implements VehicleDecisio
} }
} }
Event.scheduleWithDelay(Time.SECOND, this, null, EVENT_DECISION_MAKING_CYCLE); Event.scheduleWithDelay(EVENT_DECISION_MAKING_FREQUENCY, this, null, EVENT_DECISION_MAKING_CYCLE);
break; break;
default: default:
break; break;
......
...@@ -27,7 +27,9 @@ import java.util.Map; ...@@ -27,7 +27,9 @@ import java.util.Map;
import de.tudarmstadt.maki.simonstrator.api.Host; import de.tudarmstadt.maki.simonstrator.api.Host;
import de.tudarmstadt.maki.simonstrator.api.Time; import de.tudarmstadt.maki.simonstrator.api.Time;
import de.tudarmstadt.maki.simonstrator.api.component.ComponentNotAvailableException;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.properties.RoadProperty; import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.properties.RoadProperty;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.VehicleInformationComponent;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.AvailableInformationAttributes; import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.AvailableInformationAttributes;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.RoadInformation; import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.RoadInformation;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetwork; import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetwork;
...@@ -35,6 +37,7 @@ import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.Road ...@@ -35,6 +37,7 @@ import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.Road
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetworkRoute; import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetworkRoute;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.paths.VehiclePathTracker; import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.paths.VehiclePathTracker;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.paths.VehiclePathTrackerFactory; import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.paths.VehiclePathTrackerFactory;
import javassist.bytecode.LineNumberAttribute.Pc;
public class DynamicInformationVehicleDecisionComponent extends AbstractVehicleDecisionComponent { public class DynamicInformationVehicleDecisionComponent extends AbstractVehicleDecisionComponent {
private static Map<RoadNetworkEdge, CostGraph> _unknownCostGraphs = new HashMap<>(); private static Map<RoadNetworkEdge, CostGraph> _unknownCostGraphs = new HashMap<>();
...@@ -46,8 +49,8 @@ public class DynamicInformationVehicleDecisionComponent extends AbstractVehicleD ...@@ -46,8 +49,8 @@ public class DynamicInformationVehicleDecisionComponent extends AbstractVehicleD
@Override @Override
public BenefitBasedRoute getOptimalRoute(RoadNetworkRoute pInvestigatedRoute, List<RoadInformation> knownInformation) { public BenefitBasedRoute getOptimalRoute(RoadNetworkRoute pInvestigatedRoute, List<RoadInformation> knownInformation) {
if (getVehicleInformation().isValid() && knownInformation != null && pInvestigatedRoute.getRoute().size() > 1 && pInvestigatedRoute.getStart().getAccessibleEdges().size() > 1) { if (getVehicleInformation().isValid() && pInvestigatedRoute.getRoute().size() > 1) {
if (knownInformation.size() > 1) { if (knownInformation != null && knownInformation.size() > 1) {
for (RoadInformation roadInformation : knownInformation) { for (RoadInformation roadInformation : knownInformation) {
System.out.println("Known information for road " + roadInformation.getEdge()); System.out.println("Known information for road " + roadInformation.getEdge());
} }
...@@ -62,25 +65,50 @@ public class DynamicInformationVehicleDecisionComponent extends AbstractVehicleD ...@@ -62,25 +65,50 @@ public class DynamicInformationVehicleDecisionComponent extends AbstractVehicleD
_unknownCostGraphs.put(pInvestigatedRoute.getDestination(), costGraph); _unknownCostGraphs.put(pInvestigatedRoute.getDestination(), costGraph);
} }
if (knownInformation.size() > 0) { CostGraph unknown = _unknownCostGraphs.get(pInvestigatedRoute.getDestination());
if (knownInformation != null && knownInformation.size() > 0) {
if (!_knownCostGraphs.containsKey(knownInformation.get(0).getValue())) { if (!_knownCostGraphs.containsKey(knownInformation.get(0).getValue())) {
_knownCostGraphs.put(knownInformation.get(0).getValue(), new HashMap<>()); _knownCostGraphs.put(knownInformation.get(0).getValue(), new HashMap<>());
} }
Map<RoadNetworkEdge, CostGraph> costGraphs = _knownCostGraphs.get(knownInformation.get(0).getValue()); Map<RoadNetworkEdge, CostGraph> costGraphs = _knownCostGraphs.get(knownInformation.get(0).getValue());
if (!costGraphs.containsKey(pInvestigatedRoute.getDestination())) { if (!costGraphs.containsKey(pInvestigatedRoute.getDestination())) {
CostGraph costGraph = new CostGraph(pInvestigatedRoute.getDestination(), knownInformation.get(0), _unknownCostGraphs.get(pInvestigatedRoute.getDestination())); CostGraph costGraph = new CostGraph(pInvestigatedRoute.getDestination(), knownInformation.get(0), unknown);
// costGraph.setCostLimit(getRouteCosts(pInvestigatedRoute, knownInformation));
costGraph.createCostGraph(); costGraph.createCostGraph();
costGraphs.put(pInvestigatedRoute.getDestination(), costGraph); costGraphs.put(pInvestigatedRoute.getDestination(), costGraph);
} }
} }
if (knownInformation.size() > 0) { if (knownInformation != null && knownInformation.size() > 0 && !knownInformation.get(0).getValue().equals(knownInformation.get(0).getValue().getDefaultProperty())) {
Map<RoadNetworkEdge, CostGraph> costGraphs = _knownCostGraphs.get(knownInformation.get(0).getValue()); Map<RoadNetworkEdge, CostGraph> costGraphs = _knownCostGraphs.get(knownInformation.get(0).getValue());
usedCostGraph = costGraphs.get(pInvestigatedRoute.getDestination()); usedCostGraph = costGraphs.get(pInvestigatedRoute.getDestination());
} else { } else {
usedCostGraph = _unknownCostGraphs.get(pInvestigatedRoute.getDestination()); usedCostGraph = unknown;
} }
// String[] edges = new String[] {"gneE8", "gneE6", "gneE4", "gneE2"};
// String[] nextEdges = new String[] {"event", "gneE7", "gneE5", "gneE3"};
// String[] alternativeEdges = new String[] {"gneE10", "gneE16", "gneE51", "gneE56"};
// for (int i = 0; i < edges.length; i++) {
// String edge = edges[i];
// System.out.println(edge);
// System.out.println("\tUnknown: " + unknown.getCosts(RoadNetwork.CURRENT_ROAD_NETWORK.getEdge(edge)) + " via " + unknown.getOptimalRoute(RoadNetwork.CURRENT_ROAD_NETWORK.getEdge(edge)));
// System.out.println("\tUnknown (along path): " + (unknown.getCosts(RoadNetwork.CURRENT_ROAD_NETWORK.getEdge(nextEdges[i])) + RoadNetwork.CURRENT_ROAD_NETWORK.getEdge(edge).calculateStandardEdgeCosts()) + " via " + unknown.getOptimalRoute(RoadNetwork.CURRENT_ROAD_NETWORK.getEdge(nextEdges[i])));
// System.out.println("\tUnknown (along alternative): " + (unknown.getCosts(RoadNetwork.CURRENT_ROAD_NETWORK.getEdge(alternativeEdges[i])) + RoadNetwork.CURRENT_ROAD_NETWORK.getEdge(edge).calculateStandardEdgeCosts()) + " via " + unknown.getOptimalRoute(RoadNetwork.CURRENT_ROAD_NETWORK.getEdge(alternativeEdges[i])));
// if (knownInformation != null && knownInformation.size() > 0) {
// CostGraph known = _knownCostGraphs.get(knownInformation.get(0).getValue()).get(pInvestigatedRoute.getDestination());
// System.out.println("\tKnown: " + known.getCosts(RoadNetwork.CURRENT_ROAD_NETWORK.getEdge(edge)) + " via " + known.getOptimalRoute(RoadNetwork.CURRENT_ROAD_NETWORK.getEdge(edge)));
// System.out.println("\tKnown (along path): " + (known.getCosts(RoadNetwork.CURRENT_ROAD_NETWORK.getEdge(nextEdges[i])) + RoadNetwork.CURRENT_ROAD_NETWORK.getEdge(edge).calculateStandardEdgeCosts()) + " via " + known.getOptimalRoute(RoadNetwork.CURRENT_ROAD_NETWORK.getEdge(nextEdges[i])));
// System.out.println("\tKnown (along alternative): " + (known.getCosts(RoadNetwork.CURRENT_ROAD_NETWORK.getEdge(alternativeEdges[i])) + RoadNetwork.CURRENT_ROAD_NETWORK.getEdge(edge).calculateStandardEdgeCosts()) + " via " + known.getOptimalRoute(RoadNetwork.CURRENT_ROAD_NETWORK.getEdge(alternativeEdges[i])));
// }
// System.out.println();
// }
// System.out.println("_____________________________________________");
//
// if (knownInformation != null && knownInformation.size() > 0) {
// System.out.println();
// }
double minCosts = Double.MAX_VALUE; double minCosts = Double.MAX_VALUE;
RoadNetworkRoute optimalRoute = null; RoadNetworkRoute optimalRoute = null;
for (RoadNetworkEdge edge : pInvestigatedRoute.getStart().getAccessibleEdges()) { for (RoadNetworkEdge edge : pInvestigatedRoute.getStart().getAccessibleEdges()) {
...@@ -95,21 +123,8 @@ public class DynamicInformationVehicleDecisionComponent extends AbstractVehicleD ...@@ -95,21 +123,8 @@ public class DynamicInformationVehicleDecisionComponent extends AbstractVehicleD
if (optimalRoute != null) { if (optimalRoute != null) {
optimalRoute.getRoute().add(0, pInvestigatedRoute.getStart()); optimalRoute.getRoute().add(0, pInvestigatedRoute.getStart());
double oldCosts = 0; double oldCosts = getRouteCosts(pInvestigatedRoute, knownInformation);
for (RoadNetworkEdge edge : pInvestigatedRoute.getRoute()) { double newCosts = getRouteCosts(optimalRoute, knownInformation);
oldCosts += edge.calculateStandardEdgeCosts();
for (RoadInformation roadInformation : knownInformation) {
oldCosts += edge.calculateAdditionalCostIfKnown(roadInformation.getValue());
}
}
double newCosts = 0;
for (RoadNetworkEdge edge : optimalRoute.getRoute()) {
newCosts += edge.calculateStandardEdgeCosts();
for (RoadInformation roadInformation : knownInformation) {
newCosts += edge.calculateAdditionalCostIfKnown(roadInformation.getValue());
}
}
if (oldCosts > newCosts) { if (oldCosts > newCosts) {
return new BenefitBasedRoute(oldCosts - newCosts, optimalRoute); return new BenefitBasedRoute(oldCosts - newCosts, optimalRoute);
...@@ -120,6 +135,21 @@ public class DynamicInformationVehicleDecisionComponent extends AbstractVehicleD ...@@ -120,6 +135,21 @@ public class DynamicInformationVehicleDecisionComponent extends AbstractVehicleD
return new BenefitBasedRoute(0, pInvestigatedRoute); return new BenefitBasedRoute(0, pInvestigatedRoute);
} }
private double getRouteCosts(RoadNetworkRoute pInvestigatedRoute, List<RoadInformation> knownInformation)
throws AssertionError {
double oldCosts = 0;
for (RoadNetworkEdge edge : pInvestigatedRoute.getRoute()) {
oldCosts += edge.calculateStandardEdgeCosts();
if (knownInformation != null) {
for (RoadInformation roadInformation : knownInformation) {
double cost = edge.calculateAdditionalCostIfKnown(roadInformation.getValue());
oldCosts += cost;
}
}
}
return oldCosts;
}
private class CostGraph { private class CostGraph {
private Map<RoadNetworkEdge, Double> _costGraph = new HashMap<>(); private Map<RoadNetworkEdge, Double> _costGraph = new HashMap<>();
private Map<RoadNetworkEdge, RoadNetworkEdge> _nextEdgeGraph = new HashMap<>(); private Map<RoadNetworkEdge, RoadNetworkEdge> _nextEdgeGraph = new HashMap<>();
...@@ -129,6 +159,7 @@ public class DynamicInformationVehicleDecisionComponent extends AbstractVehicleD ...@@ -129,6 +159,7 @@ public class DynamicInformationVehicleDecisionComponent extends AbstractVehicleD
private CostGraph _costGraphWithoutEvent; private CostGraph _costGraphWithoutEvent;
private RoadNetworkEdge _destination; private RoadNetworkEdge _destination;
private double _maxCosts = Double.POSITIVE_INFINITY;
// If event inactive // If event inactive
public CostGraph(RoadNetworkEdge pDestination) { public CostGraph(RoadNetworkEdge pDestination) {
...@@ -136,6 +167,10 @@ public class DynamicInformationVehicleDecisionComponent extends AbstractVehicleD ...@@ -136,6 +167,10 @@ public class DynamicInformationVehicleDecisionComponent extends AbstractVehicleD
_destination = pDestination; _destination = pDestination;
} }
public void setCostLimit(double pRouteCosts) {
_maxCosts = pRouteCosts;
}
// If event active // If event active
public CostGraph(RoadNetworkEdge pDestination, RoadInformation pInformation, CostGraph pCostGraphWithoutEvent) { public CostGraph(RoadNetworkEdge pDestination, RoadInformation pInformation, CostGraph pCostGraphWithoutEvent) {
this(pDestination); this(pDestination);
...@@ -164,10 +199,12 @@ public class DynamicInformationVehicleDecisionComponent extends AbstractVehicleD ...@@ -164,10 +199,12 @@ public class DynamicInformationVehicleDecisionComponent extends AbstractVehicleD
} }
public void createCostGraph() { public void createCostGraph() {
createCostGraph(RoadNetwork.CURRENT_ROAD_NETWORK.getUsableEdges().size()); createCostGraph(25);
} }
public void createCostGraph(int pMaxDepth) { public void createCostGraph(int pMaxDepth) {
_costGraph.clear();
_costGraph.put(_destination, 0d);
RoadProperty property = null; RoadProperty property = null;
if (_information != null) { if (_information != null) {
property = _information.getValue(); property = _information.getValue();
...@@ -182,6 +219,7 @@ public class DynamicInformationVehicleDecisionComponent extends AbstractVehicleD ...@@ -182,6 +219,7 @@ public class DynamicInformationVehicleDecisionComponent extends AbstractVehicleD
for (int i = 0; i < pMaxDepth; i++) { for (int i = 0; i < pMaxDepth; i++) {
List<RoadNetworkEdge> labeledEdges = new ArrayList<>(_costGraph.keySet()); List<RoadNetworkEdge> labeledEdges = new ArrayList<>(_costGraph.keySet());
int updated = 0;
for (RoadNetworkEdge roadNetworkEdge : labeledEdges) { for (RoadNetworkEdge roadNetworkEdge : labeledEdges) {
List<RoadNetworkEdge> incomingEdges = roadNetworkEdge.getIncomingEdges(); List<RoadNetworkEdge> incomingEdges = roadNetworkEdge.getIncomingEdges();
...@@ -190,7 +228,9 @@ public class DynamicInformationVehicleDecisionComponent extends AbstractVehicleD ...@@ -190,7 +228,9 @@ public class DynamicInformationVehicleDecisionComponent extends AbstractVehicleD
continue; continue;
} }
double edgeCost = incomingEdge.calculateEdgeCostIfKnown(property); double edgeCost = incomingEdge.calculateStandardEdgeCosts();
double additionalCosts = incomingEdge.calculateAdditionalCostIfKnown(property);
edgeCost += additionalCosts;
double eventActiveCost = _costGraph.get(roadNetworkEdge); double eventActiveCost = _costGraph.get(roadNetworkEdge);
double eventInactiveCost = _costGraphWithoutEvent.getCosts(roadNetworkEdge); double eventInactiveCost = _costGraphWithoutEvent.getCosts(roadNetworkEdge);
...@@ -199,28 +239,40 @@ public class DynamicInformationVehicleDecisionComponent extends AbstractVehicleD ...@@ -199,28 +239,40 @@ public class DynamicInformationVehicleDecisionComponent extends AbstractVehicleD
double totalCosts = edgeCost + eventInactiveCost * (1 - stillExistProbability) double totalCosts = edgeCost + eventInactiveCost * (1 - stillExistProbability)
+ eventActiveCost * stillExistProbability; + eventActiveCost * stillExistProbability;
if (!_costGraph.containsKey(incomingEdge) || totalCosts < _costGraph.get(incomingEdge)) { if ((!_costGraph.containsKey(incomingEdge) || totalCosts < _costGraph.get(incomingEdge)) && totalCosts <= _maxCosts) {
_costGraph.put(incomingEdge, totalCosts); _costGraph.put(incomingEdge, totalCosts);
_nextEdgeGraph.put(incomingEdge, roadNetworkEdge); _nextEdgeGraph.put(incomingEdge, roadNetworkEdge);
updated++;
} }
} }
} }
if (updated == 0) {
break;
}
} }
} else { } else {
for (int i = 0; i < pMaxDepth; i++) { for (int i = 0; i < pMaxDepth; i++) {
List<RoadNetworkEdge> labeledEdges = new ArrayList<>(_costGraph.keySet()); List<RoadNetworkEdge> labeledEdges = new ArrayList<>(_costGraph.keySet());
int updated = 0;
for (RoadNetworkEdge roadNetworkEdge : labeledEdges) { for (RoadNetworkEdge roadNetworkEdge : labeledEdges) {
List<RoadNetworkEdge> incomingEdges = roadNetworkEdge.getIncomingEdges(); List<RoadNetworkEdge> incomingEdges = roadNetworkEdge.getIncomingEdges();
for (RoadNetworkEdge incomingEdge : incomingEdges) { for (RoadNetworkEdge incomingEdge : incomingEdges) {
double edgeCost = incomingEdge.calculateEdgeCostIfKnown(property); double edgeCost = incomingEdge.calculateStandardEdgeCosts();
double totalCosts = _costGraph.get(roadNetworkEdge) + edgeCost; double totalCosts = _costGraph.get(roadNetworkEdge) + edgeCost;
if (!_costGraph.containsKey(incomingEdge) || totalCosts < _costGraph.get(incomingEdge)) { if ((!_costGraph.containsKey(incomingEdge) || totalCosts < _costGraph.get(incomingEdge)) && totalCosts <= _maxCosts) {
_costGraph.put(incomingEdge, totalCosts); _costGraph.put(incomingEdge, totalCosts);
_nextEdgeGraph.put(incomingEdge, roadNetworkEdge); _nextEdgeGraph.put(incomingEdge, roadNetworkEdge);
updated++;
} }
} }
} }
if (updated == 0) {
break;
}
} }
} }
} }
......
...@@ -20,31 +20,27 @@ ...@@ -20,31 +20,27 @@
package de.tud.kom.p2psim.impl.vehicular.decision; package de.tud.kom.p2psim.impl.vehicular.decision;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import de.tudarmstadt.maki.simonstrator.api.Host; import de.tudarmstadt.maki.simonstrator.api.Host;
import de.tudarmstadt.maki.simonstrator.api.Time;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.properties.RoadProperty;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.RoadInformation;
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.paths.VehiclePathTrackerFactory;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.routing.DijkstraAlgorithm; import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.routing.DijkstraAlgorithm;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.routing.GlobalKnowledgeDijkstraAlgorithm;
public class OptimalVehicleDecisionComponent extends AbstractVehicleDecisionComponent { public class OptimalVehicleDecisionComponent extends StaticInformationVehicleDecisionComponent {
public OptimalVehicleDecisionComponent(Host pHost) { public OptimalVehicleDecisionComponent(Host pHost) {
super(pHost); super(pHost);
} }
@Override
protected DijkstraAlgorithm getRoutingAlgorithm() {
return new GlobalKnowledgeDijkstraAlgorithm();
}
/*
@Override @Override
public BenefitBasedRoute getOptimalRoute(RoadNetworkRoute pInvestigatedRoute, List<RoadInformation> knownInformation) { public BenefitBasedRoute getOptimalRoute(RoadNetworkRoute pInvestigatedRoute, List<RoadInformation> knownInformation) {
if (getVehicleInformation().isValid()) { if (getVehicleInformation().isValid()) {
DijkstraAlgorithm dijkstraAlgorithm = new DijkstraAlgorithm(); DijkstraAlgorithm dijkstraAlgorithm = new GlobalKnowledgeDijkstraAlgorithm();
List<RoadNetworkEdge> blocked = new ArrayList<>(); List<RoadInformation> relevant = new ArrayList<>();
if (knownInformation != null) { if (knownInformation != null) {
for (RoadInformation roadInformation : knownInformation) { for (RoadInformation roadInformation : knownInformation) {
RoadProperty property = roadInformation.getValue(); RoadProperty property = roadInformation.getValue();
...@@ -53,22 +49,28 @@ public class OptimalVehicleDecisionComponent extends AbstractVehicleDecisionComp ...@@ -53,22 +49,28 @@ public class OptimalVehicleDecisionComponent extends AbstractVehicleDecisionComp
|| roadInformation.getValue().getDetectionDate() || roadInformation.getValue().getDetectionDate()
+ roadInformation.getValue().getDuration() > Time.getCurrentTime() + roadInformation.getValue().getDuration() > Time.getCurrentTime()
+ getTimeToEvent(pInvestigatedRoute, roadInformation.getEdge())) { + getTimeToEvent(pInvestigatedRoute, roadInformation.getEdge())) {
if (!blocked.contains(roadInformation.getEdge())) { if (!relevant.contains(roadInformation)) {
blocked.add(roadInformation.getEdge()); relevant.add(roadInformation);
} }
} }
} }
} }
} }
RoadNetworkRoute route = dijkstraAlgorithm.findRoute(RoadNetwork.CURRENT_ROAD_NETWORK, getVehicleInformation().getCurrentRoute().getStart(), getVehicleInformation().getCurrentRoute().getDestination(), Collections.emptyList(), blocked); RoadNetworkRoute route = dijkstraAlgorithm.findRoute(RoadNetwork.CURRENT_ROAD_NETWORK, getVehicleInformation().getCurrentRoute().getStart(), getVehicleInformation().getCurrentRoute().getDestination(), Collections.emptyList(), Collections.emptyList(), relevant);
if (route != null) { if (route != null) {
double oldCosts = 0; double oldCosts = 0;
for (RoadNetworkEdge edge : pInvestigatedRoute.getRoute()) { for (RoadNetworkEdge edge : pInvestigatedRoute.getRoute()) {
oldCosts += edge.calculateStandardEdgeCosts(); oldCosts += edge.calculateStandardEdgeCosts();
if (knownInformation != null) { if (relevant != null) {
for (RoadInformation roadInformation : knownInformation) { for (RoadInformation roadInformation : relevant) {
oldCosts += edge.calculateAdditionalCostIfKnown(roadInformation.getValue()); double additionalCosts = edge.calculateAdditionalCostIfKnown(roadInformation.getValue());
if (additionalCosts > (Long) roadInformation
.getAttribute(AvailableInformationAttributes.EXPECTED_DURATION) / Time.SECOND) {
additionalCosts = (Long) roadInformation
.getAttribute(AvailableInformationAttributes.EXPECTED_DURATION) / (double) Time.SECOND;
}
oldCosts += additionalCosts;
} }
} }
} }
...@@ -76,9 +78,15 @@ public class OptimalVehicleDecisionComponent extends AbstractVehicleDecisionComp ...@@ -76,9 +78,15 @@ public class OptimalVehicleDecisionComponent extends AbstractVehicleDecisionComp
double newCosts = 0; double newCosts = 0;
for (RoadNetworkEdge edge : route.getRoute()) { for (RoadNetworkEdge edge : route.getRoute()) {
newCosts += edge.calculateStandardEdgeCosts(); newCosts += edge.calculateStandardEdgeCosts();
if (knownInformation != null) { if (relevant != null) {
for (RoadInformation roadInformation : knownInformation) { for (RoadInformation roadInformation : relevant) {
newCosts += edge.calculateAdditionalCostIfKnown(roadInformation.getValue()); double additionalCosts = edge.calculateAdditionalCostIfKnown(roadInformation.getValue());
if (additionalCosts > (Long) roadInformation
.getAttribute(AvailableInformationAttributes.EXPECTED_DURATION) / Time.SECOND) {
additionalCosts = (Long) roadInformation
.getAttribute(AvailableInformationAttributes.EXPECTED_DURATION) / (double) Time.SECOND;
}
newCosts += additionalCosts;
} }
} }
} }
...@@ -86,10 +94,6 @@ public class OptimalVehicleDecisionComponent extends AbstractVehicleDecisionComp ...@@ -86,10 +94,6 @@ public class OptimalVehicleDecisionComponent extends AbstractVehicleDecisionComp
if (oldCosts > newCosts) { if (oldCosts > newCosts) {
return new BenefitBasedRoute(oldCosts - newCosts, route); return new BenefitBasedRoute(oldCosts - newCosts, route);
} }
// if (pInvestigatedRoute.getStart().getEdgeID().equals("gneE8") && pInvestigatedRoute.getRoute().contains(RoadNetwork.CURRENT_ROAD_NETWORK.getEdge("event"))
// && RoadNetwork.CURRENT_ROAD_NETWORK.getEdge("event").isActive() && Time.getCurrentTime() > 13 * Time.SECOND) {
// System.out.println();
// }
} }
return new BenefitBasedRoute(0, pInvestigatedRoute); return new BenefitBasedRoute(0, pInvestigatedRoute);
} }
...@@ -109,7 +113,8 @@ public class OptimalVehicleDecisionComponent extends AbstractVehicleDecisionComp ...@@ -109,7 +113,8 @@ public class OptimalVehicleDecisionComponent extends AbstractVehicleDecisionComp
} }
} }
return timeToEvent * Time.SECOND; return (long) (timeToEvent * Time.SECOND * 0.9);
} }
*/
} }
...@@ -20,12 +20,11 @@ ...@@ -20,12 +20,11 @@
package de.tud.kom.p2psim.impl.vehicular.decision; package de.tud.kom.p2psim.impl.vehicular.decision;
import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import de.tudarmstadt.maki.simonstrator.api.Host; import de.tudarmstadt.maki.simonstrator.api.Host;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.properties.RoadProperty; import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.properties.JamProperty;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.RoadInformation; import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.RoadInformation;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetwork; 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.RoadNetworkEdge;
...@@ -40,33 +39,30 @@ public class StaticInformationVehicleDecisionComponent extends AbstractVehicleDe ...@@ -40,33 +39,30 @@ public class StaticInformationVehicleDecisionComponent extends AbstractVehicleDe
@Override @Override
public BenefitBasedRoute getOptimalRoute(RoadNetworkRoute pInvestigatedRoute, List<RoadInformation> knownInformation) { public BenefitBasedRoute getOptimalRoute(RoadNetworkRoute pInvestigatedRoute, List<RoadInformation> knownInformation) {
if (getVehicleInformation().isValid() && knownInformation != null) { if (getVehicleInformation().isValid() && pInvestigatedRoute.getRoute().size() > 1) {
DijkstraAlgorithm dijkstraAlgorithm = new DijkstraAlgorithm(); DijkstraAlgorithm dijkstraAlgorithm = getRoutingAlgorithm();
List<RoadNetworkEdge> blocked = new ArrayList<>();
for (RoadInformation roadInformation : knownInformation) {
RoadProperty property = roadInformation.getValue();
if (!property.getValue().equals(property.getDefaultProperty().getValue())) {
if (!blocked.contains(roadInformation.getEdge())) {
blocked.add(roadInformation.getEdge());
}
}
}
RoadNetworkRoute route = dijkstraAlgorithm.findRoute(RoadNetwork.CURRENT_ROAD_NETWORK, getVehicleInformation().getCurrentRoute().getStart(), getVehicleInformation().getCurrentRoute().getDestination(), Collections.emptyList(), blocked); RoadNetworkRoute route = dijkstraAlgorithm.findRoute(RoadNetwork.CURRENT_ROAD_NETWORK, getVehicleInformation().getCurrentRoute().getStart(), getVehicleInformation().getCurrentRoute().getDestination(), Collections.emptyList(), Collections.emptyList(), knownInformation);
if (route != null) { if (route != null) {
double oldCosts = 0; double oldCosts = 0;
for (RoadNetworkEdge edge : pInvestigatedRoute.getRoute()) { for (RoadNetworkEdge edge : pInvestigatedRoute.getRoute()) {
oldCosts += edge.calculateStandardEdgeCosts(); oldCosts += edge.calculateStandardEdgeCosts();
for (RoadInformation roadInformation : knownInformation) { if (knownInformation != null) {
oldCosts += edge.calculateAdditionalCostIfKnown(roadInformation.getValue()); for (RoadInformation roadInformation : knownInformation) {
double additionalCosts = edge.calculateAdditionalCostIfKnown(roadInformation.getValue());
oldCosts += additionalCosts;
}
} }
} }
double newCosts = 0; double newCosts = 0;
for (RoadNetworkEdge edge : route.getRoute()) { for (RoadNetworkEdge edge : route.getRoute()) {
newCosts += edge.calculateStandardEdgeCosts(); newCosts += edge.calculateStandardEdgeCosts();
for (RoadInformation roadInformation : knownInformation) { if (knownInformation != null) {
newCosts += edge.calculateAdditionalCostIfKnown(roadInformation.getValue()); for (RoadInformation roadInformation : knownInformation) {
double additionalCosts = edge.calculateAdditionalCostIfKnown(roadInformation.getValue());
newCosts += additionalCosts;
}
} }
} }
...@@ -76,7 +72,11 @@ public class StaticInformationVehicleDecisionComponent extends AbstractVehicleDe ...@@ -76,7 +72,11 @@ public class StaticInformationVehicleDecisionComponent extends AbstractVehicleDe
} }
return new BenefitBasedRoute(0, pInvestigatedRoute); return new BenefitBasedRoute(0, pInvestigatedRoute);
} }
return null; return new BenefitBasedRoute(0, pInvestigatedRoute);
}
protected DijkstraAlgorithm getRoutingAlgorithm() {
return new DijkstraAlgorithm();
} }
} }
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