Objective function is sigma(max (0, C_i[i] - d_i[i]))
my code is ..
Obj = sum([max(0, C_i[i] - d_j[i]) for i in range(1, job_num+1)])
error is …
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/ortools/linear_solver/python/linear_solver_natural_api.py", line 169, in __gt__
raise ValueError('Operators "<" and ">" not supported with the linear solver')
ValueError: Operators "<" and ">" not supported with the linear solver
how can i use “max” function in python?
I try to express “max” in other ways.
for example, split it 2 equations.
T1 = sum([w_j[i] for i in range(1, job_num+1) if C_i[i] <= d_j[i]])
T2 = sum([w_j[i]*(C_i[i] - d_j[i]) for i in range(1, job_num+1) if C_i[i] > d_j[i]])
and then minimize (T1+T2)
You cannot for 2 reasons:
- max() is interpreted by python before call the add() method, and the result is very wrong for a mathematical model.
- max() is not a linear formula. You can linearize it, but by nature, it does not work.
Some solver do support a max() operation in their API. But this is not consistent, and not exported at the linear solver method.
Note that CP-SAT supports add_max_equality(target, [expr1, …]) with its native API.