From f943acc55cfc133ad93801f3498b7662ccbe3a92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magdalena=20Grodzi=C5=84ska?= Date: Fri, 10 Jan 2020 23:18:46 +0100 Subject: Fix strategies after adding test --- .../agent/modules/GossipGirlStrategies.java | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'src/main') 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(zoneProbabilities); + expDist = new EnumeratedDistribution(zoneProbabilities); } private void initUniformZoneProbabilities() { ArrayList> zoneProbabilities; zoneProbabilities = new ArrayList<>(fullPathLength); + Double uniformProb = 1.0/fullPathLength; // TODO good direction for (int i = 0; i < fullPathLength; i++) { - Pair probPair = new Pair(fullPathComponents.get(i), 1.0); + Pair probPair = new Pair(fullPathComponents.get(i), uniformProb); zoneProbabilities.add(probPair); } @@ -77,16 +78,26 @@ public class GossipGirlStrategies { Pair nextP = roundRobinExpFreqs.get(i-1); if (2 * p.getSecond() < nextP.getSecond()) { - roundRobinExpFreqs.add(i, new Pair(p.getFirst(), p.getSecond() + 1)); + roundRobinExpFreqs.set(i, new Pair(p.getFirst(), p.getSecond() + 1)); return p.getFirst(); } } Pair rootPath = roundRobinExpFreqs.get(0); - roundRobinExpFreqs.add(0, new Pair(rootPath.getFirst(), rootPath.getSecond() + 1)); + roundRobinExpFreqs.set(0, new Pair(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)); } } -- cgit v1.2.3