Search in sources :

Example 21 with BoolVar

use of org.chocosolver.solver.variables.BoolVar in project scheduler by btrplace.

the class FastImpliesEqTest method test4.

@Test
public void test4() {
    Model s = new Model();
    BoolVar b = s.boolVar(true);
    IntVar x = s.intVar("x", 0, 2, true);
    int c = 3;
    s.post(new FastImpliesEq(b, x, c));
    Assert.assertEquals(0, 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 22 with BoolVar

use of org.chocosolver.solver.variables.BoolVar in project scheduler by btrplace.

the class CNoDelay method inject.

@Override
public boolean inject(Parameters ps, ReconfigurationProblem rp) {
    VM v = noDelay.getInvolvedVMs().iterator().next();
    // For each vm involved in the constraint
    VMTransition vt = rp.getVMAction(v);
    // Get the VMTransition start time
    // Add the constraint "start = 0" to the solver
    Slice d = vt.getDSlice();
    if (d == null) {
        return true;
    }
    if (!(vt instanceof RelocatableVM)) {
        try {
            d.getStart().instantiateTo(0, Cause.Null);
        } catch (ContradictionException ex) {
            rp.getLogger().error("Unable to prevent any delay on '" + v + "'", ex);
            return false;
        }
    } else {
        Constraint c = rp.getModel().arithm(d.getStart(), "=", 0);
        BoolVar move = ((RelocatableVM) vt).isStaying().not();
        ChocoUtils.postImplies(rp, move, c);
    }
    return true;
}
Also used : Constraint(org.chocosolver.solver.constraints.Constraint) Slice(org.btrplace.scheduler.choco.Slice) ContradictionException(org.chocosolver.solver.exception.ContradictionException) RelocatableVM(org.btrplace.scheduler.choco.transition.RelocatableVM) VM(org.btrplace.model.VM) VMTransition(org.btrplace.scheduler.choco.transition.VMTransition) RelocatableVM(org.btrplace.scheduler.choco.transition.RelocatableVM) BoolVar(org.chocosolver.solver.variables.BoolVar)

Aggregations

BoolVar (org.chocosolver.solver.variables.BoolVar)22 Model (org.chocosolver.solver.Model)17 IntVar (org.chocosolver.solver.variables.IntVar)17 Test (org.testng.annotations.Test)16 VM (org.btrplace.model.VM)4 Constraint (org.chocosolver.solver.constraints.Constraint)4 DefaultModel (org.btrplace.model.DefaultModel)2 Mapping (org.btrplace.model.Mapping)2 Model (org.btrplace.model.Model)2 Node (org.btrplace.model.Node)2 OptConstraint (org.btrplace.model.constraint.OptConstraint)2 SatConstraint (org.btrplace.model.constraint.SatConstraint)2 ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)2 Slice (org.btrplace.scheduler.choco.Slice)2 VMTransition (org.btrplace.scheduler.choco.transition.VMTransition)2 ShareableResource (org.btrplace.model.view.ShareableResource)1 CMinMTTR (org.btrplace.scheduler.choco.constraint.mttr.CMinMTTR)1 KeepRunningVM (org.btrplace.scheduler.choco.transition.KeepRunningVM)1 RelocatableVM (org.btrplace.scheduler.choco.transition.RelocatableVM)1 ContradictionException (org.chocosolver.solver.exception.ContradictionException)1