-1

i'm using Gurobi,

I have 2 decision variables x and y, and i want to linearize some constraints, here's my code :

m.addConstr( x == max(0, y) )
m.addConstr( x >= 0 )
Mohamed Benkedadra
  • 1,964
  • 3
  • 21
  • 48
huangkai
  • 21
  • 1
  • 5
  • What exactly do you mean by "linearize"? What data structure is `x`? Does your code work or not? If not, what is the problematic behaviour you are encountering? Please revise your question along the lines of [ask], and post an [mcve]! – Robert May 01 '19 at 09:12
  • If the `max` part is giving you modeling troubles, please have a look at the [`gurobipy.max_`](http://www.gurobi.com/documentation/8.1/refman/py_max_.html) function. If you don't succeed, please revise your question as suggested above. – Robert May 03 '19 at 08:47

1 Answers1

-1

Assuming Objective Function is a minimization, and you just want to track the max value of something, say an energy peak,

If m.addConstr( x >= 0 ) is a real requirement, then you can just set y=x, which makes no sense as x will stay non-negative by itself with no need for y

OR

you can use

m.addConstr(x>=0)
m.addConstr(x>=y)

and put x in the objective function with positive cost coeff. This will keep x tied to max(0,y)

ref https://orinanobworld.blogspot.com/2011/01/max-and-min-functions-in-mip.html

somedude
  • 33
  • 6
  • This doesn't achieve what @hungkai wants (the question is not quite clear though): Your constraints only guarantee that `x >= max(0, y)`, but the question asks for `x == max(0,y)`. – Robert May 03 '19 at 08:46