Search in sources :

Example 31 with Model

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

the class RoundedUpDivisionTest method test2.

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

Example 32 with Model

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

the class VectorPackingTest method modelPack.

public void modelPack(int[][] capa, int[][] height) {
    int nRes = capa.length;
    assert nRes == height.length;
    int nBins = capa[0].length;
    int nItems = height[0].length;
    s = new Model();
    loads = new IntVar[nRes][nBins];
    bins = new IntVar[nItems];
    String[] name = new String[nRes];
    for (int d = 0; d < nRes; d++) {
        name[d] = "d" + d;
        for (int i = 0; i < nBins; i++) {
            loads[d][i] = s.intVar("l" + d + "." + i, 0, capa[d][i], true);
        }
    }
    sizes = height;
    bins = s.intVarArray("b", nItems, 0, nBins, false);
    Constraint cPack = new VectorPacking(name, loads, sizes, bins);
    s.post(cPack);
}
Also used : VectorPacking(org.btrplace.scheduler.choco.extensions.pack.VectorPacking) Constraint(org.chocosolver.solver.constraints.Constraint) Model(org.chocosolver.solver.Model) Constraint(org.chocosolver.solver.constraints.Constraint)

Example 33 with Model

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

the class CLonely method inject.

@Override
public boolean inject(Parameters ps, ReconfigurationProblem rp) {
    // Remove non future-running VMs
    List<IntVar> myHosts = new ArrayList<>();
    List<IntVar> otherHosts = new ArrayList<>();
    Collection<VM> vms = new HashSet<>();
    Set<VM> otherVMs = new HashSet<>();
    for (VM vm : rp.getFutureRunningVMs()) {
        IntVar host = rp.getVMAction(vm).getDSlice().getHoster();
        if (cstr.getInvolvedVMs().contains(vm)) {
            myHosts.add(host);
            vms.add(vm);
        } else {
            otherHosts.add(host);
            otherVMs.add(vm);
        }
    }
    // Link the assignment variables with the set
    Model s = rp.getModel();
    s.post(new Disjoint(myHosts.toArray(new IntVar[myHosts.size()]), otherHosts.toArray(new IntVar[otherHosts.size()]), rp.getNodes().size()));
    if (cstr.isContinuous()) {
        continuousRestriction(rp, vms, otherVMs);
    }
    return true;
}
Also used : VM(org.btrplace.model.VM) TIntArrayList(gnu.trove.list.array.TIntArrayList) ArrayList(java.util.ArrayList) Model(org.chocosolver.solver.Model) Disjoint(org.btrplace.scheduler.choco.extensions.Disjoint) IntVar(org.chocosolver.solver.variables.IntVar) HashSet(java.util.HashSet)

Example 34 with Model

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

the class CResourceCapacity method inject.

@Override
public boolean inject(Parameters ps, ReconfigurationProblem rp) throws SchedulerException {
    Model csp = rp.getModel();
    CShareableResource rcm = (CShareableResource) rp.getView(ShareableResource.VIEW_ID_BASE + cstr.getResource());
    if (rcm == null) {
        throw new SchedulerModelingException(rp.getSourceModel(), "No resource associated to identifier '" + cstr.getResource() + "'");
    }
    if (cstr.getInvolvedNodes().size() == 1) {
        return injectWithSingleNode(rcm, rp);
    }
    if (cstr.isContinuous() && !injectContinuous(rp, rcm)) {
        return false;
    }
    List<IntVar> vs = new ArrayList<>();
    for (Node u : cstr.getInvolvedNodes()) {
        vs.add(rcm.getVirtualUsage().get(rp.getNode(u)));
    }
    IntVar mySum = csp.intVar(rp.makeVarLabel("usage(", rcm.getIdentifier(), ")"), 0, Integer.MAX_VALUE / 100, true);
    csp.post(csp.sum(vs.toArray(new IntVar[vs.size()]), "=", mySum));
    csp.post(csp.arithm(mySum, "<=", cstr.getAmount()));
    return true;
}
Also used : Node(org.btrplace.model.Node) Model(org.chocosolver.solver.Model) TIntArrayList(gnu.trove.list.array.TIntArrayList) ArrayList(java.util.ArrayList) CShareableResource(org.btrplace.scheduler.choco.view.CShareableResource) IntVar(org.chocosolver.solver.variables.IntVar) SchedulerModelingException(org.btrplace.scheduler.SchedulerModelingException)

Example 35 with Model

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

the class CRunningCapacity method inject.

@Override
public boolean inject(Parameters ps, ReconfigurationProblem rp) throws SchedulerException {
    Model csp = rp.getModel();
    if (cstr.getInvolvedNodes().size() == 1) {
        return filterWithSingleNode(rp);
    }
    if (cstr.isContinuous() && !injectContinuous(rp)) {
        return false;
    }
    List<IntVar> vs = new ArrayList<>();
    for (Node u : cstr.getInvolvedNodes()) {
        vs.add(rp.getNbRunningVMs().get(rp.getNode(u)));
    }
    // Try to get a lower bound
    // basically, we count 1 per VM necessarily in the set of nodes
    // if involved nodes == all the nodes, then sum == nb of running VMs
    IntVar mySum = csp.intVar(rp.makeVarLabel("nbRunning"), 0, rp.getFutureRunningVMs().size(), true);
    csp.post(csp.sum(vs.toArray(new IntVar[vs.size()]), "=", mySum));
    csp.post(csp.arithm(mySum, "<=", cstr.getAmount()));
    if (cstr.getInvolvedNodes().equals(rp.getSourceModel().getMapping().getAllNodes())) {
        csp.post(csp.arithm(mySum, "=", rp.getFutureRunningVMs().size()));
    }
    return true;
}
Also used : Node(org.btrplace.model.Node) Model(org.chocosolver.solver.Model) ArrayList(java.util.ArrayList) IntVar(org.chocosolver.solver.variables.IntVar)

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