Commit da0b63f8 authored by Jonathan Shahen's avatar Jonathan Shahen
Browse files

HOTFIX: EpochHistory required a Deep copy of the first...

HOTFIX: EpochHistory required a Deep copy of the first ClientToClientInformationLeak so that it can subtract properly; fixed typo in TimerManger toggleTimer*; added a new test for Half Full Equal Spread
parent 7f7236d9
...@@ -21,8 +21,7 @@ import vagabond.reduction.ReduceTo; ...@@ -21,8 +21,7 @@ import vagabond.reduction.ReduceTo;
import vagabond.reduction.RunSolver; import vagabond.reduction.RunSolver;
import vagabond.reduction.cnfsat.ReduceToCNFSAT; import vagabond.reduction.cnfsat.ReduceToCNFSAT;
import vagabond.reduction.cnfsat.RunSolverCNFSAT; import vagabond.reduction.cnfsat.RunSolverCNFSAT;
import vagabond.reduction.ilp.ReduceToILP; import vagabond.reduction.ilp.*;
import vagabond.reduction.ilp.RunSolverILP;
import vagabond.reduction.nomad.ReduceToNomad; import vagabond.reduction.nomad.ReduceToNomad;
import vagabond.reduction.nomad.RunSolverNomad; import vagabond.reduction.nomad.RunSolverNomad;
import vagabond.singleton.VagabondSettings; import vagabond.singleton.VagabondSettings;
...@@ -111,6 +110,10 @@ public class VagabondInstance { ...@@ -111,6 +110,10 @@ public class VagabondInstance {
EpochHistory epochHistory = new EpochHistory(settings.slidingWindow); EpochHistory epochHistory = new EpochHistory(settings.slidingWindow);
// IMPORTANT: add the placementMap to the EpochHistory before starting the reductions // IMPORTANT: add the placementMap to the EpochHistory before starting the reductions
epochHistory.add(placementMap); epochHistory.add(placementMap);
if (logger.isLoggable(FINE)) {
logger.fine("Summation of Client-to-Client Information Leakage (Z variable):\n"
+ epochHistory._sumOfInformationLeakage);
}
// Reduce the PlacementMap // Reduce the PlacementMap
ReduceTo reduction = null; ReduceTo reduction = null;
...@@ -155,7 +158,7 @@ public class VagabondInstance { ...@@ -155,7 +158,7 @@ public class VagabondInstance {
if (runSolver == null) { throw new Exception( if (runSolver == null) { throw new Exception(
"Unable to create a RunSolver with the settings: " + settings.toString()); } "Unable to create a RunSolver with the settings: " + settings.toString()); }
/* Timing */timing.toggleTime("VagabondInstance::main()::epochLoop::" + e + "::reduce"); /* Timing */timing.toggleTimer("VagabondInstance::main()::epochLoop::" + e + "::reduce");
/** /**
* Reduce the current EpochHistory * Reduce the current EpochHistory
*/ */
...@@ -172,19 +175,21 @@ public class VagabondInstance { ...@@ -172,19 +175,21 @@ public class VagabondInstance {
throw new Exception("Unable to reduce with the current PlacementMap"); throw new Exception("Unable to reduce with the current PlacementMap");
} }
/* Timing */timing.toggleTime("VagabondInstance::main()::epochLoop::" + e + "::reduce"); /* Timing */timing.toggleTimer("VagabondInstance::main()::epochLoop::" + e + "::reduce");
/* Timing */timing.toggleTime("VagabondInstance::main()::epochLoop::" + e + "::load"); /* Timing */timing.toggleTimer("VagabondInstance::main()::epochLoop::" + e + "::load");
// Load the Solver + Error checking // Load the Solver + Error checking
logger.info("Loading the Solver for EPOCH " + e);
if (runSolver.load(reduction) == false) { throw new Exception( if (runSolver.load(reduction) == false) { throw new Exception(
"Unable to load the reduction into the runSolver with the reduction: " "Unable to load the reduction into the runSolver with the reduction: "
+ reduction.toString()); } + reduction.toString()); }
/* Timing */timing.toggleTime("VagabondInstance::main()::epochLoop::" + e + "::load"); /* Timing */timing.toggleTimer("VagabondInstance::main()::epochLoop::" + e + "::load");
/* Timing */timing.toggleTime("VagabondInstance::main()::epochLoop::" + e + "::run"); /* Timing */timing.toggleTimer("VagabondInstance::main()::epochLoop::" + e + "::run");
// Run The Solver // Run The Solver
logger.info("Running the Solver for EPOCH " + e);
EpochHistory newEpochHistory = runSolver.run(); EpochHistory newEpochHistory = runSolver.run();
/* Timing */timing.toggleTime("VagabondInstance::main()::epochLoop::" + e + "::run"); /* Timing */timing.toggleTimer("VagabondInstance::main()::epochLoop::" + e + "::run");
// ERROR CHECKING for getting the new result // ERROR CHECKING for getting the new result
if (newEpochHistory == null) { throw new Exception( if (newEpochHistory == null) { throw new Exception(
...@@ -192,6 +197,10 @@ public class VagabondInstance { ...@@ -192,6 +197,10 @@ public class VagabondInstance {
// Adding the however many Epochs to the running Epoch History (could be 1 or a whole sliding window) // Adding the however many Epochs to the running Epoch History (could be 1 or a whole sliding window)
epochHistory.add(newEpochHistory); epochHistory.add(newEpochHistory);
if (logger.isLoggable(Level.FINE)) {
logger.fine("Summation of Client-to-Client Information Leakage (Z variable):\n"
+ epochHistory._sumOfInformationLeakage);
}
if (settings.displayPlacementMapEveryEpoch) { if (settings.displayPlacementMapEveryEpoch) {
logger.info("Placement Map at the END of Epoch " + e + "\n" + epochHistory._latestPlacementMap); logger.info("Placement Map at the END of Epoch " + e + "\n" + epochHistory._latestPlacementMap);
......
...@@ -20,6 +20,11 @@ public class ClientToClientKey { ...@@ -20,6 +20,11 @@ public class ClientToClientKey {
} }
} }
public ClientToClientKey(ClientToClientKey key) {
_lowerClientID = key._lowerClientID;
_higherClientID = key._higherClientID;
}
public boolean equals(final Object O) { public boolean equals(final Object O) {
if (!(O instanceof ClientToClientKey)) if (!(O instanceof ClientToClientKey))
return false; return false;
......
...@@ -71,6 +71,38 @@ public class ClientToClientInformationLeakage { ...@@ -71,6 +71,38 @@ public class ClientToClientInformationLeakage {
/* Timing */timing.stopTimer("ClientToClientInformationLeakage:constructor"); /* Timing */timing.stopTimer("ClientToClientInformationLeakage:constructor");
} }
/**
* Performs a Deep copy of an existing ClientToClientInformationLeakage
* @param tmp item to copy into a new ClientToClientInformationLeakage
*/
public ClientToClientInformationLeakage(ClientToClientInformationLeakage tmp) {
settings = VagabondSettings.getInstance();
logger = settings.getLogger();
timing = settings.timing;
_ref = tmp._ref;
_numberOfClients = tmp._numberOfClients;
_maxInformationLeak = tmp._maxInformationLeak;
_maxInformationLeakKey = new ClientToClientKey(tmp._maxInformationLeakKey);
_matrix = new Hashtable<>(_numberOfClients * _numberOfClients);
/* Timing */timing
.toggleTimer("ClientToClientInformationLeakage:constructor(ClientToClientInformationLeakage)");
// Deep Copy the Client IDs
_clientIDs = new ArrayList<>(_numberOfClients);
for (Integer c : tmp._clientIDs) {
_clientIDs.add(new Integer(c));
}
for (ClientToClientKey key : tmp._matrix.keySet()) {
_matrix.put(key, new Integer(tmp._matrix.get(key)));
}
/* Timing */timing
.toggleTimer("ClientToClientInformationLeakage:constructor(ClientToClientInformationLeakage)");
}
/** /**
* Calculates the &lt;R,C&gt; information leakage * Calculates the &lt;R,C&gt; information leakage
*/ */
...@@ -276,8 +308,8 @@ public class ClientToClientInformationLeakage { ...@@ -276,8 +308,8 @@ public class ClientToClientInformationLeakage {
val2 = s2._matrix.get(key); val2 = s2._matrix.get(key);
if (!val2.equals(0)) { if (!val2.equals(0)) {
val2 = val2 * -1; val1 = _matrix.get(key) - val2;
val1 = _matrix.merge(key, val2, Integer::sum); _matrix.put(key, val1);
} else { } else {
val1 = _matrix.get(key); val1 = _matrix.get(key);
} }
......
...@@ -13,7 +13,7 @@ import vagabond.singleton.VagabondSettings; ...@@ -13,7 +13,7 @@ import vagabond.singleton.VagabondSettings;
*/ */
public class EpochHistory { public class EpochHistory {
public static Logger logger; public static Logger logger;
//public RotatingArray<PlacementMap> _placementMapHistory; // public RotatingArray<PlacementMap> _placementMapHistory;
public PlacementMap _latestPlacementMap = null; public PlacementMap _latestPlacementMap = null;
public RotatingArray<ClientToClientInformationLeakage> _informationLeakageHistory; public RotatingArray<ClientToClientInformationLeakage> _informationLeakageHistory;
public ClientToClientInformationLeakage _sumOfInformationLeakage = null; public ClientToClientInformationLeakage _sumOfInformationLeakage = null;
...@@ -21,7 +21,7 @@ public class EpochHistory { ...@@ -21,7 +21,7 @@ public class EpochHistory {
public EpochHistory(Integer slidingWindow) { public EpochHistory(Integer slidingWindow) {
logger = VagabondSettings.getInstance().getLogger(); logger = VagabondSettings.getInstance().getLogger();
//_placementMapHistory = new RotatingArray<>(slidingWindow); // _placementMapHistory = new RotatingArray<>(slidingWindow);
_informationLeakageHistory = new RotatingArray<>(slidingWindow); _informationLeakageHistory = new RotatingArray<>(slidingWindow);
_slidingWindow = slidingWindow; _slidingWindow = slidingWindow;
} }
...@@ -39,6 +39,7 @@ public class EpochHistory { ...@@ -39,6 +39,7 @@ public class EpochHistory {
_latestPlacementMap = placementMap; _latestPlacementMap = placementMap;
} }
/** /**
* Adds a ClientToClientInformationLeakage to the start of the history and adds it to the sum of information leaks * Adds a ClientToClientInformationLeakage to the start of the history and adds it to the sum of information leaks
* and removes the last element in the history (taken from all of the capacity) * and removes the last element in the history (taken from all of the capacity)
...@@ -48,17 +49,22 @@ public class EpochHistory { ...@@ -48,17 +49,22 @@ public class EpochHistory {
if (tmp == null) { throw new IllegalArgumentException("ClientToClientInformationLeakage cannot be NULL!"); } if (tmp == null) { throw new IllegalArgumentException("ClientToClientInformationLeakage cannot be NULL!"); }
_latestPlacementMap = null; _latestPlacementMap = null;
// System.out.println("_sumOfInformationLeakage:\n" + _sumOfInformationLeakage);
if(_sumOfInformationLeakage == null) { if (_sumOfInformationLeakage == null) {
_sumOfInformationLeakage = tmp; _sumOfInformationLeakage = new ClientToClientInformationLeakage(tmp);
} else { } else {
_sumOfInformationLeakage.addTo(tmp); _sumOfInformationLeakage.addTo(tmp);
} }
// System.out.println("_sumOfInformationLeakage.addTo:\n" + _sumOfInformationLeakage);
ClientToClientInformationLeakage last = _informationLeakageHistory.getEndOfArray(); ClientToClientInformationLeakage last = _informationLeakageHistory.getEndOfArray();
if(last != null) { if (last != null) {
// System.out.println("last:\n" + last);
_sumOfInformationLeakage.subtractFrom(last); _sumOfInformationLeakage.subtractFrom(last);
// System.out.println("_sumOfInformationLeakage.subtractFrom:\n" + _sumOfInformationLeakage);
} }
_informationLeakageHistory.pushToFirst(tmp); _informationLeakageHistory.pushToFirst(tmp);
......
...@@ -5,8 +5,7 @@ import static org.junit.Assert.assertEquals; ...@@ -5,8 +5,7 @@ import static org.junit.Assert.assertEquals;
import org.junit.*; import org.junit.*;
import org.junit.runners.MethodSorters; import org.junit.runners.MethodSorters;
import vagabond.pieces.ClientToClientInformationLeakage; import vagabond.pieces.*;
import vagabond.pieces.PlacementMap;
import vagabond.placement.RandomPlacement; import vagabond.placement.RandomPlacement;
import vagabond.timing.TimingManager; import vagabond.timing.TimingManager;
...@@ -127,6 +126,135 @@ public class ClientToClientInformationLeakageTests { ...@@ -127,6 +126,135 @@ public class ClientToClientInformationLeakageTests {
assertEquals(0, s1.getMaxInformationLeak()); assertEquals(0, s1.getMaxInformationLeak());
} }
@Test
public void subtractionTest2() {
ClientToClientInformationLeakage s1 = new ClientToClientInformationLeakage(standardPlacement);
ClientToClientInformationLeakage s2 = new ClientToClientInformationLeakage(standardPlacement);
s1.addTo(s2);
s1.addTo(s2);
System.out.println("s1:" + s1);
System.out.println("s2:" + s2);
// subtractFrom function
s1.subtractFrom(s2);
System.out.println("s1-s2:" + s1);
// Loop through and make sure they all equal 0
Integer zero = 0;
Integer six = 6;
for (Integer c1 : s1._clientIDs) {
for (Integer c2 : s1._clientIDs) {
Integer infoLeak = s1.get(c1, c2);
System.out.println("c1=" + c1 + "; c2=" + c2 + "; infoLeak=" + infoLeak);
if (c1.equals(c2)) {
assertEquals(zero, infoLeak);
} else {
assertEquals(six, infoLeak);
}
}
}
assertEquals(3, s2.getMaxInformationLeak());
assertEquals(6, s1.getMaxInformationLeak());
}
@Test
public void epochHistoryTest() {
EpochHistory eh = new EpochHistory(5);
assertEquals(0, eh.size());
eh.add(standardPlacement);
assertEquals(1, eh.size());
eh.add(standardPlacement);
assertEquals(2, eh.size());
Integer zero = 0;
Integer six = 6;
for (Integer c1 : eh._sumOfInformationLeakage._clientIDs) {
for (Integer c2 : eh._sumOfInformationLeakage._clientIDs) {
Integer infoLeak = eh._sumOfInformationLeakage.get(c1, c2);
// System.out.println("c1=" + c1 + "; c2=" + c2 + "; infoLeak=" + infoLeak);
if (c1.equals(c2)) {
assertEquals(zero, infoLeak);
} else {
assertEquals(six, infoLeak);
}
}
}
eh.add(standardPlacement);
assertEquals(3, eh.size());
eh.add(standardPlacement);
assertEquals(4, eh.size());
Integer twelve = 12;
for (Integer c1 : eh._sumOfInformationLeakage._clientIDs) {
for (Integer c2 : eh._sumOfInformationLeakage._clientIDs) {
Integer infoLeak = eh._sumOfInformationLeakage.get(c1, c2);
// System.out.println("c1=" + c1 + "; c2=" + c2 + "; infoLeak=" + infoLeak);
if (c1.equals(c2)) {
assertEquals(zero, infoLeak);
} else {
assertEquals(twelve, infoLeak);
}
}
}
eh.add(standardPlacement);
assertEquals(5, eh.size());
Integer fifteen = 15;
for (Integer c1 : eh._sumOfInformationLeakage._clientIDs) {
for (Integer c2 : eh._sumOfInformationLeakage._clientIDs) {
Integer infoLeak = eh._sumOfInformationLeakage.get(c1, c2);
// System.out.println("c1=" + c1 + "; c2=" + c2 + "; infoLeak=" + infoLeak);
if (c1.equals(c2)) {
assertEquals(zero, infoLeak);
} else {
assertEquals(fifteen, infoLeak);
}
}
}
eh.add(standardPlacement);
assertEquals(5, eh.size());
for (Integer c1 : eh._sumOfInformationLeakage._clientIDs) {
for (Integer c2 : eh._sumOfInformationLeakage._clientIDs) {
Integer infoLeak = eh._sumOfInformationLeakage.get(c1, c2);
// System.out.println("c1=" + c1 + "; c2=" + c2 + "; infoLeak=" + infoLeak);
if (c1.equals(c2)) {
assertEquals(zero, infoLeak);
} else {
assertEquals(fifteen, infoLeak);
}
}
}
eh.add(standardPlacement);
assertEquals(5, eh.size());
for (Integer c1 : eh._sumOfInformationLeakage._clientIDs) {
for (Integer c2 : eh._sumOfInformationLeakage._clientIDs) {
Integer infoLeak = eh._sumOfInformationLeakage.get(c1, c2);
// System.out.println("c1=" + c1 + "; c2=" + c2 + "; infoLeak=" + infoLeak);
if (c1.equals(c2)) {
assertEquals(zero, infoLeak);
} else {
assertEquals(fifteen, infoLeak);
}
}
}
}
@Test @Test
public void nomadLargeILPTestSize() { public void nomadLargeILPTestSize() {
TimingManager timing = new TimingManager(); TimingManager timing = new TimingManager();
......
...@@ -9,15 +9,15 @@ public class TimingManagerTests { ...@@ -9,15 +9,15 @@ public class TimingManagerTests {
@Test @Test
public void toggleTest() throws InterruptedException { public void toggleTest() throws InterruptedException {
TimingManager timing = new TimingManager(); TimingManager timing = new TimingManager();
timing.toggleTime("key1"); timing.toggleTimer("key1");
Thread.sleep(40); Thread.sleep(40);
timing.toggleTime("key1"); timing.toggleTimer("key1");
timing.toggleTime("key2"); timing.toggleTimer("key2");
timing.toggleTime("key3"); timing.toggleTimer("key3");
Thread.sleep(20); Thread.sleep(20);
timing.toggleTime("key3"); timing.toggleTimer("key3");
Thread.sleep(30); Thread.sleep(30);
timing.toggleTime("key2"); timing.toggleTimer("key2");
System.out.println(timing.toString()); System.out.println(timing.toString());
} }
......
...@@ -84,7 +84,7 @@ public class TimingManager { ...@@ -84,7 +84,7 @@ public class TimingManager {
* </pre> * </pre>
* @param key the timer key to start or stop * @param key the timer key to start or stop
*/ */
public void toggleTime(String key) { public void toggleTimer(String key) {
TimingEvent t = timings.get(key); TimingEvent t = timings.get(key);
if (t == null) { if (t == null) {
......
# I am a comment
numberOfEpochs=16
slidingWindow=5
placement=equalSpreadHalf
equalSpreadNum=5
reduction=ilp
migrationBudget=3
# OPTIONAL: Can Comment these lines out
# numberOfMachines=-1
# numberOfMachineSlots=-1
# numberOfClients=-1
# numberOfVMsPerClient=-1
# fillInEmpty=false
# seed=12
\ No newline at end of file
Supports Markdown
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