Commit 79b45ab4 authored by Jonathan Shahen's avatar Jonathan Shahen
Browse files

Stats Manager now correctly fills for every reduction; nomad now has epoch...

Stats Manager now correctly fills for every reduction; nomad now has epoch times and correct average epoch
parent 2dd17578
......@@ -31,7 +31,7 @@ public class VagabondCUI {
printCommonCommands();
System.out.print("Enter Commandline Argument ('!exit' to run): ");
System.out.print("Enter Commandline Argument ('!e' to run): ");
String quotedStr = "";
StringBuilder fullCommand = new StringBuilder();
while (true) {
......@@ -55,11 +55,11 @@ public class VagabondCUI {
continue;
}
if (cmd.equals("!exit")) {
if (cmd.equals("!e")) {
break;
}
if (cmd.equals("!prev")) {
if (cmd.equals("!p")) {
argv.clear();
argv.addAll(Arrays.asList(previousCmd.split(" ")));
break;
......@@ -72,7 +72,7 @@ public class VagabondCUI {
System.out.println("Commands: " + argv);
try {
if (!cmd.equals("!prev")) {
if (!cmd.equals("!p")) {
FileWriter fw;
fw = new FileWriter(previousCommandFilename, false);
fw.write(fullCommand.toString());
......@@ -92,21 +92,21 @@ public class VagabondCUI {
public static void printCommonCommands() {
System.out.println("\n\n--- Common Commands ---");
System.out.println("-loglevel verbose -settings tests/simpletestILP-Random.properties !exit");
System.out.println("-loglevel verbose -settings tests/simpletestILP-NomadSubOptimal.properties !exit");
System.out.println("-loglevel verbose -settings tests/equalSpread_10.properties !exit");
System.out.println("-loglevel verbose -settings tests/simpletestILP-Random.properties !e");
System.out.println("-loglevel verbose -settings tests/simpletestILP-NomadSubOptimal.properties !e");
System.out.println("-loglevel verbose -settings tests/equalSpread_10.properties !e");
System.out.println("");
System.out.println("-loglevel verbose -settings tests/simpletestILP-NomadSubOptimal.properties !exit");
System.out.println("-loglevel verbose -settings tests/simpletestILP-NomadSubOptimal.properties !e");
System.out.println("-noplacementmaps -loglevel verbose "
+ "-settings tests/simpletestILP-NomadSubOptimal.properties !exit");
System.out.println("-loglevel verbose -settings tests/simpletestILPNoMigrationBudget.properties !exit");
System.out.println("-loglevel verbose -settings tests/simpletestILPLargeTestNoMig.properties !exit");
+ "-settings tests/simpletestILP-NomadSubOptimal.properties !e");
System.out.println("-loglevel verbose -settings tests/simpletestILPNoMigrationBudget.properties !e");
System.out.println("-loglevel verbose -settings tests/simpletestILPLargeTestNoMig.properties !e");
System.out.println("");
System.out.println("-loglevel verbose -settings tests/simpletestCNF.properties !exit");
System.out.println("-loglevel verbose -settings tests/simpletestCNFNoMigrationBudget.properties !exit");
System.out.println("-loglevel verbose -settings tests/simpletestCNF.properties !e");
System.out.println("-loglevel verbose -settings tests/simpletestCNFNoMigrationBudget.properties !e");
System.out.println("");
System.out.println("-loglevel verbose -settings tests/simpletestNomad.properties !exit");
System.out.println("-loglevel verbose -settings tests/simpletestNomadNoMigrationBudget.properties !exit");
System.out.println("-loglevel verbose -settings tests/simpletestNomad.properties !e");
System.out.println("-loglevel verbose -settings tests/simpletestNomadNoMigrationBudget.properties !e");
System.out.println("");
try {
BufferedReader bfr = new BufferedReader(new FileReader(previousCommandFilename));
......
......@@ -247,15 +247,15 @@ public class VagabondInstance {
/* Timing */stats.addEpochTime(timing.stopTimer(tp + "VagabondInstance::main()::epochLoop::totalTime"));
// STATS
stats.listTIL.add(epochHistory.get(0).getSumInformationLeak());
stats.listMCCIL.add(epochHistory.get(0).getMaxInformationLeak());
stats.listMovesPerEpoch.add(epochHistory._latestNumberOfMoves);
// Must be after the STATS
if (settings.reductionAlgorithm == VagabondOptionString.REDUCTION_NOMAD) {
logger.info("Exiting the EPOCH LOOP because Nomad does its own EPOCH LOOP.");
break;
} else {
// STATS
stats.listTIL.add(epochHistory.get(0).getSumInformationLeak());
stats.listMCCIL.add(epochHistory.get(0).getMaxInformationLeak());
stats.listMovesPerEpoch.add(epochHistory._latestNumberOfMoves);
}
}
/** *****************************************************************************
......@@ -277,7 +277,12 @@ public class VagabondInstance {
stats.eh = epochHistory;
// Write out all the stats
stats.writeOut(settings.getStatsFile());
try {
stats.writeOut(settings.getStatsFile());
} catch (IOException e) {
logger.severe("Unable to write Stats out to: " + settings.getStatsFile().getAbsolutePath());
logger.severe(stats.getCSVStatsLine());
}
// Results Final Placement
settings.results.finalPlacement = epochHistory._latestPlacementMap;
......@@ -286,7 +291,14 @@ public class VagabondInstance {
// Write out the results
logger.info("Writing Results to " + settings.getResultsFile().getAbsolutePath());
settings.results.writeOut(settings.getResultsFile().getAbsolutePath());
try {
settings.results.writeOut(settings.getResultsFile().getAbsolutePath());
} catch (IOException e) {
logger.severe("Unable to write Results out to: " + settings.getResultsFile().getAbsolutePath());
String tmp = settings.getResultsFile().getAbsolutePath() + "." + System.currentTimeMillis() + ".txt";
logger.severe("Trying again to a random filename: " + tmp);
settings.results.writeOut(tmp);
}
} catch (Exception e) {
ErrorPrinter ep = new ErrorPrinter(e);
......@@ -491,6 +503,8 @@ public class VagabondInstance {
value = prop.getProperty(VagabondOptionString.RANDOMSEED.toString(), null);
if (value != null) {
settings.randomSeed = Integer.valueOf(value);
} else {
settings.randomSeed = System.currentTimeMillis();
}
value = prop.getProperty(VagabondOptionString.TESTNAME.toString(), null);
......
......@@ -28,6 +28,19 @@ public class EpochHistory {
_slidingWindow = slidingWindow;
}
/**
* Get the ClientToClientInformationLeakage stored at a relative epoch: epoch=0 is the current epoch,
* epoch=2 is 2 epochs ago.
* <p>
* Please note: ClientToClientInformationLeakage get pushed back in time every time {@link #add} is called and thus
* erases the last element in the list, when the list is full.
* @param epoch The relative epoch that the PlacementMap was stored.
* @return the PlacementMap at the relative epoch (0 is the top, 1 is 1 epoch into the past)
*/
public ClientToClientInformationLeakage get(int epoch) {
return _informationLeakageHistory.get(epoch);
}
/**
* Adds a PlacementMap to the start of the history (to the most recent slot)
* @param placementMap complete PlacementMap to be added (cannot be NULL)
......@@ -35,15 +48,21 @@ 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);
/**
* MUST DO THIS BEFORE add(ClientToClientInformationLeakage)
*/
if (_latestPlacementMap != null) {
_latestNumberOfMoves = _latestPlacementMap.countNumberOfMoves(placementMap);
} else {
_latestNumberOfMoves = 0;
}
System.out.println("Number of Moves: " + _latestNumberOfMoves);
// System.out.println("_latest: " + _latestPlacementMap);
// System.out.println("placementMap: " + placementMap);
ClientToClientInformationLeakage tmp = new ClientToClientInformationLeakage(placementMap);
add(tmp); // nullifies _latestPlacementMap
_latestPlacementMap = placementMap;
}
......@@ -77,19 +96,6 @@ public class EpochHistory {
_informationLeakageHistory.pushToFirst(tmp);
}
/**
* Get the ClientToClientInformationLeakage stored at a relative epoch: epoch=0 is the current epoch,
* epoch=2 is 2 epochs ago.
* <p>
* Please note: ClientToClientInformationLeakage get pushed back in time every time {@link #add} is called and thus
* erases the last element in the list, when the list is full.
* @param epoch The relative epoch that the PlacementMap was stored.
* @return the PlacementMap at the relative epoch (0 is the top, 1 is 1 epoch into the past)
*/
public ClientToClientInformationLeakage get(int epoch) {
return _informationLeakageHistory.get(epoch);
}
/**
* Adds all of the PlacementMaps from the input EpochHistory into this instance.
* Adds the PlacementMaps in reverse order so that they get stored in the same orientation as the input
......
......@@ -11,6 +11,7 @@ import org.apache.commons.csv.*;
import vagabond.enums.PlacementMapDisplayStyle;
import vagabond.pieces.*;
import vagabond.results.StatisticsManager;
import vagabond.singleton.VagabondSettings;
/**
......@@ -152,7 +153,8 @@ public class PlacementMapFile {
return success;
}
public static EpochHistory readEpochHistory(File input) throws IOException {
public static EpochHistory readEpochHistory(File input, int slidingWindow, StatisticsManager stats)
throws IOException {
Logger logger = VagabondSettings.getInstance().getLogger();
if (!input.exists()) { throw new IOException(
......@@ -190,6 +192,11 @@ public class PlacementMapFile {
}
currentEpoch = Integer.decode(record.get(1));
if (stats != null) {
stats.addEpochTime(Long.decode(record.get(2)));
}
continue;
}
......@@ -215,14 +222,20 @@ public class PlacementMapFile {
}
PlacementMap place = arrangePlacementMap(flexiblePlacement);
outOfOrderPlacementMaps.put(currentEpoch, place);
flexiblePlacement.clear();
EpochHistory eh = new EpochHistory(outOfOrderPlacementMaps.size());
EpochHistory eh = new EpochHistory(slidingWindow);
PlacementMap tmp = null;
for (int i = outOfOrderPlacementMaps.size() - 1; i >= 0; i--) {
tmp = outOfOrderPlacementMaps.get(i);
if (tmp == null) { throw new IllegalArgumentException("Missing the Epoch: " + i); }
eh.add(tmp);
if (stats != null) {
// STATS
stats.listTIL.add(eh.get(0).getSumInformationLeak());
stats.listMCCIL.add(eh.get(0).getMaxInformationLeak());
stats.listMovesPerEpoch.add(eh._latestNumberOfMoves);
}
}
// Update the settings file
......
package vagabond.reduction.nomad;
import java.io.IOException;
import java.util.ArrayList;
import java.util.concurrent.TimeUnit;
import java.util.logging.Logger;
......@@ -18,6 +19,9 @@ public class RunSolverNomad implements RunSolver {
public String tp = "Epoch_Unknown";
public ReduceToNomad rt;
public ArrayList<Integer> listTIL;
public ArrayList<Integer> listMCCIL;
public ArrayList<Integer> listMovesPerEpoch;
public RunSolverNomad() {
settings = VagabondSettings.getInstance();
......@@ -84,7 +88,8 @@ public class RunSolverNomad implements RunSolver {
}
/*TIMING*/timing.toggleTimer(tp + "RunSolverNomad::run::readEpochHistory");
EpochHistory eh = PlacementMapFile.readEpochHistory(rt.nomadResultsFile);
EpochHistory eh = PlacementMapFile.readEpochHistory(rt.nomadResultsFile, settings.slidingWindow,
settings.stats);
/*TIMING*/timing.toggleTimer(tp + "RunSolverNomad::run::readEpochHistory");
/*TIMING*/timing.toggleTimer(tp + "RunSolverNomad::run::totalTime");
......
......@@ -41,12 +41,12 @@ public class StatisticsManager {
if (writeHeader) {
String header = getCSVHeader();
System.out.println(header);
// System.out.println(header);
stats.write(header);
}
String line = getCSVStatsLine();
System.out.println(line);
// System.out.println(line);
stats.write(line);
......
......@@ -237,7 +237,7 @@ public class VagabondSettings {
/**
* @see VagabondOptionString#RANDOMSEED
*/
public Integer randomSeed = -1;
public long randomSeed = -1;
/**
* @see VagabondOptionString#PLACEMENT
*/
......
......@@ -16,7 +16,7 @@ public class PlacementMapFileTests {
@Test
public void testReadEpochHistory() throws IOException {
EpochHistory eh = PlacementMapFile.readEpochHistory(new File("tests/placementMapHistory.csv"));
EpochHistory eh = PlacementMapFile.readEpochHistory(new File("tests/placementMapHistory.csv"), 5, null);
PlacementMap pControl = PlacementMapExamples.nomadSubOptimalRCPlacement();
assertEquals(5, eh.size());
......
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