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

Working version for attacker scenario

parent 1f25a59c
......@@ -187,7 +187,7 @@ public abstract class AbstractQoIBasedImpactFunction<T extends PointInformation>
return (1 - errorProbability) / pNumberOfMessages * age + errorProbability;
} else if (b == Double.NEGATIVE_INFINITY) {
if (pMessageNumber == pNumberOfMessages) {
return 1;
return 1 - errorProbability;
} else {
return 0;
}
......
......@@ -22,6 +22,7 @@
package de.tudarmstadt.maki.simonstrator.api.component.sensor.environment;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import de.tudarmstadt.maki.simonstrator.api.Host;
......@@ -57,6 +58,10 @@ public class ExtendableEnvironmentSensor implements EnvironmentSensor {
public void shutdown() {
}
public List<EnvironmentSensorPlugin> getPlugins() {
return Collections.unmodifiableList(_plugins);
}
@Override
public Environment getEnvironment() {
return getEnvironment(new Class[0]);
......
......@@ -118,4 +118,6 @@ public abstract class AbstractRoadProperty implements RoadProperty, AggregatedPr
public boolean isDetourable() {
return false;
}
public abstract AbstractRoadProperty clone();
}
......@@ -28,7 +28,8 @@ import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.Road
* @version 1.0 at 27.02.2018
*
*/
public interface RoadProperty extends LocationBasedEnvironmentProperty, AggregatedProperty, Comparable<RoadProperty> {
public interface RoadProperty
extends LocationBasedEnvironmentProperty, AggregatedProperty, Comparable<RoadProperty>, Cloneable {
RoadNetworkEdge getEdge();
void setEdge(RoadNetworkEdge pEdge);
......@@ -42,4 +43,6 @@ public interface RoadProperty extends LocationBasedEnvironmentProperty, Aggregat
boolean equalLocation(RoadProperty pRoadProperty);
boolean isDetourable();
RoadProperty clone();
}
......@@ -58,4 +58,9 @@ public class VehicleProperty extends AbstractRoadProperty {
return null;
}
@Override
public VehicleProperty clone() {
return new VehicleProperty(_id, getLocation(), getEdge(), _speed);
}
}
......@@ -33,9 +33,7 @@ import de.tudarmstadt.maki.simonstrator.api.component.relevance.path.PathPredict
import de.tudarmstadt.maki.simonstrator.api.component.relevance.path.PathPredictionContainer;
import de.tudarmstadt.maki.simonstrator.api.component.relevance.path.StatisticalRoadNetworkRoute;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.LocationBasedEnvironmentProperty;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.costs.PropertyBenefitEstimator;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.costs.PropertyBenefitEstimatorFactory;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.costs.VehicularPropertyCostEstimator;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.RoadProperty;
import de.tudarmstadt.maki.simonstrator.api.component.sis.SiSComponent;
import de.tudarmstadt.maki.simonstrator.api.component.sis.SiSRequest;
import de.tudarmstadt.maki.simonstrator.api.component.sis.exception.InformationNotAvailableException;
......@@ -77,18 +75,23 @@ public class DecisionBasedVehicularBenefitEstimator implements BenefitEstimator
@Override
public double calculateBenefit(NodeProperties pProperties, Notification pNotification) {
try {
SiSComponent sis = getHost().getComponent(SiSComponent.class);
RoadNetworkEdge currentLocation = sis.get().localObservationOf(pProperties.getId(), SiSTypes.ROAD_EDGE,
SiSRequest.NONE);
EnvironmentInformation<? extends LocationBasedEnvironmentProperty> environmentInformation = EnvironmentInformation
.createFromNotification(pNotification);
if (environmentInformation instanceof RoadInformation) {
RoadInformation roadInformation = (RoadInformation) environmentInformation;
if (pProperties.getId().value() == 171L
&& roadInformation.getValue().toString().equals("HazardProperty@39cbe4a9")) {
System.out.println();
}
PathPredictionComponent pathPredictionComponent = getHost().getComponent(PathPredictionComponent.class);
RoadNetworkEdge currentLocation = sis.get().localObservationOf(pProperties.getId(), SiSTypes.ROAD_EDGE,
SiSRequest.NONE);
PathPredictionContainer predictionContainer = pathPredictionComponent
.findPossiblePathsOverRoad(currentLocation, roadInformation.getEdge(), 3);
......@@ -111,85 +114,70 @@ public class DecisionBasedVehicularBenefitEstimator implements BenefitEstimator
costGraph.createCostGraph(depth);
_costGraphs.put(roadInformation, costGraph);
}
CostGraph costGraph = _costGraphs.get(roadInformation
);
CostGraph costGraph = _costGraphs.get(roadInformation);
RoadNetworkEdge start = networkRoute.getStart();
RoadNetworkRoute optimalRoute = costGraph.getOptimalRoute(start);
if (optimalRoute != null) {
double optimalCost = 0;
for (RoadNetworkEdge edge : optimalRoute.getRoute()) {
optimalCost += costGraph.calculateEdgeCost(edge);
}
int equalAmount = 3;
double currentCost = 0;
for (RoadNetworkEdge edge : networkRoute.getRoute()) {
currentCost += costGraph.calculateEdgeCost(edge);
}
if (optimalRoute == null) {
optimalRoute = networkRoute;
}
double originalRouteCostIfInformationKnown = 0;
for (RoadNetworkEdge edge : networkRoute.getRoute()) {
originalRouteCostIfInformationKnown += edge
.calculateEdgeCostIfKnown(roadInformation.getValue());
}
double originalRouteCostIfInformationUnknown = 0;
for (RoadNetworkEdge edge : networkRoute.getRoute()) {
originalRouteCostIfInformationUnknown += edge
.calculateEdgeCostIfUnknown(roadInformation.getValue());
}
double newRouteCostIfInformationKnown = 0;
for (RoadNetworkEdge edge : optimalRoute.getRoute()) {
newRouteCostIfInformationKnown += edge.calculateEdgeCostIfKnown(roadInformation.getValue());
}
double newRouteCostIfInformationUnknown = 0;
for (RoadNetworkEdge edge : optimalRoute.getRoute()) {
newRouteCostIfInformationUnknown += edge
.calculateEdgeCostIfUnknown(roadInformation.getValue());
}
RoadNetworkEdge decisionPoint = roadInformation.getEdge();
double decisionBenefit = originalRouteCostIfInformationUnknown
- originalRouteCostIfInformationKnown;
for (int i = 1; i < Math.min(optimalRoute.getRoute().size(),
networkRoute.getRoute().size()); i++) {
if (!optimalRoute.getRoute().get(i).equals(networkRoute.getRoute().get(i))) {
double benefit;
if (optimalRoute.getRoute().indexOf(roadInformation.getEdge()) < equalAmount) {
benefit = originalRouteCostIfInformationUnknown - newRouteCostIfInformationKnown;
} else {
benefit = originalRouteCostIfInformationUnknown - newRouteCostIfInformationUnknown;
}
int equalAmount = 2;
for (int i = 0; i < equalAmount + 1; i++) {
boolean setCosts = i < optimalRoute.getRoute().size()
^ i < networkRoute.getRoute().size();
setCosts |= i < optimalRoute.getRoute().size()
&& !optimalRoute.getRoute().get(i).equals(networkRoute.getRoute().get(i));
if (setCosts) {
expectedBenefit += Math.max(currentCost - optimalCost, 0)
* statisticalRoute.getProbability();
break;
if (benefit > decisionBenefit) {
decisionPoint = optimalRoute.getRoute().get(i - 1);
decisionBenefit = benefit;
}
break;
}
}
if (optimalRoute.getRoute().indexOf(decisionPoint) < equalAmount) {
expectedBenefit += decisionBenefit * statisticalRoute.getProbability();
} else {
return 0;
}
}
}
// PathPredictionContainer predictionContainer = pathPredictionComponent.findPossiblePathsOverRoad(
// sis.get().localObservationOf(pProperties.getId(), SiSTypes.ROAD_EDGE, SiSRequest.NONE),
// roadInformation.getEdge(), 3);
//
// PropertyBenefitEstimator benefitEstimator = PropertyBenefitEstimatorFactory
// .getPropertyBenefitEstimator();
// List<DecisionPoint> decisionPoints = benefitEstimator.getDecisionPoints(pNotification);
// Map<RoadNetworkEdge, VehicularDecisionPoint> decisionPointsByEdge = new HashMap<>();
// for (DecisionPoint decisionPoint : decisionPoints) {
// if (decisionPoint instanceof VehicularDecisionPoint) {
// decisionPointsByEdge.put(((VehicularDecisionPoint) decisionPoint).getDecisionPoint(),
// (VehicularDecisionPoint) decisionPoint);
// } else {
// throw new AssertionError("Only VehicularDecisionPoints allowed!");
// }
// }
//
// double expectedBenefit = 0;
// List<StatisticalRoadNetworkRoute> routes = predictionContainer.getRoutes();
// for (StatisticalRoadNetworkRoute statisticalRoute : routes) {
// double probability = statisticalRoute.getProbability();
// RoadNetworkRoute route = statisticalRoute.getPath();
//
// double maxBenefit = 0;
// for (RoadNetworkEdge edge : route.getRoute()) {
// if (decisionPointsByEdge.containsKey(edge)) {
// VehicularDecisionPoint decisionPoint = decisionPointsByEdge.get(edge);
// if (decisionPoint instanceof VehicularDetouringDecisionPoint) {
// VehicularDetouringDecisionPoint detouring = (VehicularDetouringDecisionPoint) decisionPoint;
// double benefit = detouring.calculateBenefit(route);
// double overhead = detouring.calculateOverhead(route);
// if (benefit > maxBenefit) {
// maxBenefit = benefit;
// }
// } else {
// double benefit = decisionPoint.getBenefit();
// if (benefit > maxBenefit) {
// maxBenefit = benefit;
// }
// }
// }
// }
// expectedBenefit += probability * maxBenefit;
// }
return expectedBenefit;
} else {
throw new AssertionError("RoadInformation required for this benefit estimator!");
......@@ -244,29 +232,12 @@ public class DecisionBasedVehicularBenefitEstimator implements BenefitEstimator
return null;
}
public double calculateEdgeCost(RoadNetworkEdge pEdge) {
if (pEdge.equals(_destination)) {
return 0;
}
double edgeCost = pEdge.getLength() / pEdge.getOriginalMaxSpeed();
public void createCostGraph(int pMaxDepth) {
RoadProperty property = null;
if (_information != null) {
if (_information.getEdge().equals(pEdge)) {
PropertyBenefitEstimator benefitEstimator = PropertyBenefitEstimatorFactory
.getPropertyBenefitEstimator();
if (benefitEstimator instanceof VehicularPropertyCostEstimator) {
edgeCost += ((VehicularPropertyCostEstimator) benefitEstimator)
.calculateCostsIfKnown(_information.getValue());
} else {
throw new AssertionError("VehicularPropertyCostEstimator required!");
}
}
property = _information.getValue();
}
return edgeCost;
}
public void createCostGraph(int pMaxDepth) {
if (_information != null) {
long duration = _information.getAttribute(AvailableInformationAttributes.EXPECTED_DURATION);
double existProbability = 1 - 1 / (double) (duration / Time.SECOND);
......@@ -282,7 +253,7 @@ public class DecisionBasedVehicularBenefitEstimator implements BenefitEstimator
continue;
}
double edgeCost = calculateEdgeCost(incomingEdge);
double edgeCost = incomingEdge.calculateEdgeCostIfKnown(property);
double eventActiveCost = _costGraph.get(roadNetworkEdge);
double eventInactiveCost = _costGraphWithoutEvent.get(roadNetworkEdge);
......@@ -305,7 +276,7 @@ public class DecisionBasedVehicularBenefitEstimator implements BenefitEstimator
for (RoadNetworkEdge roadNetworkEdge : labeledEdges) {
List<RoadNetworkEdge> incomingEdges = roadNetworkEdge.getIncomingEdges();
for (RoadNetworkEdge incomingEdge : incomingEdges) {
double edgeCost = calculateEdgeCost(incomingEdge);
double edgeCost = incomingEdge.calculateEdgeCostIfKnown(property);
double totalCosts = _costGraph.get(roadNetworkEdge) + edgeCost;
if (!_costGraph.containsKey(incomingEdge) || totalCosts < _costGraph.get(incomingEdge)) {
_costGraph.put(incomingEdge, totalCosts);
......
......@@ -54,4 +54,9 @@ public class BumpProperty extends AbstractRoadProperty {
return hasBump();
}
@Override
public BumpProperty clone() {
return new BumpProperty(getLocation(), getEdge(), _bump);
}
}
......@@ -51,13 +51,13 @@ public class DefaultVehicularPropertyCostEstimator implements VehicularPropertyC
@Override
public double calculateCostsIfKnown(Class<? extends RoadProperty> pProperty) {
if (pProperty.equals(JamProperty.class)) {
return Math.pow(10, 4);
return Math.pow(10, 2);
} else if (pProperty.equals(BumpProperty.class)) {
return Math.pow(10, -2);
return 0;
} else if (pProperty.equals(HazardProperty.class)) {
return Math.pow(10, 6);
return Math.pow(10, 4);
}
return 1;
return 0.01;
}
@Override
......@@ -164,13 +164,13 @@ public class DefaultVehicularPropertyCostEstimator implements VehicularPropertyC
@Override
public double calculateCostsIfUnknown(Class<? extends RoadProperty> pProperty) {
if (pProperty.equals(JamProperty.class)) {
return Math.pow(10, 2);
return Math.pow(10, 4);
} else if (pProperty.equals(BumpProperty.class)) {
return 0;
return Math.pow(10, -2);
} else if (pProperty.equals(HazardProperty.class)) {
return Math.pow(10, 4);
return Math.pow(10, 6);
}
return 0.01;
return 1;
}
@Override
......
......@@ -53,4 +53,9 @@ public class FogProperty extends AbstractRoadProperty {
public Object getValue() {
return hasFog();
}
@Override
public FogProperty clone() {
return new FogProperty(getLocation(), getEdge(), _fog);
}
}
......@@ -59,4 +59,9 @@ public class HazardProperty extends AbstractRoadProperty {
return true;
}
@Override
public HazardProperty clone() {
return new HazardProperty(getLocation(), getEdge(), _hazard);
}
}
......@@ -91,4 +91,9 @@ public class JamProperty extends AbstractRoadProperty {
return getAverageSpeed();
}
@Override
public JamProperty clone() {
return new JamProperty(getLocation(), getEdge(), _jammed, _averageSpeed);
}
}
......@@ -69,7 +69,7 @@ public class VectoralJamProperty extends NumericVectoralProperty {
// pAccuracy);
// break;
case GAUSSIAN:
setGaussianWithAccuracy(pSpeed / VectoralJamProperty.SCALING, pAccuracy);
setGaussianWithAccuracy(Math.min(pSpeed / VectoralJamProperty.SCALING, DIMENSIONS - 1), pAccuracy);
break;
default:
throw new AssertionError("Unknown ProbablilityDistribution " + pDist);
......
......@@ -53,4 +53,9 @@ public class RainProperty extends AbstractRoadProperty {
public Object getValue() {
return hasRain();
}
@Override
public RainProperty clone() {
return new RainProperty(getLocation(), getEdge(), _rain);
}
}
......@@ -62,4 +62,9 @@ public class RoadConditionProperty extends AbstractRoadProperty {
return new RoadConditionProperty(getLocation(), getEdge(), RoadCondition.DRY);
}
@Override
public RoadConditionProperty clone() {
return new RoadConditionProperty(getLocation(), getEdge(), _roadCondition);
}
}
......@@ -53,4 +53,9 @@ public class TrafficSignProperty extends AbstractRoadProperty {
public Object getValue() {
return hasSign();
}
@Override
public TrafficSignProperty clone() {
return new TrafficSignProperty(getLocation(), getEdge(), _sign);
}
}
......@@ -92,4 +92,8 @@ public class MaliciousEnvironmentSensorPlugin implements EnvironmentSensorPlugin
_badPlugin.setHost(pHost);
}
public boolean isMalicious() {
return _isMalicious;
}
}
......@@ -129,7 +129,7 @@ public class MaliciousVectoralJamEnvironmentSensorPlugin implements EnvironmentS
double measuredSpeed = measureValue(speed);
if (_valueOffset != 0) {
measuredSpeed *= (1 + _valueOffset);
measuredSpeed += _valueOffset;
}
VectoralJamProperty vectoralJamProperty = new VectoralJamProperty(location, edge);
......
......@@ -22,6 +22,7 @@ package de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching;
import java.util.List;
import de.tudarmstadt.maki.simonstrator.api.common.graph.INodeID;
import de.tudarmstadt.maki.simonstrator.api.component.HostComponent;
import de.tudarmstadt.maki.simonstrator.api.component.overlay.NodeInformation;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.decision.CacheDecisionStrategy;
......@@ -40,6 +41,9 @@ public interface CachingComponent extends HostComponent, NodeInformation {
<T extends PointInformation> List<T> getDecidedCacheEntries(Class<T> pCacheEntryClass, Class<?> pCacheValueClass,
RoadNetworkEdge pEdge);
<T extends PointInformation> List<T> getDecidedCacheEntries(Class<T> pCacheEntryClass, Class<?> pCacheValueClass,
RoadNetworkEdge pEdge, INodeID pWithoutID);
<T extends PointInformation> boolean containsEntry(T pCacheEntry);
<T extends PointInformation> void storeCacheEntry(T pCacheEntry);
......@@ -65,4 +69,5 @@ public interface CachingComponent extends HostComponent, NodeInformation {
void setMaxSize(int pMaxCacheSize);
void registerCacheStateListener(CacheStateListener pListener);
}
......@@ -25,6 +25,9 @@ import java.util.Collections;
import java.util.List;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.RoadProperty;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.costs.PropertyBenefitEstimator;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.costs.PropertyBenefitEstimatorFactory;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.costs.VehicularPropertyCostEstimator;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.hazard.HazardProperty;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.jam.JamProperty;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.jam.VectoralJamProperty;
......@@ -103,6 +106,7 @@ public class RoadNetworkEdge {
}
}
}
setMaxSpeed(maxSpeed);
}
......@@ -323,4 +327,54 @@ public class RoadNetworkEdge {
}
return false;
}
public double calculateStandardEdgeCosts() {
return getLength() / getOriginalMaxSpeed();
}
public double calculateEdgeCostIfKnown(RoadProperty pProperty) {
double edgeCost = calculateStandardEdgeCosts();
edgeCost = calculateAdditionalCostIfKnown(pProperty);
return edgeCost;
}
public double calculateAdditionalCostIfKnown(RoadProperty pProperty) throws AssertionError {
double additionalCost = 0;
if (pProperty != null) {
if (pProperty.getEdge().equals(this)) {
PropertyBenefitEstimator benefitEstimator = PropertyBenefitEstimatorFactory
.getPropertyBenefitEstimator();
if (benefitEstimator instanceof VehicularPropertyCostEstimator) {
additionalCost = ((VehicularPropertyCostEstimator) benefitEstimator)
.calculateCostsIfKnown(pProperty);
} else {
throw new AssertionError("VehicularPropertyCostEstimator required!");
}
}
}
return additionalCost;
}
public double calculateEdgeCostIfUnknown(RoadProperty pProperty) {
double edgeCost = calculateStandardEdgeCosts();
edgeCost += calculateAdditionalCostIfUnknown(pProperty);
return edgeCost;
}
public double calculateAdditionalCostIfUnknown(RoadProperty pProperty) throws AssertionError {
double additionalCosts = 0;
if (pProperty != null) {
if (pProperty.getEdge().equals(this)) {
PropertyBenefitEstimator benefitEstimator = PropertyBenefitEstimatorFactory
.getPropertyBenefitEstimator();
if (benefitEstimator instanceof VehicularPropertyCostEstimator) {
additionalCosts = ((VehicularPropertyCostEstimator) benefitEstimator)
.calculateCostsIfUnknown(pProperty);
} else {
throw new AssertionError("VehicularPropertyCostEstimator required!");
}
}
}
return additionalCosts;
}
}
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