/** * Set all variables to their respective value in the solution Throws an exception is this empties * a domain (i.e. this domain does not contain the solution value) * * <p>BEWARE: A restart might be required so that domains contain the solution values */ public void restore(Solver solver) throws ContradictionException { if (empty) { throw new UnsupportedOperationException("Empty solution. No solution found"); } Variable[] vars = solver.getVars(); for (int i = 0; i < vars.length; i++) { if ((vars[i].getTypeAndKind() & Variable.TYPE) != Variable.CSTE) { int kind = vars[i].getTypeAndKind() & Variable.KIND; switch (kind) { case Variable.INT: case Variable.BOOL: IntVar v = (IntVar) vars[i]; int value = intmap.get(v.getId()); if (value != NO_ENTRY) { v.instantiateTo(value, this); } // otherwise, this is not a decision variable break; case Variable.REAL: RealVar r = (RealVar) vars[i]; double[] bounds = realmap.get(r.getId()); if (bounds != null) { r.updateBounds(bounds[0], bounds[1], this); } // otherwise, this is not a decision variable break; case Variable.SET: SetVar s = (SetVar) vars[i]; int[] values = setmap.get(s.getId()); if (values != null) { s.instantiateTo(values, Cause.Null); } // otherwise, this is not a decision variable break; } } } }