Commit 1f25a59c authored by Tobias Meuser's avatar Tobias Meuser
Browse files

Added stuff for Dennis

parent 3c79589c
/*
* 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.plugin;
import java.util.List;
import java.util.Random;
import de.tudarmstadt.maki.simonstrator.api.Host;
import de.tudarmstadt.maki.simonstrator.api.Randoms;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.EnvironmentProperty;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.RoadProperty;
public class MaliciousEnvironmentSensorPlugin implements EnvironmentSensorPlugin {
private static final Random RANDOM = Randoms.getRandom(MaliciousEnvironmentSensorPlugin.class);
private EnvironmentSensorPlugin _goodPlugin;
private EnvironmentSensorPlugin _badPlugin;
private boolean _isMalicious = false;
private double _probability;
public void setMaliciousProbability(double pProbability) {
_probability = pProbability;
if (RANDOM.nextDouble() < _probability) {
_isMalicious = true;
} else {
_isMalicious = false;
}
}
public void setGoodPlugin(EnvironmentSensorPlugin pGoodPlugin) {
_goodPlugin = pGoodPlugin;
if (_badPlugin != null && !_badPlugin.getSupportedClass().equals(_goodPlugin.getSupportedClass())) {
throw new AssertionError("Both plugins need to provide the same data entry.");
}
}
public void setBadPlugin(EnvironmentSensorPlugin pBadPlugin) {
_badPlugin = pBadPlugin;
if (_goodPlugin != null && !_badPlugin.getSupportedClass().equals(_goodPlugin.getSupportedClass())) {
throw new AssertionError("Both plugins need to provide the same data entry.");
}
}
@Override
public List<EnvironmentProperty> getEnvironmentProperties() {
if (_isMalicious) {
return _badPlugin.getEnvironmentProperties();
} else {
return _goodPlugin.getEnvironmentProperties();
}
}
@Override
public EnvironmentSensorPlugin clone() throws CloneNotSupportedException {
MaliciousEnvironmentSensorPlugin maliciousEnvironmentSensorPlugin = new MaliciousEnvironmentSensorPlugin();
maliciousEnvironmentSensorPlugin.setGoodPlugin(_goodPlugin.clone());
maliciousEnvironmentSensorPlugin.setBadPlugin(_badPlugin.clone());
maliciousEnvironmentSensorPlugin.setMaliciousProbability(_probability);
return maliciousEnvironmentSensorPlugin;
}
@Override
public Class<? extends RoadProperty> getSupportedClass() {
return _goodPlugin.getSupportedClass();
}
@Override
public void setHost(Host pHost) {
_goodPlugin.setHost(pHost);
_badPlugin.setHost(pHost);
}
}
/*
* 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.plugin;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import de.tudarmstadt.maki.simonstrator.api.Host;
import de.tudarmstadt.maki.simonstrator.api.Randoms;
import de.tudarmstadt.maki.simonstrator.api.component.ComponentNotAvailableException;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.EnvironmentProperty;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.ProbabilityDistribution;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.RoadProperty;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.jam.JamProperty;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.jam.VectoralJamProperty;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.measurement.MeasurementDistributionTypeContainer;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
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;
import de.tudarmstadt.maki.simonstrator.api.component.sis.type.SiSTypes;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetworkEdge;
import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
/**
* @author Tobias Meuser (tobias.meuser@kom.tu-darmstadt.de)
* @version 1.0 at 27.02.2018
*
*/
public class MaliciousVectoralJamEnvironmentSensorPlugin implements EnvironmentSensorPlugin {
private Host _host;
private SiSComponent _sis;
private double _accuracy;
private final double _originalAccuracy;
private final double _maxDeviation;
private double _valueOffset;
private double _communicatedAccuracy;
private static Random _random = Randoms.getRandom(MaliciousVectoralJamEnvironmentSensorPlugin.class);
private static Random _accuracyRandom = Randoms.getRandom(MaliciousVectoralJamEnvironmentSensorPlugin.class + "Accuracy");
@XMLConfigurableConstructor({ "accuracy", "dist_type", "max_deviation", "value_offset", "communicated_accuracy" })
public MaliciousVectoralJamEnvironmentSensorPlugin(double pAccuracy, String pDist, double pMaxDeviation,
double pValueOffset, double pCommunicatedAccuracy) {
_originalAccuracy = pAccuracy;
_maxDeviation = pMaxDeviation;
double deviation = pMaxDeviation * pAccuracy;
int upperBound = 1;
double lowerBound = 0.4;
if (deviation + pAccuracy > upperBound) {
deviation = upperBound - pAccuracy;
}
if (pAccuracy - deviation < lowerBound) {
deviation = pAccuracy - lowerBound;
}
double accuracy = pAccuracy + _accuracyRandom.nextGaussian() * deviation;
if (accuracy < pAccuracy - deviation) {
accuracy = pAccuracy - deviation;
}
if (accuracy > pAccuracy + deviation) {
accuracy = pAccuracy + deviation;
}
setAccuracy(accuracy);
_valueOffset = pValueOffset;
_communicatedAccuracy = pCommunicatedAccuracy;
MeasurementDistributionTypeContainer.setDistribution(VectoralJamProperty.class,
ProbabilityDistribution.valueOf(pDist));
}
@Override
public void setHost(Host pHost) {
_host = pHost;
}
@Override
public List<EnvironmentProperty> getEnvironmentProperties() {
if (_sis == null) {
try {
_sis = _host.getComponent(SiSComponent.class);
} catch (ComponentNotAvailableException e) {
throw new AssertionError("SiS requried!", e);
}
}
try {
RoadNetworkEdge edge = _sis.get().localState(SiSTypes.ROAD_EDGE, SiSRequest.NONE);
Location location = _sis.get().localState(SiSTypes.PHY_LOCATION, SiSRequest.NONE);
double speed = -1;
for (RoadProperty roadProperty : edge.getActiveProperties()) {
if (roadProperty instanceof JamProperty) {
speed = ((JamProperty) roadProperty).getAverageSpeed();
}
}
if (speed == -1) {
speed = edge.getOriginalMaxSpeed();
}
double measuredSpeed = measureValue(speed);
if (_valueOffset != 0) {
measuredSpeed *= (1 + _valueOffset);
}
VectoralJamProperty vectoralJamProperty = new VectoralJamProperty(location, edge);
if (_communicatedAccuracy == 0) {
vectoralJamProperty.setSpeed(measuredSpeed, _accuracy,
MeasurementDistributionTypeContainer.getDistribution(VectoralJamProperty.class));
} else {
vectoralJamProperty.setSpeed(measuredSpeed, _communicatedAccuracy,
MeasurementDistributionTypeContainer.getDistribution(VectoralJamProperty.class));
}
List<EnvironmentProperty> properties = new ArrayList<>();
EnvironmentProperty property = vectoralJamProperty;
properties.add(property);
return properties;
} catch (InformationNotAvailableException e) {
throw new AssertionError(SiSTypes.ROAD_EDGE + " and " + SiSTypes.PHY_LOCATION + " are required!");
}
}
public double measureValue(double pRealSpeed) {
VectoralJamProperty vectoralJamProperty = new VectoralJamProperty(null, null);
vectoralJamProperty.setSpeed(pRealSpeed, _accuracy,
MeasurementDistributionTypeContainer.getDistribution(VectoralJamProperty.class));
double nextDouble = _random.nextDouble();
double currentAggregate = 0;
for (int i = 0; i < vectoralJamProperty.getValueProbabilities().length; i++) {
currentAggregate += vectoralJamProperty.getValueProbabilities()[i];
if (currentAggregate > nextDouble) {
return vectoralJamProperty.getValueAtIndex(i);
}
}
throw new AssertionError("Unexpected!");
}
@Override
public Class<? extends RoadProperty> getSupportedClass() {
return JamProperty.class;
}
@Override
public MaliciousVectoralJamEnvironmentSensorPlugin clone() throws CloneNotSupportedException {
return new MaliciousVectoralJamEnvironmentSensorPlugin(_originalAccuracy,
MeasurementDistributionTypeContainer.getDistribution(VectoralJamProperty.class).toString(),
_maxDeviation, _valueOffset, _communicatedAccuracy);
}
public void setAccuracy(double pAccuracy) {
_accuracy = pAccuracy;
}
}
......@@ -29,7 +29,7 @@ public enum AvailableInformationAttributes {
POSITION("position", Location.class), DATE("date", Long.class), VALUE("value"), OWNER("owner", INodeID.class), EDGE(
"edge", RoadNetworkEdge.class), TTL(
"ttl", Long.class), EXPECTED_DURATION(
"duration"), STANDARD_DEVIATION_DURATION(
"duration", Long.class), STANDARD_DEVIATION_DURATION(
"sd_duration"), TYPE("type", SiSType.class), COST("cost", Double.class);
private final String attributeID;
......
......@@ -25,6 +25,7 @@ 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.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;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
......@@ -82,15 +83,29 @@ public class RoadNetworkEdge {
public void addRoadProperty(RoadProperty pProperty) {
_activeProperties.add(pProperty);
if (pProperty instanceof JamProperty) {
setMaxSpeed(((JamProperty) pProperty).getAverageSpeed());
}
adjustMaxSpeed();
for (RoadNetworkEdgeListener roadNetworkEdgeListener : _listeners) {
roadNetworkEdgeListener.edgeActivated(this, pProperty);
}
}
private void adjustMaxSpeed() {
double maxSpeed = getOriginalMaxSpeed();
for (RoadProperty roadProperty : _activeProperties) {
if (roadProperty instanceof JamProperty) {
if (((JamProperty) roadProperty).getAverageSpeed() < maxSpeed) {
maxSpeed = ((JamProperty) roadProperty).getAverageSpeed();
}
} else if (roadProperty instanceof HazardProperty) {
if (0.001 < maxSpeed) {
maxSpeed = 0.001;
}
}
}
setMaxSpeed(maxSpeed);
}
/**
* @return
*/
......@@ -131,9 +146,7 @@ public class RoadNetworkEdge {
public void removeRoadProperty(RoadProperty pProperty) {
_activeProperties.remove(pProperty);
if (pProperty instanceof JamProperty) {
setMaxSpeed(getOriginalMaxSpeed());
}
adjustMaxSpeed();
for (RoadNetworkEdgeListener roadNetworkEdgeListener : _listeners) {
roadNetworkEdgeListener.edgeDeactivated(this, pProperty);
......
......@@ -24,6 +24,9 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.paths.VehiclePathTracker;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.paths.VehiclePathTrackerFactory;
public class RoadNetworkRoute {
private List<RoadNetworkEdge> _route;
......@@ -107,10 +110,12 @@ public class RoadNetworkRoute {
* @return
*/
public double getTravelTime() {
VehiclePathTracker tracker = VehiclePathTrackerFactory.getVehiclePathTracker();
double time = 0;
for (RoadNetworkEdge roadNetworkEdge : _route) {
time += roadNetworkEdge.getLength() / roadNetworkEdge.getMaxSpeed();
for (int i = 0; i < _route.size() - 1; i++) {
time += tracker.getTravelTime(_route.get(i), _route.get(i + 1));
}
time += _route.get(_route.size() - 1).getLength() / _route.get(_route.size() - 1).getMaxSpeed();
return time;
}
......
......@@ -30,6 +30,8 @@ import java.util.Queue;
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;
public class DijkstraAlgorithm implements RoutingAlgorithm {
private final double MAX_DEPTH_RATIO = 1.2;
......@@ -54,6 +56,7 @@ public class DijkstraAlgorithm implements RoutingAlgorithm {
segments.add(pCurrentPosition);
return new RoadNetworkRoute(segments);
}
VehiclePathTracker tracker = VehiclePathTrackerFactory.getVehiclePathTracker();
List<RoadNetworkEdge> visitedEdges = new ArrayList<>();
Queue<PathInformation> buffer = new PriorityQueue<>(new PathInformationComparator());
......@@ -91,7 +94,7 @@ public class DijkstraAlgorithm implements RoutingAlgorithm {
List<RoadNetworkEdge> accessibleEdges = edge.getAccessibleEdges();
for (RoadNetworkEdge roadNetworkEdge : accessibleEdges) {
double edgeLength = roadNetworkEdge.getLength() / (double) roadNetworkEdge.getMaxSpeed();
double edgeLength = tracker.getTravelTime(edge, roadNetworkEdge);
if (roadNetworkEdge.equals(pDestination)) {
PathInformation childPathInformation = new PathInformation(roadNetworkEdge, pathInformation,
......
......@@ -5,8 +5,8 @@ import java.util.regex.Pattern;
import de.tudarmstadt.maki.simonstrator.api.Host;
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.sensor.environment.data.costs.PropertyCostEstimator;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.costs.PropertyCostEstimatorFactory;
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.vehicular.information.PointInformation;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.RoadInformation;
......@@ -45,9 +45,9 @@ public class CostBasedTopic implements ProcessedTopic, Comparable<CostBasedTopic
public boolean matchesInformationRequirements(PointInformation<?> pInformation) {
if (pInformation instanceof RoadInformation) {
RoadInformation roadInfo = (RoadInformation) pInformation;
PropertyCostEstimator costEstimator = PropertyCostEstimatorFactory.getPropertyCostEstimator();
PropertyBenefitEstimator costEstimator = PropertyBenefitEstimatorFactory.getPropertyBenefitEstimator();
double costsForMissingInformation = ((VehicularPropertyCostEstimator) costEstimator)
.calculateCosts(roadInfo.getValue());
.calculateCostsIfUnknown(roadInfo.getValue());
if (costsForMissingInformation >= _costs) {
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