use of org.chocosolver.solver.Model 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.chocosolver.solver.Model 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;
}
use of org.chocosolver.solver.Model in project scheduler by btrplace.
the class ChocoUtils method postImplies.
/**
* Make and post an implies constraint where the first operand is a boolean: b1 -> c2.
* The constraint is translated into (or(not(b1,c2))
*
* @param rp the problem to solve
* @param b1 the first constraint as boolean
* @param c2 the second constraint
*/
public static void postImplies(ReconfigurationProblem rp, BoolVar b1, Constraint c2) {
Model s = rp.getModel();
BoolVar bC2 = s.boolVar(rp.makeVarLabel(c2.toString(), " satisfied"));
c2.reifyWith(bC2);
BoolVar notB1 = b1.not();
s.post(rp.getModel().arithm(b1, "!=", notB1));
s.post(rp.getModel().or(notB1, bC2));
}
use of org.chocosolver.solver.Model in project scheduler by btrplace.
the class ChocoUtils method postIfOnlyIf.
/**
* Make and post a constraint that states and(or(b1, non c2), or(non b1, c2))
*
* @param rp the problem to solve
* @param b1 the first constraint
* @param c2 the second constraint
*/
public static void postIfOnlyIf(ReconfigurationProblem rp, BoolVar b1, Constraint c2) {
Model csp = rp.getModel();
BoolVar notBC1 = b1.not();
BoolVar bC2 = csp.boolVar(rp.makeVarLabel(c2.toString(), " satisfied"));
c2.reifyWith(bC2);
BoolVar notBC2 = bC2.not();
csp.post(rp.getModel().or(rp.getModel().or(b1, bC2), rp.getModel().or(notBC1, notBC2)));
}
use of org.chocosolver.solver.Model in project scheduler by btrplace.
the class DisjointTest method test.
@Test
public void test() {
IntVar[] g1 = new IntVar[3];
IntVar[] g2 = new IntVar[3];
Model s = new Model();
for (int i = 0; i < g1.length; i++) {
g1[i] = s.intVar("G1-" + i, 0, (i + 1), false);
g2[i] = s.intVar("G2-" + i, 0, (i + 1), false);
}
s.post(new Disjoint(g1, g2, 4));
s.post(s.arithm(g2[g2.length - 1], "<=", g1[g1.length - 1]));
s.getSolver().findAllSolutions();
}
Aggregations