use of org.chocosolver.solver.constraints.Constraint in project scheduler by btrplace.
the class VectorPackingTest method modelPack.
public void modelPack(int[][] capa, int[][] height) {
int nRes = capa.length;
assert nRes == height.length;
int nBins = capa[0].length;
int nItems = height[0].length;
s = new Model();
loads = new IntVar[nRes][nBins];
bins = new IntVar[nItems];
String[] name = new String[nRes];
for (int d = 0; d < nRes; d++) {
name[d] = "d" + d;
for (int i = 0; i < nBins; i++) {
loads[d][i] = s.intVar("l" + d + "." + i, 0, capa[d][i], true);
}
}
sizes = height;
bins = s.intVarArray("b", nItems, 0, nBins, false);
Constraint cPack = new VectorPacking(name, loads, sizes, bins);
s.post(cPack);
}
use of org.chocosolver.solver.constraints.Constraint in project scheduler by btrplace.
the class CAmong method restrictGroup.
private boolean restrictGroup(Parameters ps, ReconfigurationProblem rp, Set<VM> running, List<Collection<Node>> groups, int selected) {
if (selected == -1) {
// Now, we create a variable to indicate on which group of nodes the VMs will be
vmGrpId = rp.getModel().intVar(rp.makeVarLabel(GROUP_LABEL), 0, groups.size() - 1, false);
// grp: A table to indicate the group each node belong to, -1 for no group
int[] grp = new int[rp.getNodes().size()];
for (int i = 0; i < grp.length; i++) {
Node n = rp.getNode(i);
int idx = getGroup(n, groups);
if (idx >= 0) {
grp[i] = idx;
} else {
grp[i] = -1;
}
}
// We link the VM placement variable with the group variable
for (VM vm : running) {
IntVar assign = rp.getVMAction(vm).getDSlice().getHoster();
Constraint c = rp.getModel().element(vmGrpId, grp, assign, 0);
rp.getModel().post(c);
}
} else {
// As the group is already known, it's now just a fence constraint
vmGrpId = rp.fixed(selected, GROUP_LABEL);
if (!fence(ps, rp, running, groups.get(selected))) {
return false;
}
}
return true;
}
use of org.chocosolver.solver.constraints.Constraint in project scheduler by btrplace.
the class CNoDelay method inject.
@Override
public boolean inject(Parameters ps, ReconfigurationProblem rp) {
VM v = noDelay.getInvolvedVMs().iterator().next();
// For each vm involved in the constraint
VMTransition vt = rp.getVMAction(v);
// Get the VMTransition start time
// Add the constraint "start = 0" to the solver
Slice d = vt.getDSlice();
if (d == null) {
return true;
}
if (!(vt instanceof RelocatableVM)) {
try {
d.getStart().instantiateTo(0, Cause.Null);
} catch (ContradictionException ex) {
rp.getLogger().error("Unable to prevent any delay on '" + v + "'", ex);
return false;
}
} else {
Constraint c = rp.getModel().arithm(d.getStart(), "=", 0);
BoolVar move = ((RelocatableVM) vt).isStaying().not();
ChocoUtils.postImplies(rp, move, c);
}
return true;
}
Aggregations