Commit 8cd09a42 authored by Mahesh Tripunitara's avatar Mahesh Tripunitara
Browse files

Merge branch 'master' of https://bitbucket.org/jshahen/vagabond into ReduceToCNFSAT

parents 9e9deb6a c445c6d2
......@@ -21,10 +21,10 @@ import vagabond.reduction.ReduceTo;
import vagabond.reduction.RunSolver;
import vagabond.reduction.cnfsat.ReduceToCNFSAT;
import vagabond.reduction.cnfsat.RunSolverCNFSAT;
import vagabond.reduction.ilp.ReduceToILP;
import vagabond.reduction.ilp.RunSolverILP;
import vagabond.reduction.ilp.*;
import vagabond.reduction.nomad.ReduceToNomad;
import vagabond.reduction.nomad.RunSolverNomad;
import vagabond.results.ResultsManager;
import vagabond.singleton.VagabondSettings;
import vagabond.testing.PlacementMapExamples;
import vagabond.timing.StatisticsManager;
......@@ -111,6 +111,15 @@ public class VagabondInstance {
EpochHistory epochHistory = new EpochHistory(settings.slidingWindow);
// IMPORTANT: add the placementMap to the EpochHistory before starting the reductions
epochHistory.add(placementMap);
if (logger.isLoggable(FINE)) {
logger.fine("Summation of Client-to-Client Information Leakage (Z variable):\n"
+ epochHistory._sumOfInformationLeakage);
}
// Results Initial Placement
settings.results = new ResultsManager();
settings.results.initialPlacement = placementMap;
settings.results.initialCCIL = epochHistory.get(0);
// Reduce the PlacementMap
ReduceTo reduction = null;
......@@ -135,6 +144,15 @@ public class VagabondInstance {
case REDUCTION_ILP:
reduction = new ReduceToILP();
runSolver = new RunSolverILP();
// TODO Remove me!
if (false) {
FileWriter fw = new FileWriter(settings.logFolder + "/ilpData.dat");
fw.write(WriteILPFile.toILPString(epochHistory));
fw.close();
throw new Exception("KILLING PROCESS! ILP wrote file out");
}
break;
case REDUCTION_NOMAD:
reduction = new ReduceToNomad();
......@@ -155,7 +173,7 @@ public class VagabondInstance {
if (runSolver == null) { throw new Exception(
"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
*/
......@@ -172,19 +190,21 @@ public class VagabondInstance {
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
logger.info("Loading the Solver for EPOCH " + e);
if (runSolver.load(reduction) == false) { throw new Exception(
"Unable to load the reduction into the runSolver with the reduction: "
+ 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
logger.info("Running the Solver for EPOCH " + e);
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
if (newEpochHistory == null) { throw new Exception(
......@@ -192,6 +212,10 @@ public class VagabondInstance {
// Adding the however many Epochs to the running Epoch History (could be 1 or a whole sliding window)
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) {
logger.info("Placement Map at the END of Epoch " + e + "\n" + epochHistory._latestPlacementMap);
......@@ -213,6 +237,10 @@ public class VagabondInstance {
/* Timing */timing.stopTimer("totalTime");
// Results Final Placement
settings.results.finalPlacement = epochHistory._latestPlacementMap;
settings.results.finalCCIL = epochHistory.get(0);
// Add a custom Stat event for the
timing.putRawTimeEvent("averageEpochTime", stats.getAvgEpochTimeEvent());
......@@ -220,6 +248,9 @@ public class VagabondInstance {
logger.info("Writing Timing Results to " + settings.getTimingFile().getAbsolutePath());
timing.writeOut(settings.getTimingFile(), true);
logger.info("Writing Results to " + settings.getResultsFile().getAbsolutePath());
settings.results.writeOut(settings.getResultsFile().getAbsolutePath());
} catch (Exception e) {
ErrorPrinter ep = new ErrorPrinter(e);
if (logger != null) {
......
......@@ -20,6 +20,11 @@ public class ClientToClientKey {
}
}
public ClientToClientKey(ClientToClientKey key) {
_lowerClientID = key._lowerClientID;
_higherClientID = key._higherClientID;
}
public boolean equals(final Object O) {
if (!(O instanceof ClientToClientKey))
return false;
......
......@@ -71,6 +71,38 @@ public class ClientToClientInformationLeakage {
/* 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
*/
......@@ -276,8 +308,8 @@ public class ClientToClientInformationLeakage {
val2 = s2._matrix.get(key);
if (!val2.equals(0)) {
val2 = val2 * -1;
val1 = _matrix.merge(key, val2, Integer::sum);
val1 = _matrix.get(key) - val2;
_matrix.put(key, val1);
} else {
val1 = _matrix.get(key);
}
......
......@@ -13,7 +13,7 @@ import vagabond.singleton.VagabondSettings;
*/
public class EpochHistory {
public static Logger logger;
//public RotatingArray<PlacementMap> _placementMapHistory;
// public RotatingArray<PlacementMap> _placementMapHistory;
public PlacementMap _latestPlacementMap = null;
public RotatingArray<ClientToClientInformationLeakage> _informationLeakageHistory;
public ClientToClientInformationLeakage _sumOfInformationLeakage = null;
......@@ -21,7 +21,7 @@ public class EpochHistory {
public EpochHistory(Integer slidingWindow) {
logger = VagabondSettings.getInstance().getLogger();
//_placementMapHistory = new RotatingArray<>(slidingWindow);
// _placementMapHistory = new RotatingArray<>(slidingWindow);
_informationLeakageHistory = new RotatingArray<>(slidingWindow);
_slidingWindow = slidingWindow;
}
......@@ -32,13 +32,14 @@ public class EpochHistory {
*/
public void add(PlacementMap placementMap) {
if (placementMap == null) { throw new IllegalArgumentException("PlacementMap cannot be NULL!"); }
ClientToClientInformationLeakage tmp = new ClientToClientInformationLeakage(placementMap);
add(tmp);
_latestPlacementMap = placementMap;
}
/**
* 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)
......@@ -47,20 +48,25 @@ public class EpochHistory {
public void add(ClientToClientInformationLeakage tmp) {
if (tmp == null) { throw new IllegalArgumentException("ClientToClientInformationLeakage cannot be NULL!"); }
_latestPlacementMap = null;
if(_sumOfInformationLeakage == null) {
_sumOfInformationLeakage = tmp;
// System.out.println("_sumOfInformationLeakage:\n" + _sumOfInformationLeakage);
if (_sumOfInformationLeakage == null) {
_sumOfInformationLeakage = new ClientToClientInformationLeakage(tmp);
} else {
_sumOfInformationLeakage.addTo(tmp);
_sumOfInformationLeakage.addTo(tmp);
}
// System.out.println("_sumOfInformationLeakage.addTo:\n" + _sumOfInformationLeakage);
ClientToClientInformationLeakage last = _informationLeakageHistory.getEndOfArray();
if(last != null) {
_sumOfInformationLeakage.subtractFrom(last);
if (last != null) {
// System.out.println("last:\n" + last);
_sumOfInformationLeakage.subtractFrom(last);
// System.out.println("_sumOfInformationLeakage.subtractFrom:\n" + _sumOfInformationLeakage);
}
_informationLeakageHistory.pushToFirst(tmp);
}
......@@ -95,7 +101,7 @@ public class EpochHistory {
for (int i = epochHistory.size() - 1; i >= 0; i--) {
add(epochHistory.get(i));
}
_latestPlacementMap = epochHistory._latestPlacementMap;
}
......
......@@ -221,7 +221,7 @@ public class PlacementMap {
public String getFormatString(PlacementMapDisplayStyle displayStyle) {
StringBuilder sb = new StringBuilder();
if (displayStyle != PlacementMapDisplayStyle.CSV) {
if (displayStyle == PlacementMapDisplayStyle.CSV) {
sb.append(Machine.getCSVHeaderString()).append("\n");
}
......
......@@ -69,8 +69,8 @@ public class ReduceToILP implements ReduceTo {
IloOplModelSource modelSource = oplF.createOplModelSource(settings.dataFolder + "/ilp.mod");
/*TIMING*/timing.stopTimer("ReduceToILP::reduce::readOPL");
IloOplSettings settings = oplF.createOplSettings(errHandler);
IloOplModelDefinition def = oplF.createOplModelDefinition(modelSource, settings);
IloOplSettings oplSettings = oplF.createOplSettings(errHandler);
IloOplModelDefinition def = oplF.createOplModelDefinition(modelSource, oplSettings);
cplex = oplF.createCplex();
if (!logger.isLoggable(Level.FINE)) {
......@@ -91,6 +91,9 @@ public class ReduceToILP implements ReduceTo {
opl.generate();
/*TIMING*/timing.stopTimer("ReduceToILP::reduce::generate");
// Set the optimization parameters
opl.getCplex().setParam(IloCplex.Param.MIP.Tolerances.MIPGap, settings.relativeMIPGapTolerance);
/*TIMING*/timing.stopTimer("ReduceToILP::reduce");
return true;
}
......
package vagabond.results;
import java.io.FileWriter;
import java.io.IOException;
import vagabond.enums.PlacementMapDisplayStyle;
import vagabond.pieces.ClientToClientInformationLeakage;
import vagabond.pieces.PlacementMap;
import vagabond.singleton.VagabondSettings;
public class ResultsManager {
public static String separator = "\n\n###############################\n\n";
public PlacementMap initialPlacement = null;
public PlacementMap finalPlacement = null;
public ClientToClientInformationLeakage initialCCIL = null;
public ClientToClientInformationLeakage finalCCIL = null;
public boolean writeOut(String filePath) throws IOException {
boolean result = true;
VagabondSettings settings = VagabondSettings.getInstance();
FileWriter fw = new FileWriter(filePath);
fw.write("Settings:\n");
fw.write(settings.toString().replace(", ", "\n"));
fw.write(separator);
fw.write("Initial Placement:\n");
fw.write(initialPlacement.getFormatString(PlacementMapDisplayStyle.VAGABOND));
fw.write(separator);
fw.write("Initial Client-To-Client Information Leakage:\n");
fw.write(initialCCIL.getFormatString(PlacementMapDisplayStyle.VAGABOND, 0));
fw.write(separator);
fw.write("Final Placement:\n");
fw.write(finalPlacement.getFormatString(PlacementMapDisplayStyle.VAGABOND));
fw.write(separator);
fw.write("Final Client-To-Client Information Leakage:\n");
fw.write(finalCCIL.getFormatString(PlacementMapDisplayStyle.VAGABOND, 0));
fw.close();
return result;
}
}
......@@ -10,6 +10,7 @@ import vagabond.enums.PlacementMapDisplayStyle;
import vagabond.helper.ErrorPrinter;
import vagabond.logging.CSVFileFormatter;
import vagabond.logging.ConsoleFormatter;
import vagabond.results.ResultsManager;
import vagabond.testing.PlacementMapExamples;
import vagabond.timing.StatisticsManager;
import vagabond.timing.TimingManager;
......@@ -61,11 +62,6 @@ public class VagabondSettings {
*/
public Boolean displayPlacementMapEveryEpoch = true;
/**
* Filename of the results file (should be stored under the folder stored in {@link #logFolder}
*/
public String resultsFile = "vagabond.results.csv";
/**
* Stores the output filename of the PlacementMap if the PlacementMap needs to be printed out
* @see vagabond.pieces.PlacementMap
......@@ -85,6 +81,15 @@ public class VagabondSettings {
*/
public String timingFile = "vagabond.timing.csv";
/**
* The results manager that holds all of the raw results information for the instance.
*/
public ResultsManager results = new ResultsManager();
/**
* The file name of the results results file to write out; SHOULD be stored under the folder {@link #logFolder}.
*/
public String resultsFile = "vagabond.results.txt";
/**
* The statistics manager that calculates all of the stats that can be graphed later
*/
......@@ -153,6 +158,12 @@ public class VagabondSettings {
*/
public Integer equalSpreadNum = 0;
/**
* The relative MIP Gap Tolerance to set CPLEX to; the default value in CPLEX is 1e-4.
* @vagabond.category ILP Optimization Parameter
*/
public double relativeMIPGapTolerance = .1;
/**
* Prevents programmers from creating their own settings, there must be only one copy of this.
* @see #getInstance()
......@@ -181,13 +192,20 @@ public class VagabondSettings {
s.append("numberOfEpochs=" + numberOfEpochs + ", ");
s.append("slidingWindow=" + slidingWindow + ", ");
s.append("migrationBudget=" + migrationBudget + ", ");
s.append("settingsFile=" + settingsFile);
switch (reductionAlgorithm) {
case REDUCTION_ILP:
s.append("relativeMIPGapTolerance=" + relativeMIPGapTolerance + ", ");
break;
default:
}
switch (placementAlgorithm) {
case PLACEMENT_FILE:
s.append("placementMapFile=" + placementMapFile + ", ");
break;
case PLACEMENT_EQUALSPREAD:
case PLACEMENT_EQUALSPREADHALF:
s.append("equalSpreadNum=" + equalSpreadNum + ", ");
break;
default:
......@@ -201,6 +219,8 @@ public class VagabondSettings {
break;
}
s.append("settingsFile=" + settingsFile + ", ");
s.append("}");
return s.toString();
......@@ -285,7 +305,7 @@ public class VagabondSettings {
}
/**
* Descriptive function to return the file path of the timing file. Used to write out the timing results.
* Function to return the file path of the timing file. Used to write out the timing results.
* This should be considered a WRITE only file.
* @return File object to the timing file; might not be created yet.
*/
......@@ -293,6 +313,15 @@ public class VagabondSettings {
return new File(logFolder + File.separator + timingFile);
}
/**
* Function to return the file path of the results file. Used to write out the timing results.
* This should be considered a WRITE only file.
* @return File object to the results file; might not be created yet.
*/
public File getResultsFile() {
return new File(logFolder + File.separator + resultsFile);
}
/**
* Closes all of the open handles and removes all the locks from log files.
* If System.exit() needs to be called or the program exits normally,
......
......@@ -5,8 +5,7 @@ import static org.junit.Assert.assertEquals;
import org.junit.*;
import org.junit.runners.MethodSorters;
import vagabond.pieces.ClientToClientInformationLeakage;
import vagabond.pieces.PlacementMap;
import vagabond.pieces.*;
import vagabond.placement.RandomPlacement;
import vagabond.timing.TimingManager;
......@@ -127,6 +126,135 @@ public class ClientToClientInformationLeakageTests {
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
public void nomadLargeILPTestSize() {
TimingManager timing = new TimingManager();
......
......@@ -9,15 +9,15 @@ public class TimingManagerTests {
@Test
public void toggleTest() throws InterruptedException {
TimingManager timing = new TimingManager();
timing.toggleTime("key1");
timing.toggleTimer("key1");
Thread.sleep(40);
timing.toggleTime("key1");
timing.toggleTime("key2");
timing.toggleTime("key3");
timing.toggleTimer("key1");
timing.toggleTimer("key2");
timing.toggleTimer("key3");
Thread.sleep(20);