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

Update in vehicle decision-making

parent dc10deed
......@@ -20,8 +20,7 @@
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.EventHandler;
import de.tudarmstadt.maki.simonstrator.api.Host;
......@@ -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.core.MonitorComponent.AnalyzerNotAvailableException;
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.VehicleInformationComponent;
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.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.VehicleRouteAnalyzer;
......@@ -42,6 +42,8 @@ public abstract class AbstractVehicleDecisionComponent implements VehicleDecisio
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 Host _host;
private CachingComponent _cache;
......@@ -88,7 +90,7 @@ public abstract class AbstractVehicleDecisionComponent implements VehicleDecisio
@Override
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
......@@ -98,20 +100,18 @@ public abstract class AbstractVehicleDecisionComponent implements VehicleDecisio
RoadNetworkRoute currentRoute = getVehicleInformation().getCurrentRoute();
if (currentRoute != null) {
boolean changed = false;
boolean changed = false;
if (currentRoute.getRoute().size() > 2) {
BenefitBasedRoute optimalRouteWithBenefit = getOptimalRoute(currentRoute,
_cache.getDecidedCacheEntries(RoadInformation.class), _sensors.getEnvironment());
if (optimalRouteWithBenefit != null) {
if (optimalRouteWithBenefit != null && optimalRouteWithBenefit.getBenefit() > 0) {
RoadNetworkRoute optimalRoute = optimalRouteWithBenefit.getRoute();
if (optimalRouteWithBenefit.getRoute().getRoute().size() > 1) {
if (currentRoute.getRoute().get(1) != optimalRoute.getRoute().get(1)) {
if (hasRouteAnalyzer()) {
getRouteAnalyzer().routeChanged(getHost().getId(), currentRoute, optimalRoute);
}
changed = true;
getVehicleInformation().changeCurrentRoute(optimalRouteWithBenefit.getRoute());
}
if (hasRouteAnalyzer()) {
getRouteAnalyzer().routeChanged(getHost().getId(), currentRoute, optimalRoute);
}
changed = true;
getVehicleInformation().changeCurrentRoute(optimalRouteWithBenefit.getRoute());
}
}
}
......@@ -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;
default:
break;
......
......@@ -27,7 +27,9 @@ import java.util.Map;
import de.tudarmstadt.maki.simonstrator.api.Host;
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.vehicular.VehicleInformationComponent;
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.roadnetwork.RoadNetwork;
......@@ -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.paths.VehiclePathTracker;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.paths.VehiclePathTrackerFactory;
import javassist.bytecode.LineNumberAttribute.Pc;
public class DynamicInformationVehicleDecisionComponent extends AbstractVehicleDecisionComponent {
private static Map<RoadNetworkEdge, CostGraph> _unknownCostGraphs = new HashMap<>();
......@@ -46,8 +49,8 @@ public class DynamicInformationVehicleDecisionComponent extends AbstractVehicleD
@Override
public BenefitBasedRoute getOptimalRoute(RoadNetworkRoute pInvestigatedRoute, List<RoadInformation> knownInformation) {
if (getVehicleInformation().isValid() && knownInformation != null && pInvestigatedRoute.getRoute().size() > 1 && pInvestigatedRoute.getStart().getAccessibleEdges().size() > 1) {
if (knownInformation.size() > 1) {
if (getVehicleInformation().isValid() && pInvestigatedRoute.getRoute().size() > 1) {
if (knownInformation != null && knownInformation.size() > 1) {
for (RoadInformation roadInformation : knownInformation) {
System.out.println("Known information for road " + roadInformation.getEdge());
}
......@@ -62,25 +65,50 @@ public class DynamicInformationVehicleDecisionComponent extends AbstractVehicleD
_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())) {
_knownCostGraphs.put(knownInformation.get(0).getValue(), new HashMap<>());
}
Map<RoadNetworkEdge, CostGraph> costGraphs = _knownCostGraphs.get(knownInformation.get(0).getValue());
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();
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());
usedCostGraph = costGraphs.get(pInvestigatedRoute.getDestination());
} 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;
RoadNetworkRoute optimalRoute = null;
for (RoadNetworkEdge edge : pInvestigatedRoute.getStart().getAccessibleEdges()) {
......@@ -95,21 +123,8 @@ public class DynamicInformationVehicleDecisionComponent extends AbstractVehicleD
if (optimalRoute != null) {
optimalRoute.getRoute().add(0, pInvestigatedRoute.getStart());
double oldCosts = 0;
for (RoadNetworkEdge edge : pInvestigatedRoute.getRoute()) {
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());
}
}
double oldCosts = getRouteCosts(pInvestigatedRoute, knownInformation);
double newCosts = getRouteCosts(optimalRoute, knownInformation);
if (oldCosts > newCosts) {
return new BenefitBasedRoute(oldCosts - newCosts, optimalRoute);
......@@ -120,6 +135,21 @@ public class DynamicInformationVehicleDecisionComponent extends AbstractVehicleD
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 Map<RoadNetworkEdge, Double> _costGraph = new HashMap<>();
private Map<RoadNetworkEdge, RoadNetworkEdge> _nextEdgeGraph = new HashMap<>();
......@@ -129,6 +159,7 @@ public class DynamicInformationVehicleDecisionComponent extends AbstractVehicleD
private CostGraph _costGraphWithoutEvent;
private RoadNetworkEdge _destination;
private double _maxCosts = Double.POSITIVE_INFINITY;
// If event inactive
public CostGraph(RoadNetworkEdge pDestination) {
......@@ -136,6 +167,10 @@ public class DynamicInformationVehicleDecisionComponent extends AbstractVehicleD
_destination = pDestination;
}
public void setCostLimit(double pRouteCosts) {
_maxCosts = pRouteCosts;
}
// If event active
public CostGraph(RoadNetworkEdge pDestination, RoadInformation pInformation, CostGraph pCostGraphWithoutEvent) {
this(pDestination);
......@@ -164,10 +199,12 @@ public class DynamicInformationVehicleDecisionComponent extends AbstractVehicleD
}
public void createCostGraph() {
createCostGraph(RoadNetwork.CURRENT_ROAD_NETWORK.getUsableEdges().size());
createCostGraph(25);
}
public void createCostGraph(int pMaxDepth) {
_costGraph.clear();
_costGraph.put(_destination, 0d);
RoadProperty property = null;
if (_information != null) {
property = _information.getValue();
......@@ -182,6 +219,7 @@ public class DynamicInformationVehicleDecisionComponent extends AbstractVehicleD
for (int i = 0; i < pMaxDepth; i++) {
List<RoadNetworkEdge> labeledEdges = new ArrayList<>(_costGraph.keySet());
int updated = 0;
for (RoadNetworkEdge roadNetworkEdge : labeledEdges) {
List<RoadNetworkEdge> incomingEdges = roadNetworkEdge.getIncomingEdges();
......@@ -190,7 +228,9 @@ public class DynamicInformationVehicleDecisionComponent extends AbstractVehicleD
continue;
}
double edgeCost = incomingEdge.calculateEdgeCostIfKnown(property);
double edgeCost = incomingEdge.calculateStandardEdgeCosts();
double additionalCosts = incomingEdge.calculateAdditionalCostIfKnown(property);
edgeCost += additionalCosts;
double eventActiveCost = _costGraph.get(roadNetworkEdge);
double eventInactiveCost = _costGraphWithoutEvent.getCosts(roadNetworkEdge);
......@@ -199,28 +239,40 @@ public class DynamicInformationVehicleDecisionComponent extends AbstractVehicleD
double totalCosts = edgeCost + eventInactiveCost * (1 - 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);
_nextEdgeGraph.put(incomingEdge, roadNetworkEdge);
updated++;
}
}
}
if (updated == 0) {
break;
}
}
} else {
for (int i = 0; i < pMaxDepth; i++) {
List<RoadNetworkEdge> labeledEdges = new ArrayList<>(_costGraph.keySet());
int updated = 0;
for (RoadNetworkEdge roadNetworkEdge : labeledEdges) {
List<RoadNetworkEdge> incomingEdges = roadNetworkEdge.getIncomingEdges();
for (RoadNetworkEdge incomingEdge : incomingEdges) {
double edgeCost = incomingEdge.calculateEdgeCostIfKnown(property);
double edgeCost = incomingEdge.calculateStandardEdgeCosts();
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);
_nextEdgeGraph.put(incomingEdge, roadNetworkEdge);
updated++;
}
}
}
if (updated == 0) {
break;
}
}
}
}
......
......@@ -20,31 +20,27 @@
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.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.GlobalKnowledgeDijkstraAlgorithm;
public class OptimalVehicleDecisionComponent extends AbstractVehicleDecisionComponent {
public class OptimalVehicleDecisionComponent extends StaticInformationVehicleDecisionComponent {
public OptimalVehicleDecisionComponent(Host pHost) {
super(pHost);
}
@Override
protected DijkstraAlgorithm getRoutingAlgorithm() {
return new GlobalKnowledgeDijkstraAlgorithm();
}
/*
@Override
public BenefitBasedRoute getOptimalRoute(RoadNetworkRoute pInvestigatedRoute, List<RoadInformation> knownInformation) {
if (getVehicleInformation().isValid()) {
DijkstraAlgorithm dijkstraAlgorithm = new DijkstraAlgorithm();
List<RoadNetworkEdge> blocked = new ArrayList<>();
DijkstraAlgorithm dijkstraAlgorithm = new GlobalKnowledgeDijkstraAlgorithm();
List<RoadInformation> relevant = new ArrayList<>();
if (knownInformation != null) {
for (RoadInformation roadInformation : knownInformation) {
RoadProperty property = roadInformation.getValue();
......@@ -53,22 +49,28 @@ public class OptimalVehicleDecisionComponent extends AbstractVehicleDecisionComp
|| roadInformation.getValue().getDetectionDate()
+ roadInformation.getValue().getDuration() > Time.getCurrentTime()
+ getTimeToEvent(pInvestigatedRoute, roadInformation.getEdge())) {
if (!blocked.contains(roadInformation.getEdge())) {
blocked.add(roadInformation.getEdge());
if (!relevant.contains(roadInformation)) {
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) {
double oldCosts = 0;
for (RoadNetworkEdge edge : pInvestigatedRoute.getRoute()) {
oldCosts += edge.calculateStandardEdgeCosts();
if (knownInformation != null) {
for (RoadInformation roadInformation : knownInformation) {
oldCosts += edge.calculateAdditionalCostIfKnown(roadInformation.getValue());
if (relevant != null) {
for (RoadInformation roadInformation : relevant) {
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
double newCosts = 0;
for (RoadNetworkEdge edge : route.getRoute()) {
newCosts += edge.calculateStandardEdgeCosts();
if (knownInformation != null) {
for (RoadInformation roadInformation : knownInformation) {
newCosts += edge.calculateAdditionalCostIfKnown(roadInformation.getValue());
if (relevant != null) {
for (RoadInformation roadInformation : relevant) {
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
if (oldCosts > newCosts) {
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);
}
......@@ -109,7 +113,8 @@ public class OptimalVehicleDecisionComponent extends AbstractVehicleDecisionComp
}
}
return timeToEvent * Time.SECOND;
return (long) (timeToEvent * Time.SECOND * 0.9);
}
*/
}
......@@ -20,12 +20,11 @@
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.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.roadnetwork.RoadNetwork;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetworkEdge;
......@@ -40,33 +39,30 @@ public class StaticInformationVehicleDecisionComponent extends AbstractVehicleDe
@Override
public BenefitBasedRoute getOptimalRoute(RoadNetworkRoute pInvestigatedRoute, List<RoadInformation> knownInformation) {
if (getVehicleInformation().isValid() && knownInformation != null) {
DijkstraAlgorithm dijkstraAlgorithm = new DijkstraAlgorithm();
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());
}
}
}
if (getVehicleInformation().isValid() && pInvestigatedRoute.getRoute().size() > 1) {
DijkstraAlgorithm dijkstraAlgorithm = getRoutingAlgorithm();
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) {
double oldCosts = 0;
for (RoadNetworkEdge edge : pInvestigatedRoute.getRoute()) {
oldCosts += edge.calculateStandardEdgeCosts();
for (RoadInformation roadInformation : knownInformation) {
oldCosts += edge.calculateAdditionalCostIfKnown(roadInformation.getValue());
if (knownInformation != null) {
for (RoadInformation roadInformation : knownInformation) {
double additionalCosts = edge.calculateAdditionalCostIfKnown(roadInformation.getValue());
oldCosts += additionalCosts;
}
}
}
double newCosts = 0;
for (RoadNetworkEdge edge : route.getRoute()) {
newCosts += edge.calculateStandardEdgeCosts();
for (RoadInformation roadInformation : knownInformation) {
newCosts += edge.calculateAdditionalCostIfKnown(roadInformation.getValue());
if (knownInformation != null) {
for (RoadInformation roadInformation : knownInformation) {
double additionalCosts = edge.calculateAdditionalCostIfKnown(roadInformation.getValue());
newCosts += additionalCosts;
}
}
}
......@@ -76,7 +72,11 @@ public class StaticInformationVehicleDecisionComponent extends AbstractVehicleDe
}
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