m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorMagdalena Grodzińska <mag.grodzinska@gmail.com>2020-01-10 23:18:46 +0100
committerMagdalena Grodzińska <mag.grodzinska@gmail.com>2020-01-10 23:18:46 +0100
commitf943acc55cfc133ad93801f3498b7662ccbe3a92 (patch)
treeb1a589ec06fef623813d45999902805505908a1e /src/main
parent49127ab77cdaabb867cecc6e8669b5fbdb8ccb50 (diff)
Fix strategies after adding test
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/GossipGirlStrategies.java21
1 files changed, 16 insertions, 5 deletions
diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/GossipGirlStrategies.java b/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/GossipGirlStrategies.java
index 774e509..4cd534e 100644
--- a/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/GossipGirlStrategies.java
+++ b/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/GossipGirlStrategies.java
@@ -40,16 +40,17 @@ public class GossipGirlStrategies {
zoneProbabilities.add(probPair);
}
- uniformDist = new EnumeratedDistribution<String>(zoneProbabilities);
+ expDist = new EnumeratedDistribution<String>(zoneProbabilities);
}
private void initUniformZoneProbabilities() {
ArrayList<Pair<String, Double>> zoneProbabilities;
zoneProbabilities = new ArrayList<>(fullPathLength);
+ Double uniformProb = 1.0/fullPathLength;
// TODO good direction
for (int i = 0; i < fullPathLength; i++) {
- Pair<String, Double> probPair = new Pair<String, Double>(fullPathComponents.get(i), 1.0);
+ Pair<String, Double> probPair = new Pair<String, Double>(fullPathComponents.get(i), uniformProb);
zoneProbabilities.add(probPair);
}
@@ -77,16 +78,26 @@ public class GossipGirlStrategies {
Pair<String, Integer> nextP = roundRobinExpFreqs.get(i-1);
if (2 * p.getSecond() < nextP.getSecond()) {
- roundRobinExpFreqs.add(i, new Pair<String, Integer>(p.getFirst(), p.getSecond() + 1));
+ roundRobinExpFreqs.set(i, new Pair<String, Integer>(p.getFirst(), p.getSecond() + 1));
return p.getFirst();
}
}
Pair<String, Integer> rootPath = roundRobinExpFreqs.get(0);
- roundRobinExpFreqs.add(0, new Pair<String, Integer>(rootPath.getFirst(), rootPath.getSecond() + 1));
+ roundRobinExpFreqs.set(0, new Pair<String, Integer>(rootPath.getFirst(), rootPath.getSecond() + 1));
return rootPath.getFirst();
}
+ private String formNewPath(String selectedPath) {
+ String newPath = "";
+ for (String pathEl : fullPathComponents) {
+ newPath = newPath.concat("/" + pathEl);
+ if (pathEl.equals(selectedPath))
+ break;
+ }
+ return newPath;
+ }
+
public PathName selectStrategy(ZoneSelectionStrategy selectionStrategy) {
String selectedPath = null;
@@ -108,6 +119,6 @@ public class GossipGirlStrategies {
throw new UnsupportedOperationException("Such strategy doesn't exist");
}
- return new PathName(selectedPath);
+ return new PathName(formNewPath(selectedPath));
}
}