use of org.btrplace.scheduler.choco.Slice in project scheduler by btrplace.
the class AbstractCumulatives method inject.
@Override
public boolean inject(Parameters ps, ReconfigurationProblem rp) throws SchedulerException {
cUsages = new ArrayList<>();
dUsages = new ArrayList<>();
List<Slice> dS = new ArrayList<>();
List<Slice> cS = new ArrayList<>();
non = new IntObjectMap<>(null, rp.getVMActions().size());
int dIdx = 0;
int cIdx = 0;
for (VMTransition a : rp.getVMActions()) {
Slice c = a.getCSlice();
Slice d = a.getDSlice();
if (d != null && c != null) {
non.put(a.getVM().id(), new int[] { dIdx, cIdx });
}
if (d != null) {
dS.add(dIdx, d);
dIdx++;
}
if (c != null) {
cS.add(cIdx, c);
cIdx++;
}
}
int i = 0;
cHosts = new IntVar[cS.size()];
cEnds = new IntVar[cS.size()];
for (Slice s : cS) {
cHosts[i] = s.getHoster();
cEnds[i] = s.getEnd();
i++;
}
i = 0;
dStarts = new IntVar[dS.size()];
dHosts = new IntVar[dS.size()];
for (Slice s : dS) {
dHosts[i] = s.getHoster();
dStarts[i] = s.getStart();
i++;
}
associations = makeAssociations();
return true;
}
use of org.btrplace.scheduler.choco.Slice 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.Slice in project scheduler by btrplace.
the class CMinMTTR 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.Slice in project scheduler by btrplace.
the class MovementGraph method make.
public void make() {
incoming.clear();
outgoings.clear();
for (VMTransition a : rp.getVMActions()) {
Slice cSlice = a.getCSlice();
Slice dSlice = a.getDSlice();
if (cSlice != null) {
addOutgoing(cSlice);
}
if (dSlice != null) {
addIncoming(dSlice);
}
}
}
use of org.btrplace.scheduler.choco.Slice in project scheduler by btrplace.
the class CSpread method disallowOverlap.
private static void disallowOverlap(ReconfigurationProblem rp, VMTransition t1, VMTransition t2) {
Slice dI = t1.getDSlice();
Slice cI = t1.getCSlice();
Slice dJ = t2.getDSlice();
Slice cJ = t2.getCSlice();
if (dI != null && cJ != null) {
precedenceIfOverlap(rp, dI, cJ);
}
// The inverse relation
if (dJ != null && cI != null) {
precedenceIfOverlap(rp, dJ, cI);
}
}
Aggregations