Search in sources :

Example 11 with Model

use of org.chocosolver.solver.Model in project scheduler by btrplace.

the class FastImpliesEqTest method test7.

@Test
public void test7() {
    Model s = new Model();
    BoolVar b = s.boolVar(false);
    IntVar x = s.intVar("x", 0, 2, true);
    int c = 3;
    s.post(new FastImpliesEq(b, x, c));
    Assert.assertEquals(3, s.getSolver().findAllSolutions().size());
}
Also used : Model(org.chocosolver.solver.Model) IntVar(org.chocosolver.solver.variables.IntVar) BoolVar(org.chocosolver.solver.variables.BoolVar) Test(org.testng.annotations.Test)

Example 12 with Model

use of org.chocosolver.solver.Model in project scheduler by btrplace.

the class FastImpliesEqTest method test1.

@Test
public void test1() {
    Model s = new Model();
    // SMF.log(s, true, true);
    BoolVar b = s.boolVar("b");
    IntVar x = s.intVar("x", 0, 3, true);
    int c = 2;
    s.post(new FastImpliesEq(b, x, c));
    Assert.assertEquals(5, s.getSolver().findAllSolutions().size());
}
Also used : Model(org.chocosolver.solver.Model) IntVar(org.chocosolver.solver.variables.IntVar) BoolVar(org.chocosolver.solver.variables.BoolVar) Test(org.testng.annotations.Test)

Example 13 with Model

use of org.chocosolver.solver.Model in project scheduler by btrplace.

the class PrecedencesTest method dummyTest.

/**
 * Ends variables are already instantiated.
 * Just a simple test.
 */
@Test
public void dummyTest() {
    Model s = new Model();
    IntVar[] ends = new IntVar[5];
    int[] others = new int[5];
    others[0] = 0;
    ends[0] = s.intVar(1);
    others[1] = 0;
    ends[1] = s.intVar(3);
    others[2] = 1;
    ends[2] = s.intVar(2);
    others[3] = 1;
    ends[3] = s.intVar(4);
    others[4] = 2;
    ends[4] = s.intVar(5);
    IntVar host = s.intVar("host", 0, 2, false);
    IntVar start = s.intVar("start", 0, 5, true);
    /*
           If host == 0, consume = 3,4,5
           If host == 1, consume = 4,5
           If host == 2, consume = 5
           => 6 solutions
         */
    Precedences p = new Precedences(host, start, others, ends);
    s.post(p);
    Assert.assertEquals(6, s.getSolver().findAllSolutions().size());
}
Also used : Model(org.chocosolver.solver.Model) IntVar(org.chocosolver.solver.variables.IntVar) Test(org.testng.annotations.Test)

Example 14 with Model

use of org.chocosolver.solver.Model in project scheduler by btrplace.

the class RoundedUpDivisionTest method test1.

@Test
public void test1() {
    Model s = new Model();
    IntVar a = s.intVar("a", 0, 5, true);
    IntVar b = s.intVar("b", 0, 5, true);
    double q = 1;
    s.post(new RoundedUpDivision(a, b, q));
    Assert.assertEquals(6, s.getSolver().findAllSolutions().size());
// Assert.assertEquals(s.getNbSolutions(), 6);
}
Also used : Model(org.chocosolver.solver.Model) IntVar(org.chocosolver.solver.variables.IntVar) Test(org.testng.annotations.Test)

Example 15 with Model

use of org.chocosolver.solver.Model in project scheduler by btrplace.

the class CMaxOnline method inject.

