/** * Build a {@link solver.variables.Variable} named {@code name}, defined by {@code type}. {@code * type} is expected to be a {@link parser.flatzinc.ast.declaration.DManyInt} object. * * @param name name of the variable * @param type {@link parser.flatzinc.ast.declaration.DManyInt} object. * @param map * @param solver * @return {@link solver.variables.Variable} */ private static IntVar buildWithManyInt( String name, DManyInt type, Expression expression, THashMap<String, Object> map, Solver solver) { final IntVar iv; if (expression != null) { iv = buildOnExpression(DEBUG ? name : NO_NAME, expression, map, solver); int[] values = type.getValues(); solver.post(IntConstraintFactory.member(iv, values)); } else { iv = VariableFactory.enumerated(DEBUG ? name : NO_NAME, type.getValues(), solver); } map.put(name, iv); return iv; }
/** * Build a {@link solver.variables.Variable} named {@code name}, defined by {@code type}. * * @param name name of the variable * @param type {@link parser.flatzinc.ast.declaration.DInt2} object * @param map * @param solver * @return {@link solver.variables.Variable} */ private static IntVar buildWithInt2( String name, DInt2 type, Expression expression, THashMap<String, Object> map, Solver solver) { final IntVar iv; if (expression != null) { iv = buildOnExpression(DEBUG ? name : NO_NAME, expression, map, solver); int lb = type.getLow(); int ub = type.getUpp(); solver.post(IntConstraintFactory.member(iv, lb, ub)); } else { int size = type.getUpp() - type.getLow() + 1; if (size < 256) { iv = VariableFactory.enumerated( DEBUG ? name : NO_NAME, type.getLow(), type.getUpp(), solver); } else { iv = VariableFactory.bounded(DEBUG ? name : NO_NAME, type.getLow(), type.getUpp(), solver); } } map.put(name, iv); return iv; }