use of org.chocosolver.solver.variables.BoolVar in project narchy by automenta.
the class AirPlaneLanding method buildModel.
@Override
public void buildModel() {
data = parse(mData.source());
n = data.length;
planes = new IntVar[n];
tardiness = new IntVar[n];
earliness = new IntVar[n];
LLTs = new int[n];
int obj_ub = 0;
IntVar ZERO = VariableFactory.fixed(0, solver);
for (int i = 0; i < n; i++) {
planes[i] = VariableFactory.bounded("p_" + i, data[i][ELT], data[i][LLT], solver);
// earliness[i] = VariableFactory.bounded("a_" + i, 0, data[i][TT] - data[i][ELT], solver);
// tardiness[i] = VariableFactory.bounded("t_" + i, 0, data[i][LLT] - data[i][TT], solver);
obj_ub += Math.max((data[i][TT] - data[i][ELT]) * data[i][PCBT], (data[i][LLT] - data[i][TT]) * data[i][PCAT]);
earliness[i] = Max.var(ZERO, VariableFactory.offset(VariableFactory.minus(planes[i]), data[i][TT]));
tardiness[i] = Max.var(ZERO, VariableFactory.offset(planes[i], -data[i][TT]));
LLTs[i] = data[i][LLT];
}
List<BoolVar> booleans = new ArrayList<BoolVar>();
// disjunctive
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
BoolVar boolVar = VariableFactory.bool("b_" + i + "_" + j, solver);
booleans.add(boolVar);
Constraint c1 = precedence(planes[i], data[i][ST + j], planes[j]);
Constraint c2 = precedence(planes[j], data[j][ST + i], planes[i]);
LogicalConstraintFactory.ifThenElse(boolVar, c1, c2);
}
}
bVars = booleans.toArray(new BoolVar[booleans.size()]);
objective = VariableFactory.bounded("obj", 0, obj_ub, solver);
// builder cost array
costLAT = new int[2 * n];
maxCost = new TObjectIntHashMap<IntVar>();
for (int i = 0; i < n; i++) {
costLAT[i] = data[i][PCBT];
costLAT[n + i] = data[i][PCAT];
maxCost.put(planes[i], Math.max(data[i][PCBT], data[i][PCAT]));
}
// solver.post(Sum.eq(ArrayUtils.append(earliness, tardiness), costLAT, objective, 1, solver));
IntVar obj_e = VariableFactory.bounded("obj_e", 0, obj_ub, solver);
solver.post(IntConstraintFactory.scalar(earliness, Arrays.copyOfRange(costLAT, 0, n), obj_e));
IntVar obj_t = VariableFactory.bounded("obj_t", 0, obj_ub, solver);
solver.post(IntConstraintFactory.scalar(tardiness, Arrays.copyOfRange(costLAT, n, 2 * n), obj_t));
solver.post(IntConstraintFactory.sum(new IntVar[] { obj_e, obj_t }, objective));
solver.post(IntConstraintFactory.alldifferent(planes, "BC"));
}
use of org.chocosolver.solver.variables.BoolVar in project scheduler by btrplace.
the class ChocoUtils method postIfOnlyIf.
/**
* Make and post a constraint that states and(or(b1, non c2), or(non b1, c2))
*
* @param rp the problem to solve
* @param b1 the first constraint
* @param c2 the second constraint
*/
public static void postIfOnlyIf(ReconfigurationProblem rp, BoolVar b1, Constraint c2) {
Model csp = rp.getModel();
BoolVar notBC1 = b1.not();
BoolVar bC2 = csp.boolVar(rp.makeVarLabel(c2.toString(), " satisfied"));
c2.reifyWith(bC2);
BoolVar notBC2 = bC2.not();
csp.post(rp.getModel().or(rp.getModel().or(b1, bC2), rp.getModel().or(notBC1, notBC2)));
}
use of org.chocosolver.solver.variables.BoolVar in project scheduler by btrplace.
the class ChocoUtils method postImplies.
/**
* Make and post an implies constraint where the first operand is a boolean: b1 -> c2.
* The constraint is translated into (or(not(b1,c2))
*
* @param rp the problem to solve
* @param b1 the first constraint as boolean
* @param c2 the second constraint
*/
public static void postImplies(ReconfigurationProblem rp, BoolVar b1, Constraint c2) {
Model s = rp.getModel();
BoolVar bC2 = s.boolVar(rp.makeVarLabel(c2.toString(), " satisfied"));
c2.reifyWith(bC2);
BoolVar notB1 = b1.not();
s.post(rp.getModel().arithm(b1, "!=", notB1));
s.post(rp.getModel().or(notB1, bC2));
}
use of org.chocosolver.solver.variables.BoolVar in project scheduler by btrplace.
the class FastIFFEqTest method test4.
@Test
public void test4() {
Model csp = new Model();
BoolVar b = csp.boolVar(true);
IntVar x = csp.intVar("x", 0, 2);
int c = 3;
csp.post(new FastIFFEq(b, x, c));
Assert.assertEquals(0, csp.getSolver().findAllSolutions().size());
}
use of org.chocosolver.solver.variables.BoolVar in project scheduler by btrplace.
the class FastIFFEqTest method test5.
@Test
public void test5() {
Model csp = new Model();
BoolVar b = csp.boolVar(true);
IntVar x = csp.intVar("x", 0, 3);
int c = 2;
csp.post(new FastIFFEq(b, x, c));
Assert.assertEquals(1, csp.getSolver().findAllSolutions().size());
}
Aggregations