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

Finshed offlaoding

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