use of org.chocosolver.solver.variables.IntVar 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.chocosolver.solver.variables.IntVar in project scheduler by btrplace.
the class OnStableNodeFirst method getVariable.
@Override
public IntVar getVariable(IntVar[] scope) {
makeIncoming();
IntVar v = getVMtoLeafNode();
if (v == null) {
last = null;
return null;
}
v = getMovingVM();
if (v != null) {
return v;
}
IntVar early = getEarlyVar();
last = (early != null) ? early : minInf();
return last;
}
use of org.chocosolver.solver.variables.IntVar in project scheduler by btrplace.
the class InstanceSolverRunner method call.
@Override
// for the LifeCycleViolationException
@SuppressWarnings("squid:S1166")
public SolvingStatistics call() throws SchedulerException {
stats = new SingleRunnerStatistics(params, instance, System.currentTimeMillis());
rp = null;
// Build the core problem
long d = -System.currentTimeMillis();
try {
rp = buildRP();
} catch (@SuppressWarnings("unused") LifeCycleViolationException ex) {
// If there is a violation of the cycle it is not a bug that should be propagated
// it it just indicating there is no solution
stats.setCompleted(true);
stats.setMetrics(new Metrics());
return stats;
} finally {
d += System.currentTimeMillis();
stats.setCoreBuildDuration(d);
}
stats.setNbManagedVMs(rp.getManageableVMs().size());
// Customize the core problem
d = -System.currentTimeMillis();
if (!specialise()) {
d += System.currentTimeMillis();
stats.setSpecialisationDuration(d);
stats.setCompleted(true);
return getStatistics();
}
d += System.currentTimeMillis();
stats.setSpecialisationDuration(d);
// statistics
stats.setMetrics(new Metrics(rp.getSolver().getMeasures()));
rp.getLogger().debug(stats.toString());
// The solution monitor to store the measures at each solution
rp.getSolver().plugMonitor((IMonitorSolution) () -> {
Solution solution = new Solution(rp.getModel());
solution.record();
ReconfigurationPlan plan = rp.buildReconfigurationPlan(solution, origin);
views.forEach(v -> v.insertActions(rp, solution, plan));
MeasuresRecorder m = rp.getSolver().getMeasures();
SolutionStatistics st = new SolutionStatistics(new Metrics(m), plan);
IntVar o = rp.getObjective();
if (o != null) {
st.setObjective(solution.getIntVal(o));
}
stats.addSolution(st);
params.solutionListeners().forEach(c -> c.accept(rp, plan));
});
setVerbosity();
// The actual solving process
rp.solve(params.getTimeLimit(), params.doOptimize());
return getStatistics();
}
use of org.chocosolver.solver.variables.IntVar in project scheduler by btrplace.
the class CPowerView method inject.
@Override
public boolean inject(Parameters ps, ReconfigurationProblem rp) throws SchedulerException {
powerStarts = new TIntObjectHashMap<>(rp.getNodes().size());
powerEnds = new TIntObjectHashMap<>(rp.getNodes().size());
for (Node n : rp.getNodes()) {
NodeTransition na = rp.getNodeAction(n);
if (na instanceof ShutdownableNode) {
powerStarts.put(rp.getNode(n), rp.getStart());
IntVar powerEnd = rp.makeUnboundedDuration("NodeActionType(", n, ").Pe");
TaskMonitor.build(na.getHostingEnd(), na.getDuration(), powerEnd);
powerEnds.put(rp.getNode(n), powerEnd);
rp.getModel().post(rp.getModel().arithm(powerEnd, "<=", rp.getEnd()));
} else if (na instanceof BootableNode) {
powerStarts.put(rp.getNode(n), na.getStart());
powerEnds.put(rp.getNode(n), rp.getEnd());
}
}
return true;
}
use of org.chocosolver.solver.variables.IntVar in project scheduler by btrplace.
the class CShareableResource method beforeSolve.
/**
* Set the resource usage for each of the VM.
* If the LB is < 0 , the previous consumption is used to maintain the resource usage.
* Otherwise, the usage is set to the variable lower bound.
*
* @return false if an operation leads to a problem without solution
*/
@Override
public boolean beforeSolve(ReconfigurationProblem p) throws SchedulerException {
for (VM vm : source.getMapping().getAllVMs()) {
int vmId = p.getVM(vm);
int v = getVMAllocation(vmId);
if (v < 0) {
int prevUsage = rc.getConsumption(vm);
minVMAllocation(vmId, prevUsage);
}
}
ChocoView v = rp.getView(Packing.VIEW_ID);
if (v == null) {
throw SchedulerModelingException.missingView(rp.getSourceModel(), Packing.VIEW_ID);
}
IntVar[] host = new IntVar[p.getFutureRunningVMs().size()];
int[] demand = new int[host.length];
int i = 0;
for (VM vm : p.getFutureRunningVMs()) {
host[i] = rp.getVMAction(vm).getDSlice().getHoster();
demand[i] = getVMAllocation(p.getVM(vm));
i++;
}
((Packing) v).addDim(rc.getResourceIdentifier(), virtRcUsage, demand, host);
return linkVirtualToPhysicalUsage();
}
Aggregations