Search in sources :

Example 46 with IntVar

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

the class CNetwork method addLinkConstraints.

/**
 * Add the cumulative constraints for each link.
 *
 * Full-duplex links are considered, two cumulative constraints are defined per link by looking at
 * the migration direction for each link on the migration path.
 *
 * @param rp the reconfiguration problem
 */
private void addLinkConstraints(ReconfigurationProblem rp) {
    // Links limitation
    List<Task> tasksListUp = new ArrayList<>();
    List<Task> tasksListDown = new ArrayList<>();
    List<IntVar> heightsListUp = new ArrayList<>();
    List<IntVar> heightsListDown = new ArrayList<>();
    for (Link l : net.getLinks()) {
        for (VM vm : rp.getVMs()) {
            VMTransition a = rp.getVMAction(vm);
            if (a instanceof RelocatableVM && !a.getDSlice().getHoster().isInstantiatedTo(a.getCSlice().getHoster().getValue())) {
                Node src = source.getMapping().getVMLocation(vm);
                Node dst = rp.getNode(a.getDSlice().getHoster().getValue());
                List<Link> path = net.getRouting().getPath(src, dst);
                // Check first if the link is on migration path
                if (path.contains(l)) {
                    // Get link direction
                    LinkDirection linkDirection = net.getRouting().getLinkDirection(src, dst, l);
                    // UpLink
                    if (linkDirection == LinkDirection.UPLINK) {
                        tasksListUp.add(((RelocatableVM) a).getMigrationTask());
                        heightsListUp.add(((RelocatableVM) a).getBandwidth());
                    } else // DownLink
                    {
                        tasksListDown.add(((RelocatableVM) a).getMigrationTask());
                        heightsListDown.add(((RelocatableVM) a).getBandwidth());
                    }
                }
            }
        }
        if (!tasksListUp.isEmpty()) {
            // Post the cumulative constraint for the current UpLink
            csp.post(csp.cumulative(tasksListUp.toArray(new Task[tasksListUp.size()]), heightsListUp.toArray(new IntVar[heightsListUp.size()]), csp.intVar(l.getCapacity()), true));
            tasksListUp.clear();
            heightsListUp.clear();
        }
        if (!tasksListDown.isEmpty()) {
            // Post the cumulative constraint for the current DownLink
            csp.post(csp.cumulative(tasksListDown.toArray(new Task[tasksListDown.size()]), heightsListDown.toArray(new IntVar[heightsListDown.size()]), csp.intVar(l.getCapacity()), true));
            tasksListDown.clear();
            heightsListDown.clear();
        }
    }
}
Also used : Task(org.chocosolver.solver.variables.Task) RelocatableVM(org.btrplace.scheduler.choco.transition.RelocatableVM) VM(org.btrplace.model.VM) Node(org.btrplace.model.Node) ArrayList(java.util.ArrayList) VMTransition(org.btrplace.scheduler.choco.transition.VMTransition) LinkDirection(org.btrplace.model.view.network.Routing.LinkDirection) RelocatableVM(org.btrplace.scheduler.choco.transition.RelocatableVM) IntVar(org.chocosolver.solver.variables.IntVar) Link(org.btrplace.model.view.network.Link)

Example 47 with IntVar

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

the class CShareableResource method linkVirtualToPhysicalUsage.

private boolean linkVirtualToPhysicalUsage() throws SchedulerException {
    int min = Integer.MAX_VALUE;
    // Number of VMs with a 0 usage
    int nbZeroes = 0;
    for (int vId = 0; vId < vmAllocation.size(); vId++) {
        int alloc = vmAllocation.get(vId);
        if (alloc > 0) {
            min = Math.min(alloc, min);
        } else {
            nbZeroes++;
        }
    }
    for (int nIdx = 0; nIdx < ratios.size(); nIdx++) {
        if (!linkVirtualToPhysicalUsage(nIdx)) {
            return false;
        }
        if (!capHosting(nIdx, min, nbZeroes)) {
            return false;
        }
    }
    // The slice scheduling constraint that is necessary
    TIntArrayList cUse = new TIntArrayList();
    List<IntVar> dUse = new ArrayList<>();
    for (VMTransition a : rp.getVMActions()) {
        VM vm = a.getVM();
        Slice c = a.getCSlice();
        Slice d = a.getDSlice();
        if (c != null) {
            cUse.add(getSourceResource().getConsumption(vm));
        }
        if (d != null) {
            int m = getVMAllocation(rp.getVM(vm));
            dUse.add(rp.fixed(m, "vmAllocation('", getResourceIdentifier(), "', '", vm, "'"));
        }
    }
    Cumulatives v = (Cumulatives) rp.getView(Cumulatives.VIEW_ID);
    v.addDim(virtRcUsage, cUse.toArray(), dUse.toArray(new IntVar[dUse.size()]));
    checkInitialSatisfaction();
    return true;
}
Also used : Slice(org.btrplace.scheduler.choco.Slice) MigrateVM(org.btrplace.plan.event.MigrateVM) VM(org.btrplace.model.VM) TIntArrayList(gnu.trove.list.array.TIntArrayList) ArrayList(java.util.ArrayList) TDoubleArrayList(gnu.trove.list.array.TDoubleArrayList) VMTransition(org.btrplace.scheduler.choco.transition.VMTransition) IntVar(org.chocosolver.solver.variables.IntVar) SatConstraint(org.btrplace.model.constraint.SatConstraint) TIntArrayList(gnu.trove.list.array.TIntArrayList)

Example 48 with IntVar

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

the class DefaultAliasedCumulatives method beforeSolve.

/**
 * Get the generated constraints.
 *
 * @return a list of constraint that may be empty.
 */
@Override
public boolean beforeSolve(ReconfigurationProblem r) {
    super.beforeSolve(r);
    for (int i = 0; i < aliases.size(); i++) {
        int capa = capacities.get(i);
        int[] alias = aliases.get(i);
        int[] cUse = cUsages.get(i);
        int[] dUses = new int[dUsages.get(i).length];
        for (IntVar dUseDim : dUsages.get(i)) {
            dUses[i++] = dUseDim.getLB();
        }
        r.getModel().post(new AliasedCumulatives(alias, new int[] { capa }, cHosts, new int[][] { cUse }, cEnds, dHosts, new int[][] { dUses }, dStarts, associations));
    }
    return true;
}
Also used : AliasedCumulatives(org.btrplace.scheduler.choco.extensions.AliasedCumulatives) IntVar(org.chocosolver.solver.variables.IntVar)

Example 49 with IntVar

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

the class DefaultCumulatives method beforeSolve.

/**
 * Build the constraint.
 *
 * @return the resulting constraint
 */
@Override
@SuppressWarnings("squid:S3346")
public boolean beforeSolve(ReconfigurationProblem rp) {
    super.beforeSolve(rp);
    if (rp.getSourceModel().getMapping().getNbNodes() == 0 || capacities.isEmpty()) {
        return true;
    }
    int nbDims = capacities.size();
    int nbRes = capacities.get(0).size();
    // We get the UB of the node capacity and the LB for the VM usage.
    int[][] capas = new int[nbRes][nbDims];
    int d = 0;
    for (List<IntVar> capaDim : capacities) {
        assert capaDim.size() == nbRes;
        for (int j = 0; j < capaDim.size(); j++) {
            capas[j][d] = capaDim.get(j).getUB();
        }
        d++;
    }
    assert cUsages.size() == nbDims;
    int nbCHosts = cUsages.get(0).length;
    int[][] cUses = new int[nbCHosts][nbDims];
    d = 0;
    for (int[] cUseDim : cUsages) {
        assert cUseDim.length == nbCHosts;
        for (int i = 0; i < nbCHosts; i++) {
            cUses[i][d] = cUseDim[i];
        }
        d++;
    }
    assert dUsages.size() == nbDims;
    int nbDHosts = dUsages.get(0).length;
    int[][] dUses = new int[nbDHosts][nbDims];
    d = 0;
    for (IntVar[] dUseDim : dUsages) {
        assert dUseDim.length == nbDHosts;
        for (int j = 0; j < nbDHosts; j++) {
            dUses[j][d] = dUseDim[j].getLB();
        }
        d++;
    }
    symmetryBreakingForStayingVMs(rp);
    IntVar[] earlyStarts = rp.getNodeActions().stream().map(NodeTransition::getHostingStart).toArray(IntVar[]::new);
    IntVar[] lastEnd = rp.getNodeActions().stream().map(NodeTransition::getHostingEnd).toArray(IntVar[]::new);
    rp.getModel().post(new TaskScheduler(earlyStarts, lastEnd, capas, cHosts, cUses, cEnds, dHosts, dUses, dStarts, associations));
    return true;
}
Also used : TaskScheduler(org.btrplace.scheduler.choco.extensions.TaskScheduler) IntVar(org.chocosolver.solver.variables.IntVar)

