Search in sources :

Example 6 with ContradictionException

use of org.chocosolver.solver.exception.ContradictionException 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 7 with ContradictionException

use of org.chocosolver.solver.exception.ContradictionException in project scheduler by btrplace.

the class CShareableResource method overbook.

private boolean overbook(int nIdx, double r) {
    Node n = rp.getNode(nIdx);
    int maxPhy = getSourceResource().getCapacity(n);
    int maxVirt = (int) (maxPhy * r);
    if (maxVirt != 0) {
        csp.post(new RoundedUpDivision(phyRcUsage.get(nIdx), virtRcUsage.get(nIdx), r));
        return true;
    }
    try {
        phyRcUsage.get(nIdx).instantiateTo(0, Cause.Null);
    } catch (ContradictionException ex) {
        rp.getLogger().error("Unable to restrict the physical '" + getResourceIdentifier() + "' capacity of " + n + " to " + maxPhy, ex);
        return false;
    }
    return true;
}
Also used : RoundedUpDivision(org.btrplace.scheduler.choco.extensions.RoundedUpDivision) ContradictionException(org.chocosolver.solver.exception.ContradictionException) Node(org.btrplace.model.Node) SatConstraint(org.btrplace.model.constraint.SatConstraint)

Example 8 with ContradictionException

use of org.chocosolver.solver.exception.ContradictionException in project scheduler by btrplace.

the class CBan method inject.

@Override
public boolean inject(Parameters ps, ReconfigurationProblem rp) {
    if (ban.isContinuous()) {
        for (VM vm : ban.getInvolvedVMs()) {
            if (ban.getInvolvedNodes().contains(rp.getSourceModel().getMapping().getVMLocation(vm))) {
                rp.getLogger().error("Constraint {} is not satisfied initially", ban);
                return false;
            }
        }
    }
    Collection<Node> nodes = ban.getInvolvedNodes();
    int[] nodesIdx = new int[nodes.size()];
    int i = 0;
    for (Node n : ban.getInvolvedNodes()) {
        nodesIdx[i++] = rp.getNode(n);
    }
    VM vm = ban.getInvolvedVMs().iterator().next();
    Slice t = rp.getVMAction(vm).getDSlice();
    if (t != null) {
        for (int x : nodesIdx) {
            try {
                t.getHoster().removeValue(x, Cause.Null);
            } catch (ContradictionException e) {
                rp.getLogger().error("Unable to disallow " + vm + " to be running on " + rp.getNode(x), e);
                return false;
            }
        }
    }
    return true;
}
Also used : Slice(org.btrplace.scheduler.choco.Slice) ContradictionException(org.chocosolver.solver.exception.ContradictionException) VM(org.btrplace.model.VM) Node(org.btrplace.model.Node)

Example 9 with ContradictionException

use of org.chocosolver.solver.exception.ContradictionException 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)

Example 10 with ContradictionException

use of org.chocosolver.solver.exception.ContradictionException in project scheduler by btrplace.

the class COnline method inject.

@Override
public boolean inject(Parameters ps, ReconfigurationProblem rp) throws SchedulerException {
    if (cstr.isContinuous() && !cstr.getChecker().startsWith(rp.getSourceModel())) {
        rp.getLogger().error("Constraint {} is not satisfied initially", cstr);
        return false;
    }
    Node nId = cstr.getInvolvedNodes().iterator().next();
    NodeTransition m = rp.getNodeAction(nId);
    try {
        m.getState().instantiateTo(1, Cause.Null);
        if (rp.getSourceModel().getMapping().isOnline(nId)) {
            m.getStart().instantiateTo(0, Cause.Null);
        }
    } catch (ContradictionException ex) {
        rp.getLogger().error("Unable to force node '" + nId + "' at being online", ex);
        return false;
    }
    return true;
}
Also used : ContradictionException(org.chocosolver.solver.exception.ContradictionException) Node(org.btrplace.model.Node) NodeTransition(org.btrplace.scheduler.choco.transition.NodeTransition)

Aggregations

ContradictionException (org.chocosolver.solver.exception.ContradictionException)11 Node (org.btrplace.model.Node)9 VM (org.btrplace.model.VM)6 Slice (org.btrplace.scheduler.choco.Slice)4 VMTransition (org.btrplace.scheduler.choco.transition.VMTransition)4 SatConstraint (org.btrplace.model.constraint.SatConstraint)3 IntVar (org.chocosolver.solver.variables.IntVar)3 NodeTransition (org.btrplace.scheduler.choco.transition.NodeTransition)2 RelocatableVM (org.btrplace.scheduler.choco.transition.RelocatableVM)2 HashSet (java.util.HashSet)1 Attributes (org.btrplace.model.Attributes)1 Mapping (org.btrplace.model.Mapping)1 Model (org.btrplace.model.Model)1 Killed (org.btrplace.model.constraint.Killed)1 Ready (org.btrplace.model.constraint.Ready)1 Running (org.btrplace.model.constraint.Running)1 Sleeping (org.btrplace.model.constraint.Sleeping)1 SchedulerModelingException (org.btrplace.scheduler.SchedulerModelingException)1 DefaultReconfigurationProblemBuilder (org.btrplace.scheduler.choco.DefaultReconfigurationProblemBuilder)1 ReconfigurationProblem (org.btrplace.scheduler.choco.ReconfigurationProblem)1