Commit 4f115f12 authored by Tobias Meuser's avatar Tobias Meuser
Browse files

Finshed offlaoding

parent afa7b2ce
...@@ -21,5 +21,5 @@ ...@@ -21,5 +21,5 @@
package de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.benefit; package de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.benefit;
public enum BenefitEstimatorType { public enum BenefitEstimatorType {
DECISION_BASED, INTERSECTION DECISION_BASED, INTERSECTION, VALUE_BASED, VALUE_ONLY
} }
...@@ -28,10 +28,13 @@ import java.util.Set; ...@@ -28,10 +28,13 @@ 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.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.LocationBasedEnvironmentProperty; 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.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.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.RoadNetwork;
...@@ -52,12 +55,16 @@ public class DefaultVehicularPropertyCostEstimator implements VehicularPropertyC ...@@ -52,12 +55,16 @@ public class DefaultVehicularPropertyCostEstimator implements VehicularPropertyC
public double calculateCostsIfKnown(Class<? extends RoadProperty> pProperty) { public double calculateCostsIfKnown(Class<? extends RoadProperty> pProperty) {
if (pProperty.equals(JamProperty.class)) { if (pProperty.equals(JamProperty.class)) {
return 5 * Math.pow(10, 2); return 5 * Math.pow(10, 2);
} else if (pProperty.equals(BumpProperty.class)) { } else if (pProperty.equals(RainProperty.class)) {
return 0; return 1;
} else if (pProperty.equals(FogProperty.class)) {
return 1;
} else if (pProperty.equals(HazardProperty.class)) { } else if (pProperty.equals(HazardProperty.class)) {
return Math.pow(10, 4); return Math.pow(10, 3);
} else if (pProperty.equals(TrafficSignProperty.class)) {
return 10;
} }
return 0.01; return 10;
} }
@Override @Override
......
...@@ -91,9 +91,9 @@ public abstract class AbstractRoadProperty implements RoadProperty, AggregatedPr ...@@ -91,9 +91,9 @@ public abstract class AbstractRoadProperty implements RoadProperty, AggregatedPr
@Override @Override
public int hashCode() { public int hashCode() {
if (_location != null) { if (_location != null) {
return _location.hashCode(); return _location.hashCode() * 31 + Long.hashCode(getDetectionDate());
} else { } else {
return _edge.hashCode(); return _edge.hashCode() * 31 + Long.hashCode(getDetectionDate());
} }
} }
......
...@@ -20,6 +20,8 @@ ...@@ -20,6 +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.VehicularPropertyCostEstimator;
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;
...@@ -29,7 +31,11 @@ public class JamPropertyGenerator implements RoadPropertyGenerator { ...@@ -29,7 +31,11 @@ public class JamPropertyGenerator implements RoadPropertyGenerator {
@Override @Override
public RoadProperty generateProperty(Location pLocation, RoadNetworkEdge pEdge) { public RoadProperty generateProperty(Location pLocation, RoadNetworkEdge pEdge) {
return new JamProperty(pLocation, pEdge, true, pEdge.getMaxSpeed() * 0.5); double travelTime = (pEdge.getLength() / pEdge.getMaxSpeed());
double newTravelTime = ((VehicularPropertyCostEstimator) PropertyBenefitEstimatorFactory
.getPropertyBenefitEstimator()).calculateCostsIfKnown(JamProperty.class) + travelTime;
double newSpeed = pEdge.getLength() / newTravelTime;
return new JamProperty(pLocation, pEdge, true, newSpeed);
} }
@Override @Override
......
...@@ -22,8 +22,10 @@ ...@@ -22,8 +22,10 @@
package de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.plugin; package de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.plugin;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
import java.util.Set;
import de.tudarmstadt.maki.simonstrator.api.Host; import de.tudarmstadt.maki.simonstrator.api.Host;
import de.tudarmstadt.maki.simonstrator.api.Randoms; import de.tudarmstadt.maki.simonstrator.api.Randoms;
...@@ -51,6 +53,8 @@ public class JamEnvironmentSensorPlugin implements EnvironmentSensorPlugin { ...@@ -51,6 +53,8 @@ public class JamEnvironmentSensorPlugin implements EnvironmentSensorPlugin {
private double _accuracy; private double _accuracy;
private double _range = 200;
private static Random _random = Randoms.getRandom(JamEnvironmentSensorPlugin.class); private static Random _random = Randoms.getRandom(JamEnvironmentSensorPlugin.class);
@XMLConfigurableConstructor({ "accuracy" }) @XMLConfigurableConstructor({ "accuracy" })
...@@ -63,6 +67,10 @@ public class JamEnvironmentSensorPlugin implements EnvironmentSensorPlugin { ...@@ -63,6 +67,10 @@ public class JamEnvironmentSensorPlugin implements EnvironmentSensorPlugin {
_host = pHost; _host = pHost;
} }
public void setRange(double pRange) {
_range = pRange;
}
@Override @Override
public List<EnvironmentProperty> getEnvironmentProperties() { public List<EnvironmentProperty> getEnvironmentProperties() {
if (_sis == null) { if (_sis == null) {
...@@ -74,22 +82,45 @@ public class JamEnvironmentSensorPlugin implements EnvironmentSensorPlugin { ...@@ -74,22 +82,45 @@ public class JamEnvironmentSensorPlugin implements EnvironmentSensorPlugin {
} }
try { try {
List<RoadNetworkEdge> investigated = new ArrayList<>();
RoadNetworkEdge edge = _sis.get().localState(SiSTypes.ROAD_EDGE, SiSRequest.NONE); RoadNetworkEdge edge = _sis.get().localState(SiSTypes.ROAD_EDGE, SiSRequest.NONE);
investigated.add(edge);
for (int i = 0; i < 2; i++) {
Set<RoadNetworkEdge> toBeAdded = new HashSet<>();
for (RoadNetworkEdge roadNetworkEdge : investigated) {
toBeAdded.add(roadNetworkEdge);
toBeAdded.addAll(roadNetworkEdge.getAccessibleEdges());
toBeAdded.addAll(roadNetworkEdge.getAccessibleEdges());
}
investigated = new ArrayList<>(toBeAdded);
}
Location location = _sis.get().localState(SiSTypes.PHY_LOCATION, SiSRequest.NONE); Location location = _sis.get().localState(SiSTypes.PHY_LOCATION, SiSRequest.NONE);
List<EnvironmentProperty> properties = new ArrayList<>();
for (RoadNetworkEdge roadNetworkEdge : investigated) {
boolean jammed = false; boolean jammed = false;
for (RoadProperty roadProperty : edge.getActiveProperties()) { Location eventLocation = null;
RoadNetworkEdge eventEdge = null;
for (RoadProperty roadProperty : roadNetworkEdge.getActiveProperties()) {
if (roadProperty instanceof JamProperty) { if (roadProperty instanceof JamProperty) {
if (((JamProperty) roadProperty).isJammed()) { if (((JamProperty) roadProperty).isJammed()) {
jammed = true; jammed = true;
} }
eventLocation = roadProperty.getLocation();
eventEdge = roadProperty.getEdge();
} }
} }
if (_random.nextDouble() >= _accuracy) { if (_random.nextDouble() >= _accuracy) {
jammed = !jammed; jammed = !jammed;
} }
List<EnvironmentProperty> properties = new ArrayList<>();
EnvironmentProperty property = new JamProperty(location, edge, jammed); if (eventLocation != null && location.distanceTo(eventLocation) <= _range) {
EnvironmentProperty property = new JamProperty(eventLocation, eventEdge, jammed);
properties.add(property); properties.add(property);
}
}
return properties; return properties;
} catch (InformationNotAvailableException e) { } catch (InformationNotAvailableException e) {
throw new AssertionError(SiSTypes.ROAD_EDGE + " and " + SiSTypes.PHY_LOCATION + " are required!"); throw new AssertionError(SiSTypes.ROAD_EDGE + " and " + SiSTypes.PHY_LOCATION + " are required!");
...@@ -103,7 +134,9 @@ public class JamEnvironmentSensorPlugin implements EnvironmentSensorPlugin { ...@@ -103,7 +134,9 @@ public class JamEnvironmentSensorPlugin implements EnvironmentSensorPlugin {
@Override @Override
public JamEnvironmentSensorPlugin clone() throws CloneNotSupportedException { public JamEnvironmentSensorPlugin clone() throws CloneNotSupportedException {
return new JamEnvironmentSensorPlugin(_accuracy); JamEnvironmentSensorPlugin jamEnvironmentSensorPlugin = new JamEnvironmentSensorPlugin(_accuracy);
jamEnvironmentSensorPlugin.setRange(_range);
return jamEnvironmentSensorPlugin;
} }
public void setAccuracy(double pAccuracy) { public void setAccuracy(double pAccuracy) {
......
...@@ -24,6 +24,7 @@ import java.util.ArrayList; ...@@ -24,6 +24,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import de.tudarmstadt.maki.simonstrator.api.component.HostComponent; import de.tudarmstadt.maki.simonstrator.api.component.HostComponent;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.Environment;
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.RoadNetworkRoute; import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetworkRoute;
...@@ -32,6 +33,11 @@ public interface VehicleDecisionComponent extends HostComponent { ...@@ -32,6 +33,11 @@ public interface VehicleDecisionComponent extends HostComponent {
BenefitBasedRoute getOptimalRoute(RoadNetworkRoute pInvestigatedRoute, List<RoadInformation> knownInformation); BenefitBasedRoute getOptimalRoute(RoadNetworkRoute pInvestigatedRoute, List<RoadInformation> knownInformation);
default BenefitBasedRoute getOptimalRoute(RoadNetworkRoute pInvestigatedRoute,
List<RoadInformation> knownInformation, Environment pEnvironment) {
return getOptimalRoute(pInvestigatedRoute, knownInformation);
}
default BenefitBasedRoute getOptimalRoute(RoadNetworkRoute pInvestigatedRoute, RoadInformation knownInformation) { default BenefitBasedRoute getOptimalRoute(RoadNetworkRoute pInvestigatedRoute, RoadInformation knownInformation) {
List<RoadInformation> known = new ArrayList<>(); List<RoadInformation> known = new ArrayList<>();
known.add(knownInformation); known.add(knownInformation);
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
package de.tudarmstadt.maki.simonstrator.api.component.vehicular.hybrid; package de.tudarmstadt.maki.simonstrator.api.component.vehicular.hybrid;
import de.tudarmstadt.maki.simonstrator.api.component.HostComponent; import de.tudarmstadt.maki.simonstrator.api.component.HostComponent;
import de.tudarmstadt.maki.simonstrator.api.component.pubsub.attribute.Topic;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.properties.LocationBasedEnvironmentProperty; import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.properties.LocationBasedEnvironmentProperty;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.EnvironmentInformation; import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.EnvironmentInformation;
...@@ -30,4 +31,6 @@ public interface VehicularSender extends HostComponent { ...@@ -30,4 +31,6 @@ public interface VehicularSender extends HostComponent {
boolean sendViaCellular(EnvironmentInformation<? extends LocationBasedEnvironmentProperty> pInformation); boolean sendViaCellular(EnvironmentInformation<? extends LocationBasedEnvironmentProperty> pInformation);
boolean sendLocally(EnvironmentInformation<? extends LocationBasedEnvironmentProperty> pInformation); boolean sendLocally(EnvironmentInformation<? extends LocationBasedEnvironmentProperty> pInformation);
Topic getLocalTopic();
} }
...@@ -24,6 +24,7 @@ package de.tudarmstadt.maki.simonstrator.api.component.vehicular.information; ...@@ -24,6 +24,7 @@ package de.tudarmstadt.maki.simonstrator.api.component.vehicular.information;
import java.util.List; import java.util.List;
import de.tudarmstadt.maki.simonstrator.api.Time; import de.tudarmstadt.maki.simonstrator.api.Time;
import de.tudarmstadt.maki.simonstrator.api.common.Transmitable;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.aggregation.AggregationInformation; import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.aggregation.AggregationInformation;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.properties.AggregatedProperty; import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.properties.AggregatedProperty;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.properties.RoadProperty; import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.properties.RoadProperty;
...@@ -35,7 +36,7 @@ import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.Road ...@@ -35,7 +36,7 @@ import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.Road
* *
*/ */
public class RoadInformation extends EnvironmentInformation<RoadProperty> public class RoadInformation extends EnvironmentInformation<RoadProperty>
implements VehicularPointInformation<RoadProperty>, AggregatedInformation, Cloneable { implements VehicularPointInformation<RoadProperty>, AggregatedInformation, Cloneable, Transmitable {
private boolean _local = false; private boolean _local = false;
public RoadInformation(RoadProperty pEnvironment) { public RoadInformation(RoadProperty pEnvironment) {
...@@ -132,7 +133,7 @@ public class RoadInformation extends EnvironmentInformation<RoadProperty> ...@@ -132,7 +133,7 @@ public class RoadInformation extends EnvironmentInformation<RoadProperty>
@Override @Override
public RoadInformation clone() { public RoadInformation clone() {
RoadInformation roadInformation = new RoadInformation(getValue()); RoadInformation roadInformation = new RoadInformation(getValue().clone());
for (AvailableInformationAttributes attribute : AvailableInformationAttributes.values()) { for (AvailableInformationAttributes attribute : AvailableInformationAttributes.values()) {
if (hasAttribute(attribute)) { if (hasAttribute(attribute)) {
roadInformation.setAttribute(attribute, getAttribute(attribute)); roadInformation.setAttribute(attribute, getAttribute(attribute));
...@@ -141,4 +142,9 @@ public class RoadInformation extends EnvironmentInformation<RoadProperty> ...@@ -141,4 +142,9 @@ public class RoadInformation extends EnvironmentInformation<RoadProperty>
roadInformation._local = _local; roadInformation._local = _local;
return roadInformation; return roadInformation;
} }
@Override
public int getTransmissionSize() {
return 250;
}
} }
...@@ -108,7 +108,7 @@ public class RoadNetworkEdge { ...@@ -108,7 +108,7 @@ public class RoadNetworkEdge {
} }
} }
setMaxSpeed(maxSpeed); changeEdgeMaxSpeed(maxSpeed);
} }
/** /**
...@@ -342,11 +342,8 @@ public class RoadNetworkEdge { ...@@ -342,11 +342,8 @@ public class RoadNetworkEdge {
public double calculateAdditionalCostIfKnown(RoadProperty pProperty) throws AssertionError { public double calculateAdditionalCostIfKnown(RoadProperty pProperty) throws AssertionError {
double additionalCost = 0; double additionalCost = 0;
if (pProperty != null && pProperty.getValue().equals(false)) { if (pProperty != null && pProperty.getDefaultProperty() != null
System.out.println(); && !propertyEquals(pProperty, pProperty.getDefaultProperty())) {
}
if (pProperty != null && !propertyEquals(pProperty, pProperty.getDefaultProperty())) {
if (pProperty.getEdge().equals(this)) { if (pProperty.getEdge().equals(this)) {
PropertyBenefitEstimator benefitEstimator = PropertyBenefitEstimatorFactory PropertyBenefitEstimator benefitEstimator = PropertyBenefitEstimatorFactory
.getPropertyBenefitEstimator(); .getPropertyBenefitEstimator();
......
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