Commit 040822f5 authored by Tobias Meuser's avatar Tobias Meuser
Browse files

First version for privacy-aware offloading

parent 18180bef
/*
* 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.privacy;
import de.tudarmstadt.maki.simonstrator.api.Host;
import de.tudarmstadt.maki.simonstrator.api.component.HostComponent;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
public class PrivacyComponent implements HostComponent {
private Host _host;
private PrivacyLevel _privacy = PrivacyLevel.NO_PRIVACY;
public PrivacyComponent(Host pHost) {
_host = pHost;
}
public void setPrivacy(PrivacyLevel pLevel) {
_privacy = pLevel;
}
@Override
public void initialize() {
}
@Override
public void shutdown() {
}
@Override
public Host getHost() {
return _host;
}
public Location obscureLocation(Location pLocation) {
Location location = pLocation.clone();
location.setAccuracy(_privacy.getImprecisionAreaRadius());
return location;
}
public PrivacyLevel getPrivacyLevel() {
return _privacy;
}
}
/*
* 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.privacy;
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.HostComponent;
import de.tudarmstadt.maki.simonstrator.api.component.HostComponentFactory;
import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
public class PrivacyComponentFactory implements HostComponentFactory {
private List<PrivacyLevelFrequency> _levels = new ArrayList<>();
private double _sum = 0;
private Random _random = Randoms.getRandom(getClass());
@Override
public HostComponent createComponent(Host pHost) {
PrivacyLevel level = PrivacyLevel.NO_PRIVACY;
double randomValue = _random.nextDouble() * _sum;
double count = 0;
for (int i = 0; i < _levels.size(); i++) {
count += _levels.get(i).getProbability();
if (count > randomValue) {
level = _levels.get(i).getLevel();
break;
}
}
PrivacyComponent privacyComponent = new PrivacyComponent(pHost);
privacyComponent.setPrivacy(level);
return privacyComponent;
}
public void setPrivacyFrequency(PrivacyLevelFrequency pPrivacyLevel) {
_levels.add(pPrivacyLevel);
_sum += pPrivacyLevel.getProbability();
PrivacyLevel.PRIVACY_LEVELS.add(pPrivacyLevel.getLevel());
}
public static class PrivacyLevelFrequency {
private PrivacyLevel _level;
private double _probability;
@XMLConfigurableConstructor({ "privacy", "probability" })
public PrivacyLevelFrequency(PrivacyLevel pLevel, double pProbability) {
_level = pLevel;
_probability = pProbability;
}
public double getProbability() {
return _probability;
}
public PrivacyLevel getLevel() {
return _level;
}
}
}
package de.tudarmstadt.maki.simonstrator.api.component.privacy;
import java.util.ArrayList;
import java.util.List;
import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
public class PrivacyLevel implements Comparable<PrivacyLevel> {
public static final PrivacyLevel NO_PRIVACY = new PrivacyLevel(0);
public static final List<PrivacyLevel> PRIVACY_LEVELS = new ArrayList<>();
private static int staticID = 0;
private final int id;
private double imprecisionAreaRadius;
@XMLConfigurableConstructor({ "imprecision" })
public PrivacyLevel(double pImprecisionAreaRadius) {
synchronized (PrivacyLevel.class) {
id = staticID++;
}
imprecisionAreaRadius = pImprecisionAreaRadius;
}
public int getId() {
return id;
}
public double getImprecisionAreaRadius() {
return imprecisionAreaRadius;
}
@Override
public int hashCode() {
return id;
}
@Override
public boolean equals(Object pObj) {
if (pObj instanceof PrivacyLevel) {
return ((PrivacyLevel) pObj).id == id;
}
return false;
}
@Override
public int compareTo(PrivacyLevel pArg0) {
return Double.compare(imprecisionAreaRadius, pArg0.getImprecisionAreaRadius());
}
}
......@@ -29,6 +29,8 @@ public interface CostBasedPubSubComponent extends PubSubComponent {
public Subscription createSubscription(Topic topic, Filter filter, double costs);
public Subscription createSubscription(Topic topic, Filter filter, double[] costs);
public Notification createNotification(Topic topic,
List<Attribute<?>> attributes, double costs, byte[] payload);
}
......@@ -21,6 +21,7 @@
package de.tudarmstadt.maki.simonstrator.api.component.relevance.vehicular;
import de.tudarmstadt.maki.simonstrator.api.component.HostComponent;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.VehicularPointInformation;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetworkEdge;
......@@ -33,6 +34,12 @@ import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.Road
*
*/
public interface VehicularRelevanceCalculationComponent extends HostComponent {
public enum PositionRepresentation {
ROAD_BASED, LOCATION_BASED
}
PositionRepresentation getPositionRepresentation();
/**
* This method calculates the relevance of an event for a vehicle, combining
* the temporal and the geographical relevance.
......@@ -45,6 +52,18 @@ public interface VehicularRelevanceCalculationComponent extends HostComponent {
*/
double calculateRelevance(RoadNetworkEdge pVehiclePosition, VehicularPointInformation pInformation);
/**
* This method calculates the relevance of an event for a vehicle, combining the
* temporal and the geographical relevance.
*
* @param pVehiclePosition
* The vehicle's position
* @param pInformation
* The information for which the relevance is calculated.
* @return The relevance of the event.
*/
double calculateRelevance(Location pLocation, VehicularPointInformation pInformation);
/**
* This method calculates the relevance of an event for a vehicle, combining
* the temporal and the geographical relevance.
......
......@@ -20,34 +20,45 @@
package de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.costs;
import java.util.HashMap;
import java.util.Map;
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;
import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
public class ConfigurableVehicularPropertyImpactEstimator implements VehicularPropertyImpactEstimator {
private Map<Class<?>, VehicularPropertyImpact> _properties = new HashMap<>();
public ConfigurableVehicularPropertyImpactEstimator() {
PropertyImpactEstimatorFactory.registerPropertyBenefitEstimator(this);
}
public void setPropertyImpact(VehicularPropertyImpact pImpact) {
try {
_properties.put(Class.forName(pImpact.getProperty()), pImpact);
} catch (ClassNotFoundException e) {
throw new AssertionError("Unknown class: ", e);
}
}
@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;
if (_properties.containsKey(pProperty)) {
return _properties.get(pProperty).getImpactKnown();
}
return 10;
return 0;
}
@Override
public double calculateImpactIfUnknown(Class<? extends RoadProperty> pProperty) {
if (_properties.containsKey(pProperty)) {
return _properties.get(pProperty).getImpactUnknown();
}
return 0;
}
@Override
......@@ -74,16 +85,35 @@ public class ConfigurableVehicularPropertyImpactEstimator implements VehicularPr
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);
public static class VehicularPropertyImpact {
private String _property;
private double _impactKnown;
private double _impactUnknown;
@XMLConfigurableConstructor({ "property", "known", "unknown" })
public VehicularPropertyImpact(String pProperty, double pImpactKnown, double pImpactUnknown) {
_property = pProperty;
_impactKnown = pImpactKnown;
_impactUnknown = pImpactUnknown;
}
return 1;
}
@XMLConfigurableConstructor({ "property", "known" })
public VehicularPropertyImpact(String pProperty, double pImpactKnown) {
_property = pProperty;
_impactKnown = pImpactKnown;
_impactUnknown = pImpactKnown;
}
public String getProperty() {
return _property;
}
public double getImpactKnown() {
return _impactKnown;
}
public double getImpactUnknown() {
return _impactUnknown;
}
}
}
......@@ -37,7 +37,7 @@ public class DefaultVehicularPropertyImpactEstimator implements VehicularPropert
@Override
public double calculateImpactIfKnown(Class<? extends RoadProperty> pProperty) {
if (pProperty.equals(JamProperty.class)) {
return 3 * Math.pow(10, 2);
return Math.pow(10, 2);
} else if (pProperty.equals(RainProperty.class)) {
return 1;
} else if (pProperty.equals(FogProperty.class)) {
......
......@@ -23,7 +23,7 @@ package de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.costs;
public class PropertyImpactEstimatorFactory {
private static PropertyImpactEstimator _costEstimator = null;
public void registerPropertyBenefitEstimator(PropertyImpactEstimator pBenefitEstimator) {
public static void registerPropertyBenefitEstimator(PropertyImpactEstimator pBenefitEstimator) {
synchronized (PropertyImpactEstimatorFactory.class) {
_costEstimator = pBenefitEstimator;
}
......
......@@ -33,8 +33,9 @@ import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.pr
*/
public class EventInformationContainer {
private static Map<Class<? extends RoadProperty>, Long> durations = new HashMap<>();
private static Map<Class<? extends RoadProperty>, Double> disseminationRange = new HashMap<>();
public static void registerEvent(Class<? extends RoadProperty> pClass, long pDuration) {
public static void registerEventDuration(Class<? extends RoadProperty> pClass, long pDuration) {
if (!durations.containsKey(pClass)) {
durations.put(pClass, pDuration);
} else {
......@@ -42,10 +43,25 @@ public class EventInformationContainer {
}
}
public static void registerEventRange(Class<? extends RoadProperty> pClass, double pRange) {
if (!disseminationRange.containsKey(pClass)) {
disseminationRange.put(pClass, pRange);
} else {
throw new AssertionError(pClass + " has already been registered!");
}
}
public static long getEventDuration(Class<? extends RoadProperty> pClass) {
if (durations.containsKey(pClass)) {
return durations.get(pClass);
}
throw new AssertionError(pClass + " has not been registered!");
}
public static double getEventRange(Class<? extends RoadProperty> pClass) {
if (disseminationRange.containsKey(pClass)) {
return disseminationRange.get(pClass);
}
return Double.POSITIVE_INFINITY;
}
}
......@@ -21,6 +21,7 @@
package de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.properties;
import de.tudarmstadt.maki.simonstrator.api.component.privacy.PrivacyLevel;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetworkEdge;
......@@ -35,12 +36,20 @@ public class VehicleProperty extends AbstractRoadProperty {
private final double _speed;
private final double _length;
private PrivacyLevel _privacy;
public VehicleProperty(long pId, Location pLocation, RoadNetworkEdge pEdge, double pSpeed, double pLength) {
this(pId, pLocation, pEdge, pSpeed, pLength, PrivacyLevel.NO_PRIVACY);
}
public VehicleProperty(long pId, Location pLocation, RoadNetworkEdge pEdge, double pSpeed, double pLength,
PrivacyLevel pPrivacyLevel) {
super(pLocation, pEdge);
_id = pId;
_speed = pSpeed;
_length = pLength;
_privacy = pPrivacyLevel;
}
public long getId() {
......@@ -60,6 +69,10 @@ public class VehicleProperty extends AbstractRoadProperty {
return _length;
}
public PrivacyLevel getPrivacy() {
return _privacy;
}
@Override
public RoadProperty getDefaultProperty() {
return null;
......@@ -67,7 +80,7 @@ public class VehicleProperty extends AbstractRoadProperty {
@Override
public VehicleProperty clone() {
return new VehicleProperty(_id, getLocation(), getEdge(), _speed, _length);
return new VehicleProperty(_id, getLocation(), getEdge(), _speed, _length, _privacy);
}
}
......@@ -26,4 +26,6 @@ public interface VehicularReceiver extends HostComponent {
void initialize();
void registerCommunicationListener(CommunicationListener pListener);
double getAvailableBandwidth();
}
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