I used https://developers.google.com/optimization/cp/cp_solver to try to resovle a constraint programming problem, and I would like to maximize a function, then maximize another.
I tried to call Maximize twice, but it does not seems to work.
Here is a minimal example code :
var solver = new CpSolver();
var model = new CpModel();
IntVar var1 = model.NewIntVar(100, 300, "var1");
IntVar var2 = model.NewIntVar(200, 500, "var2");
IntVar var3 = model.NewIntVar(100, 400, "var3");
model.Add(var1 + var2 + var3 == 1000);
int prio1 = 1;
int prio2 = 2;
int prio3 = 1;
int secondPrio1 = 4;
int secondPrio2 = 1;
int secondPrio3 = 5;
LinearExpression priority = prio1 * var1 + prio2 * var2 + prio3 * var3;
LinearExpression secondPriority = secondPrio1 * var1 + secondPrio2 * var2 + secondPrio3 * var3;
model.Maximize(priority); // Is overwritten by second Maximize, does not work
model.Maximize(secondPriority);
CpSolverStatus result = solver.Solve(model);
I would like that my solver put the max value to var2 (500) because it has the highest prio#, then it puts the max value to var3 (400) because it has the highest secondPrio#. Then, the remaining (100) would be assigned to var1.
Thanks in advance.