use of org.chocosolver.solver.search.loop.monitors.IMonitorSolution 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.search.loop.monitors.IMonitorSolution in project scheduler by btrplace.
the class RelocatableVMTest method testWorthyReInstantiation.
/**
* The re-instantiation is possible and worthy.
*
* @throws org.btrplace.scheduler.SchedulerException
* @throws ContradictionException
*/
@Test
public void testWorthyReInstantiation() throws SchedulerException, ContradictionException {
Model mo = new DefaultModel();
Mapping map = mo.getMapping();
Node n1 = mo.newNode();
Node n2 = mo.newNode();
VM vm10 = mo.newVM();
map.addOnlineNode(n1);
map.addOnlineNode(n2);
// Not using vm1 because intPool starts at 0 so their will be multiple (0,1) VMs.
map.addRunningVM(vm10, n1);
Parameters ps = new DefaultParameters();
DurationEvaluators dev = ps.getDurationEvaluators();
dev.register(org.btrplace.plan.event.MigrateVM.class, new ConstantActionDuration<>(20));
dev.register(org.btrplace.plan.event.ForgeVM.class, new ConstantActionDuration<>(3));
dev.register(org.btrplace.plan.event.BootVM.class, new ConstantActionDuration<>(2));
dev.register(org.btrplace.plan.event.ShutdownVM.class, new ConstantActionDuration<>(1));
mo.getAttributes().put(vm10, "template", "small");
mo.getAttributes().put(vm10, "clone", true);
ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setNextVMsStates(Collections.emptySet(), map.getAllVMs(), Collections.emptySet(), Collections.emptySet()).setParams(ps).setManageableVMs(map.getAllVMs()).build();
RelocatableVM am = (RelocatableVM) rp.getVMAction(vm10);
am.getDSlice().getHoster().instantiateTo(rp.getNode(n2), Cause.Null);
Solution sol = new Solution(rp.getModel());
sol.record();
rp.getSolver().plugMonitor((IMonitorSolution) () -> {
sol.record();
});
new CMinMTTR().inject(ps, rp);
ReconfigurationPlan p = rp.solve(10, true);
Assert.assertNotNull(p);
Assert.assertEquals(sol.getIntVal(am.getRelocationMethod()), 1);
Assert.assertEquals(p.getSize(), 3);
Model res = p.getResult();
// Check the VM has been relocated
Assert.assertEquals(res.getMapping().getRunningVMs(n1).size(), 0);
Assert.assertEquals(res.getMapping().getRunningVMs(n2).size(), 1);
Assert.assertNotNull(p);
for (Action a : p) {
Assert.assertTrue(a.getStart() >= 0, a.toString());
Assert.assertTrue(a.getEnd() >= a.getStart(), a.toString());
}
}
use of org.chocosolver.solver.search.loop.monitors.IMonitorSolution in project scheduler by btrplace.
the class DefaultReconfigurationProblem method solve.
@Override
public ReconfigurationPlan solve(int timeLimit, boolean optimize) throws SchedulerException {
// Check for multiple destination state
if (!distinctVMStates()) {
return null;
}
if (!optimize) {
solvingPolicy = ResolutionPolicy.SATISFACTION;
}
linkCardinalityWithSlices();
addContinuousResourceCapacities();
getView(Packing.VIEW_ID).beforeSolve(this);
getView(Cumulatives.VIEW_ID).beforeSolve(this);
getView(AliasedCumulatives.VIEW_ID).beforeSolve(this);
// Set the timeout
if (timeLimit > 0) {
solver.limitTime(timeLimit * 1000L);
}
// getLogger().debug("{} constraints; {} integers", csp.getNbCstrs(), csp.getNbIntVar(true));
if (solver.getSearch() == null) {
defaultHeuristic();
}
solver.plugMonitor((IMonitorSolution) () -> {
Solution s = new Solution(csp);
s.record();
solutions.add(s);
});
if (solvingPolicy == ResolutionPolicy.SATISFACTION) {
solver.findSolution();
} else {
solver.findOptimalSolution(objective, solvingPolicy.equals(ResolutionPolicy.MAXIMIZE));
}
if (solver.isFeasible() == ESat.UNDEFINED) {
// We don't know if the CSP has a solution
throw new UnstatableProblemException(model, timeLimit);
}
return makeResultingPlan();
}
Aggregations