Commit 1b43e579 authored by Jonathan Shahen's avatar Jonathan Shahen
Browse files

Intermediate commit for the Stats manager to fix CNF SAT not working multiple times

parent 587e7237
......@@ -26,9 +26,9 @@ import vagabond.reduction.ilp.RunSolverILP;
import vagabond.reduction.nomad.ReduceToNomad;
import vagabond.reduction.nomad.RunSolverNomad;
import vagabond.results.ResultsManager;
import vagabond.results.StatisticsManager;
import vagabond.singleton.VagabondSettings;
import vagabond.testing.PlacementMapExamples;
import vagabond.timing.StatisticsManager;
import vagabond.timing.TimingManager;
/**
......@@ -257,18 +257,18 @@ public class VagabondInstance {
/* Timing */timing.stopTimer("totalTime");
logger.info(timing.toString());
logger.info("Writing Timing Results to " + settings.getTimingFile().getAbsolutePath());
timing.writeOut(settings.getTimingFile(), true);
// Write out all the stats
// Results Final Placement
settings.results.finalPlacement = epochHistory._latestPlacementMap;
settings.results.finalCCIL = epochHistory.get(0);
settings.results.eh = epochHistory;
// Add a custom Stat event for the
timing.putRawTimeEvent("averageEpochTime", stats.getAvgEpochTimeEvent());
logger.info(timing.toString());
logger.info("Writing Timing Results to " + settings.getTimingFile().getAbsolutePath());
timing.writeOut(settings.getTimingFile(), true);
// Write out the results
logger.info("Writing Results to " + settings.getResultsFile().getAbsolutePath());
settings.results.writeOut(settings.getResultsFile().getAbsolutePath());
......
......@@ -19,6 +19,8 @@ public class EpochHistory {
public ClientToClientInformationLeakage _sumOfInformationLeakage = null;
public Integer _slidingWindow = null;
public Integer _numberOfMoves = null;
public EpochHistory(Integer slidingWindow) {
logger = VagabondSettings.getInstance().getLogger();
// _placementMapHistory = new RotatingArray<>(slidingWindow);
......@@ -37,6 +39,9 @@ public class EpochHistory {
add(tmp);
if (_latestPlacementMap != null) {
_numberOfMoves = _latestPlacementMap.countNumberOfMoves(placementMap);
}
_latestPlacementMap = placementMap;
}
......
......@@ -2,7 +2,6 @@ package vagabond.pieces;
import java.io.BufferedWriter;
import java.io.IOException;
import java.util.*;
import vagabond.enums.PlacementMapDisplayStyle;
......@@ -251,7 +250,7 @@ public class PlacementMap {
m.writeOut(writer, displayStyle);
}
}
/**
* Get the VMs of a client on this machine. Return's null if no such machine exists.
*
......@@ -260,24 +259,27 @@ public class PlacementMap {
* @return a list of VMs
*/
public List<VM> getClientVMsOnMachine(Integer mID, Integer cID) {
Machine theMachine = null;
for(Iterator<Machine> i = _machines.iterator(); i.hasNext(); ) {
Machine m = i.next();
if(m._machineID.equals(mID)) {
theMachine = m; break;
}
}
if(theMachine == null) return null;
List<VM> ret = new LinkedList<VM>();
for(Iterator<VM> i = theMachine._vms.iterator(); i.hasNext(); ) {
VM avm = i.next();
if(avm._clientID.equals(cID)) ret.add(avm);
}
return ret;
}
Machine theMachine = null;
for (Iterator<Machine> i = _machines.iterator(); i.hasNext();) {
Machine m = i.next();
if (m._machineID.equals(mID)) {
theMachine = m;
break;
}
}
if (theMachine == null)
return null;
List<VM> ret = new LinkedList<VM>();
for (Iterator<VM> i = theMachine._vms.iterator(); i.hasNext();) {
VM avm = i.next();
if (avm._clientID.equals(cID))
ret.add(avm);
}
return ret;
}
/**
* Returns the maximum number of VMs any Client has
......@@ -383,4 +385,50 @@ public class PlacementMap {
return true;
}
/**
* Counts the number of moves that occur between this placement map to get to the placement map provided
* @param placementMap the end placement map to calculate the number of moves made
* @return how many moves it takes to get to the provided placement
*/
public Integer countNumberOfMoves(PlacementMap placementMap) {
// VM Global ID => Machine ID
Hashtable<Integer, Integer> vmLocation1 = new Hashtable<Integer, Integer>(getNumberOfVMs());
Hashtable<Integer, Integer> vmLocation2 = new Hashtable<Integer, Integer>(placementMap.getNumberOfVMs());
// Fill vmLocation1
for (Machine m : _machines) {
for (VM vm : m._vms) {
vmLocation1.put(vm._globalID, m._machineID);
}
}
// Fill vmLocation2
for (Machine m : placementMap._machines) {
for (VM vm : m._vms) {
vmLocation2.put(vm._globalID, m._machineID);
}
}
if (vmLocation1.size() != vmLocation2
.size()) { throw new IllegalArgumentException(
"Placement Maps must have the same number of VMs\nthis=" + toString() + "\ninput="
+ placementMap); }
Integer numMoves = 0;
Integer tmp;
for (Integer vmID : vmLocation1.keySet()) {
tmp = vmLocation2.get(vmID);
if (tmp == null) { throw new IllegalArgumentException(
"Unable to find VM ID " + vmID + " in the input placement map!\nthis=" + toString() + "\ninput="
+ placementMap); }
if (vmLocation1.get(vmID) != tmp) {
numMoves++;
}
}
return numMoves;
}
}
package vagabond.timing;
package vagabond.results;
import java.sql.Timestamp;
import java.util.ArrayList;
public class StatisticsManager {
public ArrayList<Long> epochTimes;
public Long avgEpochTime = null;
public StatisticsManager() {
epochTimes = new ArrayList<>();
......@@ -15,23 +15,18 @@ public class StatisticsManager {
}
public Long getAvgEpochTime() {
Long sum = (long) 0;
for (Long epochTime : epochTimes) {
sum += epochTime;
}
return (long) ((double) sum) / epochTimes.size();
return getAvgEpochTime(false);
}
public TimingEvent getAvgEpochTimeEvent() {
TimingEvent avgEpochTimeEvent = new TimingEvent();
avgEpochTimeEvent.category = "STATS";
avgEpochTimeEvent.comment = "Calculated in Java";
avgEpochTimeEvent.failed = false;
avgEpochTimeEvent.finishTimeMilliSec = avgEpochTimeEvent.getCurrentMilliSec();
avgEpochTimeEvent.startTimeMilliSec = avgEpochTimeEvent.finishTimeMilliSec - getAvgEpochTime();
avgEpochTimeEvent.finishTime = new Timestamp(avgEpochTimeEvent.finishTimeMilliSec);
avgEpochTimeEvent.startTime = new Timestamp(avgEpochTimeEvent.startTimeMilliSec);
return avgEpochTimeEvent;
public Long getAvgEpochTime(boolean recalculate) {
if (avgEpochTime == null || recalculate) {
Long sum = (long) 0;
for (Long epochTime : epochTimes) {
sum += epochTime;
}
avgEpochTime = (long) ((double) sum) / epochTimes.size();
}
return avgEpochTime;
}
}
......@@ -15,8 +15,8 @@ import vagabond.helper.ErrorPrinter;
import vagabond.logging.CSVFileFormatter;
import vagabond.logging.ConsoleFormatter;
import vagabond.results.ResultsManager;
import vagabond.results.StatisticsManager;
import vagabond.testing.PlacementMapExamples;
import vagabond.timing.StatisticsManager;
import vagabond.timing.TimingManager;
/**
......@@ -121,7 +121,7 @@ public class VagabondSettings {
* Filename of the CNF Solver executable for Windows;
* Automatically changes this if you are on Linux/Mac to the binary compiled for that system.
*/
public String cnfSolverProgram_Win = "lingeling.exe";
public String cnfSolverProgram_Win = "plingeling.exe";
/**
* Filename of the CNF Solver executable for Linux;
* Automatically changes this if you are on Linux/Mac to the binary compiled for that system.
......
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