Search in sources :

Example 16 with IntegerVariable

use of choco.kernel.model.variables.integer.IntegerVariable in project abstools by abstools.

the class ChocoSolver method addIntVar.

public void addIntVar(String name, int[] vals) {
    IntegerVariable v = Choco.makeIntVar(name, vals);
    vars.put(name, v);
    // vals has at least 1 element! (by the
    defaultvals.put(name, vals[0]);
    // parser constraints)
    if (absmodel.debug)
        absmodel.println("  adding Int var '" + name + "' (default -> " + vals[0] + ")");
    // needed to include the variable in the constraints
    cpmodel.addVariable(v);
// to be solved.
}
Also used : IntegerVariable(choco.kernel.model.variables.integer.IntegerVariable)

Example 17 with IntegerVariable

use of choco.kernel.model.variables.integer.IntegerVariable in project abstools by abstools.

the class ChocoSolver method getSolutions.

/*
     * Return ALL solutions of the feature model
     */
public Set<Map<String, Integer>> getSolutions() {
    Set<Map<String, Integer>> solutions = new HashSet<>();
    // int i=0;
    while (solveAgain()) {
        Map<String, Integer> sol = new HashMap<>();
        Iterator<IntegerVariable> it = cpmodel.getIntVarIterator();
        while (it.hasNext()) {
            IntegerVariable var = it.next();
            sol.put(var.getName(), solver.getVar(var).getVal());
        }
        // System.out.println(i++ + " sol: " + sol);
        solutions.add(sol);
    }
    return solutions;
}
Also used : IntegerVariable(choco.kernel.model.variables.integer.IntegerVariable) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 18 with IntegerVariable

use of choco.kernel.model.variables.integer.IntegerVariable in project abstools by abstools.

the class ChocoSolver method addIntVar.

public void addIntVar(String name, int fromto, boolean from) {
    IntegerVariable v = Choco.makeIntVar(name);
    if (from)
        addConstraint(Choco.geq(v, fromto));
    else
        addConstraint(Choco.leq(v, fromto));
    vars.put(name, v);
    defaultvals.put(name, fromto);
    if (absmodel.debug)
        absmodel.println("  adding Int var '" + name + "' (default -> " + fromto + ")");
// m.addVariable(v); // not needed, since v is used in the constraints
}
Also used : IntegerVariable(choco.kernel.model.variables.integer.IntegerVariable)

Example 19 with IntegerVariable

use of choco.kernel.model.variables.integer.IntegerVariable in project abstools by abstools.

the class ChocoSolver method addIntVar.

public void addIntVar(String name) {
    IntegerVariable v = Choco.makeIntVar(name);
    vars.put(name, v);
    defaultvals.put(name, 0);
    if (absmodel.debug)
        absmodel.println("  adding Int var '" + name + "' (default -> 0)");
// m.addVariable(v); // not needed - if variable is not constrained in
// any way, it should not be considered when solving.
}
Also used : IntegerVariable(choco.kernel.model.variables.integer.IntegerVariable)

Example 20 with IntegerVariable

use of choco.kernel.model.variables.integer.IntegerVariable in project Malai by arnobl.

the class ChocoWrapper method pushVariable.

/*
	 * Add the variable at the top of the stack
	 */
public static void pushVariable(String var) {
    IntegerVariable theVar = varMap.get(var);
    if (theVar == null) {
        theVar = Choco.makeIntVar(var, 0, 1);
        varMap.put(var, theVar);
    }
    // FIXME:find a better way
    Constraint res = Choco.or(theVar, theVar);
    stack.push(res);
}
Also used : IntegerVariable(choco.kernel.model.variables.integer.IntegerVariable) Constraint(choco.kernel.model.constraints.Constraint)

Aggregations

IntegerVariable (choco.kernel.model.variables.integer.IntegerVariable)26 Constraint (choco.kernel.model.constraints.Constraint)8 CPModel (choco.cp.model.CPModel)7 CPSolver (choco.cp.solver.CPSolver)7 HashMap (java.util.HashMap)6 ComponentConstraint (choco.kernel.model.constraints.ComponentConstraint)4 MetaConstraint (choco.kernel.model.constraints.MetaConstraint)4 HashSet (java.util.HashSet)4 Map (java.util.Map)4 ContradictionException (choco.kernel.solver.ContradictionException)2 ArrayList (java.util.ArrayList)2