use of org.btrplace.scheduler.UnstatableProblemException in project scheduler by btrplace.
the class DefaultReconfigurationProblemTest method testTimeout.
/**
* Test the report of a timeout.
*/
@Test(expectedExceptions = { UnstatableProblemException.class })
public void testTimeout() throws UnstatableProblemException {
Model mo = new DefaultModel();
Mapping map = mo.getMapping();
for (int i = 0; i < 10; i++) {
Node n = mo.newNode();
VM vm = mo.newVM();
map.addOnlineNode(n);
map.addRunningVM(vm, n);
}
Parameters ps = new DefaultParameters();
ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setParams(ps).build();
Solver s = rp.getSolver();
IntVar nbNodes = rp.getModel().intVar("nbNodes", 1, map.getAllNodes().size(), true);
Stream<Slice> dSlices = rp.getVMActions().stream().filter(t -> t.getDSlice() != null).map(VMTransition::getDSlice);
IntVar[] hosters = dSlices.map(Slice::getHoster).toArray(IntVar[]::new);
rp.getModel().post(rp.getModel().atMostNValues(hosters, nbNodes, true));
rp.setObjective(true, nbNodes);
// 1 ms
rp.getSolver().limitTime(1);
// -1 will be ignored as it is a negative value (assumed no timeout)
ReconfigurationPlan plan = rp.solve(-1, true);
Assert.assertNotNull(plan);
Assert.assertEquals(s.getMeasures().getSolutionCount(), 1);
Mapping dst = plan.getResult().getMapping();
Assert.assertEquals(usedNodes(dst), 1);
}
use of org.btrplace.scheduler.UnstatableProblemException 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();
}
use of org.btrplace.scheduler.UnstatableProblemException in project scheduler by btrplace.
the class Bench method solve.
private static void solve(LabelledInstance i, Parameters ps) throws IOException {
ChocoScheduler s = new DefaultChocoScheduler().setParameters(ps);
String status = "OK";
try {
s.solve(i);
} catch (@SuppressWarnings("unused") UnstatableProblemException ex) {
status = "TO";
} catch (@SuppressWarnings("unused") SchedulerException ex) {
status = "FAIL";
}
if (opts.single()) {
out(0, "%s%n", s.getStatistics());
} else {
SolvingStatistics stats = s.getStatistics();
if (stats.getSolutions().isEmpty()) {
status = "KO*";
} else {
status = "OK";
if (stats.completed()) {
status += "*";
}
}
if (opts.verbosity() == 0) {
out(0, "%s: %s%n", i.label, status);
} else {
out(1, "----- %s -----%n", i.label);
out(1, "%s%n", stats);
out(1, "%n");
}
File output = opts.output();
store(i, stats, output);
}
}
Aggregations