Search in sources :

Example 6 with Among

use of org.btrplace.model.constraint.Among in project scheduler by btrplace.

the class CSplitAmong method inject.

@Override
public boolean inject(Parameters ps, ReconfigurationProblem rp) throws SchedulerException {
    if (cstr.isContinuous() && !cstr.isSatisfied(rp.getSourceModel())) {
        rp.getLogger().error("The constraint '{}' must be already satisfied to provide a continuous restriction", cstr);
        return false;
    }
    Collection<Collection<VM>> vGroups = cstr.getGroupsOfVMs();
    Collection<Collection<Node>> pGroups = cstr.getGroupsOfNodes();
    Model csp = rp.getModel();
    IntVar[] grpVars = new IntVar[vGroups.size()];
    // VM is assigned on a node <-> group variable associated to the VM
    // is assigned to the group of nodes it belong too.
    int i = 0;
    for (Collection<VM> vms : vGroups) {
        Among a = new Among(vms, pGroups);
        // If the constraint is continuous, there is no way a group of VMs already bound to a group of
        // nodes can move to another group. It also means the group of VMs will never overlap
        a.setContinuous(cstr.isContinuous());
        CAmong ca = new CAmong(a);
        if (!ca.inject(ps, rp)) {
            return false;
        }
        grpVars[i++] = ca.getGroupVariable();
    }
    // forces all the vGroups to use different group of nodes
    csp.post(csp.allDifferent(grpVars, "DEFAULT"));
    return true;
}
Also used : VM(org.btrplace.model.VM) Model(org.chocosolver.solver.Model) Collection(java.util.Collection) Among(org.btrplace.model.constraint.Among) SplitAmong(org.btrplace.model.constraint.SplitAmong) IntVar(org.chocosolver.solver.variables.IntVar)

Aggregations

Among (org.btrplace.model.constraint.Among)6 Collection (java.util.Collection)3 VM (org.btrplace.model.VM)3 Test (org.testng.annotations.Test)3 DefaultModel (org.btrplace.model.DefaultModel)2 Node (org.btrplace.model.Node)2 TIntIntHashMap (gnu.trove.map.hash.TIntIntHashMap)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 ScriptBuilder (org.btrplace.btrpsl.ScriptBuilder)1 Model (org.btrplace.model.Model)1 MinMTTR (org.btrplace.model.constraint.MinMTTR)1 SatConstraint (org.btrplace.model.constraint.SatConstraint)1 SplitAmong (org.btrplace.model.constraint.SplitAmong)1 Spread (org.btrplace.model.constraint.Spread)1 DefaultParameters (org.btrplace.scheduler.choco.DefaultParameters)1 FixedNodeSetsPartitioning (org.btrplace.scheduler.runner.disjoint.FixedNodeSetsPartitioning)1 ElementSubSet (org.btrplace.scheduler.runner.disjoint.model.ElementSubSet)1 Model (org.chocosolver.solver.Model)1 IntVar (org.chocosolver.solver.variables.IntVar)1