Commit 44bee7a8 authored by Tobias Meuser's avatar Tobias Meuser
Browse files

Updated decision making for vehits, used processing server

parent 70f0b7c3
......@@ -2,17 +2,17 @@
* Copyright (c) 2005-2011 KOM - Multimedia Communications Lab
*
* This file is part of PeerfactSim.KOM.
*
*
* PeerfactSim.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/>.
*
......@@ -32,9 +32,9 @@ import de.tud.kom.p2psim.impl.util.guirunner.GUIRunner;
import de.tud.kom.p2psim.impl.util.guirunner.seed.SeedDetermination;
/**
*
*
* Runs the simulator or invokes operations on the view.
*
*
* @author Leo Nobach
* @version 3.0, 25.11.2008
*
......@@ -45,11 +45,11 @@ public class RunnerController implements ActionListener {
ConfigFile selectedFile = null;
JButton launchButton = null;
private GUIRunner runner;
private List<IRunnerCtrlListener> listeners = new LinkedList<IRunnerCtrlListener>();
SeedDetermination det = new SeedDetermination();
/**
* Runs the simulator with the specified config file string.
* @param configFile
......@@ -57,9 +57,9 @@ public class RunnerController implements ActionListener {
private void runSimulator() {
SimulationThread simulationThread = new SimulationThread(selectedFile, det.getChosenSeed());
simulationThread.start();
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
while (true) {
......@@ -78,30 +78,30 @@ public class RunnerController implements ActionListener {
});
// thread.start();
}
public void setLastOpened(LastOpened lastOpened) {
this.lastOpened = lastOpened;
}
public SeedDetermination getDetermination() {
return det;
}
/**
* Called when the user wants to start the simulation.
*/
public void invokeRunSimulator() {
if (selectedFile == null) return; //No file is selected!
if (lastOpened != null) lastOpened.append(selectedFile);
lastOpened.saveToFile();
System.out.println("GUIRunner: Starting simulator with " + selectedFile.getFile().getAbsolutePath());
runner.disposeRunner();
det.saveSettings();
runSimulator();
}
......@@ -111,11 +111,11 @@ public class RunnerController implements ActionListener {
*/
public void selectFile(final ConfigFile file) {
selectedFile = file;
if (selectedFile == null) {
return;
}
selectedFile.loadConfiguration(new ConfigLoadedCallback() {
@Override
public void loadingFinished() {
......@@ -123,11 +123,11 @@ public class RunnerController implements ActionListener {
launchButton.setEnabled(selectedFile != null);
}
if (file != null) det.loadFile(selectedFile);
newFileSelected(file);
newFileSelected(file);
}
});
}
/**
* Sets the launch button that invokes the launch of the
* simulation
......@@ -144,15 +144,15 @@ public class RunnerController implements ActionListener {
invokeRunSimulator();
}
}
public void addListener(IRunnerCtrlListener l) {
listeners.add(l);
}
public void removeListener(IRunnerCtrlListener l) {
listeners.remove(l);
}
void newFileSelected(ConfigFile f) {
for (IRunnerCtrlListener l : listeners) l.newFileSelected(f);
}
......@@ -164,16 +164,16 @@ public class RunnerController implements ActionListener {
public void setMainWindow(GUIRunner runner) {
this.runner=runner;
}
public static interface IRunnerCtrlListener {
public void newFileSelected(ConfigFile f);
}
public ConfigFile getSelectedFile() {
return selectedFile;
}
}
......@@ -25,17 +25,20 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import de.tud.kom.p2psim.impl.vehicular.caching.decision.NewestCacheDecisionStrategy;
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.transition.TransitionEngine;
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;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.decision.CacheDecisionStrategy;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.decision.CacheSizeAwareCacheDecisionStrategy;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.invalidation.CacheInvalidationStrategy;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.replacement.CacheReplacementStrategy;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.AggregatedInformation;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.AvailableInformationAttributes;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.JamInformation;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.PointInformation;
......@@ -43,8 +46,8 @@ import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.Road
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetworkEdge;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetworkRoute;
public class DefaultCachingComponent
implements CachingComponent, ConnectivityListener {
public class DefaultCachingComponent implements CachingComponent, ConnectivityListener {
private Map<Class<? extends Object>, List<PointInformation>> _cache = new HashMap<>();
private Map<Integer, Integer> _lastColorValues = new HashMap<>();
......@@ -59,6 +62,8 @@ implements CachingComponent, ConnectivityListener {
private int _minObservations = 0;
private int _maxCacheSizePerEntry = Integer.MAX_VALUE;
private double[] informationRatios = new double[] {1, 0.75, 0.5, 0.25, 0};
public DefaultCachingComponent(Host pHost,
......@@ -68,13 +73,8 @@ implements CachingComponent, ConnectivityListener {
_host = pHost;
if (_host != null) {
NetInterface wifi = _host.getNetworkComponent().getByName(NetInterfaceName.WIFI);
if (wifi != null) {
wifi.addConnectivityListener(this);
} else {
NetInterface cellular = _host.getNetworkComponent().getByName(NetInterfaceName.MOBILE);
cellular.addConnectivityListener(this);
}
NetInterface cellular = _host.getNetworkComponent().getByName(NetInterfaceName.MOBILE);
cellular.addConnectivityListener(this);
}
_invalidationStrategy = pInvalidationStrategy;
......@@ -82,6 +82,14 @@ implements CachingComponent, ConnectivityListener {
_decisionStrategy = pDecisionStrategy;
}
private TransitionEngine getTransitionEngine() throws AssertionError {
try {
return getHost().getComponent(TransitionEngine.class);
} catch (ComponentNotAvailableException e) {
throw new AssertionError("Unable to get transition engine!");
}
}
@Override
public <T extends PointInformation> List<T> getDecidedCacheEntries(
Class<T> pCacheEntryClass) {
......@@ -121,6 +129,51 @@ implements CachingComponent, ConnectivityListener {
return decidedInformation;
}
@Override
public <T extends PointInformation> List<T> getDecidedCacheEntries(
Class<T> pCacheEntryClass, RoadNetworkEdge pEdge) {
return getDecidedCacheEntries(pCacheEntryClass, null, pEdge);
}
@Override
public <T extends PointInformation> List<T> getDecidedCacheEntries(
Class<T> pCacheEntryClass, Class<?> pCacheValueClass, RoadNetworkEdge pEdge) {
List<T> cacheEntries = getCacheEntries(pCacheEntryClass);
if (cacheEntries == null) {
return null;
}
Map<Class<? extends Object>, List<PointInformation>> similarCacheEntries = new HashMap<>();
for (T t : cacheEntries) {
Object position = getEdgeOrPosition(t);
// System.out.println(t.getDetectionDate() + " --> " + ((AggregatedInformation)t).getAggregationInformation().getMinTimestamp());
if (position.equals(pEdge) && (pCacheValueClass == null || t.getValue().getClass().equals(pCacheValueClass))) {
if (!similarCacheEntries.containsKey(t.getValue().getClass())) {
similarCacheEntries.put(t.getValue().getClass(), new ArrayList<PointInformation>());
}
similarCacheEntries.get(t.getValue().getClass()).add(t);
}
}
List<T> decidedInformation = new ArrayList<>();
for (List<PointInformation> similarInformation : similarCacheEntries.values()) {
if (similarInformation.size() >= _minObservations) {
PointInformation correctInformation = _decisionStrategy
.decideOnCorrectInformation(similarInformation);
decidedInformation.add((T) correctInformation);
}
}
return decidedInformation;
}
public void setMinObservations(int pMinObservations) {
this._minObservations = pMinObservations;
}
......@@ -163,12 +216,30 @@ implements CachingComponent, ConnectivityListener {
}
List<PointInformation> entries = _cache.get(pCacheEntry.getClass());
List<PointInformation> toBeRemoved = new ArrayList<>();
for (PointInformation pointInformation : entries) {
if (_replacementStrategy.replaceInformation(pointInformation, pCacheEntry)) {
toBeRemoved.add(pointInformation);
}
}
for (PointInformation pointInformation : toBeRemoved) {
entries.remove(pointInformation);
}
while (entries.size() > _maxCacheSizePerEntry - 1) {
entries.remove(0);
}
entries.add(pCacheEntry);
}
@Override
public void initialize() {
_cache.clear();
TransitionEngine tEngine = getTransitionEngine();
_decisionStrategy = tEngine.createMechanismProxy(CacheDecisionStrategy.class, _decisionStrategy, DECISION_STRATEGY);
}
@Override
......@@ -190,11 +261,41 @@ implements CachingComponent, ConnectivityListener {
}
@Override
public void performDecisionTransition(Class<? extends CacheDecisionStrategy> pCacheDecisionStrategy) {
getTransitionEngine().executeAtomicTransition(DECISION_STRATEGY, pCacheDecisionStrategy);
}
@Override
public void adjustCacheSizePerEntry(int pMaxCacheSizePerEntry) {
getTransitionEngine().alterLocalState(DECISION_STRATEGY, CacheSizeAwareCacheDecisionStrategy.class, "CacheSize", pMaxCacheSizePerEntry);
_maxCacheSizePerEntry = pMaxCacheSizePerEntry;
}
@Override
public void clear() {
_cache.clear();
}
@Override
public <T extends PointInformation> void partialClear(Class<T> pCacheEntryClass, Class<?> pCacheValueClass, RoadNetworkEdge pEdge) {
List<PointInformation> cacheEntries = _cache.get(pCacheEntryClass);
if (cacheEntries == null) {
return;
}
List<PointInformation> toBeRemoved = new ArrayList<>();
for (PointInformation entry : cacheEntries) {
if ((pEdge == null || getEdgeOrPosition(entry).equals(pEdge))
&& (pCacheEntryClass == null || entry.getValue().getClass().equals(pCacheValueClass))) {
toBeRemoved.add(entry);
}
}
cacheEntries.removeAll(toBeRemoved);
}
public Object getEdgeOrPosition(PointInformation information) {
if (information.hasAttribute(AvailableInformationAttributes.EDGE)) {
return information
......
......@@ -21,14 +21,25 @@
package de.tud.kom.p2psim.impl.vehicular.caching.decision;
import java.util.List;
import java.util.Map;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.NumericVectoralProperty;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.jam.VectoralJamProperty;
import de.tudarmstadt.maki.simonstrator.api.component.transition.TransferState;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.decision.AbstractCacheDecisionStrategy;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.decision.CacheDecisionStrategy;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.decision.CacheDecisionStrategyParameters;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.PointInformation;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.RoadInformation;
public class AveragingCacheDecisionStrategy implements CacheDecisionStrategy {
public class AveragingCacheDecisionStrategy extends AbstractCacheDecisionStrategy implements CacheDecisionStrategy {
private Map<CacheDecisionStrategyParameters, String> _params;
@TransferState(value = { "Params" })
public AveragingCacheDecisionStrategy(Map<CacheDecisionStrategyParameters, String> pParams) {
_params = pParams;
}
@Override
public <T extends PointInformation> T decideOnCorrectInformation(
......@@ -39,33 +50,38 @@ public class AveragingCacheDecisionStrategy implements CacheDecisionStrategy {
} else if (pSimilarPointInformation.size() == 0) {
return null;
}
double sum = 0;
double count = 0;
NumericVectoralProperty cloned = null;
for (T t : pSimilarPointInformation) {
RoadInformation roadInformation = ((RoadInformation) t);
NumericVectoralProperty property = (NumericVectoralProperty) roadInformation.getValue();
if (cloned == null) {
cloned = property.clone();
}
sum += property.getMostProbableValue();
count++;
}
double value = sum / count;
if (cloned instanceof VectoralJamProperty) {
((VectoralJamProperty) cloned).setSpeed(((int)(value / VectoralJamProperty.SCALING)) * VectoralJamProperty.SCALING);
} else {
throw new AssertionError("Unknown data type " + cloned.getClass().getSimpleName());
}
return (T) new RoadInformation(cloned);
RoadInformation aggregate = new RoadInformation(cloned);
addAggregationInformation(pSimilarPointInformation, aggregate);
return (T) aggregate;
}
public Map<CacheDecisionStrategyParameters, String> getParams() {
return _params;
}
}
......@@ -26,12 +26,13 @@ import java.util.HashMap;
import java.util.Map;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.decision.CacheDecisionStrategy;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.decision.CacheDecisionStrategyParameters;
public enum CacheDecisionStrategyType {
DEFAULT(NewestCacheDecisionStrategy.class), NEWEST(NewestCacheDecisionStrategy.class), MAJORITY(MajorityVotingCacheDecisionStrategy.class), AVERAGING(AveragingCacheDecisionStrategy.class), TTL(TTLbasedCacheDecisionStrategy.class), OPTIMAL(OptimalCacheDecisionStrategy.class), RANDOM(RandomCacheDecisionStrategy.class), TTL_VECTOR(TTLbasedVectoralCacheDecisionStrategy.class), MAJORITY_VECTOR(MajorityVotingVectoralCacheDecisionStrategy.class);
private final Class<? extends CacheDecisionStrategy> decisionStrategy;
private final Map<String, String> params = new HashMap<>();
private final Map<CacheDecisionStrategyParameters, String> params = new HashMap<>();
private CacheDecisionStrategyType(final Class<? extends CacheDecisionStrategy> decisionStrategy) {
this.decisionStrategy = decisionStrategy;
......@@ -50,7 +51,7 @@ public enum CacheDecisionStrategyType {
}
}
public void addAttribute(String pKey, String pValue) {
params.put(pKey, pValue);
public void addAttribute(CacheDecisionStrategyParameters pParam, String pValue) {
params.put(pParam, pValue);
}
}
......@@ -25,10 +25,21 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import de.tudarmstadt.maki.simonstrator.api.component.transition.TransferState;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.decision.AbstractCacheDecisionStrategy;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.decision.CacheDecisionStrategy;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.decision.CacheDecisionStrategyParameters;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.PointInformation;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.RoadInformation;
public class MajorityVotingCacheDecisionStrategy implements CacheDecisionStrategy {
public class MajorityVotingCacheDecisionStrategy extends AbstractCacheDecisionStrategy implements CacheDecisionStrategy {
private Map<CacheDecisionStrategyParameters, String> _params;
@TransferState(value = { "Params" })
public MajorityVotingCacheDecisionStrategy(Map<CacheDecisionStrategyParameters, String> pParams) {
_params = pParams;
}
@Override
public <T extends PointInformation> T decideOnCorrectInformation(
......@@ -64,7 +75,12 @@ public class MajorityVotingCacheDecisionStrategy implements CacheDecisionStrateg
}
}
addAggregationInformation(pSimilarPointInformation, maxFitting);
return maxFitting;
}
public Map<CacheDecisionStrategyParameters, String> getParams() {
return _params;
}
}
......@@ -21,23 +21,34 @@
package de.tud.kom.p2psim.impl.vehicular.caching.decision;
import java.util.List;
import java.util.Map;
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.transition.TransferState;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.decision.AbstractCacheDecisionStrategy;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.decision.CacheDecisionStrategy;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.decision.CacheDecisionStrategyParameters;
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 MajorityVotingVectoralCacheDecisionStrategy implements CacheDecisionStrategy {
public class MajorityVotingVectoralCacheDecisionStrategy extends AbstractCacheDecisionStrategy implements CacheDecisionStrategy {
private static final long SCALING = Time.SECOND;
private Map<CacheDecisionStrategyParameters, String> _params;
@TransferState(value = { "Params" })
public MajorityVotingVectoralCacheDecisionStrategy(Map<CacheDecisionStrategyParameters, String> pParams) {
_params = pParams;
}
@Override
public <T extends PointInformation> T decideOnCorrectInformation(
List<T> pSimilarPointInformation) {
VectoralProperty currentProperty = null;
long minTimestamp = Long.MAX_VALUE;
long maxTimestamp = 0;
for (T t : pSimilarPointInformation) {
......@@ -50,14 +61,14 @@ public class MajorityVotingVectoralCacheDecisionStrategy implements CacheDecisio
maxTimestamp = timestamp;
}
}
for (T t : pSimilarPointInformation) {
RoadInformation roadInformation = ((RoadInformation) t);
VectoralProperty property = (VectoralProperty) roadInformation.getValue();
TemporalDependencyMatrix dependencyMatrix = property.getDependencyMatrix();
VectoralProperty agedProperty = property.age((maxTimestamp - property.getDetectionDate()) / SCALING, dependencyMatrix);
if (currentProperty != null) {
currentProperty = currentProperty.combine(agedProperty);
......@@ -65,15 +76,16 @@ public class MajorityVotingVectoralCacheDecisionStrategy implements CacheDecisio
currentProperty = agedProperty;
}
}
// TemporalDependencyMatrix dependencyMatrix = currentProperty.getDependencyMatrix();
//
//
// VectoralProperty agedProperty = currentProperty.age((Time.getCurrentTime() - maxTimestamp) / SCALING, dependencyMatrix);
RoadInformation roadInformation = new RoadInformation(currentProperty);
copyAttributes((RoadInformation) pSimilarPointInformation.get(0), roadInformation);
addAggregationInformation(pSimilarPointInformation, roadInformation);
return (T) roadInformation;
}
......@@ -87,4 +99,8 @@ public class MajorityVotingVectoralCacheDecisionStrategy implements CacheDecisio
}
}
public Map<CacheDecisionStrategyParameters, String> getParams() {
return _params;
}
}
......@@ -21,11 +21,22 @@
package de.tud.kom.p2psim.impl.vehicular.caching.decision;
import java.util.List;
import java.util.Map;
import de.tudarmstadt.maki.simonstrator.api.component.transition.TransferState;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.decision.AbstractCacheDecisionStrategy;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.decision.CacheDecisionStrategy;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.decision.CacheDecisionStrategyParameters;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.PointInformation;
public class NewestCacheDecisionStrategy implements CacheDecisionStrategy {
public class NewestCacheDecisionStrategy extends AbstractCacheDecisionStrategy implements CacheDecisionStrategy {
private Map<CacheDecisionStrategyParameters, String> _params;
@TransferState(value = { "Params" })
public NewestCacheDecisionStrategy(Map<CacheDecisionStrategyParameters, String> pParams) {
_params = pParams;
}
@Override
public <T extends PointInformation> T decideOnCorrectInformation(
......@@ -41,4 +52,8 @@ public class NewestCacheDecisionStrategy implements CacheDecisionStrategy {
return chosenInformation;
}
public Map<CacheDecisionStrategyParameters, String> getParams() {
return _params;
}
}
......@@ -21,17 +21,26 @@
package de.tud.kom.p2psim.impl.vehicular.caching.decision;
import java.util.List;
import java.util.Map;
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.jam.JamProperty;
import de.tudarmstadt.maki.simonstrator.api.component.transition.TransferState;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.decision.AbstractCacheDecisionStrategy;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.decision.CacheDecisionStrategy;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.decision.CacheDecisionStrategyParameters;
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.roadnetwork.RoadNetworkEdge;
public class OptimalCacheDecisionStrategy implements CacheDecisionStrategy {
public OptimalCacheDecisionStrategy() {
public class OptimalCacheDecisionStrategy extends AbstractCacheDecisionStrategy implements CacheDecisionStrategy {
private Map<CacheDecisionStrategyParameters, String> _params;
@TransferState(value = { "Params" })
public OptimalCacheDecisionStrategy(Map<CacheDecisionStrategyParameters, String> pParams) {
_params = pParams;
}
@Override
......@@ -43,11 +52,11 @@ public class OptimalCacheDecisionStrategy implements CacheDecisionStrategy {
} else if (pSimilarPointInformation.size() == 0) {
return null;
}
RoadNetworkEdge edge = (RoadNetworkEdge) pSimilarPointInformation.get(0).getAttribute(AvailableInformationAttributes.EDGE);
double actualSpeed = edge.getCurrentSpeed();
JamProperty jamProperty = edge.getJamProperty();
long maxTimestamp;
......@@ -66,7 +75,7 @@ public class OptimalCacheDecisionStrategy implements CacheDecisionStrategy {
if (currentValue instanceof VectoralProperty) {
currentValue = ((VectoralProperty) currentValue).getMostProbableValue();
}
if (timestamp >= maxTimestamp) {
if (currentValue.equals(actualSpeed)) {
maxFitting = t;
......@@ -93,4 +102,9 @@ public class OptimalCacheDecisionStrategy implements CacheDecisionStrategy {
return maxFitting;
}
public Map<CacheDecisionStrategyParameters, String> getParams() {
return _params;
}
}
......@@ -21,16 +21,24 @@
package de.tud.kom.p2psim.impl.vehicular.caching.decision;
import java.util.List;
import java.util.Map;
import java.util.Random;
import de.tudarmstadt.maki.simonstrator.api.Randoms;
import de.tudarmstadt.maki.simonstrator.api.component.transition.TransferState;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.decision.AbstractCacheDecisionStrategy;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.decision.CacheDecisionStrategy;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.decision.CacheDecisionStrategyParameters;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.PointInformation;
public class RandomCacheDecisionStrategy implements CacheDecisionStrategy {
public class RandomCacheDecisionStrategy extends AbstractCacheDecisionStrategy implements CacheDecisionStrategy {
private Random _random = Randoms.getRandom(getClass());
public RandomCacheDecisionStrategy() {
private Map<CacheDecisionStrategyParameters, String> _params;
@TransferState(value = { "Params" })
public RandomCacheDecisionStrategy(Map<CacheDecisionStrategyParameters, String> pParams) {
_params = pParams;
}
@Override
......@@ -45,4 +53,9 @@ public class RandomCacheDecisionStrategy implements CacheDecisionStrategy {
return pSimilarPointInformation.get(_random.nextInt(pSimilarPointInformation.size()));
}
public Map<CacheDecisionStrategyParameters, String> getParams() {
return _params;
}
}
......@@ -32,17 +32,23 @@ 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.VectoralProperty;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.jam.VectoralJamProperty;
import de.tudarmstadt.maki.simonstrator.api.component.transition.TransferState;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.decision.AbstractCacheDecisionStrategy;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.decision.CacheDecisionStrategy;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.decision.CacheDecisionStrategyParameters;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.decision.CacheSizeAwareCacheDecisionStrategy;
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.relevance.impl.SimpleQoIBasedImpactFunction;
public class TTLbasedCacheDecisionStrategy implements CacheDecisionStrategy {
public class TTLbasedCacheDecisionStrategy extends AbstractCacheDecisionStrategy implements CacheSizeAwareCacheDecisionStrategy {
private static final long SCALING = Time.SECOND;
private static final double ACCURACY_FACTOR = 100000;
private final Map<CacheDecisionStrategyParameters, String> _params;
private long ttl = 300 * Time.SECOND / SCALING;
private double accuracy = 1;
......@@ -51,13 +57,17 @@ public class TTLbasedCacheDecisionStrategy implements CacheDecisionStrategy {
private Object _lastDecision = false;
public TTLbasedCacheDecisionStrategy(Map<String, String> pParams) {
for (Entry<String, String> param : pParams.entrySet()) {
private int _maxCacheSize = Integer.MAX_VALUE;
@TransferState(value = { "Params" })
public TTLbasedCacheDecisionStrategy(Map<CacheDecisionStrategyParameters, String> pParams) {
_params = pParams;
for (Entry<CacheDecisionStrategyParameters, String> param : pParams.entrySet()) {
switch (param.getKey()) {
case "ACCURACY":
case ACCURACY:
accuracy = Double.valueOf(param.getValue());
break;
case "COST_RATIO":
case COST_RATIO:
double ratio = Double.valueOf(param.getValue());
costWrongChange = 2 / (ratio + 1);
costWrongKeep = 2 - costWrongChange;
......@@ -81,6 +91,8 @@ public class TTLbasedCacheDecisionStrategy implements CacheDecisionStrategy {
List<T> pSimilarPointInformation) {
if (pSimilarPointInformation.size() == 1) {
T decision = pSimilarPointInformation.get(0);
addAggregationInformation(pSimilarPointInformation, decision);
_lastDecision = decision.getValue();
return decision;
} else if (pSimilarPointInformation.size() == 0) {
......@@ -104,94 +116,88 @@ public class TTLbasedCacheDecisionStrategy implements CacheDecisionStrategy {
}
}
if (differentValue) {
SimpleQoIBasedImpactFunction<T> impactFunction = new SimpleQoIBasedImpactFunction<>(pSimilarPointInformation, accuracy);
SimpleQoIBasedImpactFunction<T> impactFunction = new SimpleQoIBasedImpactFunction<>(pSimilarPointInformation, accuracy, _maxCacheSize);
Map<Object, Double> weight = new HashMap<>();
Map<Object, Double> weight = new HashMap<>();
for (T t : pSimilarPointInformation) {
double impact = impactFunction.calculateImpact(t);
double sumImpact = 0;
for (T t : pSimilarPointInformation) {
double impact = impactFunction.calculateImpact(t);
Object currentValue = t.getValue();
double sumImpact = 0;
if (currentValue instanceof VectoralJamProperty) {
currentValue = ((VectoralJamProperty) currentValue).getMostProbableValue();
}
Object currentValue = t.getValue();
if (weight.containsKey(currentValue)) {
sumImpact = weight.get(currentValue);
}
sumImpact += impact;
if (currentValue instanceof VectoralJamProperty) {
currentValue = ((VectoralJamProperty) currentValue).getMostProbableValue();
}
weight.put(currentValue, sumImpact);
if (weight.containsKey(currentValue)) {
sumImpact = weight.get(currentValue);
}
sumImpact += impact;
double maxWeight = -1;
Object maxValue = null;
weight.put(currentValue, sumImpact);
}
for (Object key : weight.keySet()) {
if (weight.get(key) > maxWeight) {
maxWeight = weight.get(key);
maxValue = key;
}
}
double maxWeight = -1;
Object maxValue = null;
long maxTimestamp = -1;
T maxFitting = null;
for (T t : pSimilarPointInformation) {
long timestamp = t.getDetectionDate();
for (Object key : weight.keySet()) {
if (weight.get(key) > maxWeight) {
maxWeight = weight.get(key);
maxValue = key;
}
}
Object currentValue = t.getValue();
if (currentValue instanceof VectoralProperty) {
currentValue = ((VectoralProperty)currentValue).getMostProbableValue();
}
long maxTimestamp = -1;
T maxFitting = null;
for (T t : pSimilarPointInformation) {
long timestamp = t.getDetectionDate();
if (currentValue.equals(maxValue) && timestamp > maxTimestamp) {
maxTimestamp = timestamp;
maxFitting = t;
}
Object currentValue = t.getValue();
if (currentValue instanceof VectoralProperty) {
currentValue = ((VectoralProperty)currentValue).getMostProbableValue();
}
if (maxFitting.getValue() instanceof VectoralProperty) {
VectoralProperty vectoralProperty = ((VectoralProperty)maxFitting.getValue()).clone();
double[] valueProbabilities = vectoralProperty.getValueProbabilities();
Arrays.fill(valueProbabilities, 0);
if (currentValue.equals(maxValue) && timestamp > maxTimestamp) {
maxTimestamp = timestamp;
maxFitting = t;
}
}
double sum = 0;
for (Object key : weight.keySet()) {
valueProbabilities[vectoralProperty.getIndexForValue(key)] = weight.get(key);
sum += weight.get(key);
}
if (maxFitting.getValue() instanceof VectoralProperty) {
VectoralProperty vectoralProperty = ((VectoralProperty)maxFitting.getValue()).clone();
double[] valueProbabilities = vectoralProperty.getValueProbabilities();
Arrays.fill(valueProbabilities, 0);
for (int i = 0; i < valueProbabilities.length; i++) {
valueProbabilities[i] /= sum;
}
double sum = 0;
for (Object key : weight.keySet()) {
valueProbabilities[vectoralProperty.getIndexForValue(key)] = weight.get(key);
sum += weight.get(key);
}
RoadInformation roadInformation = new RoadInformation(vectoralProperty);
roadInformation.copyAttributes((RoadInformation)maxFitting);
maxFitting = (T) roadInformation;
for (int i = 0; i < valueProbabilities.length; i++) {
valueProbabilities[i] /= sum;
}
_lastDecision = maxFitting.getValue();
RoadInformation roadInformation = new RoadInformation(vectoralProperty);
roadInformation.copyAttributes((RoadInformation)maxFitting);
maxFitting = (T) roadInformation;
}
return maxFitting;
} else {
long maxTimestamp = -1;
T maxFitting = null;
for (T t : pSimilarPointInformation) {
long timestamp = (long) t.getAttribute(AvailableInformationAttributes.TTL);
_lastDecision = maxFitting.getValue();
if (timestamp > maxTimestamp) {
maxTimestamp = timestamp;
maxFitting = t;
}
}
addAggregationInformation(pSimilarPointInformation, maxFitting);
_lastDecision = maxFitting.getValue();
return maxFitting;
}
return maxFitting;
}
public Map<CacheDecisionStrategyParameters, String> getParams() {
return _params;
}
@Override
public void setCacheSize(int pCacheSize) {
_maxCacheSize = pCacheSize;
}
}
......@@ -30,29 +30,42 @@ import java.util.Map.Entry;
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.transition.MechanismState;
import de.tudarmstadt.maki.simonstrator.api.component.transition.TransferState;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.decision.AbstractCacheDecisionStrategy;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.decision.CacheDecisionStrategy;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.decision.CacheDecisionStrategyParameters;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.decision.CacheSizeAwareCacheDecisionStrategy;
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.relevance.impl.VectoralQoIBasedImpactFunction;
public class TTLbasedVectoralCacheDecisionStrategy implements CacheDecisionStrategy {
public class TTLbasedVectoralCacheDecisionStrategy extends AbstractCacheDecisionStrategy implements CacheSizeAwareCacheDecisionStrategy {
private static final long SCALING = Time.SECOND;
private final Map<CacheDecisionStrategyParameters, String> _params;
private double accuracy = 1;
private double costWrongKeep = 1;
private double costWrongChange = 1;
@MechanismState(value = "CacheSize")
private int cacheSize = Integer.MAX_VALUE;
private Object _lastDecision = null;
public TTLbasedVectoralCacheDecisionStrategy(Map<String, String> pParams) {
for (Entry<String, String> param : pParams.entrySet()) {
@TransferState(value = { "Params" })
public TTLbasedVectoralCacheDecisionStrategy(Map<CacheDecisionStrategyParameters, String> pParams) {
_params = pParams;
for (Entry<CacheDecisionStrategyParameters, String> param : pParams.entrySet()) {
switch (param.getKey()) {
case "ACCURACY":
case ACCURACY:
accuracy = Double.valueOf(param.getValue());
break;
case "COST_RATIO":
case COST_RATIO:
double ratio = Double.valueOf(param.getValue());
costWrongChange = 2 / (ratio + 1);
costWrongKeep = 2 - costWrongChange;
......@@ -76,6 +89,8 @@ public class TTLbasedVectoralCacheDecisionStrategy implements CacheDecisionStrat
List<T> pSimilarPointInformation) {
if (pSimilarPointInformation.size() == 1) {
T decision = pSimilarPointInformation.get(0);
addAggregationInformation(pSimilarPointInformation, decision);
_lastDecision = decision.getValue();
return decision;
} else if (pSimilarPointInformation.size() == 0) {
......@@ -131,55 +146,39 @@ public class TTLbasedVectoralCacheDecisionStrategy implements CacheDecisionStrat
}
}
if (differentValue) {
VectoralProperty currentProperty = null;
VectoralQoIBasedImpactFunction<T> impactFunction = new VectoralQoIBasedImpactFunction<>(pSimilarPointInformation, accuracy, _lastDecision);
for (T t : pSimilarPointInformation) {
RoadInformation roadInformation = ((RoadInformation) t);
VectoralProperty property = (VectoralProperty) roadInformation.getValue();
VectoralProperty currentProperty = null;
double impact = impactFunction.calculateImpact(t);
VectoralQoIBasedImpactFunction<T> impactFunction = new VectoralQoIBasedImpactFunction<>(pSimilarPointInformation, accuracy, cacheSize, _lastDecision);
for (T t : pSimilarPointInformation) {
RoadInformation roadInformation = ((RoadInformation) t);
VectoralProperty property = (VectoralProperty) roadInformation.getValue();
double impact = impactFunction.calculateImpact(t);
TemporalDependencyMatrix dependencyMatrix = property.getDependencyMatrix();
dependencyMatrix = modifyDependencyMatrix(dependencyMatrix.age((maxTimestamp - property.getDetectionDate()) / SCALING), impact);
VectoralProperty agedProperty = property.age(1, dependencyMatrix);
if (currentProperty != null) {
currentProperty = currentProperty.combine(agedProperty);
} else {
currentProperty = agedProperty;
}
}
TemporalDependencyMatrix dependencyMatrix = property.getDependencyMatrix();
dependencyMatrix = modifyDependencyMatrix(dependencyMatrix.age((maxTimestamp - property.getDetectionDate()) / SCALING), impact);
if (Double.isNaN(currentProperty.getValueProbabilities()[0])) {
return pSimilarPointInformation.get(pSimilarPointInformation.size() - 1);
VectoralProperty agedProperty = property.age(1, dependencyMatrix);
if (currentProperty != null) {
currentProperty = currentProperty.combine(agedProperty);
} else {
currentProperty = agedProperty;
}
}
RoadInformation roadInformation = new RoadInformation(currentProperty);
copyAttributes((RoadInformation) pSimilarPointInformation.get(0), roadInformation);
_lastDecision = roadInformation.getValue();
if (Double.isNaN(currentProperty.getValueProbabilities()[0])) {
return pSimilarPointInformation.get(pSimilarPointInformation.size() - 1);
}
return (T) roadInformation;
} else {
maxTimestamp = -1;
T maxFitting = null;
for (T t : pSimilarPointInformation) {
long timestamp = (long) t.getAttribute(AvailableInformationAttributes.TTL);
RoadInformation roadInformation = new RoadInformation(currentProperty);
if (timestamp > maxTimestamp) {
maxTimestamp = timestamp;
maxFitting = t;
}
}
copyAttributes((RoadInformation) pSimilarPointInformation.get(pSimilarPointInformation.size() - 1), roadInformation);
addAggregationInformation(pSimilarPointInformation, roadInformation);
_lastDecision = maxFitting.getValue();
_lastDecision = roadInformation.getValue();
return maxFitting;
}
return (T) roadInformation;
}
/**
......@@ -208,4 +207,13 @@ public class TTLbasedVectoralCacheDecisionStrategy implements CacheDecisionStrat
return result;
}
public Map<CacheDecisionStrategyParameters, String> getParams() {
return _params;
}
@Override
public void setCacheSize(int pCacheSize) {
cacheSize = pCacheSize;
}
}
......@@ -21,9 +21,10 @@
package de.tud.kom.p2psim.impl.vehicular.caching.replacement;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.replacement.CacheReplacementStrategy;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.replacement.SimilarInformationReplacementStrategy;
public enum CacheReplacementStrategyType {
DEFAULT(NoCacheReplacementStrategy.class), NONE(NoCacheReplacementStrategy.class), IMMEDIATE(ImmediateCacheReplacementStrategy.class), TTL(TTLbasedCacheReplacementStrategy.class);
DEFAULT(NoCacheReplacementStrategy.class), NONE(NoCacheReplacementStrategy.class), IMMEDIATE(ImmediateCacheReplacementStrategy.class), TTL(TTLbasedCacheReplacementStrategy.class), SIMILAR(SimilarInformationReplacementStrategy.class);
private final Class<? extends CacheReplacementStrategy> replacementStrategy;
......
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