use of org.chocosolver.solver.variables.IntVar in project scheduler by btrplace.
the class DefaultReconfigurationProblemTest method testVMCounting.
/**
* Check the consistency between the variables counting the number of VMs on
* each node, and the placement variable.
*
* @throws org.btrplace.scheduler.SchedulerException
* @throws ContradictionException
*/
@Test
public void testVMCounting() throws SchedulerException, ContradictionException {
Model mo = new DefaultModel();
Node n3 = mo.newNode();
Node n2 = mo.newNode();
Mapping map = mo.getMapping();
for (int i = 0; i < 7; i++) {
VM v = mo.newVM();
map.addReadyVM(v);
}
map.addOnlineNode(n3);
map.addOnlineNode(n2);
Parameters ps = new DefaultParameters();
ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setParams(ps).setNextVMsStates(new HashSet<>(), map.getAllVMs(), new HashSet<>(), new HashSet<>()).build();
// Restrict the capacity to 5 at most
for (IntVar capa : rp.getNbRunningVMs()) {
capa.updateUpperBound(5, Cause.Null);
}
new CMinMTTR().inject(ps, rp);
ReconfigurationPlan p = rp.solve(-1, false);
Assert.assertNotNull(p);
// Check consistency between the counting and the hoster variables
int[] counts = new int[map.getAllNodes().size()];
for (Node n : map.getOnlineNodes()) {
int nIdx = rp.getNode(n);
counts[nIdx] = rp.getNbRunningVMs().get(nIdx).getValue();
}
for (VM vm : rp.getFutureRunningVMs()) {
VMTransition vmo = rp.getVMActions().get(rp.getVM(vm));
int on = vmo.getDSlice().getHoster().getValue();
counts[on]--;
}
for (int count : counts) {
Assert.assertEquals(count, 0);
}
}
use of org.chocosolver.solver.variables.IntVar in project scheduler by btrplace.
the class IssuesTest method testIssue10.
@Test
public void testIssue10() throws SchedulerException, ContradictionException {
Model model = new DefaultModel();
Node n1 = model.newNode();
Node n2 = model.newNode();
Node n3 = model.newNode();
VM vm1 = model.newVM();
VM vm2 = model.newVM();
Mapping map = model.getMapping().on(n1, n2).off(n3).run(n1, vm1, vm2);
// model.attach(resources);
ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(model).build();
// n3 goes online
rp.getNodeAction(n3).getState().instantiateTo(1, Cause.Null);
rp.getModel().post(rp.getModel().arithm(rp.getEnd(), "<=", 10));
int NUMBER_OF_NODE = map.getAllNodes().size();
// Extract all the state of the involved nodes (all nodes in this case)
List<IntVar> VMsOnAllNodes = rp.getNbRunningVMs();
// Each element is the number of VMs on each node
IntVar[] vmsOnInvolvedNodes = new IntVar[NUMBER_OF_NODE];
BoolVar[] idles = new BoolVar[NUMBER_OF_NODE];
int i = 0;
int maxVMs = rp.getSourceModel().getMapping().getAllVMs().size();
for (Node n : map.getAllNodes()) {
vmsOnInvolvedNodes[i] = rp.getModel().intVar("nVMs" + n, -1, maxVMs, true);
IntVar state = rp.getNodeAction(n).getState();
// If the node is offline -> the temporary variable is 1, otherwise, it equals the number of VMs on that node
Constraint elem = rp.getModel().element(vmsOnInvolvedNodes[i], new IntVar[] { rp.getModel().intVar(-1), VMsOnAllNodes.get(rp.getNode(n)) }, state, 0);
rp.getModel().post(elem);
// IF number of VMs on a node is 0 -> Idle
idles[i] = rp.getModel().boolVar("idle" + n);
ChocoUtils.postIfOnlyIf(rp, idles[i], rp.getModel().arithm(vmsOnInvolvedNodes[i], "=", 0));
i++;
}
IntVar sum = rp.getModel().intVar("sum", 0, 1000, true);
rp.getModel().post(rp.getModel().sum(idles, "=", sum));
// idle should be less than Amount for MaxSN (0, in this case)
rp.getModel().post(rp.getModel().arithm(sum, "=", 0));
System.err.flush();
CMinMTTR obj = new CMinMTTR();
obj.inject(new DefaultParameters(), rp);
ReconfigurationPlan plan = rp.solve(0, false);
Assert.assertNotNull(plan);
}
use of org.chocosolver.solver.variables.IntVar in project scheduler by btrplace.
the class IssuesTest method testIssue5c.
/**
* Test a suspicious bug in issue #5
*/
@Test
public void testIssue5c() throws SchedulerException {
Model model = new DefaultModel();
Node n1 = model.newNode();
Node n2 = model.newNode();
Node n3 = model.newNode();
VM vm1 = model.newVM();
VM vm2 = model.newVM();
VM vm3 = model.newVM();
VM vm4 = model.newVM();
Mapping map = model.getMapping().on(n1, n2, n3).run(n2, vm1, vm2, vm3, vm4);
ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(model).build();
List<IntVar> nodes_state = rp.getNbRunningVMs();
IntVar[] nodeVM = new IntVar[map.getAllNodes().size()];
int i = 0;
for (Node n : map.getAllNodes()) {
nodeVM[i++] = nodes_state.get(rp.getNode(n));
// rp.getNodeAction(n).getState().setVal(1);
}
IntVar idle = rp.getModel().intVar("Nidles", 0, map.getAllNodes().size(), true);
rp.getModel().post(rp.getModel().count(0, nodeVM, idle));
rp.getModel().post(rp.getModel().arithm(idle, "<=", 1));
ReconfigurationPlan plan = rp.solve(0, false);
Assert.assertNotNull(plan);
}
use of org.chocosolver.solver.variables.IntVar in project scheduler by btrplace.
the class CShareableResourceTest method testSimple.
/**
* Test the instantiation and the creation of the variables.
*
* @throws org.btrplace.scheduler.SchedulerException should not occur
*/
@Test
public void testSimple() throws SchedulerException {
Model mo = new DefaultModel();
Mapping ma = mo.getMapping();
VM vm1 = mo.newVM();
VM vm2 = mo.newVM();
VM vm3 = mo.newVM();
Node n1 = mo.newNode();
Node n2 = mo.newNode();
ma.addOnlineNode(n1);
ma.addOfflineNode(n2);
ma.addRunningVM(vm1, n1);
ma.addRunningVM(vm2, n1);
ma.addReadyVM(vm3);
ShareableResource rc = new ShareableResource("foo", 0, 0);
rc.setConsumption(vm2, 3);
rc.setCapacity(n1, 4);
ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).build();
CShareableResource rcm = new CShareableResource(rc);
rcm.inject(new DefaultParameters(), rp);
Assert.assertEquals(rc.getIdentifier(), rcm.getIdentifier());
// Assert.assertEquals(-1, rcm.getVMsAllocation(rp.getVM(vm1)).getLB());
Assert.assertEquals(-1, rcm.getVMAllocation(rp.getVM(vm1)));
// Assert.assertEquals(-1, rcm.getVMsAllocation(rp.getVM(vm2)).getLB());
Assert.assertEquals(-1, rcm.getVMAllocation(rp.getVM(vm2)));
// Assert.assertEquals(0, rcm.getVMsAllocation(rp.getVM(vm3)).getUB()); //Will not be running so 0
// Will not be running so 0
Assert.assertEquals(0, rcm.getVMAllocation(rp.getVM(vm3)));
IntVar pn1 = rcm.getPhysicalUsage().get(rp.getNode(n1));
IntVar pn2 = rcm.getPhysicalUsage().get(rp.getNode(n2));
Assert.assertTrue(pn1.getLB() == 0 && pn1.getUB() == 4);
Assert.assertTrue(pn2.getLB() == 0 && pn2.getUB() == 0);
pn1 = rcm.getPhysicalUsage(rp.getNode(n1));
Assert.assertTrue(pn1.getLB() == 0 && pn1.getUB() == 4);
IntVar vn1 = rcm.getVirtualUsage().get(rp.getNode(n1));
IntVar vn2 = rcm.getVirtualUsage().get(rp.getNode(n2));
Assert.assertEquals(vn1.getLB(), 0);
Assert.assertEquals(vn2.getLB(), 0);
Assert.assertEquals(rc, rcm.getSourceResource());
}
use of org.chocosolver.solver.variables.IntVar in project scheduler by btrplace.
the class DisjointTest method test.
@Test
public void test() {
IntVar[] g1 = new IntVar[3];
IntVar[] g2 = new IntVar[3];
Model s = new Model();
for (int i = 0; i < g1.length; i++) {
g1[i] = s.intVar("G1-" + i, 0, (i + 1), false);
g2[i] = s.intVar("G2-" + i, 0, (i + 1), false);
}
s.post(new Disjoint(g1, g2, 4));
s.post(s.arithm(g2[g2.length - 1], "<=", g1[g1.length - 1]));
s.getSolver().findAllSolutions();
}
Aggregations