@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 boolean inject(ReconfigurationProblem rp) { Collection<Node> nodes = constraint.getInvolvedNodes(); Solver solver = rp.getSolver(); PowerView pvServers = (PowerView) rp.getSourceModel().getView(F4GConfigurationAdapter.VIEW_POWER_IDLES); PowerView pvVMs = (PowerView) rp.getSourceModel().getView(F4GConfigurationAdapter.VIEW_POWER_PER_VM); for (Node node : nodes) { IntVar powerIdle = VariableFactory.fixed(pvServers.getPower(node), solver); IntVar powerperVM = VariableFactory.fixed(pvVMs.getPower(node), solver); IntVar powerVMS = VariableFactory.bounded("powerVMS", 0, Integer.MAX_VALUE / 100, solver); IntConstraintFactory.times(rp.getNbRunningVMs()[rp.getNode(node)], powerperVM, powerVMS); solver.post( IntConstraintFactory.arithm( powerVMS, "+", powerIdle, "<=", constraint.getMaxServerPower())); } return true; }