Commit 40c90caf authored by Mahesh Tripunitara's avatar Mahesh Tripunitara
Browse files

edits for supporting total info leak, as opposed to max CtoC info leak. Also...

edits for supporting total info leak, as opposed to max CtoC info leak. Also fixed a "memory leak." The BigAndOr subcircuit we were adding at the end in each iteration in run() was not getting deleted and recreated. So the older ones would have been bloating the circuit. Fixed by adding a band parameter to the Ub() method that tacks on a <= circuit in each iteration.
parent 122e9bff
package vagabond.reduction.cnfsat;
import java.io.*;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.TimeUnit;
......@@ -177,18 +178,43 @@ public class RunSolverCNFSAT implements RunSolver {
}
}
}
// If we're doing total info. leak, we should add all of values in s[] up, and return a single
// sum circuit
if(!VagabondSettings.getInstance().minimizeMaxClientToClientInfoLeak) {
List<Integer> li = new ArrayList<Integer>();
for(int i = 0; i < s.length; i++) {
li.add(new Integer(s[i].getOutputs().size()));
}
Sum tot = new Sum(li);
c.union(tot);
int totinidx = 0;
for(int i = 0; i < s.length; i++) {
for(int j = 0; j < s[i].getOutputs().size(); j++) {
c.fuse(s[i].getOutputs().get(j), tot.getInputs().get(totinidx++));
}
}
for(int i = 0; i < tot.getOutputs().size(); i++) {
c.removeAsOutput(tot.getOutputs().get(i));
}
s = new Sum[1];
s[0] = tot;
}
return s;
}
public void constraintInfoLeakUb(Circuit c, LessEquals le[], Sum s[], int nclientpairs, int ub) throws Exception {
public void constraintInfoLeakUb(Circuit c, LessEquals le[], BigAndOr band, Sum s[], int nclientpairs, int ub) throws Exception {
IntegerAsCircuit midc = new IntegerAsCircuit(ub);
c.union(midc);
for (int j = 0; j < midc.getOutputs().size(); j++) {
c.removeAsOutput(midc.getOutputs().get(j));
}
for (int i = 0; i < nclientpairs; i++) {
for (int i = 0; i < le.length; i++) {
if (le[i] != null) {
c.gates.removeAll(le[i].gates);
c.wires.removeAll(le[i].wires);
......@@ -206,13 +232,26 @@ public class RunSolverCNFSAT implements RunSolver {
}
}
// Now we have all the constraints. Big AND of all the outputs of c
addBigAnd(c);
if(band != null) {
c.gates.removeAll(band.gates);
c.wires.removeAll(band.wires);
c.inputs.removeAll(band.wires);
c.outputs.removeAll(band.wires);
}
band = addBigAnd(c);
}
public void addBigAnd(Circuit c) {
/**
* Big AND of all the outputs of a circuit
*
* @param c the circuit whose outputs we should AND. This is an in-out param. I.e., c is changed up on return.
* @return the big-and circuit that was created
*/
public BigAndOr addBigAnd(Circuit c) {
BigAndOr band = null;
try {
BigAndOr band = new BigAndOr(false, c.getOutputs().size());
band = new BigAndOr(false, c.getOutputs().size());
c.union(band);
for (int i = 0; c.getOutputs().size() > 1; i++) {
c.fuse(c.getOutputs().get(0), band.getInputs().get(i));
......@@ -223,6 +262,7 @@ public class RunSolverCNFSAT implements RunSolver {
}
assert c.getOutputs().size() == 1;
return band;
}
public String tp = "Epoch_Unknown";
......@@ -282,18 +322,38 @@ public class RunSolverCNFSAT implements RunSolver {
}
// All the sum circuits whose outputs we want to compare against are now in s[]
int maxclientnv = -1;
for (int i = 0; i < _r.nv.size(); i++) {
if (_r.nv.get(i) > maxclientnv) {
maxclientnv = _r.nv.get(i);
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 hi = _r._eh._sumOfInformationLeakage.getMaxInformationLeak() + maxclientnv * maxclientnv;
int lo = 0;
LessEquals le[] = new LessEquals[nclientpairs];
for (int i = 0; i < nclientpairs; i++) {
le[i] = null;
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 = null;
List<String> cnfcert = null;
// certificate from cnf-sat
......@@ -303,7 +363,7 @@ public class RunSolverCNFSAT implements RunSolver {
/*TIMING*/ timing.toggleTimer("RunSolverCNFSAT::run::binarySearch::loopVal=" + mid);
// System.out.println("mid = "+mid); System.out.flush();
try {
constraintInfoLeakUb(c, le, s, nclientpairs, mid);
constraintInfoLeakUb(c, le, band, s, nclientpairs, mid);
/*TIMING*/ timing.toggleTimer("RunSolverCNFSAT::run::binarySearch::cnfSatToFile " + mid);
// Now convert to cnf, invoke solver and adjust mid as needed.
......
......@@ -21,6 +21,8 @@ public class CNFEverythingTests {
@Test
public void equalSpreadTest() throws Exception {
boolean minMaxCtoCInfoLeak = false;
VagabondSettings vs = VagabondSettings.getInstance();
vs.migrationBudget = new Integer(-1);
vs.numberOfClients = new Integer(3);
......@@ -28,6 +30,7 @@ public class CNFEverythingTests {
vs.numberOfEpochs = new Integer(5);
vs.numberOfMachines = new Integer(3);
vs.numberOfVMsPerClient = new Integer(3);
vs.minimizeMaxClientToClientInfoLeak = minMaxCtoCInfoLeak;
vs.timing = new TimingManager();
// No meaningful way to do this test except with all the other constraints thrown in
......@@ -56,8 +59,9 @@ public class CNFEverythingTests {
@Test
public void equalSpreadBiggerTest() throws Exception {
int testparam = 12;
int migbudget = 4;
int testparam = 8;
int migbudget = -1;
boolean minMaxCtoCInfoLeak = false;
VagabondSettings vs = VagabondSettings.getInstance();
vs.migrationBudget = new Integer(migbudget);
vs.numberOfClients = new Integer(testparam);
......@@ -65,6 +69,7 @@ public class CNFEverythingTests {
vs.numberOfEpochs = new Integer(2);
vs.numberOfMachines = new Integer(testparam);
vs.numberOfVMsPerClient = new Integer(testparam);
vs.minimizeMaxClientToClientInfoLeak = minMaxCtoCInfoLeak;
vs.timing = new TimingManager();
// No meaningful way to do this test except with all the other constraints thrown in
......@@ -93,6 +98,7 @@ public class CNFEverythingTests {
@Test
public void nomadILPTest() throws Exception {
boolean minMaxCtoCInfoLeak = true;
VagabondSettings vs = VagabondSettings.getInstance();
vs.migrationBudget = new Integer(-1);
......@@ -102,6 +108,7 @@ public class CNFEverythingTests {
vs.numberOfMachines = new Integer(40);
vs.numberOfVMsPerClient = new Integer(4);
vs.slidingWindow = new Integer(5);
vs.minimizeMaxClientToClientInfoLeak = minMaxCtoCInfoLeak;
vs.timing = new TimingManager();
PlacementMap inipm = (new RandomPlacement()).generatePlacementMapNomadHardILP();
......
......@@ -10,6 +10,7 @@ import java.util.List;
import org.junit.Test;
import vagabond.circuit.BigAndOr;
import vagabond.circuit.Circuit;
import vagabond.circuit.CircuitUtils;
import vagabond.circuit.LessEquals;
......@@ -110,9 +111,10 @@ public class InfoLeakSumTests {
*/
LessEquals le[] = new LessEquals[nclientpairs];
BigAndOr band = null;
for(int i = 0; i < nclientpairs; i++) le[i] = null;
int ub = 4; // Change this as needed. < 3 should result in false. > 2 should result in true
rs.constraintInfoLeakUb(c, le, s, nclientpairs, ub);
rs.constraintInfoLeakUb(c, le, band, s, nclientpairs, ub);
assertEquals(c.getOutputs().size(), 1);
......@@ -188,9 +190,10 @@ public class InfoLeakSumTests {
assertEquals(c.getOutputs().size(), 0);
LessEquals le[] = new LessEquals[nclientpairs];
BigAndOr band = null;
for(int i = 0; i < nclientpairs; i++) le[i] = null;
int ub = 5; // Change this as needed. < 8 should result in false. > 7 should result in true
rs.constraintInfoLeakUb(c, le, s, nclientpairs, ub);
rs.constraintInfoLeakUb(c, le, band, s, nclientpairs, ub);
assertEquals(c.getOutputs().size(), 1);
......
......@@ -17,6 +17,7 @@ import java.util.Random;
import org.junit.Before;
import org.junit.Test;
import vagabond.circuit.BigAndOr;
import vagabond.circuit.Circuit;
import vagabond.circuit.CircuitUtils;
import vagabond.circuit.LessEquals;
......@@ -147,8 +148,9 @@ public class PlacementMapFromCNFSATTests {
Sum s[];
s = rs.constraintSumInfoLeak(c, _r, nclientpairs);
LessEquals le[] = new LessEquals[nclientpairs];
BigAndOr band = null;
for(int i = 0; i < le.length; i++) le[i] = null;
rs.constraintInfoLeakUb(c, le, s, nclientpairs, 6);
rs.constraintInfoLeakUb(c, le, band, s, nclientpairs, 6);
CircuitUtils.cnfSatToFile(c, cnfloc);
Process p = Runtime.getRuntime().exec(solverloc+" "+cnfloc);
......
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