Commit 70f0b7c3 authored by Tobias Meuser's avatar Tobias Meuser
Browse files

Merge changes of Björn Büschke

parents c911a273 58f23c9b
......@@ -40,7 +40,6 @@ 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.PointInformation;
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.RoadNetworkRoute;
......@@ -58,6 +57,8 @@ implements CachingComponent, ConnectivityListener {
private CacheDecisionStrategy _decisionStrategy;
private int _minObservations = 0;
private double[] informationRatios = new double[] {1, 0.75, 0.5, 0.25, 0};
public DefaultCachingComponent(Host pHost,
......@@ -67,8 +68,13 @@ implements CachingComponent, ConnectivityListener {
_host = pHost;
if (_host != null) {
_host.getNetworkComponent().getByName(NetInterfaceName.WIFI)
.addConnectivityListener(this);
NetInterface wifi = _host.getNetworkComponent().getByName(NetInterfaceName.WIFI);
if (wifi != null) {
wifi.addConnectivityListener(this);
} else {
NetInterface cellular = _host.getNetworkComponent().getByName(NetInterfaceName.MOBILE);
cellular.addConnectivityListener(this);
}
}
_invalidationStrategy = pInvalidationStrategy;
......@@ -85,28 +91,40 @@ implements CachingComponent, ConnectivityListener {
return null;
}
Map<Object, List<PointInformation>> similarCacheEntries = new HashMap<>();
Map<Object, Map<Class<? extends Object>, List<PointInformation>>> similarCacheEntries = new HashMap<>();
for (T t : cacheEntries) {
Object position = getEdgeOrPosition(t);
if (!similarCacheEntries.containsKey(position)) {
similarCacheEntries.put(position, new ArrayList<>());
similarCacheEntries.put(position, new HashMap<>());
}
similarCacheEntries.get(position).add(t);
if (!similarCacheEntries.get(position).containsKey(t.getValue().getClass())) {
similarCacheEntries.get(position).put(t.getValue().getClass(), new ArrayList<PointInformation>());
}
similarCacheEntries.get(position).get(t.getValue().getClass()).add(t);
}
List<T> decidedInformation = new ArrayList<>();
for (List<PointInformation> similarEntries : similarCacheEntries
for (Map<Class<? extends Object>, List<PointInformation>> similarEdges : similarCacheEntries
.values()) {
PointInformation correctInformation = _decisionStrategy
.decideOnCorrectInformation(similarEntries);
decidedInformation.add((T) correctInformation);
for (List<PointInformation> similarInformation : similarEdges.values()) {
if (similarInformation.size() >= _minObservations) {
PointInformation correctInformation = _decisionStrategy
.decideOnCorrectInformation(similarInformation);
decidedInformation.add((T) correctInformation);
}
}
}
return decidedInformation;
}
public void setMinObservations(int pMinObservations) {
this._minObservations = pMinObservations;
}
@Override
public <T extends PointInformation> List<T> getCacheEntries(
Class<T> pCacheEntryClass) {
......
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