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

First really working version for adhoc

parent ed38bb7e
...@@ -40,6 +40,7 @@ import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.Avai ...@@ -40,6 +40,7 @@ import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.Avai
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.JamInformation; import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.JamInformation;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.PointInformation; import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.PointInformation;
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.RoadNetworkEdge; 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.RoadNetworkRoute;
...@@ -88,6 +89,7 @@ implements CachingComponent, ConnectivityListener { ...@@ -88,6 +89,7 @@ implements CachingComponent, ConnectivityListener {
for (T t : cacheEntries) { for (T t : cacheEntries) {
Object position = getEdgeOrPosition(t); Object position = getEdgeOrPosition(t);
if (!similarCacheEntries.containsKey(position)) { if (!similarCacheEntries.containsKey(position)) {
similarCacheEntries.put(position, new ArrayList<>()); similarCacheEntries.put(position, new ArrayList<>());
} }
......
...@@ -23,7 +23,7 @@ package de.tud.kom.p2psim.impl.vehicular.caching.decision; ...@@ -23,7 +23,7 @@ package de.tud.kom.p2psim.impl.vehicular.caching.decision;
import java.util.List; import java.util.List;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.NumericVectoralProperty; import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.NumericVectoralProperty;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.VectoralJamProperty; import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.jam.VectoralJamProperty;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.decision.CacheDecisionStrategy; import de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.decision.CacheDecisionStrategy;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.PointInformation; import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.PointInformation;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.RoadInformation; import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.RoadInformation;
......
...@@ -23,8 +23,8 @@ package de.tud.kom.p2psim.impl.vehicular.caching.decision; ...@@ -23,8 +23,8 @@ package de.tud.kom.p2psim.impl.vehicular.caching.decision;
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.component.sensor.environment.data.TemporalDependencyMatrix;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.VectoralProperty; import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.VectoralProperty;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.vector.TemporalDependencyMatrix;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.decision.CacheDecisionStrategy; import de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.decision.CacheDecisionStrategy;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.AvailableInformationAttributes; import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.AvailableInformationAttributes;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.PointInformation; import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.PointInformation;
......
...@@ -22,12 +22,12 @@ package de.tud.kom.p2psim.impl.vehicular.caching.decision; ...@@ -22,12 +22,12 @@ package de.tud.kom.p2psim.impl.vehicular.caching.decision;
import java.util.List; import java.util.List;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.JamProperty; import de.tudarmstadt.maki.simonstrator.api.Time;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.VectoralProperty; import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.VectoralProperty;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.jam.JamProperty;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.decision.CacheDecisionStrategy; import de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.decision.CacheDecisionStrategy;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.AvailableInformationAttributes; import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.AvailableInformationAttributes;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.PointInformation; import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.PointInformation;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.RoadInformation;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetworkEdge; import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetworkEdge;
public class OptimalCacheDecisionStrategy implements CacheDecisionStrategy { public class OptimalCacheDecisionStrategy implements CacheDecisionStrategy {
...@@ -43,14 +43,10 @@ public class OptimalCacheDecisionStrategy implements CacheDecisionStrategy { ...@@ -43,14 +43,10 @@ public class OptimalCacheDecisionStrategy implements CacheDecisionStrategy {
} else if (pSimilarPointInformation.size() == 0) { } else if (pSimilarPointInformation.size() == 0) {
return null; return null;
} }
RoadNetworkEdge edge = (RoadNetworkEdge) pSimilarPointInformation.get(0).getAttribute(AvailableInformationAttributes.EDGE);
double actualSpeed = edge.getCurrentSpeedState(); RoadNetworkEdge edge = (RoadNetworkEdge) pSimilarPointInformation.get(0).getAttribute(AvailableInformationAttributes.EDGE);
if (actualSpeed == 24d) { double actualSpeed = edge.getCurrentSpeed();
System.out.println();
}
JamProperty jamProperty = edge.getJamProperty(); JamProperty jamProperty = edge.getJamProperty();
...@@ -61,6 +57,7 @@ public class OptimalCacheDecisionStrategy implements CacheDecisionStrategy { ...@@ -61,6 +57,7 @@ public class OptimalCacheDecisionStrategy implements CacheDecisionStrategy {
maxTimestamp = -1; maxTimestamp = -1;
} }
double difference = Double.MAX_VALUE;
T maxFitting = null; T maxFitting = null;
for (T t : pSimilarPointInformation) { for (T t : pSimilarPointInformation) {
long timestamp = t.getDetectionDate(); long timestamp = t.getDetectionDate();
...@@ -69,9 +66,15 @@ public class OptimalCacheDecisionStrategy implements CacheDecisionStrategy { ...@@ -69,9 +66,15 @@ public class OptimalCacheDecisionStrategy implements CacheDecisionStrategy {
if (currentValue instanceof VectoralProperty) { if (currentValue instanceof VectoralProperty) {
currentValue = ((VectoralProperty) currentValue).getMostProbableValue(); currentValue = ((VectoralProperty) currentValue).getMostProbableValue();
} }
if (currentValue.equals(actualSpeed) && timestamp > maxTimestamp) {
maxTimestamp = timestamp; if (timestamp >= maxTimestamp) {
maxFitting = t; if (currentValue.equals(actualSpeed)) {
maxFitting = t;
difference = 0;
} else if (currentValue instanceof Number && Math.abs(((Number)currentValue).doubleValue() - actualSpeed) < difference) {
maxFitting = t;
difference = Math.abs(((Number)currentValue).doubleValue() - actualSpeed);
}
} }
} }
...@@ -81,7 +84,7 @@ public class OptimalCacheDecisionStrategy implements CacheDecisionStrategy { ...@@ -81,7 +84,7 @@ public class OptimalCacheDecisionStrategy implements CacheDecisionStrategy {
for (T t : pSimilarPointInformation) { for (T t : pSimilarPointInformation) {
long timestamp = t.getDetectionDate(); long timestamp = t.getDetectionDate();
if (timestamp > maxTimestamp) { if (timestamp >= maxTimestamp) {
maxTimestamp = timestamp; maxTimestamp = timestamp;
maxFitting = t; maxFitting = t;
} }
......
...@@ -27,14 +27,15 @@ import java.util.List; ...@@ -27,14 +27,15 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import cern.colt.Arrays;
import de.tudarmstadt.maki.simonstrator.api.Time; import de.tudarmstadt.maki.simonstrator.api.Time;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.RoadProperty; import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.RoadProperty;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.VectoralJamProperty; import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.VectoralProperty;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.jam.VectoralJamProperty;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.decision.CacheDecisionStrategy; import de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.decision.CacheDecisionStrategy;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.AvailableInformationAttributes; import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.AvailableInformationAttributes;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.PointInformation; import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.PointInformation;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.RoadInformation; import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.RoadInformation;
import edu.emory.mathcs.backport.java.util.Arrays;
public class TTLbasedCacheDecisionStrategy implements CacheDecisionStrategy { public class TTLbasedCacheDecisionStrategy implements CacheDecisionStrategy {
private static final long SCALING = Time.SECOND; private static final long SCALING = Time.SECOND;
...@@ -117,10 +118,6 @@ public class TTLbasedCacheDecisionStrategy implements CacheDecisionStrategy { ...@@ -117,10 +118,6 @@ public class TTLbasedCacheDecisionStrategy implements CacheDecisionStrategy {
} }
if (differentValue) { if (differentValue) {
if (Time.getCurrentTime() == 463500000) {
System.out.println();
}
long difference = maxTimestamp - minTimestamp; long difference = maxTimestamp - minTimestamp;
if (difference == 0) { if (difference == 0) {
...@@ -176,8 +173,8 @@ public class TTLbasedCacheDecisionStrategy implements CacheDecisionStrategy { ...@@ -176,8 +173,8 @@ public class TTLbasedCacheDecisionStrategy implements CacheDecisionStrategy {
long timestamp = t.getDetectionDate(); long timestamp = t.getDetectionDate();
Object currentValue = t.getValue(); Object currentValue = t.getValue();
if (currentValue instanceof VectoralJamProperty) { if (currentValue instanceof VectoralProperty) {
currentValue = ((VectoralJamProperty)currentValue).getMostProbableValue(); currentValue = ((VectoralProperty)currentValue).getMostProbableValue();
} }
if (currentValue.equals(maxValue) && timestamp > maxTimestamp) { if (currentValue.equals(maxValue) && timestamp > maxTimestamp) {
...@@ -185,6 +182,26 @@ public class TTLbasedCacheDecisionStrategy implements CacheDecisionStrategy { ...@@ -185,6 +182,26 @@ public class TTLbasedCacheDecisionStrategy implements CacheDecisionStrategy {
maxFitting = t; maxFitting = t;
} }
} }
if (maxFitting.getValue() instanceof VectoralProperty) {
VectoralProperty vectoralProperty = ((VectoralProperty)maxFitting.getValue()).clone();
double[] valueProbabilities = vectoralProperty.getValueProbabilities();
Arrays.fill(valueProbabilities, 0);
double sum = 0;
for (Object key : weight.keySet()) {
valueProbabilities[vectoralProperty.getIndexForValue(key)] = weight.get(key);
sum += weight.get(key);
}
for (int i = 0; i < valueProbabilities.length; i++) {
valueProbabilities[i] /= sum;
}
RoadInformation roadInformation = new RoadInformation(vectoralProperty);
roadInformation.copyAttributes((RoadInformation)maxFitting);
maxFitting = (T) roadInformation;
}
_lastDecision = maxFitting.getValue(); _lastDecision = maxFitting.getValue();
...@@ -206,7 +223,7 @@ public class TTLbasedCacheDecisionStrategy implements CacheDecisionStrategy { ...@@ -206,7 +223,7 @@ public class TTLbasedCacheDecisionStrategy implements CacheDecisionStrategy {
return maxFitting; return maxFitting;
} }
} }
public double calculateImpact(double errorProbability, long ttl, long time, double b, long maxTimestamp) { public double calculateImpact(double errorProbability, long ttl, long time, double b, long maxTimestamp) {
long age = maxTimestamp - time; long age = maxTimestamp - time;
if (errorProbability == 0) { if (errorProbability == 0) {
......
...@@ -21,15 +21,16 @@ ...@@ -21,15 +21,16 @@
package de.tud.kom.p2psim.impl.vehicular.caching.decision; package de.tud.kom.p2psim.impl.vehicular.caching.decision;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import de.tudarmstadt.maki.simonstrator.api.Time; import de.tudarmstadt.maki.simonstrator.api.Time;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.VectoralJamProperty; import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.TemporalDependencyMatrix;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.VectoralProperty; import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.VectoralProperty;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.vector.TemporalDependencyMatrix; import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.measurement.MeasurementDistributionTypeContainer;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.decision.CacheDecisionStrategy; import de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.decision.CacheDecisionStrategy;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.AvailableInformationAttributes; import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.AvailableInformationAttributes;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.PointInformation; import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.PointInformation;
...@@ -100,11 +101,11 @@ public class TTLbasedVectoralCacheDecisionStrategy implements CacheDecisionStrat ...@@ -100,11 +101,11 @@ public class TTLbasedVectoralCacheDecisionStrategy implements CacheDecisionStrat
long maxTimestamp = 0; long maxTimestamp = 0;
Object value = pSimilarPointInformation.get(0).getValue(); Object value = pSimilarPointInformation.get(0).getValue();
if (value instanceof VectoralProperty) { if (value instanceof VectoralProperty) {
value = ((VectoralProperty) value).getMostProbableValue(); value = ((VectoralProperty) value).getMostProbableIndex();
} }
boolean differentValue = false; boolean differentValue = false;
List<Double> possibleValues = new ArrayList<>(); List<Integer> possibleValues = new ArrayList<>();
for (T t : pSimilarPointInformation) { for (T t : pSimilarPointInformation) {
if (!t.hasAttribute(AvailableInformationAttributes.TTL)) { if (!t.hasAttribute(AvailableInformationAttributes.TTL)) {
...@@ -122,13 +123,16 @@ public class TTLbasedVectoralCacheDecisionStrategy implements CacheDecisionStrat ...@@ -122,13 +123,16 @@ public class TTLbasedVectoralCacheDecisionStrategy implements CacheDecisionStrat
Object currentValue = t.getValue(); Object currentValue = t.getValue();
if (currentValue instanceof VectoralProperty) { if (currentValue instanceof VectoralProperty) {
VectoralProperty currentProperty = (VectoralProperty) currentValue; VectoralProperty currentProperty = (VectoralProperty) currentValue;
currentValue = currentProperty.getMostProbableValue(); currentValue = currentProperty.getMostProbableIndex();
if (!value.equals(currentValue)) { if (!value.equals(currentValue)) {
differentValue = true; differentValue = true;
} }
if (!possibleValues.contains(currentValue)) { for (int i = 0; i < currentProperty.getValueProbabilities().length; i++) {
possibleValues.add((Double) currentValue); if (!possibleValues.contains(i)) {
possibleValues.add(i);
}
} }
} }
} }
...@@ -143,26 +147,33 @@ public class TTLbasedVectoralCacheDecisionStrategy implements CacheDecisionStrat ...@@ -143,26 +147,33 @@ public class TTLbasedVectoralCacheDecisionStrategy implements CacheDecisionStrat
double rate = difference / ((double) (pSimilarPointInformation.size() - 1) * SCALING); double rate = difference / ((double) (pSimilarPointInformation.size() - 1) * SCALING);
long ttl = getTTL(pSimilarPointInformation.get(0)); long ttl = getTTL(pSimilarPointInformation.get(0));
double numberOfMessages = ttl / rate; double numberOfMessages = ttl / rate + 1;
VectoralProperty currentProperty = null; VectoralProperty currentProperty = null;
double b = 0; List<Double> bValues = new ArrayList<>();
int count = 0; double b;
for (Double possibleValue : possibleValues) { for (Integer possibleValue : possibleValues) {
double temp = determineB(((RoadInformation)pSimilarPointInformation.get(0)).getEdge(), possibleValue, getChangeRate(pSimilarPointInformation.get(0), rate), rate, 1 - accuracy, numberOfMessages, costWrongKeep, costWrongChange); double temp = determineB((VectoralProperty) pSimilarPointInformation.get(0).getValue(), ((RoadInformation)pSimilarPointInformation.get(0)).getEdge(), possibleValue, getChangeRate(pSimilarPointInformation.get(0), rate), rate, 1 - accuracy, numberOfMessages, costWrongKeep, costWrongChange);
if (!Double.isNaN(temp)) { if (!Double.isNaN(temp)) {
b += temp; bValues.add(temp);
count++;
} }
} }
if (count > 0) { Collections.sort(bValues);
b /= count;
if (bValues.size() > 0) {
if (bValues.size() % 2 == 0) {
b = (bValues.get(bValues.size() / 2) + bValues.get(bValues.size() / 2 - 1)) / 2.0;
} else {
b = bValues.get(bValues.size() / 2);
}
} else { } else {
b = Double.NEGATIVE_INFINITY; b = Double.NEGATIVE_INFINITY;
} }
int count = 0;
for (T t : pSimilarPointInformation) { for (T t : pSimilarPointInformation) {
RoadInformation roadInformation = ((RoadInformation) t); RoadInformation roadInformation = ((RoadInformation) t);
VectoralProperty property = (VectoralProperty) roadInformation.getValue(); VectoralProperty property = (VectoralProperty) roadInformation.getValue();
...@@ -214,12 +225,12 @@ public class TTLbasedVectoralCacheDecisionStrategy implements CacheDecisionStrat ...@@ -214,12 +225,12 @@ public class TTLbasedVectoralCacheDecisionStrategy implements CacheDecisionStrat
* @return * @return
*/ */
private <T extends PointInformation> double getAccuracy(T pT) { private <T extends PointInformation> double getAccuracy(T pT) {
if (pT instanceof RoadInformation) { // if (pT instanceof RoadInformation) {
RoadInformation roadInformation = ((RoadInformation) pT); // RoadInformation roadInformation = ((RoadInformation) pT);
VectoralProperty property = (VectoralProperty) roadInformation.getValue(); // VectoralProperty property = (VectoralProperty) roadInformation.getValue();
double accuracy = property.getProbabilityForValue(property.getMostProbableValue()); // double accuracy = property.getProbabilityForIndex(property.getMostProbableIndex());
return accuracy; // return accuracy;
} // }
return this.accuracy; return this.accuracy;
} }
...@@ -296,17 +307,17 @@ public class TTLbasedVectoralCacheDecisionStrategy implements CacheDecisionStrat ...@@ -296,17 +307,17 @@ public class TTLbasedVectoralCacheDecisionStrategy implements CacheDecisionStrat
return (int) Math.round(Math.log(-changeProbability / Math.log(errorProbability) * costSlow / costFast) / Math.log(errorProbability)); return (int) Math.round(Math.log(-changeProbability / Math.log(errorProbability) * costSlow / costFast) / Math.log(errorProbability));
} }
public double determineB(RoadNetworkEdge pRoadNetworkEdge, double pPossibleValue, double change, double rate, double errorProbability, double pNumberOfMessages, double costSlow, double costFast) { public double determineB(VectoralProperty pTemplate, RoadNetworkEdge pRoadNetworkEdge, int pPossibleValue, double change, double rate, double errorProbability, double pNumberOfMessages, double costSlow, double costFast) {
if (errorProbability == 0 || errorProbability == 1 || errorProbability == 0.5) { if (errorProbability == 0 || errorProbability == 1 || errorProbability == 0.5) {
return Double.NaN; return Double.NaN;
} }
if (_lastDecision != null) { if (_lastDecision != null) {
if (pPossibleValue == ((VectoralJamProperty)_lastDecision).getMostProbableValue()) { if (pPossibleValue == ((VectoralProperty)_lastDecision).getMostProbableIndex()) {
return Double.NaN; return Double.NaN;
} }
} else { } else {
if (pPossibleValue == pRoadNetworkEdge.getCurrentSpeedState()) { if (pPossibleValue == pTemplate.getDefaultIndex()) {
return Double.NaN; return Double.NaN;
} }
} }
...@@ -316,6 +327,10 @@ public class TTLbasedVectoralCacheDecisionStrategy implements CacheDecisionStrat ...@@ -316,6 +327,10 @@ public class TTLbasedVectoralCacheDecisionStrategy implements CacheDecisionStrat
int optimalAmount = getOptimalMessageAmountForSwitch(p_c, errorProbability, costSlow, costFast); int optimalAmount = getOptimalMessageAmountForSwitch(p_c, errorProbability, costSlow, costFast);
if ((int)pNumberOfMessages <= optimalAmount) {
return Double.POSITIVE_INFINITY;
}
if (optimalAmount == 1) { if (optimalAmount == 1) {
return Double.NEGATIVE_INFINITY; return Double.NEGATIVE_INFINITY;
} }
...@@ -331,15 +346,15 @@ public class TTLbasedVectoralCacheDecisionStrategy implements CacheDecisionStrat ...@@ -331,15 +346,15 @@ public class TTLbasedVectoralCacheDecisionStrategy implements CacheDecisionStrat
} }
do { do {
VectoralJamProperty valueAfterN = calculateMostProbableValue(pRoadNetworkEdge, pPossibleValue, optimalAmount, rate, errorProbability, pNumberOfMessages, b); VectoralProperty valueAfterN = calculateMostProbable(pTemplate, pRoadNetworkEdge, pPossibleValue, optimalAmount, rate, errorProbability, pNumberOfMessages, b);
double probableValueAfterN = Double.NaN; double probableValueAfterN = Double.NaN;
if (valueAfterN != null) { if (valueAfterN != null) {
probableValueAfterN = valueAfterN.getMostProbableValue(); probableValueAfterN = valueAfterN.getMostProbableIndex();
} }
VectoralJamProperty valueBeforeN = calculateMostProbableValue(pRoadNetworkEdge, pPossibleValue, optimalAmount - 1, rate, errorProbability, pNumberOfMessages, b); VectoralProperty valueBeforeN = calculateMostProbable(pTemplate, pRoadNetworkEdge, pPossibleValue, optimalAmount - 1, rate, errorProbability, pNumberOfMessages, b);
double probableValueBeforeN = Double.NaN; double probableValueBeforeN = Double.NaN;
if (valueBeforeN != null) { if (valueBeforeN != null) {
probableValueBeforeN = valueBeforeN.getMostProbableValue(); probableValueBeforeN = valueBeforeN.getMostProbableIndex();
} }
if (probableValueAfterN == pPossibleValue && probableValueAfterN != probableValueBeforeN) { if (probableValueAfterN == pPossibleValue && probableValueAfterN != probableValueBeforeN) {
...@@ -378,16 +393,16 @@ public class TTLbasedVectoralCacheDecisionStrategy implements CacheDecisionStrat ...@@ -378,16 +393,16 @@ public class TTLbasedVectoralCacheDecisionStrategy implements CacheDecisionStrat
} while (true); } while (true);
} }
public VectoralJamProperty calculateMostProbableValue(RoadNetworkEdge pRoadNetworkEdge, double pNewValue, int optimalMessageAmount, double rate, double errorProbability, double pNumberOfMessages, double b) { public VectoralProperty calculateMostProbable(VectoralProperty pTemplate, RoadNetworkEdge pRoadNetworkEdge, int pNewValue, int optimalMessageAmount, double rate, double errorProbability, double pNumberOfMessages, double b) {
VectoralJamProperty currentProperty = null; VectoralProperty currentProperty = null;
for (int a = optimalMessageAmount + 1; a <= pNumberOfMessages; a++) { for (int a = optimalMessageAmount + 1; a <= pNumberOfMessages; a++) {
VectoralJamProperty jamProperty = new VectoralJamProperty(); VectoralProperty jamProperty = pTemplate.clone();
if (_lastDecision != null) { if (_lastDecision != null) {
jamProperty.setGaussianSpeedWithAccuracy(((VectoralJamProperty)_lastDecision).getMostProbableValue(), accuracy); jamProperty.set(((VectoralProperty)_lastDecision).getMostProbableIndex(), accuracy, MeasurementDistributionTypeContainer.getDistribution(pTemplate.getClass()));
} else { } else {
jamProperty.setGaussianSpeedWithAccuracy(pRoadNetworkEdge.getCurrentSpeedState(), accuracy); jamProperty.set(pTemplate.getDefaultIndex(), accuracy, MeasurementDistributionTypeContainer.getDistribution(pTemplate.getClass()));
} }
TemporalDependencyMatrix temporalDependencyMatrix = jamProperty.getDependencyMatrix(); TemporalDependencyMatrix temporalDependencyMatrix = jamProperty.getDependencyMatrix();
temporalDependencyMatrix = temporalDependencyMatrix.age((long) (a * rate)); temporalDependencyMatrix = temporalDependencyMatrix.age((long) (a * rate));
...@@ -398,18 +413,18 @@ public class TTLbasedVectoralCacheDecisionStrategy implements CacheDecisionStrat ...@@ -398,18 +413,18 @@ public class TTLbasedVectoralCacheDecisionStrategy implements CacheDecisionStrat
} }
temporalDependencyMatrix = modifyDependencyMatrix(temporalDependencyMatrix, impact); temporalDependencyMatrix = modifyDependencyMatrix(temporalDependencyMatrix, impact);
jamProperty = (VectoralJamProperty) jamProperty.age(1, temporalDependencyMatrix); jamProperty = (VectoralProperty) jamProperty.age(1, temporalDependencyMatrix);
if (currentProperty != null) { if (currentProperty != null) {
currentProperty = (VectoralJamProperty) currentProperty.combine(jamProperty); currentProperty = (VectoralProperty) currentProperty.combine(jamProperty);
} else { } else {
currentProperty = jamProperty; currentProperty = jamProperty;
} }
} }
for (int a = 0; a <= optimalMessageAmount; a++) { for (int a = 0; a <= optimalMessageAmount; a++) {
VectoralJamProperty jamProperty = new VectoralJamProperty(); VectoralProperty jamProperty = pTemplate.clone();
jamProperty.setGaussianSpeedWithAccuracy(pNewValue, accuracy); jamProperty.setGaussianWithAccuracy(pNewValue, accuracy);
TemporalDependencyMatrix temporalDependencyMatrix = jamProperty.getDependencyMatrix(); TemporalDependencyMatrix temporalDependencyMatrix = jamProperty.getDependencyMatrix();
temporalDependencyMatrix = temporalDependencyMatrix.age((long) (a * rate)); temporalDependencyMatrix = temporalDependencyMatrix.age((long) (a * rate));
...@@ -420,10 +435,10 @@ public class TTLbasedVectoralCacheDecisionStrategy implements CacheDecisionStrat ...@@ -420,10 +435,10 @@ public class TTLbasedVectoralCacheDecisionStrategy implements CacheDecisionStrat
} }
temporalDependencyMatrix = modifyDependencyMatrix(temporalDependencyMatrix, impact); temporalDependencyMatrix = modifyDependencyMatrix(temporalDependencyMatrix, impact);
jamProperty = (VectoralJamProperty) jamProperty.age(1, temporalDependencyMatrix); jamProperty = (VectoralProperty) jamProperty.age(1, temporalDependencyMatrix);
if (currentProperty != null) { if (currentProperty != null) {
currentProperty = (VectoralJamProperty) currentProperty.combine(jamProperty); currentProperty = (VectoralProperty) currentProperty.combine(jamProperty);
} else { } else {
currentProperty = jamProperty; currentProperty = jamProperty;
} }
......
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