Search in sources :

Example 1 with ContradictionException

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

the class CShareableResource method capHosting.

/**
 * Reduce the cardinality wrt. the worst case scenario.
 *
 * @param nIdx the node index
 * @param min  the min (but > 0 ) consumption for a VM
 * @param nbZeroes the number of VMs consuming 0
 * @return {@code false} if the problem no longer has a solution
 */
private boolean capHosting(int nIdx, int min, int nbZeroes) {
    Node n = rp.getNode(nIdx);
    double capa = getSourceResource().getCapacity(n) * getOverbookRatio(nIdx);
    int card = (int) (capa / min) + nbZeroes + 1;
    if (card < source.getMapping().getRunningVMs(n).size()) {
        // TODO: revise the notion of continuous constraint for the cardinality issue.
        return true;
    }
    try {
        // Restrict the hosting capacity.
        rp.getNbRunningVMs().get(nIdx).updateUpperBound(card, Cause.Null);
    } catch (ContradictionException ex) {
        rp.getLogger().error("Unable to cap the hosting capacity of '" + n + " ' to " + card, ex);
        return false;
    }
    return true;
}
Also used : ContradictionException(org.chocosolver.solver.exception.ContradictionException) Node(org.btrplace.model.Node) SatConstraint(org.btrplace.model.constraint.SatConstraint)

Example 2 with ContradictionException

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

the class COffline 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();
    int id = rp.getNode(nId);
    NodeTransition m = rp.getNodeAction(nId);
    try {
        m.getState().instantiateTo(0, Cause.Null);
        if (rp.getSourceModel().getMapping().isOffline(nId)) {
            m.getStart().instantiateTo(0, Cause.Null);
        }
    } catch (ContradictionException ex) {
        rp.getLogger().error("Unable to force node '" + nId + "' at being offline", ex);
        return false;
    }
    for (VMTransition am : rp.getVMActions()) {
        Slice s = am.getDSlice();
        if (s != null) {
            try {
                s.getHoster().removeValue(id, Cause.Null);
            } catch (ContradictionException e) {
                rp.getLogger().error("Unable to remove " + am.getVM() + " of node " + nId, e);
            }
        }
    }
    return true;
}
Also used : ContradictionException(org.chocosolver.solver.exception.ContradictionException) Slice(org.btrplace.scheduler.choco.Slice) Node(org.btrplace.model.Node) NodeTransition(org.btrplace.scheduler.choco.transition.NodeTransition) VMTransition(org.btrplace.scheduler.choco.transition.VMTransition)

Example 3 with ContradictionException

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

the class CResourceCapacity method injectWithSingleNode.

private boolean injectWithSingleNode(CShareableResource rcm, ReconfigurationProblem rp) {
    int amount = cstr.getAmount();
    Model csp = rp.getModel();
    Node n = cstr.getInvolvedNodes().iterator().next();
    int nIdx = rp.getNode(n);
    IntVar v = rcm.getVirtualUsage().get(nIdx);
    csp.post(csp.arithm(v, "<=", amount));
    // Continuous in practice ?
    if (cstr.isContinuous()) {
        if (cstr.isSatisfied(rp.getSourceModel())) {
            try {
                v.updateUpperBound(cstr.getAmount(), Cause.Null);
            } catch (ContradictionException e) {
                rp.getLogger().error("Unable to restrict to up to " + cstr.getAmount() + ", the maximum '" + rcm.getResourceIdentifier() + "' usage on " + n, e);
                return false;
            }
        } else {
            rp.getLogger().error("The constraint '{}' must be already satisfied to provide a continuous restriction", cstr);
            return false;
        }
    }
    return true;
}
Also used : ContradictionException(org.chocosolver.solver.exception.ContradictionException) Node(org.btrplace.model.Node) Model(org.chocosolver.solver.Model) IntVar(org.chocosolver.solver.variables.IntVar)

Example 4 with ContradictionException

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

the class CRoot method inject.

