Commit 587e7237 authored by Jonathan Shahen's avatar Jonathan Shahen
Browse files

Moving things around (some java code styling is done)

parent 1d77ec06
......@@ -174,6 +174,7 @@ public class RunSolverCNFSAT implements RunSolver {
recordlines = true;
}
}
p.destroyForcibly();
/*TIMING*/ timing.toggleTimer(tp + "RunSolverCNFSAT::run::binarySearch::exec::" + searchVal);
if (!recordlines)
......
/**
*
*/
package vagabond.testing;
package vagabond.reduction.cnfsat.tests;
import java.util.LinkedList;
import java.util.List;
......@@ -11,9 +11,9 @@ import vagabond.reduction.cnfsat.ReduceToCNFSAT;
/**
* @author tripunit
*
* @deprecated
*/
public class AbsCircTest {
public class CNFSATAbsCircTest {
/**
* @param args args
......
/**
*
*/
package vagabond.testing;
package vagabond.reduction.cnfsat.tests;
import java.util.LinkedList;
import java.util.List;
......@@ -12,7 +12,7 @@ import vagabond.circuit.*;
* @author tripunit
*
*/
public class BasicBinSearchTest {
public class CNFSATBasicBinSearchTest {
/**
* @param args args
......
package vagabond.testing;
package vagabond.reduction.cnfsat.tests;
import static org.junit.Assert.assertEquals;
......@@ -13,9 +13,9 @@ import vagabond.circuit.*;
* @author tripunit
*
* Simple test of circuit
*
* @deprecated
*/
public class BitSumAndCompare {
public class CNFSATBitSumAndCompare {
/**
* @param i the number of bit-inputs to treat as integer 0 or 1.
* @param c the number against which to compare the sum of those i bits. c should be an upper-bound for that sum.
......
package vagabond.reduction.cnfsat.tests;
import static org.junit.Assert.assertEquals;
import java.util.*;
import org.junit.Test;
import vagabond.circuit.Circuit;
import vagabond.circuit.CircuitUtils;
import vagabond.pieces.SumOfClientVMsPerMachine;
import vagabond.placement.RandomPlacement;
import vagabond.reduction.cnfsat.ReduceToCNFSAT;
import vagabond.reduction.cnfsat.RunSolverCNFSAT;
import vagabond.singleton.VagabondSettings;
import vagabond.testing.PlacementMapExamples;
public class CNFSATMigrationBudgetTests {
@Test
public void equalSpread() throws Exception {
ReduceToCNFSAT r = new ReduceToCNFSAT();
int nc = 3;
List<Integer> nv = new LinkedList<Integer>();
nv.add(new Integer(3));
nv.add(new Integer(3));
nv.add(new Integer(3));
int ns = 3;
int mig = 6;
int nvbitsum = 0;
for (int i = 0; i < nv.size(); i++) {
nvbitsum += ReduceToCNFSAT.nbits(nv.get(i));
}
Circuit.resetIDs();
Circuit c = new Circuit();
for (int i = 0; i < ns * nvbitsum; i++) {
c.addNewInput();
}
SumOfClientVMsPerMachine currp = new SumOfClientVMsPerMachine(PlacementMapExamples.equalSpreadClients());
r.constraintMigrationBudget(c, nc, nv, ns, currp, mig);
assertEquals(c.getInputs().size(), ns * nvbitsum);
assertEquals(c.getOutputs().size(), 1);
// Set up new placement via inputs to c
// New placement is as follows. Format is: #VMs x Client ID
/*
Machine 0 {2 x 0, 0 x 1, 1 x 2}
Machine 1 {0 x 0, 3 x 1, 0 x 2}
Machine 2 {1 x 0, 0 x 1, 2 x 2}
*/
List<Boolean> lb = new LinkedList<Boolean>();
// Client 0
// Machine 0
lb.add(new Boolean(false));
lb.add(new Boolean(true));
// Machine 1
lb.add(new Boolean(false));
lb.add(new Boolean(false));
// Machine 2
lb.add(new Boolean(true));
lb.add(new Boolean(false));
// Client 1
// Machine 0
lb.add(new Boolean(false));
lb.add(new Boolean(false));
// Machine 1
lb.add(new Boolean(true));
lb.add(new Boolean(true));
// Machine 2
lb.add(new Boolean(false));
lb.add(new Boolean(false));
// Client 2
// Machine 0
lb.add(new Boolean(true));
lb.add(new Boolean(false));
// Machine 1
lb.add(new Boolean(false));
lb.add(new Boolean(false));
// Machine 2
lb.add(new Boolean(false));
lb.add(new Boolean(true));
List<Boolean> res = c.evaluate(lb);
// System.out.println(res);
assertEquals(res.get(0), (mig >= 4));
// New placement is as follows. Format is: #VMs x Client ID
// NOTE: following placement does not respect server capacity. But we don't care about
// that constraint in this test.
/*
Machine 0 {0 x 0, 3 x 1, 0 x 2}
Machine 1 {3 x 0, 0 x 1, 0 x 2}
Machine 2 {0 x 0, 0 x 1, 3 x 2}
*/
lb.clear();
// Client 0
// Machine 0
lb.add(new Boolean(false));
lb.add(new Boolean(false));
// Machine 1
lb.add(new Boolean(true));
lb.add(new Boolean(true));
// Machine 2
lb.add(new Boolean(false));
lb.add(new Boolean(false));
// Client 1
// Machine 0
lb.add(new Boolean(false));
lb.add(new Boolean(false));
// Machine 1
lb.add(new Boolean(true));
lb.add(new Boolean(true));
// Machine 2
lb.add(new Boolean(false));
lb.add(new Boolean(false));
// Client 2
// Machine 0
lb.add(new Boolean(false));
lb.add(new Boolean(false));
// Machine 1
lb.add(new Boolean(false));
lb.add(new Boolean(false));
// Machine 2
lb.add(new Boolean(true));
lb.add(new Boolean(true));
res = c.evaluate(lb);
System.out.println(res);
assertEquals(res.get(0), (mig >= 6));
}
@Test
public void equalSpreadWithClientConstraintTest() throws Exception {
ReduceToCNFSAT r = new ReduceToCNFSAT();
int nc = 3;
List<Integer> nv = new LinkedList<Integer>();
nv.add(new Integer(3));
nv.add(new Integer(3));
nv.add(new Integer(3));
int ns = 3;
int mig = 6;
int nvbitsum = 0;
for (int i = 0; i < nv.size(); i++) {
nvbitsum += ReduceToCNFSAT.nbits(nv.get(i));
}
Circuit.resetIDs();
Circuit c = new Circuit();
for (int i = 0; i < ns * nvbitsum; i++) {
c.addNewInput();
}
r.constraintTotalNumberOfClientVMs(c, nc, nv, ns);
SumOfClientVMsPerMachine currp = new SumOfClientVMsPerMachine(PlacementMapExamples.equalSpreadClients());
r.constraintMigrationBudget(c, nc, nv, ns, currp, mig);
Circuit.Wire wirestoand[] = new Circuit.Wire[c.getOutputs().size()];
for (int i = 0; i < wirestoand.length; i++) {
wirestoand[i] = c.getOutputs().get(i);
}
// System.out.println(c.getOutputs().size());
(new RunSolverCNFSAT()).addBigAnd(c, wirestoand);
System.out.println(c.getOutputs().size());
CircuitUtils.cnfSatToFile(c, VagabondSettings.getInstance().getCNFInstanceFile().getAbsolutePath());
}
@Test
public void randomTest() throws Exception {
int ns = 4; // # servers/machines
int nslots = 6; // slots/machine
int nc = 8; // # clients
int nvperclient = 3; // #vms per client
List<Integer> nv = new LinkedList<Integer>();
for (int i = 0; i < nc; i++) {
nv.add(new Integer(nvperclient));
}
int nvbitsum = 0;
for (int i = 0; i < nv.size(); i++) {
nvbitsum += ReduceToCNFSAT.nbits(nv.get(i));
}
assertEquals(nvbitsum, nc * ReduceToCNFSAT.nbits(nvperclient));
Circuit.resetIDs();
Circuit c = new Circuit();
for (int i = 0; i < ns * nvbitsum; i++) {
c.addNewInput();
}
int mig = (new Random()).nextInt((nc * nvperclient));
SumOfClientVMsPerMachine currp = new SumOfClientVMsPerMachine(
(new RandomPlacement()).generatePlacementMap(ns, nslots, nc, nvperclient, false));
(new ReduceToCNFSAT()).constraintMigrationBudget(c, nc, nv, ns, currp, mig);
CircuitUtils.cnfSatToFile(c, VagabondSettings.getInstance().getCNFInstanceFile().getAbsolutePath());
assertEquals(c.getInputs().size(), ns * nvbitsum);
assertEquals(c.getOutputs().size(), 1);
// new random placement with same parameters
SumOfClientVMsPerMachine newp = new SumOfClientVMsPerMachine(
(new RandomPlacement()).generatePlacementMap(ns, nslots, nc, nvperclient, false));
List<Boolean> in = new LinkedList<Boolean>();
int neededmig = 0;
for (int i = 0; i < nc; i++) {
for (int j = 0; j < ns; j++) {
neededmig += Math.abs(newp.get(j, i) - currp.get(j, i));
for (int k = 0; k < ReduceToCNFSAT.nbits(nv.get(i)); k++) {
if ((newp.get(j, i).intValue() >> k) % 2 == 1) {
in.add(new Boolean(Boolean.TRUE));
} else {
in.add(new Boolean(Boolean.FALSE));
}
}
}
}
neededmig /= 2;
System.out.println("mig = " + mig + ", need = " + neededmig);
assertEquals(in.size(), ns * nvbitsum);
List<Boolean> res = c.evaluate(in);
System.out.println("res = " + res);
assertEquals(res.get(0), mig >= neededmig);
}
}
/**
*
*/
package vagabond.testing;
package vagabond.reduction.cnfsat.tests;
import java.util.LinkedList;
import java.util.List;
......
/**
*
*/
package vagabond.testing;
package vagabond.reduction.cnfsat.tests;
import java.util.LinkedList;
import java.util.List;
......
/**
*
*/
package vagabond.testing;
import static org.junit.Assert.assertEquals;
import java.util.LinkedList;
import java.util.List;
import org.junit.Test;
import vagabond.circuit.*;
import vagabond.pieces.EpochHistory;
import vagabond.reduction.cnfsat.ReduceToCNFSAT;
import vagabond.reduction.cnfsat.RunSolverCNFSAT;
import vagabond.singleton.VagabondSettings;
/**
* @author tripunit
*
*/
public class CNFSATInfoLeakSumTests {
@Test
public void equalSpreadTest() throws Exception {
EpochHistory eh = new EpochHistory(2);
eh.add(PlacementMapExamples.equalSpreadClients());
ReduceToCNFSAT _r = new ReduceToCNFSAT();
_r.setEh(eh);
int nvbitsum = 0;
for (int i = 0; i < _r.getNv().size(); i++) {
nvbitsum += ReduceToCNFSAT.nbits(_r.getNv().get(i));
}
Circuit.resetIDs();
Circuit c = new Circuit();
for (int i = 0; i < _r.getNs() * nvbitsum; i++) {
c.addNewInput();
}
int nclientpairs = ((_r.getNc() - 1) * (_r.getNc())) / 2;
RunSolverCNFSAT rs = new RunSolverCNFSAT();
rs.load(_r);
Sum s[] = rs.constraintSumInfoLeak(c, _r, nclientpairs);
assertEquals(c.getInputs().size(), _r.getNs() * nvbitsum);
assertEquals(c.getOutputs().size(), 0);
// System.out.println(c.getOutputs().size());
/* The following was relevant only when we allowed outputs of s[]'s to be outputs of c.
* We did that by commenting out Lines 157-159 in RunSolverCNFSAT.java
// Place each client's VMs on a single machine. This should be optimal
// And the sum of info. leakage across the 3 epochs should be 3 per pair of clients
List<Boolean> in = new LinkedList<Boolean>();
//Client 1
// Machine 1
in.add(new Boolean(Boolean.TRUE));
in.add(new Boolean(Boolean.TRUE));
// Machine 2
in.add(new Boolean(Boolean.FALSE));
in.add(new Boolean(Boolean.FALSE));
// Machine 3
in.add(new Boolean(Boolean.FALSE));
in.add(new Boolean(Boolean.FALSE));
//Client 2
// Machine 1
in.add(new Boolean(Boolean.FALSE));
in.add(new Boolean(Boolean.FALSE));
// Machine 2
in.add(new Boolean(Boolean.TRUE));
in.add(new Boolean(Boolean.TRUE));
// Machine 3
in.add(new Boolean(Boolean.FALSE));
in.add(new Boolean(Boolean.FALSE));
//Client 3
// Machine 1
in.add(new Boolean(Boolean.FALSE));
in.add(new Boolean(Boolean.FALSE));
// Machine 2
in.add(new Boolean(Boolean.FALSE));
in.add(new Boolean(Boolean.FALSE));
// Machine 3
in.add(new Boolean(Boolean.TRUE));
in.add(new Boolean(Boolean.TRUE));
List<Boolean> res = c.evaluate(in);
System.out.println(res);
// We should have 3 for each sum
List<Boolean> comp = new LinkedList<Boolean>();
for(int i = 0; i < c.getOutputs().size(); i++) {
if(i%7 == 0 || i %7 == 1) {
comp.add(new Boolean(Boolean.TRUE));
}
else {
comp.add(new Boolean(Boolean.FALSE));
}
}
assertEquals(res, comp);
*/
LessEquals le[] = new LessEquals[nclientpairs];
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
Circuit.Wire wirestoand[] = new Circuit.Wire[c.getOutputs().size()];
for (int i = 0; i < wirestoand.length; i++) {
wirestoand[i] = c.getOutputs().get(i);
}
BigAndOr band[] = new BigAndOr[1];
band[0] = null;
rs.constraintInfoLeakUb(c, le, band, s, nclientpairs, ub, wirestoand, 0);
assertEquals(c.getOutputs().size(), 1);
// Place each client's VMs on a single machine. This should be optimal
// And the sum of info. leakage across the 3 epochs should be 3 per pair of clients
List<Boolean> in = new LinkedList<Boolean>();
// Client 1
// Machine 1
in.add(new Boolean(Boolean.TRUE));
in.add(new Boolean(Boolean.TRUE));
// Machine 2
in.add(new Boolean(Boolean.FALSE));
in.add(new Boolean(Boolean.FALSE));
// Machine 3
in.add(new Boolean(Boolean.FALSE));
in.add(new Boolean(Boolean.FALSE));
// Client 2
// Machine 1
in.add(new Boolean(Boolean.FALSE));
in.add(new Boolean(Boolean.FALSE));
// Machine 2
in.add(new Boolean(Boolean.TRUE));
in.add(new Boolean(Boolean.TRUE));
// Machine 3
in.add(new Boolean(Boolean.FALSE));
in.add(new Boolean(Boolean.FALSE));
// Client 3
// Machine 1
in.add(new Boolean(Boolean.FALSE));
in.add(new Boolean(Boolean.FALSE));
// Machine 2
in.add(new Boolean(Boolean.FALSE));
in.add(new Boolean(Boolean.FALSE));
// Machine 3
in.add(new Boolean(Boolean.TRUE));
in.add(new Boolean(Boolean.TRUE));
List<Boolean> res = c.evaluate(in);
System.out.println(res);
assertEquals(res.get(0), ub >= 3);
CircuitUtils.cnfSatToFile(c, VagabondSettings.getInstance().getCNFInstanceFile().getAbsolutePath());
}
@Test
public void largerEqualSpreadTest() throws Exception {
EpochHistory eh = new EpochHistory(2);
eh.add(PlacementMapExamples.equalSpreadClients(5));
ReduceToCNFSAT _r = new ReduceToCNFSAT();
_r.setEh(eh);
int nvbitsum = 0;
for (int i = 0; i < _r.getNv().size(); i++) {
nvbitsum += ReduceToCNFSAT.nbits(_r.getNv().get(i));
}
Circuit.resetIDs();
Circuit c = new Circuit();
for (int i = 0; i < _r.getNs() * nvbitsum; i++) {
c.addNewInput();
}
int nclientpairs = ((_r.getNc() - 1) * (_r.getNc())) / 2;
RunSolverCNFSAT rs = new RunSolverCNFSAT();
rs.load(_r);
Sum s[] = rs.constraintSumInfoLeak(c, _r, nclientpairs);
assertEquals(c.getInputs().size(), _r.getNs() * nvbitsum);
assertEquals(c.getOutputs().size(), 0);
LessEquals le[] = new LessEquals[nclientpairs];
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
Circuit.Wire wirestoand[] = new Circuit.Wire[c.getOutputs().size()];
for (int i = 0; i < wirestoand.length; i++) {
wirestoand[i] = c.getOutputs().get(i);
}
BigAndOr band[] = new BigAndOr[1];
band[0] = null;
rs.constraintInfoLeakUb(c, le, band, s, nclientpairs, ub, wirestoand, 0);
assertEquals(c.getOutputs().size(), 1);
CircuitUtils.cnfSatToFile(c, VagabondSettings.getInstance().getCNFInstanceFile().getAbsolutePath());
}
}
......@@ -9,7 +9,7 @@ import org.junit.Test;
import vagabond.circuit.Circuit;
import vagabond.reduction.cnfsat.ReduceToCNFSAT;
public class ServerCapacityTests {
public class CNFSATServerCapacityTests {
@Test
public void small() throws Exception {
......
/**
*
*/
package vagabond.testing;
import static org.junit.Assert.*;
import java.util.LinkedList;
import java.util.List;
import org.junit.Test;
import vagabond.circuit.BigAndOr;
import vagabond.circuit.Circuit;
import vagabond.circuit.CircuitUtils;
import vagabond.circuit.LessEquals;
import vagabond.circuit.Sum;
import vagabond.pieces.EpochHistory;
import vagabond.reduction.cnfsat.ReduceToCNFSAT;
import vagabond.reduction.cnfsat.RunSolverCNFSAT;
/**
* @author tripunit
*
*/
public class InfoLeakSumTests {
@Test
public void equalSpreadTest() throws Exception {