# Issues with broadcasting min and max operators to matrixes in JuMP expression

Hello,

New to JuMP and trying to implement a matrix-based expression in JuMP that uses min and max operators broadcasted to the vector. Having trouble getting the min and max operators working in the ‘tx’ expression, was planning to implement this as a custom function but it’s my understanding JuMP doesn’t support user-defined functions with multiple vector inputs. So I’m trying to implement it as an underlying expression. Is there a better way to do this / a better package? I tried to use Convex.jl but since ‘tx’ is only convex when constrained by u * z > 0 it’s not DCP. I’ve read several stack overflow questions where the problem is reformulated to get around the use of max but I don’t think that will work here since it’s part of the computation, not a constraint. This implementation works perfectly in julia outside of JuMP. I played around a little with user-defined versions of max and min operators and registering those for a non-linear model but that didn’t work either. Any help would be greatly appreciated.

some randomly generated variables for example code that produces error:
‘’’
## generate some random data
hBm = rand(50) # > 0
hInit = rand(50) # > 0

``````n = length(hInit)

vMat = rand(100,50)
tMat = randn(100,50)

q = rand(50,50) # > 0

cumV = cumsum(vMat, dims=1)

model = Model(Ipopt.Optimizer)
set_silent(model)

@variable(model, u[1:n])

h = @expression(model, hInit + u)
te = @expression(model, (h - hBm)' * q * (h - hBm))

tx = @expression(model, sum(tMat .* (vMat .- min.(max.(cumV .+ min.(u, 0.0)', 0.0), vMat))))

## objective
@objective(model, Min, te + tx)

## constraints
@constraint(model, z .* u .>= 0)
@constraint(model, sum(hInit + u) == sum(hInit))

# optimize and print some logs
optimize!(model)
solution_summary(model)
``````

‘’’

the error:
‘’’
ERROR: MethodError: no method matching isless(::Float64, ::VariableRef)
Closest candidates are:
isless(::T, ::T) where T<:Union{Float16, Float32, Float64} at float.jl:424
isless(::AbstractFloat, ::AbstractFloat) at operators.jl:184
isless(::AbstractFloat, ::ForwardDiff.Dual{Ty}) where Ty at C:\Users\templ.julia\packages\ForwardDiff\QdStj\src\dual.jl:145
‘’’

This is supposed to be a Linear Programming model, correct?

For linearising a max or min expression inside a constraint you need an extra variable for the result and breaking the expression into many constraints, there is a step-by-step guide on how to do the math part (i.e., not JuMP-specific): mixed integer programming - How to linearize min function as a constraint? - Operations Research Stack Exchange