Example 50 with IntVar

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

the class DefaultReconfigurationProblemTest method testMinimize.

/**
 * Test a minimization problem: use the minimum number of nodes.
 *
 * @throws org.btrplace.scheduler.SchedulerException
 */
@Test
public void testMinimize() throws SchedulerException {
    Model mo = new DefaultModel();
    Mapping map = mo.getMapping();
    for (int i = 0; i < 10; i++) {
        Node n = mo.newNode();
        VM vm = mo.newVM();
        map.addOnlineNode(n);
        map.addRunningVM(vm, n);
    }
    Parameters ps = new DefaultParameters();
    ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setParams(ps).build();
    Solver s = rp.getSolver();
    IntVar nbNodes = rp.getModel().intVar("nbNodes", 1, map.getAllNodes().size(), true);
    Stream<Slice> dSlices = rp.getVMActions().stream().filter(t -> t.getDSlice() != null).map(VMTransition::getDSlice);
    IntVar[] hosters = dSlices.map(Slice::getHoster).toArray(IntVar[]::new);
    rp.getModel().post(rp.getModel().atMostNValues(hosters, nbNodes, true));
    rp.setObjective(true, nbNodes);
    ReconfigurationPlan plan = rp.solve(-1, true);
    Assert.assertNotNull(plan);
    Assert.assertEquals(s.getMeasures().getSolutionCount(), 1);
    Mapping dst = plan.getResult().getMapping();
    Assert.assertEquals(usedNodes(dst), 1);
}
Also used : ShutdownableNode(org.btrplace.scheduler.choco.transition.ShutdownableNode) ChocoView(org.btrplace.scheduler.choco.view.ChocoView) Arrays(java.util.Arrays) SchedulerException(org.btrplace.scheduler.SchedulerException) SuspendVM(org.btrplace.scheduler.choco.transition.SuspendVM) Node(org.btrplace.model.Node) ModelView(org.btrplace.model.view.ModelView) UnstatableProblemException(org.btrplace.scheduler.UnstatableProblemException) NodeTransition(org.btrplace.scheduler.choco.transition.NodeTransition) ContradictionException(org.chocosolver.solver.exception.ContradictionException) Test(org.testng.annotations.Test) Solver(org.chocosolver.solver.Solver) RelocatableVM(org.btrplace.scheduler.choco.transition.RelocatableVM) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) HashSet(java.util.HashSet) VM(org.btrplace.model.VM) BootableNode(org.btrplace.scheduler.choco.transition.BootableNode) Assert(org.testng.Assert) Mapping(org.btrplace.model.Mapping) StayAwayVM(org.btrplace.scheduler.choco.transition.StayAwayVM) Model(org.btrplace.model.Model) DurationEvaluators(org.btrplace.scheduler.choco.duration.DurationEvaluators) ResumeVM(org.btrplace.scheduler.choco.transition.ResumeVM) Set(java.util.Set) DefaultModel(org.btrplace.model.DefaultModel) Cause(org.chocosolver.solver.Cause) VMTransition(org.btrplace.scheduler.choco.transition.VMTransition) IntVar(org.chocosolver.solver.variables.IntVar) Stream(java.util.stream.Stream) KillVM(org.btrplace.scheduler.choco.transition.KillVM) CMinMTTR(org.btrplace.scheduler.choco.constraint.mttr.CMinMTTR) BootVM(org.btrplace.scheduler.choco.transition.BootVM) ForgeVM(org.btrplace.scheduler.choco.transition.ForgeVM) ShutdownVM(org.btrplace.scheduler.choco.transition.ShutdownVM) ShareableResource(org.btrplace.model.view.ShareableResource) Solution(org.chocosolver.solver.Solution) Collections(java.util.Collections) DefaultModel(org.btrplace.model.DefaultModel) Solver(org.chocosolver.solver.Solver) 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) 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