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