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

Removed timing from CtoC InfoLeak; better timing names for RunSolverCNF;...

Removed timing from CtoC InfoLeak; better timing names for RunSolverCNF; reordering RunSolverCNF function so interface functions are up top
parent e7810d42
......@@ -7,7 +7,6 @@ import java.util.logging.Logger;
import vagabond.enums.PlacementMapDisplayStyle;
import vagabond.keys.ClientToClientKey;
import vagabond.singleton.VagabondSettings;
import vagabond.timing.TimingManager;
public class ClientToClientInformationLeakage {
/**
......@@ -17,7 +16,6 @@ public class ClientToClientInformationLeakage {
public static final Integer TOSTRING_LIMIT = 20;
private static Logger logger;
private TimingManager timing = null;
private VagabondSettings settings = null;
private Hashtable<ClientToClientKey, Integer> _matrix;
......@@ -36,7 +34,6 @@ public class ClientToClientInformationLeakage {
public ClientToClientInformationLeakage(PlacementMap place) {
settings = VagabondSettings.getInstance();
logger = settings.getLogger();
timing = settings.timing;
_ref = place;
_numberOfClients = place.getNumberOfClients();
......@@ -45,8 +42,6 @@ public class ClientToClientInformationLeakage {
if (_numberOfClients < 1) { throw new IllegalArgumentException(
"The number of Clients must be greater than 0!"); }
/* Timing */timing.startTimer("ClientToClientInformationLeakage:constructor");
switch (settings.informationLeakageType) {
case ReplicationAndCollaboration:
calculateRC_ClientToClientInfoLeak();
......@@ -68,7 +63,6 @@ public class ClientToClientInformationLeakage {
throw new IllegalArgumentException("Picked an unimplemented information leakage type");
}
/* Timing */timing.stopTimer("ClientToClientInformationLeakage:constructor");
}
/**
......@@ -78,7 +72,6 @@ public class ClientToClientInformationLeakage {
public ClientToClientInformationLeakage(ClientToClientInformationLeakage tmp) {
settings = VagabondSettings.getInstance();
logger = settings.getLogger();
timing = settings.timing;
_ref = tmp._ref;
_numberOfClients = tmp._numberOfClients;
......@@ -86,9 +79,6 @@ public class ClientToClientInformationLeakage {
_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) {
......@@ -98,9 +88,6 @@ public class ClientToClientInformationLeakage {
for (ClientToClientKey key : tmp._matrix.keySet()) {
_matrix.put(key, new Integer(tmp._matrix.get(key)));
}
/* Timing */timing
.toggleTimer("ClientToClientInformationLeakage:constructor(ClientToClientInformationLeakage)");
}
/**
......
......@@ -35,6 +35,186 @@ public class RunSolverCNFSAT implements RunSolver {
tp = keyPrefix;
}
@Override
public boolean checkIfSolverIsReachable() {
return (new File(solverloc)).exists();
}
@Override
public boolean load(ReduceTo r) {
// Confirm that the timing manager is setup
if (timing == null) {
timing = VagabondSettings.getInstance().timing;
}
// Store a reference to r in this object.
_r = (ReduceToCNFSAT) r;
return true;
}
@Override
public EpochHistory run() throws Exception {
/*TIMING*/ timing.toggleTimer(tp + "RunSolverCNFSAT::run::totalTime");
// Get CNF-SAT instance from ReduceTo argument to load().
// Run the solver. Get raw string result. Then invoke
// PlacementMapFromCNFSATSolver.getPlacementMap() to get a placement map.
// Convert the placement map to an EpochHistory with 1 entry, which is that placement map.
// Constraint Line (1) -- optimization objective
// Setup for binary search
Circuit c = _r._circ;
// for each pair of clients a sum circuit
int nclientpairs = ((_r.nc - 1) * (_r.nc)) / 2;
Sum s[];
try {
s = constraintSumInfoLeak(c, _r, nclientpairs);
} catch (Exception e) {
e.printStackTrace();
/*TIMING*/ timing.cancelTimer(tp + "RunSolverCNFSAT::run::totalTime");
return null;
}
// At this point, we know how many output wires to AND with the <= circuit's output that's coming up
Circuit.Wire wirestoand[];
int orignoutputs = c.getOutputs().size();
if (VagabondSettings.getInstance().minimizeMaxClientToClientInfoLeak) {
wirestoand = new Circuit.Wire[orignoutputs + nclientpairs];
} else {
wirestoand = new Circuit.Wire[orignoutputs + 1];
}
for (int i = 0; i < orignoutputs; i++) {
wirestoand[i] = c.getOutputs().get(0);
c.removeAsOutput(wirestoand[i]);
}
// All the sum circuits whose outputs we want to compare against are now in s[]
int hi;
if (VagabondSettings.getInstance().minimizeMaxClientToClientInfoLeak) {
int maxclientnv = -1;
for (int i = 0; i < _r.nv.size(); i++) {
if (_r.nv.get(i) > maxclientnv) {
maxclientnv = _r.nv.get(i);
}
}
hi = _r._eh._sumOfInformationLeakage.getMaxInformationLeak() + maxclientnv * maxclientnv;
} else {
hi = _r._eh._sumOfInformationLeakage.getSumInformationLeak() + _r._eh.get(0).getSumInformationLeak();
}
int lo = 0;
LessEquals le[];
if (VagabondSettings.getInstance().minimizeMaxClientToClientInfoLeak) {
le = new LessEquals[nclientpairs];
for (int i = 0; i < nclientpairs; i++) {
le[i] = null;
}
} else {
le = new LessEquals[1];
le[0] = null;
}
BigAndOr band[] = new BigAndOr[1];
band[0] = null;
List<String> cnfcert = null;
// certificate from cnf-sat
// Binary search
/*TIMING*/ timing.toggleTimer(tp + "RunSolverCNFSAT::run::binarySearch::totalTime");
String searchVal;
int loopCount = 0;
for (int mid = hi; hi >= lo; mid = (hi + lo) / 2) {
searchVal = StringUtils.leftPad(loopCount + "", (int) Math.floor(Math.log10(hi)) + 1, "0") + "::mid::"
+ StringUtils.leftPad(mid + "", (int) Math.floor(Math.log10(hi)) + 1, "0");
/*TIMING*/ timing.toggleTimer(tp + "RunSolverCNFSAT::run::binarySearch::loopVal::" + searchVal);
// System.out.println("mid = "+mid); System.out.flush();
try {
constraintInfoLeakUb(c, le, band, s, nclientpairs, mid, wirestoand, orignoutputs);
/*TIMING*/ timing.toggleTimer(tp + "RunSolverCNFSAT::run::binarySearch::cnfSatToFile::" + searchVal);
// Now convert to cnf, invoke solver and adjust mid as needed.
CircuitUtils.cnfSatToFile(c, cnfloc);
/*TIMING*/ timing.toggleTimer(tp + "RunSolverCNFSAT::run::binarySearch::cnfSatToFile::" + searchVal);
/*TIMING*/ timing.toggleTimer(tp + "RunSolverCNFSAT::run::binarySearch::exec::" + searchVal);
Process p = Runtime.getRuntime().exec(solverloc + " " + cnfloc);
// Activate the following 'if,' if we want to put in a time-limit for every decision instance.
if (mid < hi && EACH_DECISION_INSTANCE_TIMEOUT > 0
&& !p.waitFor(EACH_DECISION_INSTANCE_TIMEOUT, TimeUnit.SECONDS)) {
// Treat this as unsat
lo = mid + 1;
/*TIMING*/ timing.toggleTimer(tp + "RunSolverCNFSAT::run::binarySearch::exec::" + searchVal);
continue;
}
BufferedReader solveroutput = new BufferedReader(new InputStreamReader(p.getInputStream()));
// save the certificate
List<String> lines = new LinkedList<String>();
boolean recordlines = false;
for (String str = null; (str = solveroutput.readLine()) != null;) {
if (recordlines) {
lines.add(str);
if (str.contains(Integer.toString(c.getInputs().size()))) {
// System.out.println("Breaking at: "+str+", #inputs = "+c.getInputs().size());
break;
}
// else
continue;
}
// else
if (str.contains("s SATISFIABLE")) {
// Start to record sufficient # of variables
recordlines = true;
}
}
/*TIMING*/ timing.toggleTimer(tp + "RunSolverCNFSAT::run::binarySearch::exec::" + searchVal);
if (!recordlines)
lo = mid + 1; // unsat
else {
cnfcert = lines;
hi = mid - 1;
}
// /*TIMING*/ timing.toggleTime("RunSolverCNFSAT::run::binarySearch::searchSatisfiable"+searchVal);
// if (lines.contains("s SATISFIABLE")) {
// cnfcert = lines;
// hi = mid - 1;
// } else {
// lo = mid + 1;
// }
// /*TIMING*/ timing.toggleTime("RunSolverCNFSAT::run::binarySearch::searchSatisfiable"+searchVal);
// /*TIMING*/
// timing.writeOutSingle(fw,"RunSolverCNFSAT::run::binarySearch::searchSatisfiable"+searchVal);
} catch (Exception e) {
e.printStackTrace();
/*TIMING*/ timing.cancelTimer(tp + "RunSolverCNFSAT::run::totalTime");
return null;
}
/*TIMING*/ timing.toggleTimer(tp + "RunSolverCNFSAT::run::binarySearch::loopVal::" + searchVal);
}
/*TIMING*/ timing.toggleTimer(tp + "RunSolverCNFSAT::run::binarySearch::totalTime");
// Build an epochhistory data structure as required by this function's signature
if (cnfcert == null) {
/*TIMING*/ timing.cancelTimer(tp + "RunSolverCNFSAT::run::totalTime");
return null;
}
EpochHistory ret = new EpochHistory(1);
ret.add(PlacementMapFromCNFSATSolver.getPlacementMap(_r, cnfcert));
/*TIMING*/ timing.toggleTimer(tp + "RunSolverCNFSAT::run::totalTime");
return ret;
}
/**
* A circuit that multiplies two non-negative integers. The first encoded in n bits, and the second in m bits.
*
......@@ -287,184 +467,4 @@ public class RunSolverCNFSAT implements RunSolver {
return band;
}
@Override
public boolean load(ReduceTo r) {
// Confirm that the timing manager is setup
if (timing == null) {
timing = VagabondSettings.getInstance().timing;
}
// Store a reference to r in this object.
_r = (ReduceToCNFSAT) r;
return true;
}
@Override
public boolean checkIfSolverIsReachable() {
return (new File(solverloc)).exists();
}
@Override
public EpochHistory run() throws Exception {
/*TIMING*/ timing.toggleTimer(tp + "RunSolverCNFSAT::run");
// Get CNF-SAT instance from ReduceTo argument to load().
// Run the solver. Get raw string result. Then invoke
// PlacementMapFromCNFSATSolver.getPlacementMap() to get a placement map.
// Convert the placement map to an EpochHistory with 1 entry, which is that placement map.
// Constraint Line (1) -- optimization objective
// Setup for binary search
Circuit c = _r._circ;
// for each pair of clients a sum circuit
int nclientpairs = ((_r.nc - 1) * (_r.nc)) / 2;
Sum s[];
try {
s = constraintSumInfoLeak(c, _r, nclientpairs);
} catch (Exception e) {
e.printStackTrace();
/*TIMING*/ timing.cancelTimer(tp + "RunSolverCNFSAT::run");
return null;
}
// At this point, we know how many output wires to AND with the <= circuit's output that's coming up
Circuit.Wire wirestoand[];
int orignoutputs = c.getOutputs().size();
if (VagabondSettings.getInstance().minimizeMaxClientToClientInfoLeak) {
wirestoand = new Circuit.Wire[orignoutputs + nclientpairs];
} else {
wirestoand = new Circuit.Wire[orignoutputs + 1];
}
for (int i = 0; i < orignoutputs; i++) {
wirestoand[i] = c.getOutputs().get(0);
c.removeAsOutput(wirestoand[i]);
}
// All the sum circuits whose outputs we want to compare against are now in s[]
int hi;
if (VagabondSettings.getInstance().minimizeMaxClientToClientInfoLeak) {
int maxclientnv = -1;
for (int i = 0; i < _r.nv.size(); i++) {
if (_r.nv.get(i) > maxclientnv) {
maxclientnv = _r.nv.get(i);
}
}
hi = _r._eh._sumOfInformationLeakage.getMaxInformationLeak() + maxclientnv * maxclientnv;
} else {
hi = _r._eh._sumOfInformationLeakage.getSumInformationLeak() + _r._eh.get(0).getSumInformationLeak();
}
int lo = 0;
LessEquals le[];
if (VagabondSettings.getInstance().minimizeMaxClientToClientInfoLeak) {
le = new LessEquals[nclientpairs];
for (int i = 0; i < nclientpairs; i++) {
le[i] = null;
}
} else {
le = new LessEquals[1];
le[0] = null;
}
BigAndOr band[] = new BigAndOr[1];
band[0] = null;
List<String> cnfcert = null;
// certificate from cnf-sat
// Binary search
/*TIMING*/ timing.toggleTimer(tp + "RunSolverCNFSAT::run::binarySearch::totalTime");
String searchVal;
int loopCount = 0;
for (int mid = hi; hi >= lo; mid = (hi + lo) / 2) {
searchVal = StringUtils.leftPad(loopCount + "", (int) Math.floor(Math.log10(hi)) + 1, "0") + "::mid::"
+ StringUtils.leftPad(mid + "", (int) Math.floor(Math.log10(hi)) + 1, "0");
/*TIMING*/ timing.toggleTimer(tp + "RunSolverCNFSAT::run::binarySearch::loopVal::" + searchVal);
// System.out.println("mid = "+mid); System.out.flush();
try {
constraintInfoLeakUb(c, le, band, s, nclientpairs, mid, wirestoand, orignoutputs);
/*TIMING*/ timing.toggleTimer(tp + "RunSolverCNFSAT::run::binarySearch::cnfSatToFile::" + searchVal);
// Now convert to cnf, invoke solver and adjust mid as needed.
CircuitUtils.cnfSatToFile(c, cnfloc);
/*TIMING*/ timing.toggleTimer(tp + "RunSolverCNFSAT::run::binarySearch::cnfSatToFile::" + searchVal);
/*TIMING*/ timing.toggleTimer(tp + "RunSolverCNFSAT::run::binarySearch::exec::" + searchVal);
Process p = Runtime.getRuntime().exec(solverloc + " " + cnfloc);
// Activate the following 'if,' if we want to put in a time-limit for every decision instance.
if (mid < hi && EACH_DECISION_INSTANCE_TIMEOUT > 0
&& !p.waitFor(EACH_DECISION_INSTANCE_TIMEOUT, TimeUnit.SECONDS)) {
// Treat this as unsat
lo = mid + 1;
/*TIMING*/ timing.toggleTimer(tp + "RunSolverCNFSAT::run::binarySearch::exec::" + searchVal);
continue;
}
BufferedReader solveroutput = new BufferedReader(new InputStreamReader(p.getInputStream()));
// save the certificate
List<String> lines = new LinkedList<String>();
boolean recordlines = false;
for (String str = null; (str = solveroutput.readLine()) != null;) {
if (recordlines) {
lines.add(str);
if (str.contains(Integer.toString(c.getInputs().size()))) {
// System.out.println("Breaking at: "+str+", #inputs = "+c.getInputs().size());
break;
}
// else
continue;
}
// else
if (str.contains("s SATISFIABLE")) {
// Start to record sufficient # of variables
recordlines = true;
}
}
/*TIMING*/ timing.toggleTimer(tp + "RunSolverCNFSAT::run::binarySearch::exec::" + searchVal);
if (!recordlines)
lo = mid + 1; // unsat
else {
cnfcert = lines;
hi = mid - 1;
}
// /*TIMING*/ timing.toggleTime("RunSolverCNFSAT::run::binarySearch::searchSatisfiable"+searchVal);
// if (lines.contains("s SATISFIABLE")) {
// cnfcert = lines;
// hi = mid - 1;
// } else {
// lo = mid + 1;
// }
// /*TIMING*/ timing.toggleTime("RunSolverCNFSAT::run::binarySearch::searchSatisfiable"+searchVal);
// /*TIMING*/
// timing.writeOutSingle(fw,"RunSolverCNFSAT::run::binarySearch::searchSatisfiable"+searchVal);
} catch (Exception e) {
e.printStackTrace();
/*TIMING*/ timing.cancelTimer(tp + "RunSolverCNFSAT::run");
return null;
}
/*TIMING*/ timing.toggleTimer(tp + "RunSolverCNFSAT::run::binarySearch::loopVal::" + searchVal);
}
/*TIMING*/ timing.toggleTimer(tp + "RunSolverCNFSAT::run::binarySearch::totalTime");
// Build an epochhistory data structure as required by this function's signature
if (cnfcert == null) {
/*TIMING*/ timing.cancelTimer(tp + "RunSolverCNFSAT::run");
return null;
}
EpochHistory ret = new EpochHistory(1);
ret.add(PlacementMapFromCNFSATSolver.getPlacementMap(_r, cnfcert));
/*TIMING*/ timing.toggleTimer(tp + "RunSolverCNFSAT::run");
return ret;
}
}
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