use of org.chocosolver.solver.variables.IntVar in project narchy by automenta.
the class AllIntervalSeries method buildModel.
@Override
public void buildModel() {
vars = VariableFactory.enumeratedArray("v", m, 0, m - 1, solver);
dist = new IntVar[m - 1];
if (!use_views) {
dist = VariableFactory.enumeratedArray("dist", m - 1, 1, m - 1, solver);
for (int i = 0; i < m - 1; i++) {
solver.post(IntConstraintFactory.distance(vars[i + 1], vars[i], "=", dist[i]));
}
} else {
for (int i = 0; i < m - 1; i++) {
IntVar k = VariableFactory.bounded(StringUtils.randomName(), -20000, 20000, solver);
solver.post(IntConstraintFactory.sum(new IntVar[] { vars[i], k }, vars[i + 1]));
dist[i] = VariableFactory.abs(k);
solver.post(IntConstraintFactory.member(dist[i], 1, m - 1));
}
}
ALLDIFF = new Constraint[2];
ALLDIFF[0] = (IntConstraintFactory.alldifferent(vars, "BC"));
ALLDIFF[1] = (IntConstraintFactory.alldifferent(dist, "BC"));
solver.post(ALLDIFF);
// break symetries
OTHERS = new Constraint[2];
OTHERS[0] = (IntConstraintFactory.arithm(vars[1], ">", vars[0]));
OTHERS[1] = (IntConstraintFactory.arithm(dist[0], ">", dist[m - 2]));
solver.post(OTHERS);
}
use of org.chocosolver.solver.variables.IntVar in project narchy by automenta.
the class AirPlaneLanding method solve.
@Override
public void solve() {
IntVar[] ivars = solver.retrieveIntVars();
// LNSFactory.pglns(solver, ivars, 30, 10, 200, 0, new FailCounter(100));
solver.plugMonitor(new GUI(solver));
// because PGLNS is not complete (due to Fast Restarts), we add a time limit
SMF.limitTime(solver, "55s");
// SMF.log(solver, true, true);
solver.findOptimalSolution(ResolutionPolicy.MINIMIZE, objective);
}
use of org.chocosolver.solver.variables.IntVar 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.IntVar in project scheduler by btrplace.
the class CMinMTTRMig method inject.
@Override
public boolean inject(Parameters ps, ReconfigurationProblem rp) throws SchedulerException {
this.rp = rp;
List<IntVar> endVars = new ArrayList<>();
// Define the cost constraint: sum of all actions' end time
for (VMTransition m : rp.getVMActions()) {
endVars.add(m.getEnd());
}
for (NodeTransition m : rp.getNodeActions()) {
endVars.add(m.getEnd());
}
IntVar[] costs = endVars.toArray(new IntVar[endVars.size()]);
IntVar cost = rp.getModel().intVar(rp.makeVarLabel("costEndVars"), 0, Integer.MAX_VALUE / 100, true);
costConstraints.add(rp.getModel().sum(costs, "=", cost));
// Set the objective, minimize the cost
rp.setObjective(true, cost);
// Inject the scheduling heuristic
injectSchedulingHeuristic(cost);
// Post the cost constraint
postCostConstraints();
return true;
}
use of org.chocosolver.solver.variables.IntVar in project scheduler by btrplace.
the class CMinMigrations method postCostConstraints.
@Override
public void postCostConstraints() {
if (!costActivated) {
costActivated = true;
rp.getLogger().debug("Post the cost-oriented constraints");
List<IntVar> stays = new ArrayList<>();
for (VMTransition t : rp.getVMActions()) {
if (t instanceof RelocatableVM && rp.getManageableVMs().contains(t.getVM())) {
stays.add(t.getDuration());
}
}
// With choco 4.0.1, we cannot post a simple sum() constraint due to hardcore
// simplification it made. So we bypass the optimisation phase and post the propagator
rp.getModel().post(rp.getModel().sum(stays.toArray(new IntVar[0]), "=", cost));
/*stays.add(cost);
Propagator<IntVar> p =
new PropSum(stays.toArray(new IntVar[0]), stays.size() - 1, Operator.EQ, 0);
rp.getModel().post(new org.chocosolver.solver.constraints.Constraint("sumCost", p));
*/
}
}
Aggregations