Search in sources :

Example 11 with IntVar

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);
    }
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) ShutdownableNode(org.btrplace.scheduler.choco.transition.ShutdownableNode) Node(org.btrplace.model.Node) BootableNode(org.btrplace.scheduler.choco.transition.BootableNode) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) VMTransition(org.btrplace.scheduler.choco.transition.VMTransition) Mapping(org.btrplace.model.Mapping) IntVar(org.chocosolver.solver.variables.IntVar) SuspendVM(org.btrplace.scheduler.choco.transition.SuspendVM) RelocatableVM(org.btrplace.scheduler.choco.transition.RelocatableVM) VM(org.btrplace.model.VM) StayAwayVM(org.btrplace.scheduler.choco.transition.StayAwayVM) ResumeVM(org.btrplace.scheduler.choco.transition.ResumeVM) KillVM(org.btrplace.scheduler.choco.transition.KillVM) BootVM(org.btrplace.scheduler.choco.transition.BootVM) ForgeVM(org.btrplace.scheduler.choco.transition.ForgeVM) ShutdownVM(org.btrplace.scheduler.choco.transition.ShutdownVM) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) CMinMTTR(org.btrplace.scheduler.choco.constraint.mttr.CMinMTTR) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 12 with IntVar

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);
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) OptConstraint(org.btrplace.model.constraint.OptConstraint) Constraint(org.chocosolver.solver.constraints.Constraint) SatConstraint(org.btrplace.model.constraint.SatConstraint) Node(org.btrplace.model.Node) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) Mapping(org.btrplace.model.Mapping) IntVar(org.chocosolver.solver.variables.IntVar) OptConstraint(org.btrplace.model.constraint.OptConstraint) Constraint(org.chocosolver.solver.constraints.Constraint) SatConstraint(org.btrplace.model.constraint.SatConstraint) BoolVar(org.chocosolver.solver.variables.BoolVar) VM(org.btrplace.model.VM) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) CMinMTTR(org.btrplace.scheduler.choco.constraint.mttr.CMinMTTR) Test(org.testng.annotations.Test)

Example 13 with IntVar

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);
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Node(org.btrplace.model.Node) VM(org.btrplace.model.VM) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) Mapping(org.btrplace.model.Mapping) IntVar(org.chocosolver.solver.variables.IntVar) OptConstraint(org.btrplace.model.constraint.OptConstraint) Constraint(org.chocosolver.solver.constraints.Constraint) SatConstraint(org.btrplace.model.constraint.SatConstraint) Test(org.testng.annotations.Test)

Example 14 with IntVar

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());
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) DefaultParameters(org.btrplace.scheduler.choco.DefaultParameters) VM(org.btrplace.model.VM) Node(org.btrplace.model.Node) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) DefaultReconfigurationProblemBuilder(org.btrplace.scheduler.choco.DefaultReconfigurationProblemBuilder) Mapping(org.btrplace.model.Mapping) ReconfigurationProblem(org.btrplace.scheduler.choco.ReconfigurationProblem) ShareableResource(org.btrplace.model.view.ShareableResource) IntVar(org.chocosolver.solver.variables.IntVar) Test(org.testng.annotations.Test)

Example 15 with IntVar

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();
}
Also used : Model(org.chocosolver.solver.Model) IntVar(org.chocosolver.solver.variables.IntVar) Test(org.testng.annotations.Test)

Aggregations

IntVar (org.chocosolver.solver.variables.IntVar)78 VM (org.btrplace.model.VM)35 Model (org.chocosolver.solver.Model)32 Test (org.testng.annotations.Test)30 Node (org.btrplace.model.Node)29 ArrayList (java.util.ArrayList)23 VMTransition (org.btrplace.scheduler.choco.transition.VMTransition)22 BoolVar (org.chocosolver.solver.variables.BoolVar)17 Mapping (org.btrplace.model.Mapping)16 Model (org.btrplace.model.Model)15 RelocatableVM (org.btrplace.scheduler.choco.transition.RelocatableVM)13 HashSet (java.util.HashSet)11 Slice (org.btrplace.scheduler.choco.Slice)10 DefaultModel (org.btrplace.model.DefaultModel)9 TIntArrayList (gnu.trove.list.array.TIntArrayList)8 ShareableResource (org.btrplace.model.view.ShareableResource)8 ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)8 Constraint (org.chocosolver.solver.constraints.Constraint)8 List (java.util.List)7 Set (java.util.Set)7