@Override
public boolean inject(Parameters ps, ReconfigurationProblem rp) throws SchedulerException {
    VM vm = cstr.getInvolvedVMs().iterator().next();
    VMTransition m = rp.getVMAction(vm);
    Slice cSlice = m.getCSlice();
    Slice dSlice = m.getDSlice();
    if (cSlice != null && dSlice != null) {
        try {
            dSlice.getHoster().instantiateTo(cSlice.getHoster().getValue(), Cause.Null);
        } catch (ContradictionException ex) {
            Node n = rp.getSourceModel().getMapping().getVMLocation(vm);
            rp.getLogger().error("Unable to force '" + vm + "' to be running on node '" + n + "'", ex);
            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) VMTransition(org.btrplace.scheduler.choco.transition.VMTransition)

Example 5 with ContradictionException

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

the class InstanceSolverRunner method buildRP.

private ReconfigurationProblem buildRP() throws SchedulerException {
    // Build the RP. As VM state management is not possible
    // We extract VM-state related constraints first.
    // For other constraint, we just create the right choco constraint
    Set<VM> toRun = new HashSet<>();
    Set<VM> toForge = new HashSet<>();
    Set<VM> toKill = new HashSet<>();
    Set<VM> toSleep = new HashSet<>();
    cConstraints = new ArrayList<>();
    for (SatConstraint cstr : cstrs) {
        checkNodesExistence(origin, cstr.getInvolvedNodes());
        // (when they will be forged)
        if (!(cstrs instanceof Ready)) {
            checkUnknownVMsInMapping(origin, cstr.getInvolvedVMs());
        }
        if (cstr instanceof Running) {
            toRun.addAll(cstr.getInvolvedVMs());
        } else if (cstr instanceof Sleeping) {
            toSleep.addAll(cstr.getInvolvedVMs());
        } else if (cstr instanceof Ready) {
            checkUnknownVMsInMapping(origin, cstr.getInvolvedVMs());
            toForge.addAll(cstr.getInvolvedVMs());
        } else if (cstr instanceof Killed) {
            checkUnknownVMsInMapping(origin, cstr.getInvolvedVMs());
            toKill.addAll(cstr.getInvolvedVMs());
        }
        cConstraints.add(build(cstr));
    }
    cConstraints.add(build(obj));
    views = makeViews();
    DefaultReconfigurationProblemBuilder rpb = new DefaultReconfigurationProblemBuilder(origin).setNextVMsStates(toForge, toRun, toSleep, toKill).setParams(params);
    if (params.doRepair()) {
        Set<VM> toManage = new HashSet<>();
        cConstraints.forEach(c -> toManage.addAll(c.getMisPlacedVMs(instance)));
        views.forEach(v -> toManage.addAll(v.getMisPlacedVMs(instance)));
        rpb.setManageableVMs(toManage);
    }
    // The core views have been instantiated and available through rp.getViews()
    // Set the maximum duration
    ReconfigurationProblem p = rpb.build();
    try {
        p.getEnd().updateUpperBound(params.getMaxEnd(), Cause.Null);
    } catch (ContradictionException e) {
        p.getLogger().error("Unable to restrict the maximum plan duration to " + params.getMaxEnd(), e);
        return null;
    }
    return p;
}
Also used : Ready(org.btrplace.model.constraint.Ready) Sleeping(org.btrplace.model.constraint.Sleeping) ContradictionException(org.chocosolver.solver.exception.ContradictionException) VM(org.btrplace.model.VM) SatConstraint(org.btrplace.model.constraint.SatConstraint) Running(org.btrplace.model.constraint.Running) Killed(org.btrplace.model.constraint.Killed) DefaultReconfigurationProblemBuilder(org.btrplace.scheduler.choco.DefaultReconfigurationProblemBuilder) ReconfigurationProblem(org.btrplace.scheduler.choco.ReconfigurationProblem) HashSet(java.util.HashSet)

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