@Override public boolean inject(ReconfigurationProblem rp) { Solver solver = rp.getSolver(); Collection<Node> nodes = constraint.getInvolvedNodes(); BoolVar[] spareNode = new BoolVar[nodes.size()]; int i = 0; for (Node node : constraint.getInvolvedNodes()) { BoolVar state = rp.getNodeAction(node).getState(); IntVar NbVms = rp.getNbRunningVMs()[rp.getNode(node)]; spareNode[i] = VF.bool(StringUtils.randomName(), solver); // if the server is off (state = false), then it is not free solver.post(new FastImpliesEq(VF.not(state), spareNode[i], 0)); // if the server hosts VMs, then it is not free solver.post(new FastImpliesEq(ICF.arithm(NbVms, "!=", 0).reif(), spareNode[i], 0)); i++; } IntVar spareNodes = VF.bounded("freeNumber", 0, nodes.size(), solver); solver.post(ICF.sum(spareNode, spareNodes)); solver.post(ICF.arithm(spareNodes, ">=", constraint.getMinSpareNodes())); return true; }
@Override public String toString() { return constraint.toString(); }