Search in sources :

Example 41 with IntVar

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

the class MovingVMs method setToNextMovingVM.

@SuppressWarnings("squid:S3346")
private boolean setToNextMovingVM(IntVar[] scopes) {
    assert actions.size() == scopes.length;
    for (int i = idx.get(); i < scopes.length; i++) {
        IntVar h = scopes[i];
        if (!h.isInstantiated()) {
            VM vm = actions.get(i).getVM();
            Node nId = map.getVMLocation(vm);
            if (!h.contains(rp.getNode(nId))) {
                // VM was running, otherwise -1 so not inside h
                idx.set(i);
                return true;
            }
        }
        i++;
    }
    return false;
}
Also used : VM(org.btrplace.model.VM) Node(org.btrplace.model.Node) IntVar(org.chocosolver.solver.variables.IntVar)

Example 42 with IntVar

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

the class VMPlacementUtils method makePlacementMap.

/**
 * Map a map where keys are the placement variable of the future-running VMs
 * and values are the VM identifier.
 *
 * @param rp the problem
 * @return the resulting map.
 */
public static Map<IntVar, VM> makePlacementMap(ReconfigurationProblem rp) {
    Map<IntVar, VM> m = new HashMap<>(rp.getFutureRunningVMs().size());
    for (VM vm : rp.getFutureRunningVMs()) {
        IntVar v = rp.getVMAction(vm).getDSlice().getHoster();
        m.put(v, vm);
    }
    return m;
}
Also used : HashMap(java.util.HashMap) VM(org.btrplace.model.VM) IntVar(org.chocosolver.solver.variables.IntVar)

Example 43 with IntVar

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

the class VectorPackingPropagator method checkLoadConsistency.

// ****************************************************************//
// ********* Checkers *********************************************//
// ****************************************************************//
/**
 * Check the consistency of the assigned and candidate loads with regards to the assignment variables:
 * for each bin: sumAssignedItemSizes == binAssignedLoad, sumAllPossibleItemSizes == binPotentialLoad
 * rule 2, for each bin: binAssignedLoad <= binLoad <= binPotentialLoad
 *
 * @return {@code false} if not consistent.
 */
private boolean checkLoadConsistency() {
    boolean check = true;
    int[][] rs = new int[nbDims][nbBins];
    int[][] cs = new int[nbDims][nbBins];
    for (int i = 0; i < bins.length; i++) {
        if (bins[i].isInstantiated()) {
            for (int d = 0; d < nbDims; d++) {
                rs[d][bins[i].getValue()] += iSizes[d][i];
            }
        } else {
            DisposableValueIterator it = bins[i].getValueIterator(true);
            try {
                while (it.hasNext()) {
                    int v = it.next();
                    for (int d = 0; d < nbDims; d++) {
                        cs[d][v] += iSizes[d][i];
                    }
                }
            } finally {
                it.dispose();
            }
        }
    }
    for (int d = 0; d < nbDims; d++) {
        check = check && checkDimension(d, rs, cs);
    }
    if (!check) {
        for (IntVar v : bins) {
            System.err.println(v.toString());
        }
    }
    return check;
}
Also used : DisposableValueIterator(org.chocosolver.util.iterators.DisposableValueIterator) IntVar(org.chocosolver.solver.variables.IntVar)

Example 44 with IntVar

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

the class CNetwork method beforeSolve.

