Commit 18180bef authored by Tobias Meuser's avatar Tobias Meuser
Browse files

Renamed property benefit/cost to property impact

parent 11bd32e1
...@@ -20,12 +20,6 @@ ...@@ -20,12 +20,6 @@
package de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.costs; package de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.costs;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import de.tudarmstadt.maki.simonstrator.api.component.pubsub.Notification; import de.tudarmstadt.maki.simonstrator.api.component.pubsub.Notification;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.properties.BumpProperty; import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.properties.BumpProperty;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.properties.FogProperty; import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.properties.FogProperty;
...@@ -37,22 +31,11 @@ import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.pr ...@@ -37,22 +31,11 @@ import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.pr
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.properties.TrafficSignProperty; import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.properties.TrafficSignProperty;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.EnvironmentInformation; import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.EnvironmentInformation;
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.paths.VehiclePathTracker;
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.RoutingAlgorithm;
public class DefaultVehicularPropertyCostEstimator implements VehicularPropertyCostEstimator {
private static final int MAX_DETOUR = 3;
private RoutingAlgorithm routing = new DijkstraAlgorithm(); public class ConfigurableVehicularPropertyImpactEstimator implements VehicularPropertyImpactEstimator {
@Override @Override
public double calculateCostsIfKnown(Class<? extends RoadProperty> pProperty) { public double calculateImpactIfKnown(Class<? extends RoadProperty> pProperty) {
if (pProperty.equals(JamProperty.class)) { if (pProperty.equals(JamProperty.class)) {
return 3 * Math.pow(10, 2); return 3 * Math.pow(10, 2);
} else if (pProperty.equals(RainProperty.class)) { } else if (pProperty.equals(RainProperty.class)) {
...@@ -68,108 +51,31 @@ public class DefaultVehicularPropertyCostEstimator implements VehicularPropertyC ...@@ -68,108 +51,31 @@ public class DefaultVehicularPropertyCostEstimator implements VehicularPropertyC
} }
@Override @Override
public double calculateCostsIfKnown(Notification pNotification) { public double calculateImpactIfKnown(Notification pNotification) {
EnvironmentInformation<? extends LocationBasedEnvironmentProperty> environmentInformation = EnvironmentInformation
.createFromNotification(pNotification);
if (environmentInformation instanceof RoadInformation) {
return calculateCostsIfKnown(((RoadInformation) environmentInformation).getValue());
}
throw new AssertionError("Cost calculation only valid for road information!");
}
@Override
public List<DecisionPoint> getDecisionPoints(Notification pNotification) {
EnvironmentInformation<? extends LocationBasedEnvironmentProperty> environmentInformation = EnvironmentInformation EnvironmentInformation<? extends LocationBasedEnvironmentProperty> environmentInformation = EnvironmentInformation
.createFromNotification(pNotification); .createFromNotification(pNotification);
if (environmentInformation instanceof RoadInformation) { if (environmentInformation instanceof RoadInformation) {
RoadInformation roadInformation = (RoadInformation) environmentInformation; return calculateImpactIfKnown(((RoadInformation) environmentInformation).getValue());
List<DecisionPoint> decisionPoints = new ArrayList<>();
decisionPoints.add(new VehicularDecisionPoint(roadInformation.getEdge(), roadInformation.getLocation(),
calculateCostsIfKnown(roadInformation.getValue())));
if (roadInformation.getValue().isDetourable()) {
Set<RoadNetworkEdge> edges = new HashSet<>();
edges.add(roadInformation.getEdge());
for (int i = 0; i < MAX_DETOUR; i++) {
Set<RoadNetworkEdge> newEdges = new HashSet<>();
for (RoadNetworkEdge roadNetworkEdge : edges) {
newEdges.addAll(roadNetworkEdge.getIncomingEdges());
}
edges.addAll(newEdges);
}
for (RoadNetworkEdge roadNetworkEdge : edges) {
decisionPoints.add(new VehicularDetouringDecisionPoint(roadNetworkEdge, roadInformation.getEdge(),
roadInformation.getLocation(), calculateCostsIfKnown(roadInformation.getValue())));
}
}
return decisionPoints;
} }
throw new AssertionError("Cost calculation only valid for road information!"); throw new AssertionError("Cost calculation only valid for road information!");
} }
@Override @Override
public double calculateCostsIfKnown(RoadProperty pProperty, RoadNetworkEdge pDecisionPoint, public double calculateImpactIfUnknown(Notification pNotification) {
VehicleCostPreference pVehicle, RoadNetworkRoute pPath) {
VehiclePathTracker tracker = VehiclePathTrackerFactory.getVehiclePathTracker();
if (pPath.containsEdge(pDecisionPoint) && pPath.containsEdge(pProperty.getEdge())) {
if (pPath.getStart().equals(pProperty.getEdge())) {
return calculateCostsIfKnown(pProperty);
}
if (pProperty.isDetourable()) {
// Find other route...
List<RoadNetworkEdge> edgesToAvoid = new ArrayList<>();
edgesToAvoid.add(pProperty.getEdge());
RoadNetworkRoute route = routing.findRoute(RoadNetwork.CURRENT_ROAD_NETWORK, pPath.getStart(),
pPath.getDestination(), Collections.emptyList(), edgesToAvoid);
if (route != null) {
double newRouteTravelTime = route.getTravelTime();
double routeTravelTime = pPath.getTravelTime();
boolean found = false;
for (int i = 0; i < pPath.getRoute().size() - 1; i++) {
if (pPath.getRoute().get(i).equals(pProperty.getEdge())) {
routeTravelTime -= tracker.getTravelTime(pPath.getRoute().get(i),
pPath.getRoute().get(i + 1));
found = true;
}
}
if (found) {
routeTravelTime += (pProperty.getEdge().getLength() / pProperty.getEdge().getMaxSpeed());
}
if (routeTravelTime > newRouteTravelTime) {
return calculateCostsIfKnown(pProperty) + (routeTravelTime - newRouteTravelTime) * 10;
}
}
}
}
return calculateCostsIfKnown(pProperty);
}
@Override
public double calculateCostsIfUnknown(Notification pNotification) {
EnvironmentInformation<? extends LocationBasedEnvironmentProperty> environmentInformation = EnvironmentInformation EnvironmentInformation<? extends LocationBasedEnvironmentProperty> environmentInformation = EnvironmentInformation
.createFromNotification(pNotification); .createFromNotification(pNotification);
if (environmentInformation instanceof RoadInformation) { if (environmentInformation instanceof RoadInformation) {
return calculateCostsIfUnknown(((RoadInformation) environmentInformation).getValue()); return calculateImpactIfUnknown(((RoadInformation) environmentInformation).getValue());
} }
throw new AssertionError("Cost calculation only valid for road information!"); throw new AssertionError("Cost calculation only valid for road information!");
} }
@Override @Override
public double calculateCostsIfUnknown(Class<? extends RoadProperty> pProperty) { public double calculateImpactIfUnknown(Class<? extends RoadProperty> pProperty) {
if (pProperty.equals(JamProperty.class)) { if (pProperty.equals(JamProperty.class)) {
return Math.pow(10, 4); return Math.pow(10, 4);
} else if (pProperty.equals(BumpProperty.class)) { } else if (pProperty.equals(BumpProperty.class)) {
...@@ -180,10 +86,4 @@ public class DefaultVehicularPropertyCostEstimator implements VehicularPropertyC ...@@ -180,10 +86,4 @@ public class DefaultVehicularPropertyCostEstimator implements VehicularPropertyC
return 1; return 1;
} }
@Override
public double calculateCostsIfUnknown(RoadProperty pProperty, RoadNetworkEdge pDecisionPoint,
VehicleCostPreference pVehicle, RoadNetworkRoute pPath) {
return 0;
}
} }
/*
* 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.sensor.environment.costs;
import de.tudarmstadt.maki.simonstrator.api.component.pubsub.Notification;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.properties.BumpProperty;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.properties.FogProperty;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.properties.HazardProperty;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.properties.JamProperty;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.properties.LocationBasedEnvironmentProperty;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.properties.RainProperty;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.properties.RoadProperty;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.properties.TrafficSignProperty;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.EnvironmentInformation;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.RoadInformation;
public class DefaultVehicularPropertyImpactEstimator implements VehicularPropertyImpactEstimator {
@Override
public double calculateImpactIfKnown(Class<? extends RoadProperty> pProperty) {
if (pProperty.equals(JamProperty.class)) {
return 3 * Math.pow(10, 2);
} else if (pProperty.equals(RainProperty.class)) {
return 1;
} else if (pProperty.equals(FogProperty.class)) {
return 1;
} else if (pProperty.equals(HazardProperty.class)) {
return Math.pow(10, 3);
} else if (pProperty.equals(TrafficSignProperty.class)) {
return 10;
}
return 10;
}
@Override
public double calculateImpactIfKnown(Notification pNotification) {
EnvironmentInformation<? extends LocationBasedEnvironmentProperty> environmentInformation = EnvironmentInformation
.createFromNotification(pNotification);
if (environmentInformation instanceof RoadInformation) {
return calculateImpactIfKnown(((RoadInformation) environmentInformation).getValue());
}
throw new AssertionError("Cost calculation only valid for road information!");
}
@Override
public double calculateImpactIfUnknown(Notification pNotification) {
EnvironmentInformation<? extends LocationBasedEnvironmentProperty> environmentInformation = EnvironmentInformation
.createFromNotification(pNotification);
if (environmentInformation instanceof RoadInformation) {
return calculateImpactIfUnknown(((RoadInformation) environmentInformation).getValue());
}
throw new AssertionError("Cost calculation only valid for road information!");
}
@Override
public double calculateImpactIfUnknown(Class<? extends RoadProperty> pProperty) {
if (pProperty.equals(JamProperty.class)) {
return Math.pow(10, 4);
} else if (pProperty.equals(BumpProperty.class)) {
return Math.pow(10, -2);
} else if (pProperty.equals(HazardProperty.class)) {
return Math.pow(10, 6);
}
return 1;
}
}
...@@ -20,14 +20,10 @@ ...@@ -20,14 +20,10 @@
package de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.costs; package de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.costs;
import java.util.List;
import de.tudarmstadt.maki.simonstrator.api.component.pubsub.Notification; import de.tudarmstadt.maki.simonstrator.api.component.pubsub.Notification;
public interface PropertyBenefitEstimator { public interface PropertyImpactEstimator {
double calculateCostsIfKnown(Notification pNotification); double calculateImpactIfKnown(Notification pNotification);
double calculateCostsIfUnknown(Notification pNotification);
List<DecisionPoint> getDecisionPoints(Notification pNotification); double calculateImpactIfUnknown(Notification pNotification);
} }
/*
* 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.sensor.environment.costs;
public class PropertyImpactEstimatorFactory {
private static PropertyImpactEstimator _costEstimator = null;
public void registerPropertyBenefitEstimator(PropertyImpactEstimator pBenefitEstimator) {
synchronized (PropertyImpactEstimatorFactory.class) {
_costEstimator = pBenefitEstimator;
}
}
public static PropertyImpactEstimator getPropertyBenefitEstimator() {
synchronized (PropertyImpactEstimatorFactory.class) {
if (_costEstimator == null) {
System.err.println("No property impact estimator set! Falling back to "
+ DefaultVehicularPropertyImpactEstimator.class.getSimpleName());
_costEstimator = new DefaultVehicularPropertyImpactEstimator();
}
}
return _costEstimator;
}
}
...@@ -20,10 +20,18 @@ ...@@ -20,10 +20,18 @@
package de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.costs; package de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.costs;
public class PropertyBenefitEstimatorFactory { import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.properties.RoadProperty;
private static DefaultVehicularPropertyCostEstimator _costEstimator = new DefaultVehicularPropertyCostEstimator();
public static PropertyBenefitEstimator getPropertyBenefitEstimator() { public interface VehicularPropertyImpactEstimator extends PropertyImpactEstimator {
return _costEstimator; default double calculateImpactIfKnown(RoadProperty pProperty) {
return calculateImpactIfKnown(pProperty.getClass());
} }
double calculateImpactIfKnown(Class<? extends RoadProperty> pProperty);
default double calculateImpactIfUnknown(RoadProperty pProperty) {
return calculateImpactIfUnknown(pProperty.getClass());
}
double calculateImpactIfUnknown(Class<? extends RoadProperty> pProperty);
} }
...@@ -20,8 +20,8 @@ ...@@ -20,8 +20,8 @@
package de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.generator; package de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.generator;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.costs.PropertyBenefitEstimatorFactory; import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.costs.PropertyImpactEstimatorFactory;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.costs.VehicularPropertyCostEstimator; import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.costs.VehicularPropertyImpactEstimator;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.properties.JamProperty; import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.properties.JamProperty;
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.sensor.location.Location; import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
...@@ -32,8 +32,8 @@ public class JamPropertyGenerator implements RoadPropertyGenerator { ...@@ -32,8 +32,8 @@ public class JamPropertyGenerator implements RoadPropertyGenerator {
@Override @Override
public RoadProperty generateProperty(Location pLocation, RoadNetworkEdge pEdge) { public RoadProperty generateProperty(Location pLocation, RoadNetworkEdge pEdge) {
double travelTime = (pEdge.getLength() / pEdge.getMaxSpeed()); double travelTime = (pEdge.getLength() / pEdge.getMaxSpeed());
double newTravelTime = ((VehicularPropertyCostEstimator) PropertyBenefitEstimatorFactory double newTravelTime = ((VehicularPropertyImpactEstimator) PropertyImpactEstimatorFactory
.getPropertyBenefitEstimator()).calculateCostsIfKnown(JamProperty.class) + travelTime; .getPropertyBenefitEstimator()).calculateImpactIfKnown(JamProperty.class) + travelTime;
double newSpeed = pEdge.getLength() / newTravelTime; double newSpeed = pEdge.getLength() / newTravelTime;
return new JamProperty(pLocation, pEdge, true, newSpeed); return new JamProperty(pLocation, pEdge, true, newSpeed);
} }
......
...@@ -21,5 +21,5 @@ ...@@ -21,5 +21,5 @@
package de.tudarmstadt.maki.simonstrator.api.component.vehicular; package de.tudarmstadt.maki.simonstrator.api.component.vehicular;
public enum VehicleDecisionStrategyType { public enum VehicleDecisionStrategyType {
NONE, DUMMY, VISION_ONLY, STATIC_INFO, DYNAMIC_INFO, COMBINED_INFO, OPTIMAL NONE, DUMMY, VISION_ONLY, STATIC_INFO, DYNAMIC_INFO, COMBINED_INFO, OPTIMAL, LATEST
} }
...@@ -24,9 +24,9 @@ import java.util.ArrayList; ...@@ -24,9 +24,9 @@ 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.component.sensor.environment.costs.PropertyBenefitEstimator; import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.costs.PropertyImpactEstimator;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.costs.PropertyBenefitEstimatorFactory; import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.costs.PropertyImpactEstimatorFactory;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.costs.VehicularPropertyCostEstimator; import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.costs.VehicularPropertyImpactEstimator;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.properties.HazardProperty; import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.properties.HazardProperty;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.properties.JamProperty; import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.properties.JamProperty;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.properties.RoadProperty; import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.properties.RoadProperty;
...@@ -36,6 +36,8 @@ import de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.EdgeControll ...@@ -36,6 +36,8 @@ import de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.EdgeControll
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.paths.VehiclePathTrackerFactory; import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.paths.VehiclePathTrackerFactory;
public class RoadNetworkEdge { public class RoadNetworkEdge {
private static final boolean ENABLE_SPEED_ADAPTATION = false;
private String _edgeID; private String _edgeID;
private double _angle; private double _angle;
...@@ -95,6 +97,7 @@ public class RoadNetworkEdge { ...@@ -95,6 +97,7 @@ public class RoadNetworkEdge {
} }
private void adjustMaxSpeed() { private void adjustMaxSpeed() {
if (ENABLE_SPEED_ADAPTATION) {
double maxSpeed = getOriginalMaxSpeed(); double maxSpeed = getOriginalMaxSpeed();
for (RoadProperty roadProperty : _activeProperties) { for (RoadProperty roadProperty : _activeProperties) {
if (roadProperty instanceof JamProperty) { if (roadProperty instanceof JamProperty) {
...@@ -110,6 +113,7 @@ public class RoadNetworkEdge { ...@@ -110,6 +113,7 @@ public class RoadNetworkEdge {
changeEdgeMaxSpeed(maxSpeed); changeEdgeMaxSpeed(maxSpeed);
} }
}
/** /**
* @return * @return
...@@ -330,6 +334,10 @@ public class RoadNetworkEdge { ...@@ -330,6 +334,10 @@ public class RoadNetworkEdge {
} }
public double calculateStandardEdgeCosts() { public double calculateStandardEdgeCosts() {
return calculateStandardDrivingDuration();
}
public double calculateStandardDrivingDuration() {
return VehiclePathTrackerFactory.getVehiclePathTracker().getTravelTime(this); return VehiclePathTrackerFactory.getVehiclePathTracker().getTravelTime(this);
} }
...@@ -345,11 +353,11 @@ public class RoadNetworkEdge { ...@@ -345,11 +353,11 @@ public class RoadNetworkEdge {
if (pProperty != null && pProperty.getDefaultProperty() != null if (pProperty != null && pProperty.getDefaultProperty() != null
&& !propertyEquals(pProperty, pProperty.getDefaultProperty())) { && !propertyEquals(pProperty, pProperty.getDefaultProperty())) {
if (pProperty.getEdge().equals(this)) { if (pProperty.getEdge().equals(this)) {
PropertyBenefitEstimator benefitEstimator = PropertyBenefitEstimatorFactory PropertyImpactEstimator benefitEstimator = PropertyImpactEstimatorFactory
.getPropertyBenefitEstimator(); .getPropertyBenefitEstimator();
if (benefitEstimator instanceof VehicularPropertyCostEstimator) { if (benefitEstimator instanceof VehicularPropertyImpactEstimator) {
additionalCost = ((VehicularPropertyCostEstimator) benefitEstimator) additionalCost = ((VehicularPropertyImpactEstimator) benefitEstimator)
.calculateCostsIfKnown(pProperty); .calculateImpactIfKnown(pProperty);
} else { } else {
throw new AssertionError("VehicularPropertyCostEstimator required!"); throw new AssertionError("VehicularPropertyCostEstimator required!");
} }
...@@ -368,11 +376,11 @@ public class RoadNetworkEdge { ...@@ -368,11 +376,11 @@ public class RoadNetworkEdge {
double additionalCosts = 0; double additionalCosts = 0;
if (pProperty != null && !propertyEquals(pProperty, pProperty.getDefaultProperty())) { if (pProperty != null && !propertyEquals(pProperty, pProperty.getDefaultProperty())) {
if (pProperty.getEdge().equals(this)) { if (pProperty.getEdge().equals(this)) {
PropertyBenefitEstimator benefitEstimator = PropertyBenefitEstimatorFactory PropertyImpactEstimator benefitEstimator = PropertyImpactEstimatorFactory
.getPropertyBenefitEstimator(); .getPropertyBenefitEstimator();
if (benefitEstimator instanceof VehicularPropertyCostEstimator) { if (benefitEstimator instanceof VehicularPropertyImpactEstimator) {
additionalCosts = ((VehicularPropertyCostEstimator) benefitEstimator) additionalCosts = ((VehicularPropertyImpactEstimator) benefitEstimator)
.calculateCostsIfUnknown(pProperty); .calculateImpactIfUnknown(pProperty);
} else { } else {
throw new AssertionError("VehicularPropertyCostEstimator required!"); throw new AssertionError("VehicularPropertyCostEstimator required!");
} }
......
...@@ -155,4 +155,16 @@ public class RoadNetworkRoute implements Iterable<RoadNetworkEdge> { ...@@ -155,4 +155,16 @@ public class RoadNetworkRoute implements Iterable<RoadNetworkEdge> {
} }
return sum; return sum;
} }
public double calculateDrivingDurationTo(RoadNetworkEdge pDestination) {
double sum = 0;
for (int i = 1; i < _route.size(); i++) {
if (!_route.get(i).equals(pDestination)) {
sum += _route.get(i).calculateStandardEdgeCosts();
} else {
break;
}
}
return sum;
}
} }
...@@ -18,29 +18,26 @@ ...@@ -18,29 +18,26 @@
* *
*/ */
package de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.costs; package de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.routing;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.properties.RoadProperty; 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 interface VehicularPropertyCostEstimator extends PropertyBenefitEstimator {
default double calculateCostsIfKnown(RoadProperty pProperty) {
return calculateCostsIfKnown(pProperty.getClass());
}
double calculateCostsIfKnown(Class<? extends RoadProperty> pProperty); import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.RoadInformation;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetworkEdge;
double calculateCostsIfKnown(RoadProperty pProperty, RoadNetworkEdge pDecisionPoint, VehicleCostPreference pVehicle, public class LatestPossibleDijkstraAlgorithm extends DijkstraAlgorithm {
RoadNetworkRoute pPath);
default double calculateCostsIfUnknown(RoadProperty pProperty) { protected double calculateAdditionalEdgeCosts(RoadNetworkEdge pEdge, List<RoadInformation> pInfo,
return calculateCostsIfUnknown(pProperty.getClass()); double pCurrentPathLength, List<RoadNetworkEdge> pCurrentRouteList) {
if (pInfo != null && pCurrentRouteList.size() > 0) {
for (RoadInformation roadInformation : pInfo) {
if (pCurrentRouteList.get(0).equals(roadInformation.getEdge())
|| pCurrentRouteList.get(0).getAccessibleEdges().contains(roadInformation.getEdge())) {
double additionalCostIfKnown = pEdge.calculateAdditionalCostIfKnown(roadInformation.getValue());
return additionalCostIfKnown;
}
}
}
return 0d;
} }
double calculateCostsIfUnknown(Class<? extends RoadProperty> pProperty);
double calculateCostsIfUnknown(RoadProperty pProperty, RoadNetworkEdge pDecisionPoint,
VehicleCostPreference pVehicle, RoadNetworkRoute pPath);
} }
...@@ -5,9 +5,9 @@ import java.util.regex.Pattern; ...@@ -5,9 +5,9 @@ import java.util.regex.Pattern;
import de.tudarmstadt.maki.simonstrator.api.Host; import de.tudarmstadt.maki.simonstrator.api.Host;
import de.tudarmstadt.maki.simonstrator.api.component.pubsub.PubSubComponent; import de.tudarmstadt.maki.simonstrator.api.component.pubsub.PubSubComponent;
import de.tudarmstadt.maki.simonstrator.api.component.pubsub.attribute.Topic; import de.tudarmstadt.maki.simonstrator.api.component.pubsub.attribute.Topic;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.costs.PropertyBenefitEstimator; import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.costs.PropertyImpactEstimator;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.costs.PropertyBenefitEstimatorFactory; import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.costs.PropertyImpactEstimatorFactory;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.costs.VehicularPropertyCostEstimator; import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.costs.VehicularPropertyImpactEstimator;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.PointInformation; import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.PointInformation;
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.subscriptions.SubscriptionTopicType; import de.tudarmstadt.maki.simonstrator.api.component.vehicular.subscriptions.SubscriptionTopicType;
...@@ -45,9 +45,9 @@ public class CostBasedTopic implements ProcessedTopic, Comparable<CostBasedTopic ...@@ -45,9 +45,9 @@ public class CostBasedTopic implements ProcessedTopic, Comparable<CostBasedTopic
public boolean matchesInformationRequirements(PointInformation<?> pInformation) { public boolean matchesInformationRequirements(PointInformation<?> pInformation) {
if (pInformation instanceof RoadInformation) { if (pInformation instanceof RoadInformation) {
RoadInformation roadInfo = (RoadInformation) pInformation; RoadInformation roadInfo = (RoadInformation) pInformation;
PropertyBenefitEstimator costEstimator = PropertyBenefitEstimatorFactory.getPropertyBenefitEstimator(); PropertyImpactEstimator costEstimator = PropertyImpactEstimatorFactory.getPropertyBenefitEstimator();
double costsForMissingInformation = ((VehicularPropertyCostEstimator) costEstimator) double costsForMissingInformation = ((VehicularPropertyImpactEstimator) costEstimator)
.calculateCostsIfUnknown(roadInfo.getValue()); .calculateImpactIfUnknown(roadInfo.getValue());
if (costsForMissingInformation >= _costs) { if (costsForMissingInformation >= _costs) {
return true; return true;
......
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