use of org.chocosolver.solver.Model in project scheduler by btrplace.
the class RoundedUpDivisionTest method test2.
@Test
public void test2() {
Model s = new Model();
IntVar a = s.intVar("a", 0, 32, true);
IntVar b = s.intVar("b", 0, 48, true);
double q = 1.5;
s.post(new RoundedUpDivision(a, b, q));
Assert.assertEquals(s.getSolver().findAllSolutions().size(), 49);
// Assert.assertEquals(s.getNbSolutions(), 33);
}
use of org.chocosolver.solver.Model 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.Model in project scheduler by btrplace.
the class CLonely method inject.
@Override
public boolean inject(Parameters ps, ReconfigurationProblem rp) {
// Remove non future-running VMs
List<IntVar> myHosts = new ArrayList<>();
List<IntVar> otherHosts = new ArrayList<>();
Collection<VM> vms = new HashSet<>();
Set<VM> otherVMs = new HashSet<>();
for (VM vm : rp.getFutureRunningVMs()) {
IntVar host = rp.getVMAction(vm).getDSlice().getHoster();
if (cstr.getInvolvedVMs().contains(vm)) {
myHosts.add(host);
vms.add(vm);
} else {
otherHosts.add(host);
otherVMs.add(vm);
}
}
// Link the assignment variables with the set
Model s = rp.getModel();
s.post(new Disjoint(myHosts.toArray(new IntVar[myHosts.size()]), otherHosts.toArray(new IntVar[otherHosts.size()]), rp.getNodes().size()));
if (cstr.isContinuous()) {
continuousRestriction(rp, vms, otherVMs);
}
return true;
}
use of org.chocosolver.solver.Model in project scheduler by btrplace.
the class CResourceCapacity method inject.
@Override
public boolean inject(Parameters ps, ReconfigurationProblem rp) throws SchedulerException {
Model csp = rp.getModel();
CShareableResource rcm = (CShareableResource) rp.getView(ShareableResource.VIEW_ID_BASE + cstr.getResource());
if (rcm == null) {
throw new SchedulerModelingException(rp.getSourceModel(), "No resource associated to identifier '" + cstr.getResource() + "'");
}
if (cstr.getInvolvedNodes().size() == 1) {
return injectWithSingleNode(rcm, rp);
}
if (cstr.isContinuous() && !injectContinuous(rp, rcm)) {
return false;
}
List<IntVar> vs = new ArrayList<>();
for (Node u : cstr.getInvolvedNodes()) {
vs.add(rcm.getVirtualUsage().get(rp.getNode(u)));
}
IntVar mySum = csp.intVar(rp.makeVarLabel("usage(", rcm.getIdentifier(), ")"), 0, Integer.MAX_VALUE / 100, true);
csp.post(csp.sum(vs.toArray(new IntVar[vs.size()]), "=", mySum));
csp.post(csp.arithm(mySum, "<=", cstr.getAmount()));
return true;
}
use of org.chocosolver.solver.Model in project scheduler by btrplace.
the class CRunningCapacity method inject.
@Override
public boolean inject(Parameters ps, ReconfigurationProblem rp) throws SchedulerException {
Model csp = rp.getModel();
if (cstr.getInvolvedNodes().size() == 1) {
return filterWithSingleNode(rp);
}
if (cstr.isContinuous() && !injectContinuous(rp)) {
return false;
}
List<IntVar> vs = new ArrayList<>();
for (Node u : cstr.getInvolvedNodes()) {
vs.add(rp.getNbRunningVMs().get(rp.getNode(u)));
}
// Try to get a lower bound
// basically, we count 1 per VM necessarily in the set of nodes
// if involved nodes == all the nodes, then sum == nb of running VMs
IntVar mySum = csp.intVar(rp.makeVarLabel("nbRunning"), 0, rp.getFutureRunningVMs().size(), true);
csp.post(csp.sum(vs.toArray(new IntVar[vs.size()]), "=", mySum));
csp.post(csp.arithm(mySum, "<=", cstr.getAmount()));
if (cstr.getInvolvedNodes().equals(rp.getSourceModel().getMapping().getAllNodes())) {
csp.post(csp.arithm(mySum, "=", rp.getFutureRunningVMs().size()));
}
return true;
}
Aggregations