@Override
public boolean beforeSolve(ReconfigurationProblem rp) throws SchedulerException {
    Model mo = rp.getSourceModel();
    Attributes attrs = mo.getAttributes();
    // Pre-compute duration and bandwidth for each VM migration
    for (VMTransition migration : rp.getVMActions()) {
        if (!(migration instanceof RelocatableVM)) {
            continue;
        }
        // Get vars from migration
        VM vm = migration.getVM();
        IntVar bandwidth = ((RelocatableVM) migration).getBandwidth();
        IntVar duration = migration.getDuration();
        Node src = rp.getSourceModel().getMapping().getVMLocation(vm);
        // Try to get the destination node
        Node dst;
        if (!migration.getDSlice().getHoster().isInstantiated()) {
            throw new SchedulerModelingException(null, "Destination node for VM '" + vm + "' should be known !");
        }
        if (!mo.getAttributes().isSet(vm, "memUsed")) {
            throw new SchedulerModelingException(null, "Unable to retrieve 'memUsed' attribute for the vm '" + vm + "'");
        }
        dst = rp.getNode(migration.getDSlice().getHoster().getValue());
        if (src.equals(dst)) {
            try {
                ((RelocatableVM) migration).getBandwidth().instantiateTo(0, Cause.Null);
                continue;
            } catch (ContradictionException e) {
                rp.getLogger().error("Contradiction exception when trying to instantiate bandwidth and " + " duration variables for " + vm + " migration", e);
                return false;
            }
        }
        // Get attribute vars
        int memUsed = attrs.get(vm, "memUsed", -1);
        // Get VM memory activity attributes if defined, otherwise set an idle workload on the VM
        // Minimal observed value on idle VM
        double hotDirtySize = attrs.get(vm, "hotDirtySize", 5.0);
        // Minimal observed value on idle VM
        double hotDirtyDuration = attrs.get(vm, "hotDirtyDuration", 2.0);
        double coldDirtyRate = attrs.get(vm, "coldDirtyRate", 0.0);
        // Get the maximal bandwidth available on the migration path
        int maxBW = net.getRouting().getMaxBW(src, dst);
        // Compute the duration related to each enumerated bandwidth
        double durationMin;
        double durationColdPages;
        double durationHotPages;
        double durationTotal;
        // Cheat a bit, real is less than theoretical (8->9)
        double bandwidthOctet = maxBW / 9.0;
        // Estimate the duration for the current bandwidth
        durationMin = memUsed / bandwidthOctet;
        if (durationMin > hotDirtyDuration) {
            durationColdPages = (hotDirtySize + (durationMin - hotDirtyDuration) * coldDirtyRate) / (bandwidthOctet - coldDirtyRate);
            durationHotPages = (hotDirtySize / bandwidthOctet * ((hotDirtySize / hotDirtyDuration) / (bandwidthOctet - (hotDirtySize / hotDirtyDuration))));
            durationTotal = durationMin + durationColdPages + durationHotPages;
        } else {
            durationTotal = durationMin + (((hotDirtySize / hotDirtyDuration) * durationMin) / (bandwidthOctet - (hotDirtySize / hotDirtyDuration)));
        }
        // Instantiate the computed bandwidth and duration
        try {
            // prevent from a 0 duration when the memory usage is very low
            int dd = (int) Math.max(1, Math.round(durationTotal));
            duration.instantiateTo(dd, Cause.Null);
            bandwidth.instantiateTo(maxBW, Cause.Null);
        } catch (ContradictionException e) {
            rp.getLogger().error("Contradiction exception when trying to instantiate bandwidth and " + " duration variables for " + vm + " migration: ", e);
            return false;
        }
    }
    // Add links and switches constraints
    addLinkConstraints(rp);
    addSwitchConstraints(rp);
    return true;
}
Also used : ContradictionException(org.chocosolver.solver.exception.ContradictionException) RelocatableVM(org.btrplace.scheduler.choco.transition.RelocatableVM) VM(org.btrplace.model.VM) Node(org.btrplace.model.Node) Model(org.btrplace.model.Model) Attributes(org.btrplace.model.Attributes) VMTransition(org.btrplace.scheduler.choco.transition.VMTransition) RelocatableVM(org.btrplace.scheduler.choco.transition.RelocatableVM) IntVar(org.chocosolver.solver.variables.IntVar) SchedulerModelingException(org.btrplace.scheduler.SchedulerModelingException)

Example 45 with IntVar

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

the class CNetwork method addSwitchConstraints.

/**
 * Add the cumulative constraints for each blocking switch (having limited capacity)
 *
 * @param rp the reconfiguration problem
 */
private void addSwitchConstraints(ReconfigurationProblem rp) {
    // Switches capacity limitation
    List<Task> tasksList = new ArrayList<>();
    List<IntVar> heightsList = new ArrayList<>();
    for (Switch sw : net.getSwitches()) {
        // Only if the capacity is limited
        if (sw.getCapacity() != Integer.MAX_VALUE) {
            for (VM vm : rp.getVMs()) {
                VMTransition a = rp.getVMAction(vm);
                if (a != null && a instanceof RelocatableVM) {
                    if (a.getDSlice().getHoster().isInstantiated()) {
                        if (a.getCSlice().getHoster().getValue() != a.getDSlice().getHoster().getValue()) {
                            Node src = source.getMapping().getVMLocation(vm);
                            Node dst = rp.getNode(a.getDSlice().getHoster().getValue());
                            if (!Collections.disjoint(net.getConnectedLinks(sw), net.getRouting().getPath(src, dst))) {
                                tasksList.add(new Task(a.getStart(), a.getDuration(), a.getEnd()));
                                heightsList.add(((RelocatableVM) a).getBandwidth());
                            }
                        }
                    }
                }
            }
            if (!tasksList.isEmpty()) {
                // Post the cumulative constraint for the current switch
                csp.post(csp.cumulative(tasksList.toArray(new Task[tasksList.size()]), heightsList.toArray(new IntVar[heightsList.size()]), csp.intVar(sw.getCapacity()), true));
                tasksList.clear();
                heightsList.clear();
            }
        }
    }
}
Also used : Task(org.chocosolver.solver.variables.Task) Switch(org.btrplace.model.view.network.Switch) 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) RelocatableVM(org.btrplace.scheduler.choco.transition.RelocatableVM) IntVar(org.chocosolver.solver.variables.IntVar)

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