use of org.btrplace.scheduler.choco.transition.VMTransition in project scheduler by btrplace.
the class CSpread method inject.
@Override
public boolean inject(Parameters ps, ReconfigurationProblem rp) {
if (cstr.isContinuous()) {
Set<Node> usedNodes = new HashSet<>();
for (VM vm : cstr.getInvolvedVMs()) {
Node node = rp.getSourceModel().getMapping().getVMLocation(vm);
if (node != null && !usedNodes.add(node)) {
rp.getLogger().error("Constraint {} is not satisfied initially", cstr);
// System.out.println(rp.getSourceModel().getMapping());
return false;
}
}
}
List<IntVar> running = placementVariables(rp);
Model csp = rp.getModel();
if (running.isEmpty()) {
return true;
}
// The lazy spread implementation for the placement
csp.post(csp.allDifferent(running.toArray(new IntVar[running.size()]), "AC"));
if (cstr.isContinuous()) {
List<VM> vms = new ArrayList<>(cstr.getInvolvedVMs());
for (int i = 0; i < vms.size(); i++) {
VM vm = vms.get(i);
VMTransition aI = rp.getVMAction(vm);
for (int j = 0; j < i; j++) {
VM vmJ = vms.get(j);
VMTransition aJ = rp.getVMAction(vmJ);
disallowOverlap(rp, aI, aJ);
}
}
}
return true;
}
use of org.btrplace.scheduler.choco.transition.VMTransition in project scheduler by btrplace.
the class CSpread method placementVariables.
private List<IntVar> placementVariables(ReconfigurationProblem rp) {
List<IntVar> running = new ArrayList<>();
for (VM vmId : cstr.getInvolvedVMs()) {
if (rp.getFutureRunningVMs().contains(vmId)) {
VMTransition a = rp.getVMAction(vmId);
Slice d = a.getDSlice();
if (d != null) {
running.add(d.getHoster());
}
}
}
return running;
}
use of org.btrplace.scheduler.choco.transition.VMTransition in project scheduler by btrplace.
the class CMinMTTRMig method injectSchedulingHeuristic.
/**
* Inject a specific scheduling heuristic to the solver.
*
* @param cost the global cost variable.
*/
private void injectSchedulingHeuristic(IntVar cost) {
// Init a list of strategies
List<AbstractStrategy<?>> strategies = new ArrayList<>();
// Init a list of vars
List<IntVar> endVars = new ArrayList<>();
// Boot nodes
for (Node n : rp.getNodes()) {
if (rp.getNodeAction(n) instanceof BootableNode) {
endVars.add(rp.getNodeAction(n).getEnd());
}
}
if (!endVars.isEmpty()) {
strategies.add(Search.intVarSearch(new FirstFail(rp.getModel()), new IntDomainMin(), // Split from max
DecisionOperatorFactory.makeIntSplit(), endVars.toArray(new IntVar[endVars.size()])));
}
endVars.clear();
// Migrate VMs
MovementGraph gr = new MovementGraph(rp);
OnStableNodeFirst schedHeuristic = new OnStableNodeFirst(rp);
Stream<Slice> s = rp.getVMActions().stream().map(VMTransition::getDSlice).filter(Objects::nonNull);
IntVar[] starts = s.map(Slice::getStart).toArray(IntVar[]::new);
strategies.add(new IntStrategy(starts, new StartOnLeafNodes(rp, gr), new IntDomainMin()));
strategies.add(new IntStrategy(schedHeuristic.getScope(), schedHeuristic, new IntDomainMin()));
// Add remaining VMs actions
for (VMTransition a : rp.getVMActions()) {
endVars.add(a.getEnd());
}
if (!endVars.isEmpty()) {
strategies.add(Search.intVarSearch(new FirstFail(rp.getModel()), new IntDomainMin(), // Split from max
DecisionOperatorFactory.makeIntSplit(), endVars.toArray(new IntVar[endVars.size()])));
}
endVars.clear();
// Shutdown nodes
for (Node n : rp.getNodes()) {
if (rp.getNodeAction(n) instanceof ShutdownableNode) {
endVars.add(rp.getNodeAction(n).getEnd());
}
}
if (!endVars.isEmpty()) {
strategies.add(Search.intVarSearch(new FirstFail(rp.getModel()), new IntDomainMin(), DecisionOperatorFactory.makeIntSplit(), endVars.toArray(new IntVar[endVars.size()])));
}
// Set the strategies in the correct order (as added before)
strategies.add(new IntStrategy(new IntVar[] { rp.getEnd(), cost }, new MyInputOrder<>(rp.getSolver(), this), new IntDomainMin()));
// Add all defined strategies
rp.getSolver().setSearch(new StrategiesSequencer(rp.getModel().getEnvironment(), strategies.toArray(new AbstractStrategy[strategies.size()])));
}
use of org.btrplace.scheduler.choco.transition.VMTransition in project scheduler by btrplace.
the class CMinMigrations method placeVMs.
/*
* Try to place the VMs associated on the actions in a random node while trying first to stay on the current node
*/
private void placeVMs(Parameters ps, List<AbstractStrategy<?>> strategies, List<VMTransition> actions, OnStableNodeFirst schedHeuristic, Map<IntVar, VM> map) {
IntValueSelector rnd = new WorstFit(map, rp, new BiggestDimension());
if (!useResources) {
rnd = new RandomVMPlacement(rp, map, true, ps.getRandomSeed());
}
IntVar[] hosts = dSlices(actions).map(Slice::getHoster).filter(v -> !v.isInstantiated()).toArray(IntVar[]::new);
if (hosts.length > 0) {
strategies.add(new IntStrategy(hosts, new HostingVariableSelector(rp.getModel(), schedHeuristic), rnd));
}
}
use of org.btrplace.scheduler.choco.transition.VMTransition in project scheduler by btrplace.
the class CSerialize method inject.
@Override
public boolean inject(Parameters ps, ReconfigurationProblem rp) throws SchedulerException {
// Get the solver
Model csp = rp.getModel();
// Not enough VMs
if (ser.getInvolvedVMs().size() < 2) {
return true;
}
// Get all migrations involved
for (VM vm : ser.getInvolvedVMs()) {
VMTransition vt = rp.getVMAction(vm);
if (vt instanceof RelocatableVM) {
migrationList.add((RelocatableVM) vt);
}
}
// Not enough migrations
if (migrationList.size() < 2) {
return true;
}
// Using a cumulative
List<Task> tasks = new ArrayList<>();
for (RelocatableVM mig : migrationList) {
tasks.add(new Task(mig.getStart(), mig.getDuration(), mig.getEnd()));
}
IntVar[] heights = new IntVar[tasks.size()];
Arrays.fill(heights, csp.intVar(1));
csp.post(csp.cumulative(tasks.toArray(new Task[tasks.size()]), heights, csp.intVar(1), true));
return true;
}
Aggregations