Hi, I'm new to linear programming using or-tools. I have x numbers of variables which can be both negative and positive but need to adds up to 0 in both vertically and horizontally.
I'm looking at using CP-SAT Solver in Java to do this with the codes as below. How do I get the maximize positives and minimize negatives? Do I need to model.maximize or model.minimize few or all of the variables or call the solver.bestObjectiveBound()?
a1 = 100, b1 = -100
a2 = -125, b2 = 150
a3 = 200, b3 = -100, c3 = 50
a4 = 50, b4 = -100, c4 = -25
//create variables
IntVar a1 = model.newIntVar(0, 100, "a1");
IntVar a2 = model.newIntVar(-125, 0, "a2");
...
//create constraints
model.addEquality(LinearExpr.newBuilder().add(a1).add(a2).add(a3).add(a4), 0);
model.addEquality(LinearExpr.newBuilder().add(b1).add(b2).add(b3).add(b4), 0);
model.addEquality(LinearExpr.newBuilder().add(c3).add(c4), 0);
model.addEquality(LinearExpr.newBuilder().add(a1).add(b1), 0);
model.addEquality(LinearExpr.newBuilder().add(a2).add(b2), 0);
model.addEquality(LinearExpr.newBuilder().add(a3).add(b3).add(c3), 0);
model.addEquality(LinearExpr.newBuilder().add(a4).add(b4).add(c4), 0);
//model.minimize(b2);
CpSolver solver = new CpSolver();
CpSolverStatus status = solver.solve(model);
...