Search in sources :

Example 6 with IntegerVariable

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

the class ChocoWrapper method initialization.

/*
	 * Initialize the warpper.
	 */
public static void initialization() {
    m = new CPModel();
    s = new CPSolver();
    stack = new Stack<Constraint>();
    varMap = new HashMap<String, IntegerVariable>();
    solved = false;
}
Also used : CPSolver(choco.cp.solver.CPSolver) IntegerVariable(choco.kernel.model.variables.integer.IntegerVariable) Constraint(choco.kernel.model.constraints.Constraint) CPModel(choco.cp.model.CPModel)

Example 7 with IntegerVariable

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

the class ChocoSolver method addIntVar.

/**
 * add int variable
 *
 * @param name
 *            - name of the variable to be added
 * @param from
 *            - lowerlimit of the domain of the variable
 * @param to
 *            - upper limit of the domain of the variable
 */
public void addIntVar(String name, int from, int to) {
    IntegerVariable v = Choco.makeIntVar(name, from, to);
    // addConstraint(Choco.geq(v,from)); // needed to include the variable
    // in the constraints to be solved.
    vars.put(name, v);
    defaultvals.put(name, from);
    if (absmodel.debug)
        absmodel.println("  adding Int var '" + name + "' (default -> " + from + ")");
    // needed to include the variable in the constraints
    cpmodel.addVariable(v);
// to be solved.
}
Also used : IntegerVariable(choco.kernel.model.variables.integer.IntegerVariable)

Example 8 with IntegerVariable

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

the class ChocoSolver method forceTrue.

/**
 * set a bool variable to true *
 */
public void forceTrue(String name) {
    IntegerVariable v = Choco.makeIntVar(name, 1, 1);
    vars.put(name, v);
    defaultvals.put(name, 1);
    cpmodel.addVariable(v);
}
Also used : IntegerVariable(choco.kernel.model.variables.integer.IntegerVariable)

Example 9 with IntegerVariable

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

the class ChocoSolver method getSolution.

public Map<String, Integer> getSolution() {
    if (!solved)
        solve();
    HashMap<String, Integer> result = new HashMap<>();
    Iterator<IntegerVariable> it = cpmodel.getIntVarIterator();
    while (it.hasNext()) {
        IntegerVariable var = it.next();
        result.put(var.getName(), solver.getVar(var).getVal());
    }
    return result;
}
Also used : IntegerVariable(choco.kernel.model.variables.integer.IntegerVariable) HashMap(java.util.HashMap)

Example 10 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)

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