use of choco.kernel.model.constraints.Constraint in project abstools by abstools.
the class ChocoSolver method optimise.
public boolean optimise(String var, Boolean minimise) {
// add the constraints
if (!solved) {
for (Constraint c : constraints) cpmodel.addConstraint(c);
}
// Impose the feature name to be present
if (var.contains(".")) {
String feat = var.split("\\.")[0];
if (absmodel.debug)
// and its
absmodel.println("## including feature '" + feat + "'");
// parents.");
if (vars.containsKey(feat)) {
if (absmodel.debug)
absmodel.println(" " + feat + " (selected) -> 1");
cpmodel.addConstraint(Choco.eq(vars.get(feat), 1));
// // collect parents of 'newFeatures'
// Set<String> newFeatures = new HashSet<String>();
// Set<String> newParents = new HashSet<String>();
//
// if (model != null) {
// newFeatures.add(feat);
// model.collectParents(newFeatures,newParents);
// }
// // add newParents and default values to the solution
// Iterator<IntegerVariable> it = m.getIntVarIterator();
// while (it.hasNext()) { // for all variables in the
// constraints (model): round 2
// IntegerVariable var2 = it.next();
//
// // If it is a parent to include, set
// if (newParents.contains(var2.getName())) {
// if (ast.debug)
// ast.println(" "+var2+" (parent) -> 1");
// m.addConstraint(Choco.eq(var2, 1));
// }
// }
}
}
// show the problem
if (absmodel.debug) {
absmodel.println("## The constraints:");
// ast.println(m.pretty());
for (Constraint c : constraints) {
if (!c.pretty().startsWith("true"))
absmodel.println(prettyConst(c));
}
absmodel.println("-----");
}
// Read the model
solver.read(cpmodel);
// Minmise the model, if possible
if (vars.containsKey(var))
if (solver.contains(vars.get(var))) {
solved = true;
if (minimise)
newsol = solver.minimize(solver.getVar(vars.get(var)), true);
else
newsol = solver.maximize(solver.getVar(vars.get(var)), true);
return newsol;
}
return false;
}
use of choco.kernel.model.constraints.Constraint in project Malai by arnobl.
the class ChocoWrapper method pushOR.
/*
* Remove the two top elements (elem1 and elem2) from the stack.
* Then add on the top of the stack the "elem1 OR elem2" constraint.
*/
public static void pushOR() {
Constraint elem1 = stack.pop();
Constraint elem2 = stack.pop();
Constraint res = Choco.or(elem1, elem2);
stack.push(res);
}
use of choco.kernel.model.constraints.Constraint in project Malai by arnobl.
the class ChocoWrapper method pushAND.
/*
* Remove the two top elements (elem1 and elem2) from the stack.
* Then add on the top of the stack the "elem1 AND elem2" constraint.
*/
public static void pushAND() {
Constraint elem1 = stack.pop();
Constraint elem2 = stack.pop();
Constraint res = Choco.and(elem1, elem2);
stack.push(res);
}
use of choco.kernel.model.constraints.Constraint 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);
}
use of choco.kernel.model.constraints.Constraint in project abstools by abstools.
the class ChocoSolver method optimise.
public boolean optimise(String var, Boolean minimise) {
// add the constraints
if (!solved) {
for (Constraint c : constraints) cpmodel.addConstraint(c);
}
// Impose the feature name to be present
if (var.contains(".")) {
String feat = var.split("\\.")[0];
if (absmodel.debug)
// and its
absmodel.println("## including feature '" + feat + "'");
// parents.");
if (vars.containsKey(feat)) {
if (absmodel.debug)
absmodel.println(" " + feat + " (selected) -> 1");
cpmodel.addConstraint(Choco.eq(vars.get(feat), 1));
// // collect parents of 'newFeatures'
// Set<String> newFeatures = new HashSet<String>();
// Set<String> newParents = new HashSet<String>();
//
// if (model != null) {
// newFeatures.add(feat);
// model.collectParents(newFeatures,newParents);
// }
// // add newParents and default values to the solution
// Iterator<IntegerVariable> it = m.getIntVarIterator();
// while (it.hasNext()) { // for all variables in the
// constraints (model): round 2
// IntegerVariable var2 = it.next();
//
// // If it is a parent to include, set
// if (newParents.contains(var2.getName())) {
// if (ast.debug)
// ast.println(" "+var2+" (parent) -> 1");
// m.addConstraint(Choco.eq(var2, 1));
// }
// }
}
}
// show the problem
if (absmodel.debug) {
absmodel.println("## The constraints:");
// ast.println(m.pretty());
for (Constraint c : constraints) {
if (!c.pretty().startsWith("true"))
absmodel.println(prettyConst(c));
}
absmodel.println("-----");
}
// Read the model
solver.read(cpmodel);
// Minmise the model, if possible
if (vars.containsKey(var))
if (solver.contains(vars.get(var))) {
solved = true;
if (minimise)
newsol = solver.minimize(solver.getVar(vars.get(var)), true);
else
newsol = solver.maximize(solver.getVar(vars.get(var)), true);
return newsol;
}
return false;
}
Aggregations