Commit ae21935b authored by Tobias Meuser's avatar Tobias Meuser Committed by Jose Ignacio Monreal Bailey
Browse files

First really working version for ad-hoc

parent d03603ae
......@@ -55,7 +55,28 @@ public class RunnerController implements ActionListener {
* @param configFile
*/
private void runSimulator() {
new SimulationThread(selectedFile, det.getChosenSeed()).start();
SimulationThread simulationThread = new SimulationThread(selectedFile, det.getChosenSeed());
simulationThread.start();
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
while (true) {
StackTraceElement[] stackTrace = simulationThread.getStackTrace();
System.out.println();
System.out.println();
for (int i = 0; i < stackTrace.length; i++) {
System.out.println(stackTrace[i]);
}
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
}
}
});
// thread.start();
}
public void setLastOpened(LastOpened lastOpened) {
......
......@@ -29,6 +29,7 @@ import de.tudarmstadt.maki.simonstrator.api.Host;
import de.tudarmstadt.maki.simonstrator.api.component.ComponentNotAvailableException;
import de.tudarmstadt.maki.simonstrator.api.component.network.NetInterface;
import de.tudarmstadt.maki.simonstrator.api.component.network.NetworkComponent.NetInterfaceName;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.VectoralProperty;
import de.tudarmstadt.maki.simonstrator.api.component.transport.ConnectivityListener;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.VehicleInformationComponent;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.CachingComponent;
......@@ -98,7 +99,6 @@ implements CachingComponent, ConnectivityListener {
.values()) {
PointInformation correctInformation = _decisionStrategy
.decideOnCorrectInformation(similarEntries);
decidedInformation.add((T) correctInformation);
}
......
......@@ -60,7 +60,7 @@ public class AveragingCacheDecisionStrategy implements CacheDecisionStrategy {
double value = sum / count;
if (cloned instanceof VectoralJamProperty) {
((VectoralJamProperty) cloned).setSpeed(((int)(value / VectoralJamProperty.SCALING)) * VectoralJamProperty.SCALING, 0);
((VectoralJamProperty) cloned).setSpeed(((int)(value / VectoralJamProperty.SCALING)) * VectoralJamProperty.SCALING);
} else {
throw new AssertionError("Unknown data type " + cloned.getClass().getSimpleName());
}
......
......@@ -20,7 +20,6 @@
package de.tud.kom.p2psim.impl.vehicular.caching.decision;
import java.util.Arrays;
import java.util.List;
import de.tudarmstadt.maki.simonstrator.api.Time;
......@@ -71,7 +70,21 @@ public class MajorityVotingVectoralCacheDecisionStrategy implements CacheDecisio
VectoralProperty agedProperty = currentProperty.age((Time.getCurrentTime() - maxTimestamp) / SCALING, dependencyMatrix);
return (T) new RoadInformation(agedProperty);
RoadInformation roadInformation = new RoadInformation(agedProperty);
copyAttributes((RoadInformation) pSimilarPointInformation.get(0), roadInformation);
return (T) roadInformation;
}
/**
* @param pT
* @param pRoadInformation
*/
private void copyAttributes(RoadInformation pSrc, RoadInformation pDest) {
for (AvailableInformationAttributes attribute : pSrc.getAvailableAttributes()) {
pDest.setAttribute(attribute, pSrc.getAttribute(attribute));
}
}
}
......@@ -22,9 +22,12 @@ package de.tud.kom.p2psim.impl.vehicular.caching.decision;
import java.util.List;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.JamProperty;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.VectoralProperty;
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.PointInformation;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.RoadInformation;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetworkEdge;
public class OptimalCacheDecisionStrategy implements CacheDecisionStrategy {
......@@ -42,18 +45,31 @@ public class OptimalCacheDecisionStrategy implements CacheDecisionStrategy {
}
RoadNetworkEdge edge = (RoadNetworkEdge) pSimilarPointInformation.get(0).getAttribute(AvailableInformationAttributes.EDGE);
double actualSpeed = edge.getCurrentSpeedState();
if (actualSpeed == 24d) {
System.out.println();
}
JamProperty jamProperty = edge.getJamProperty();
boolean jam = false;
if (edge.getLastStepMeanSpeed() < 5) {
jam = true;
long maxTimestamp;
if (jamProperty != null) {
maxTimestamp = jamProperty.getDetectionDate();
} else {
maxTimestamp = -1;
}
long maxTimestamp = -1;
T maxFitting = null;
for (T t : pSimilarPointInformation) {
long timestamp = t.getDetectionDate();
if (t.getValue().equals(jam) && timestamp > maxTimestamp) {
Object currentValue = t.getValue();
if (currentValue instanceof VectoralProperty) {
currentValue = ((VectoralProperty) currentValue).getMostProbableValue();
}
if (currentValue.equals(actualSpeed) && timestamp > maxTimestamp) {
maxTimestamp = timestamp;
maxFitting = t;
}
......
......@@ -20,16 +20,21 @@
package de.tud.kom.p2psim.impl.vehicular.caching.decision;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import cern.colt.Arrays;
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.VectoralJamProperty;
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.PointInformation;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.RoadInformation;
public class TTLbasedCacheDecisionStrategy implements CacheDecisionStrategy {
private static final long SCALING = Time.SECOND;
......@@ -79,6 +84,15 @@ public class TTLbasedCacheDecisionStrategy implements CacheDecisionStrategy {
} else if (pSimilarPointInformation.size() == 0) {
return null;
}
Collections.sort(pSimilarPointInformation, new Comparator<T>() {
@Override
public int compare(T pArg0, T pArg1) {
return Long.compare(pArg0.getDetectionDate(), pArg1.getDetectionDate());
}
});
long minTimestamp = Long.MAX_VALUE;
long maxTimestamp = 0;
......@@ -103,6 +117,10 @@ public class TTLbasedCacheDecisionStrategy implements CacheDecisionStrategy {
}
if (differentValue) {
if (Time.getCurrentTime() == 463500000) {
System.out.println();
}
long difference = maxTimestamp - minTimestamp;
if (difference == 0) {
......@@ -111,7 +129,8 @@ public class TTLbasedCacheDecisionStrategy implements CacheDecisionStrategy {
double rate = difference / ((double) (pSimilarPointInformation.size() - 1) * SCALING);
rate = Math.min(rate, ttl / 20);
long ttl = (long)pSimilarPointInformation.get(0).getAttribute(AvailableInformationAttributes.TTL) / SCALING;
rate = Math.min(rate, ttl / 10.0);
double b;
if (Boolean.FALSE.equals(_lastDecision)) {
......@@ -121,18 +140,24 @@ public class TTLbasedCacheDecisionStrategy implements CacheDecisionStrategy {
}
Map<Object, Double> weight = new HashMap<>();
for (T t : pSimilarPointInformation) {
double impact = calculateImpact(1 - accuracy, ttl, t.getDetectionDate() / SCALING, b, maxTimestamp / SCALING);
double sumImpact = 0;
if (weight.containsKey(t.getValue())) {
sumImpact = weight.get(t.getValue());
Object currentValue = t.getValue();
if (currentValue instanceof VectoralJamProperty) {
currentValue = ((VectoralJamProperty) currentValue).getMostProbableValue();
}
if (weight.containsKey(currentValue)) {
sumImpact = weight.get(currentValue);
}
sumImpact += impact;
weight.put(t.getValue(), sumImpact);
weight.put(currentValue, sumImpact);
}
double maxWeight = -1;
......@@ -150,7 +175,12 @@ public class TTLbasedCacheDecisionStrategy implements CacheDecisionStrategy {
for (T t : pSimilarPointInformation) {
long timestamp = t.getDetectionDate();
if (t.getValue().equals(maxValue) && timestamp > maxTimestamp) {
Object currentValue = t.getValue();
if (currentValue instanceof VectoralJamProperty) {
currentValue = ((VectoralJamProperty)currentValue).getMostProbableValue();
}
if (currentValue.equals(maxValue) && timestamp > maxTimestamp) {
maxTimestamp = timestamp;
maxFitting = t;
}
......@@ -178,8 +208,7 @@ public class TTLbasedCacheDecisionStrategy implements CacheDecisionStrategy {
}
public double calculateImpact(double errorProbability, long ttl, long time, double b, long maxTimestamp) {
long currentTime = Time.getCurrentTime() / SCALING;
long age = currentTime - time;
long age = maxTimestamp - time;
if (errorProbability == 0) {
if (time == maxTimestamp) {
return 1;
......@@ -190,6 +219,12 @@ public class TTLbasedCacheDecisionStrategy implements CacheDecisionStrategy {
return 1;
} else if (errorProbability == 0.5) {
return (errorProbability - 1) / ttl * age + errorProbability;
} else if (b == Double.NEGATIVE_INFINITY) {
if (time == maxTimestamp) {
return 1;
} else {
return 0;
}
}
return (1 - errorProbability) * (Math.exp(b * age) - Math.exp(b * ttl)) / (1 - Math.exp(b * ttl));
......@@ -217,6 +252,10 @@ public class TTLbasedCacheDecisionStrategy implements CacheDecisionStrategy {
int optimalAmount = getOptimalMessageAmountForSwitch(p_c, errorProbability, costSlow, costFast);
if (optimalAmount == 1) {
return Double.NEGATIVE_INFINITY;
}
boolean first = true;
double leftSide;
......@@ -290,16 +329,16 @@ public class TTLbasedCacheDecisionStrategy implements CacheDecisionStrategy {
public double calculateWeightingForOldState(int optimalMessageAmount, double rate, double errorProbability, long ttl, double b) {
double impact = 0;
for (int a = optimalMessageAmount + 1; a < Math.max(Math.floor(ttl / rate), optimalMessageAmount + 2); a++) {
impact += calculateImpact(errorProbability, ttl, Time.getCurrentTime() / SCALING - (long)Math.floor(a * rate), b, 0);
for (int a = optimalMessageAmount; a < Math.max(Math.floor(ttl / rate), optimalMessageAmount + 2); a++) {
impact += calculateImpact(errorProbability, ttl, Time.getCurrentTime() / SCALING - (long)Math.floor(a * rate), b, Time.getCurrentTime() / SCALING);
}
return impact;
}
public double calculateWeightingForNewState(int optimalMessageAmount, double rate, double errorProbability, long ttl, double b) {
double impact = 0;
for (int a = 0; a <= optimalMessageAmount; a++) {
impact += calculateImpact(errorProbability, ttl, Time.getCurrentTime() / SCALING - (long)Math.floor(a * rate), b, 0);
for (int a = 0; a < optimalMessageAmount; a++) {
impact += calculateImpact(errorProbability, ttl, Time.getCurrentTime() / SCALING - (long)Math.floor(a * rate), b, Time.getCurrentTime() / SCALING);
}
return impact;
}
......
......@@ -20,18 +20,21 @@
package de.tud.kom.p2psim.impl.vehicular.caching.decision;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
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.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.information.AvailableInformationAttributes;
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 edu.emory.mathcs.backport.java.util.Collections;
public class TTLbasedVectoralCacheDecisionStrategy implements CacheDecisionStrategy {
......@@ -39,12 +42,14 @@ public class TTLbasedVectoralCacheDecisionStrategy implements CacheDecisionStrat
private static final double ACCURACY_FACTOR = 100000;
private static final double MIN_STEP = 0.00001;
private double accuracy = 1;
private double costWrongKeep = 1;
private double costWrongChange = 1;
private Object _lastDecision = false;
private Object _lastDecision = null;
public TTLbasedVectoralCacheDecisionStrategy(Map<String, String> pParams) {
for (Entry<String, String> param : pParams.entrySet()) {
......@@ -94,7 +99,13 @@ public class TTLbasedVectoralCacheDecisionStrategy implements CacheDecisionStrat
long minTimestamp = Long.MAX_VALUE;
long maxTimestamp = 0;
Object value = pSimilarPointInformation.get(0).getValue();
if (value instanceof VectoralProperty) {
value = ((VectoralProperty) value).getMostProbableValue();
}
boolean differentValue = false;
List<Double> possibleValues = new ArrayList<>();
for (T t : pSimilarPointInformation) {
if (!t.hasAttribute(AvailableInformationAttributes.TTL)) {
throw new AssertionError("Unable to perform TTL-based majority voting witout TTL");
......@@ -108,8 +119,17 @@ public class TTLbasedVectoralCacheDecisionStrategy implements CacheDecisionStrat
maxTimestamp = timestamp;
}
if (!value.equals(t.getValue())) {
differentValue = true;
Object currentValue = t.getValue();
if (currentValue instanceof VectoralProperty) {
VectoralProperty currentProperty = (VectoralProperty) currentValue;
currentValue = currentProperty.getMostProbableValue();
if (!value.equals(currentValue)) {
differentValue = true;
}
if (!possibleValues.contains(currentValue)) {
possibleValues.add((Double) currentValue);
}
}
}
......@@ -122,24 +142,37 @@ public class TTLbasedVectoralCacheDecisionStrategy implements CacheDecisionStrat
double rate = difference / ((double) (pSimilarPointInformation.size() - 1) * SCALING);
long ttl = (long)pSimilarPointInformation.get(0).getAttribute(AvailableInformationAttributes.TTL) / SCALING;
rate = Math.min(rate, ttl / 10);
double b = determineB(rate, 1 - accuracy, ttl, costWrongKeep, costWrongChange);
long ttl = getTTL(pSimilarPointInformation.get(0));
double numberOfMessages = ttl / rate;
VectoralProperty currentProperty = null;
double b = 0;
int count = 0;
for (Double possibleValue : possibleValues) {
double temp = determineB(((RoadInformation)pSimilarPointInformation.get(0)).getEdge(), possibleValue, getChangeRate(pSimilarPointInformation.get(0), rate), rate, 1 - accuracy, numberOfMessages, costWrongKeep, costWrongChange);
if (!Double.isNaN(temp)) {
b += temp;
count++;
}
}
if (count > 0) {
b /= count;
} else {
b = Double.NEGATIVE_INFINITY;
}
for (T t : pSimilarPointInformation) {
RoadInformation roadInformation = ((RoadInformation) t);
VectoralProperty property = (VectoralProperty) roadInformation.getValue();
double impact = calculateImpact(1 - accuracy, ttl, t.getDetectionDate() / SCALING, b, maxTimestamp / SCALING) / (accuracy);
double impact = calculateImpact(1 - accuracy, numberOfMessages, (((t.getDetectionDate() - maxTimestamp) / SCALING + ttl) / (double)ttl) * numberOfMessages, b) / (accuracy);
TemporalDependencyMatrix dependencyMatrix = property.getDependencyMatrix();
dependencyMatrix = dependencyMatrix.age((maxTimestamp - property.getDetectionDate()) / SCALING);
dependencyMatrix = modifyDependencyMatrix(dependencyMatrix, impact);
dependencyMatrix = modifyDependencyMatrix(dependencyMatrix.age((maxTimestamp - property.getDetectionDate()) / SCALING), impact);
VectoralProperty agedProperty = property.age(1, dependencyMatrix);
VectoralProperty agedProperty = property.age(1, dependencyMatrix);
if (currentProperty != null) {
currentProperty = currentProperty.combine(agedProperty);
} else {
......@@ -147,7 +180,17 @@ public class TTLbasedVectoralCacheDecisionStrategy implements CacheDecisionStrat
}
}
return (T) new RoadInformation(currentProperty);
if (Double.isNaN(currentProperty.getValueProbabilities()[0])) {
return pSimilarPointInformation.get(pSimilarPointInformation.size() - 1);
}
RoadInformation roadInformation = new RoadInformation(currentProperty);
copyAttributes((RoadInformation) pSimilarPointInformation.get(0), roadInformation);
_lastDecision = roadInformation.getValue();
return (T) roadInformation;
} else {
maxTimestamp = -1;
T maxFitting = null;
......@@ -166,6 +209,46 @@ public class TTLbasedVectoralCacheDecisionStrategy implements CacheDecisionStrat
}
}
/**
* @param pT
* @return
*/
private <T extends PointInformation> double getAccuracy(T pT) {
if (pT instanceof RoadInformation) {
RoadInformation roadInformation = ((RoadInformation) pT);
VectoralProperty property = (VectoralProperty) roadInformation.getValue();
double accuracy = property.getProbabilityForValue(property.getMostProbableValue());
return accuracy;
}
return this.accuracy;
}
private <T extends PointInformation> double getChangeRate(T pT, double pRate) {
// if (pT instanceof RoadInformation) {
// RoadInformation roadInformation = ((RoadInformation) pT);
// VectoralProperty property = (VectoralProperty) roadInformation.getValue();
//
// TemporalDependencyMatrix dependencyMatrix = property.getDependencyMatrix();
// return 1 - Math.pow(1 - dependencyMatrix.getChangeProbability(0), pRate * (SCALING / Time.SECOND));
// }
return getChangeProbability((long) (getTTL(pT) / pRate));
}
public <T extends PointInformation> long getTTL(
T pT) {
return (long)pT.getAttribute(AvailableInformationAttributes.TTL) / SCALING;
}
/**
* @param pT
* @param pRoadInformation
*/
private void copyAttributes(RoadInformation pSrc, RoadInformation pDest) {
for (AvailableInformationAttributes attribute : pSrc.getAvailableAttributes()) {
pDest.setAttribute(attribute, pSrc.getAttribute(attribute));
}
}
private TemporalDependencyMatrix modifyDependencyMatrix(
TemporalDependencyMatrix pDependencyMatrix, double pImpact) {
TemporalDependencyMatrix result = pDependencyMatrix.clone();
......@@ -175,34 +258,34 @@ public class TTLbasedVectoralCacheDecisionStrategy implements CacheDecisionStrat
double finalPercentages = 1.0 / dependencies[i].length;
for (int j = 0; j < dependencies[i].length; j++) {
dependencies[i][j] = finalPercentages + (dependencies[i][j] - finalPercentages) * pImpact;
dependencies[i][j] = finalPercentages + (pDependencyMatrix.getDependencies()[i][j] - finalPercentages) * pImpact;
}
}
return result;
}
public double calculateImpact(double errorProbability, long ttl, long time, double b, long maxTimestamp) {
long age = maxTimestamp - time;
public double calculateImpact(double errorProbability, double pNumberOfMessages, double pMessageNumber, double b) {
double age = pNumberOfMessages - pMessageNumber;
if (errorProbability == 0) {
if (time == maxTimestamp) {
if (pMessageNumber == pNumberOfMessages) {
return 1;
} else {
return 0;
}
} else if (errorProbability == 1) {
return 1;
} else if (errorProbability == 0.5) {
return (errorProbability - 1) / ttl * age + errorProbability;
} else if (errorProbability == 0.5 || b == 0) {
return (1 - errorProbability) / pNumberOfMessages * age + errorProbability;
} else if (b == Double.NEGATIVE_INFINITY) {
if (time == maxTimestamp) {
if (pMessageNumber == pNumberOfMessages) {
return 1;
} else {
return 0;
}
}
return (1 - errorProbability) * (Math.exp(b * age) - Math.exp(b * ttl)) / (1 - Math.exp(b * ttl));
return (1 - errorProbability) * (Math.exp(b * age) - Math.exp(b * pNumberOfMessages)) / (1 - Math.exp(b * pNumberOfMessages));
}
public double getChangeProbability(long ttl) {
......@@ -213,109 +296,139 @@ public class TTLbasedVectoralCacheDecisionStrategy implements CacheDecisionStrat
return (int) Math.round(Math.log(-changeProbability / Math.log(errorProbability) * costSlow / costFast) / Math.log(errorProbability));
}
public double determineB(double rate, double errorProbability, long ttl, double costSlow, double costFast) {
return determineB(rate, errorProbability, ttl, costSlow, costFast, 1);
}
public double determineB(double rate, double errorProbability, long ttl, double costSlow, double costFast, int reversed) {
public double determineB(RoadNetworkEdge pRoadNetworkEdge, double pPossibleValue, double change, double rate, double errorProbability, double pNumberOfMessages, double costSlow, double costFast) {
if (errorProbability == 0 || errorProbability == 1 || errorProbability == 0.5) {
return Double.NaN;
}
if (_lastDecision != null) {
if (pPossibleValue == ((VectoralJamProperty)_lastDecision).getMostProbableValue()) {
return Double.NaN;
}
} else {
if (pPossibleValue == pRoadNetworkEdge.getCurrentSpeedState()) {
return Double.NaN;
}
}
double b;
double p_c = getChangeProbability((long) (ttl / rate));
double p_c = change;
int optimalAmount = getOptimalMessageAmountForSwitch(p_c, errorProbability, costSlow, costFast);
if (optimalAmount == 1) {
return Double.NEGATIVE_INFINITY;
}
boolean first = true;
double leftSide;
double rightSide;
double step = 5;
double step = 10;
if (errorProbability < 0.5) {
b = -2 * step * reversed;
b = -1 * step;
} else {
b = 2 * step * reversed;
b = 1 * step;
}
int similar = 0;
double lastDifference = -1;
do {
leftSide = calculateWeightingForOldState(optimalAmount, rate, errorProbability, ttl, b);
rightSide = calculateWeightingForNewState(optimalAmount, rate, errorProbability, ttl, b);
VectoralJamProperty valueAfterN = calculateMostProbableValue(pRoadNetworkEdge, pPossibleValue, optimalAmount, rate, errorProbability, pNumberOfMessages, b);
double probableValueAfterN = Double.NaN;
if (valueAfterN != null) {
probableValueAfterN = valueAfterN.getMostProbableValue();
}
VectoralJamProperty valueBeforeN = calculateMostProbableValue(pRoadNetworkEdge, pPossibleValue, optimalAmount - 1, rate, errorProbability, pNumberOfMessages, b);
double probableValueBeforeN = Double.NaN;
if (valueBeforeN != null) {
probableValueBeforeN = valueBeforeN.getMostProbableValue();
}
if (Math.abs(Math.round((rightSide - leftSide) * ACCURACY_FACTOR)) == lastDifference) {
similar++;
} else {
lastDifference = Math.abs(Math.round((rightSide - leftSide) * ACCURACY_FACTOR));
similar = 0;
if (probableValueAfterN == pPossibleValue && probableValueAfterN != probableValueBeforeN) {
return b;
}
if (Double.isNaN(leftSide) || Double.isNaN(rightSide) || similar > 100) {
if (reversed != -1) {
double determineB = determineB(rate, errorProbability, ttl, costSlow, costFast, -1);
if (!Double.isNaN(determineB)) {
return determineB;
if (!Double.isNaN(probableValueBeforeN) && !Double.isNaN(probableValueBeforeN) && step >= MIN_STEP) {
if (probableValueAfterN != pPossibleValue) {
if (b < 0) {
b -= step;
if (!first) {
step *= 0.5;
}
} else {
return b;
}
} else {
return Double.NaN;
}
}
leftSide = Math.round(leftSide * ACCURACY_FACTOR);
rightSide = Math.round(rightSide * ACCURACY_FACTOR);
if (leftSide > rightSide) {
if (b < 0) {
b -= step;
if (!first) {
b -= step;
step *= 0.5;
first = false;
}
} else {
b -= step;
step *= 0.5;
first = false;
}
} else if (leftSide < rightSide) {
if (b > 0) {
b += step;
if (!first) {
} else if (probableValueAfterN == pPossibleValue && probableValueAfterN == probableValueBeforeN) {
if (b > 0) {
b += step;
if (!first) {
step *= 0.5;
}
} else {
b += step;
step *= 0.5;
first = false;
}
} else {
b += step;
step *= 0.5;
first = false;
return Double.NaN;
}
} else {
break;
return Double.NaN;
}
} while (true);
return b;
}
public double calculateWeightingForOldState(int optimalMessageAmount, double rate, double errorProbability, long ttl, double b) {
double impact = 0;
for (int a = optimalMessageAmount; a < Math.max(Math.floor(ttl / rate), optimalMessageAmount + 2); a++) {
impact += calculateImpact(errorProbability, ttl, Time.getCurrentTime() / SCALING - (long)Math.floor(a * rate), b, Time.getCurrentTime() / SCALING);
public VectoralJamProperty calculateMostProbableValue(RoadNetworkEdge pRoadNetworkEdge, double pNewValue, int optimalMessageAmount, double rate, double errorProbability, double pNumberOfMessages, double b) {
VectoralJamProperty currentProperty = null;
for (int a = optimalMessageAmount + 1; a <= pNumberOfMessages; a++) {
VectoralJamProperty jamProperty = new VectoralJamProperty();
if (_lastDecision != null) {
jamProperty.setGaussianSpeedWithAccuracy(((VectoralJamProperty)_lastDecision).getMostProbableValue(), accuracy);
} else {
jamProperty.setGaussianSpeedWithAccuracy(pRoadNetworkEdge.getCurrentSpeedState(), accuracy);
}
TemporalDependencyMatrix temporalDependencyMatrix = jamProperty.getDependencyMatrix();
temporalDependencyMatrix = temporalDependencyMatrix.age((long) (a * rate));
double impact = calculateImpact(errorProbability, pNumberOfMessages, pNumberOfMessages - a, b);
if (Double.isNaN(impact)) {
return null;
}
temporalDependencyMatrix = modifyDependencyMatrix(temporalDependencyMatrix, impact);
jamProperty = (VectoralJamProperty) jamProperty.age(1, temporalDependencyMatrix);
if (currentProperty != null) {
currentProperty = (VectoralJamProperty) currentProperty.combine(jamProperty);
} else {
currentProperty = jamProperty;
}
}
return impact;
}
for (int a = 0; a <= optimalMessageAmount; a++) {
VectoralJamProperty jamProperty = new VectoralJamProperty();
jamProperty.setGaussianSpeedWithAccuracy(pNewValue, accuracy);
TemporalDependencyMatrix temporalDependencyMatrix = jamProperty.getDependencyMatrix();
temporalDependencyMatrix = temporalDependencyMatrix.age((long) (a * rate));
double impact = calculateImpact(errorProbability, pNumberOfMessages, pNumberOfMessages - a, b);
if (Double.isNaN(impact)) {
return null;
}
temporalDependencyMatrix = modifyDependencyMatrix(temporalDependencyMatrix, impact);
jamProperty = (VectoralJamProperty) jamProperty.age(1, temporalDependencyMatrix);
public double calculateWeightingForNewState(int optimalMessageAmount, double rate, double errorProbability, long ttl, double b) {
double impact = 0;
for (int a = 0; a < optimalMessageAmount; a++) {
impact += calculateImpact(errorProbability, ttl, Time.getCurrentTime() / SCALING - (long)Math.floor(a * rate), b, Time.getCurrentTime() / SCALING);
if (currentProperty != null) {
currentProperty = (VectoralJamProperty) currentProperty.combine(jamProperty);
} else {
currentProperty = jamProperty;
}
}
return impact;
return currentProperty;
}
}
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