@Override
public boolean inject(Parameters ps, ReconfigurationProblem rp) throws SchedulerException {
    Model csp = rp.getModel();
    if (constraint.getInvolvedNodes().isEmpty()) {
        // The constraint is entailed as it contains no node.
        return true;
    }
    if (constraint.isContinuous()) {
        CPowerView view = (CPowerView) rp.getView(CPowerView.VIEW_ID);
        if (view == null) {
            view = new CPowerView();
            if (!rp.addView(view)) {
                throw new SchedulerModelingException(rp.getSourceModel(), "Unable to attach view '" + CPowerView.VIEW_ID + "'");
            }
            if (!view.inject(ps, rp)) {
                throw new SchedulerModelingException(rp.getSourceModel(), "Unable to inject view '" + CPowerView.VIEW_ID + "'");
            }
        }
        int numberOfTasks = constraint.getInvolvedNodes().size();
        int i = 0;
        int[] nodeIdx = new int[numberOfTasks];
        for (Node n : constraint.getInvolvedNodes()) {
            nodeIdx[i++] = rp.getNode(n);
        }
        IntVar capacity = rp.fixed(constraint.getAmount(), "capacity");
        // The state of the node:
        IntVar[] heights = new IntVar[numberOfTasks];
        IntVar[] starts = new IntVar[numberOfTasks];
        IntVar[] ends = new IntVar[numberOfTasks];
        // Online duration:
        IntVar[] durations = new IntVar[numberOfTasks];
        // Online duration is modeled as a task
        Task[] taskVars = new Task[numberOfTasks];
        for (int idx = 0; idx < nodeIdx.length; idx++) {
            Node n = rp.getNode(nodeIdx[idx]);
            // ---------------GET PowerStart and PowerEnd of the node------------------
            starts[idx] = view.getPowerStart(rp.getNode(n));
            ends[idx] = view.getPowerEnd(rp.getNode(n));
            // ------------------------------------------------------------------------
            durations[idx] = rp.makeUnboundedDuration(rp.makeVarLabel("Dur(", n, ")"));
            csp.post(csp.arithm(durations[idx], "<=", rp.getEnd()));
            // All tasks have to be scheduled
            heights[idx] = csp.intVar(1);
            taskVars[idx] = new Task(starts[idx], durations[idx], ends[idx]);
        }
        csp.post(csp.cumulative(taskVars, heights, capacity, true));
    }
    // Constraint for discrete model
    List<IntVar> nodesState = new ArrayList<>(constraint.getInvolvedNodes().size());
    for (Node ni : constraint.getInvolvedNodes()) {
        nodesState.add(rp.getNodeAction(ni).getState());
    }
    IntVar mySum = csp.intVar(rp.makeVarLabel("nbOnline"), 0, constraint.getAmount(), true);
    csp.post(csp.sum(nodesState.toArray(new IntVar[nodesState.size()]), "=", mySum));
    csp.post(csp.arithm(mySum, "<=", constraint.getAmount()));
    return true;
}
Also used : Task(org.chocosolver.solver.variables.Task) Node(org.btrplace.model.Node) Model(org.chocosolver.solver.Model) ArrayList(java.util.ArrayList) CPowerView(org.btrplace.scheduler.choco.view.CPowerView) IntVar(org.chocosolver.solver.variables.IntVar) SchedulerModelingException(org.btrplace.scheduler.SchedulerModelingException)

Aggregations

Model (org.chocosolver.solver.Model)38 IntVar (org.chocosolver.solver.variables.IntVar)32 Test (org.testng.annotations.Test)20 BoolVar (org.chocosolver.solver.variables.BoolVar)17 Node (org.btrplace.model.Node)7 VM (org.btrplace.model.VM)7 ArrayList (java.util.ArrayList)6 VMTransition (org.btrplace.scheduler.choco.transition.VMTransition)4 TIntArrayList (gnu.trove.list.array.TIntArrayList)3 RelocatableVM (org.btrplace.scheduler.choco.transition.RelocatableVM)3 HashSet (java.util.HashSet)2 SchedulerModelingException (org.btrplace.scheduler.SchedulerModelingException)2 Task (org.chocosolver.solver.variables.Task)2 Collection (java.util.Collection)1 Collections (java.util.Collections)1 List (java.util.List)1 Objects (java.util.Objects)1 Among (org.btrplace.model.constraint.Among)1 SplitAmong (org.btrplace.model.constraint.SplitAmong)1 Parameters (org.btrplace.scheduler.choco.Parameters)1