# Can't use minimum() on constraint -MethodError: no method matching isless(...)

**URL:** <https://discourse.julialang.org/t/cant-use-minimum-on-constraint-methoderror-no-method-matching-isless/51219>\
**Category:** Optimization (Mathematical)\
**Tags:** question, jump\
**Created:** [December 3, 2020, 7:21pm UTC](https://discourse.julialang.org/t/cant-use-minimum-on-constraint-methoderror-no-method-matching-isless/51219 "2020-12-03T19:21:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![valenmgama](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/valenmgama/32/18623_2.png) [@valenmgama](https://discourse.julialang.org/u/valenmgama)\
**Post date:** [December 3, 2020, 7:21pm UTC](https://discourse.julialang.org/t/cant-use-minimum-on-constraint-methoderror-no-method-matching-isless/51219/1 "2020-12-03T19:21:01Z")

</div>

I am trying to use minimum on a Julia Contraint but I get the following Method Error. I am 100% using the minimum() function is what causes the trouble. Any ideas on a work around?

LoadError: MethodError: no method matching isless(::GenericAffExpr{Float64,VariableRef}, ::GenericAffExpr{Float64,VariableRef})

```julia
for n = 1:numNeighborhoods
    @constraint(eModel, minimum(travelTimeMatrix[n,:].*openedRooms[:]) >= maxTravelTime[n])
end

```

The general idea is that at least one element of an array should be less than that max.

Thanks in advance

More complete snip of code:

```julia
using JuMP, Cbc, CSV

file = "Emergency.csv"

data_import = CSV.read(file, header=true)

travelTimeMatrix = Matrix{Int}(data_import[1:10,2:13])
maxTravelTime = Array{Int}(data_import[1:10,14])
emergencyRoomCost = Array{Int}(data_import[11,2:13])

numNeighborhoods = size(maxTravelTime,1)
numEmergencyRooms = size(emergencyRoomCost,1)

eModel = Model(Cbc.Optimizer)

@variable(eModel, openedRooms[1:numEmergencyRooms], binary=true)
@objective(eModel, Min, sum(openedRooms.*emergencyRoomCost))

for n = 1:numNeighborhoods
    @constraint(eModel, minimum(travelTimeMatrix[n,:].*openedRooms[:]) >= maxTravelTime[n])
end

stats = JuMP.optimize!(eModel)
result = JuMP.value.(openedRooms)

println(data_import)
println(result)

```

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [December 3, 2020, 8:03pm UTC](https://discourse.julialang.org/t/cant-use-minimum-on-constraint-methoderror-no-method-matching-isless/51219/2 "2020-12-03T20:03:22Z")

</div>

You cannot use arbitrary functions in a `@constraint`. Since you are using Cbc, you need to formulate a mixed-integer linear program with linear constraints.

```nohighlight
for n = 1:numNeighborhoods
    @constraint(eModel, minimum(travelTimeMatrix[n,:].*openedRooms[:]) >= maxTravelTime[n])
end

# is equivalent to

@constraint(
    eModel, 
    [n = 1:numNeighborhoods, r=1:numEmergencyRooms], 
    travelTimeMatrix[n, r] * openedRooms[r] >= maxTravelTime[n],
)

```
