Comparison involving variables with JuMP



I am new to Julia/JuMP. Is it possible to perform comparison on variable. For example, is there something close to the following?

maximum(M[1,:]. * myFunction(x))

M is a nxn matrix and x is a variable.

If not, what’s the best way to deal with this kind of issues?

I’d really appreciate any suggestions.


In an optimization problem, rather than writing y = maximum(x), we typically would create a new slack variable called y and constrain that:

@constraint model y .>= x

That will work if there is something in your objective or other constraints which is pushing “down” on y. For example

@variable model x >= 0
(add some other constraints on x)
@variable model y
@constraint model y .>= x
@objective model Min y

If you can’t rely on your objective or other constraints to push down on the value of y, then you have a much harder problem. You could implement that as a mixed-integer optimization, but I wouldn’t go down that road right away.


Thanks for the quick response. Yes, the min max approach worked. I actually tried that before. It failed, but on something else which I just found out was a simple typo :frowning: