# JuMP constraint MethodError: no method matching isless(::Int64, ::VariableRef)

**URL:** <https://discourse.julialang.org/t/jump-constraint-methoderror-no-method-matching-isless-int64-variableref/46498>\
**Category:** Optimization (Mathematical)\
**Tags:** question, jump\
**Created:** [September 12, 2020, 7:14am UTC](https://discourse.julialang.org/t/jump-constraint-methoderror-no-method-matching-isless-int64-variableref/46498 "2020-09-12T07:14:37Z")\
**Posts on this page:** 4\
**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:** [September 12, 2020, 7:14am UTC](https://discourse.julialang.org/t/jump-constraint-methoderror-no-method-matching-isless-int64-variableref/46498/1 "2020-09-12T07:14:37Z")

</div>

Hey, I need your help!

What I am basically trying is to add a constraint to a JuMP matrix variable that no more than one element of a row can be a value larger than 0.

In other words only 1 element in the row can be a non Zero value.

```julia
@variable(ExModel, matrixVaribale[1:nSize,1:nSize] >= 0, Int)

for n = 1:nSize
    @constraint(ExModel, sum((matrixVariable[n,s] > 0) for s=1:nSize) <= 1)
end

```

However when I try to run my code I get the following error:

```julia
LoadError: MethodError: no method matching isless(::Int64, ::VariableRef)
...
in expression starting at ..\caseStudy.jl:48
<(::Int64, ::VariableRef) at operators.jl:268
>(::VariableRef, ::Int64) at operators.jl:294
macro expansion at rewrite.jl:227 [inlined]
macro expansion at macros.jl:416 [inlined]
top-level scope at caseStudy.jl:49

```

Any ideas on other ways to acomplish this?

It must have to do something with the way Julia interprets the JuMP variabale as a VariableRef instead of as an Int or Float

Thanks in advance

valenmgama

Note: I also get this error when trying to perform other operations on the variable such as %

---

<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:** [September 12, 2020, 7:55am UTC](https://discourse.julialang.org/t/jump-constraint-methoderror-no-method-matching-isless-int64-variableref/46498/2 "2020-09-12T07:55:34Z")

</div>

I managed to find a work around by adding another variable:

```julia
@variable(ExModel, matrixVariable[1:nSize,1:nSize] >= 0, Int)
@variable(ExModel, relationsVariable[1:nSize,1:nSize], Bin)

for n = 1:nSize
    @constraint(ExModel,sum(relationsVariable[n,:] <= 1)
end

@constraint(ExModel, matrixVariable[:,:] .<= relationsVariable[:,:]*typemax(Int)

```

Still would love to hear if anybody out there has any other ideas.  
valenmgama

---

<div class="post-metadata">

**Author:** ![tomerarnon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomerarnon/32/3170_2.png) [@tomerarnon](https://discourse.julialang.org/u/tomerarnon)\
**Post date:** [September 12, 2020, 11:42am UTC](https://discourse.julialang.org/t/jump-constraint-methoderror-no-method-matching-isless-int64-variableref/46498/3 "2020-09-12T11:42:11Z")

</div>

See [https://jump.dev/JuMP.jl/dev/constraints/#Special-Ordered-Sets-(SOS1-and-SOS2)-1](https://jump.dev/JuMP.jl/dev/constraints/#Special-Ordered-Sets-(SOS1-and-SOS2)-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:** [September 12, 2020, 4:54pm UTC](https://discourse.julialang.org/t/jump-constraint-methoderror-no-method-matching-isless-int64-variableref/46498/4 "2020-09-12T16:54:47Z")

</div>

Thanks! Just what was needed! For anyone else checking this thread my code in the end was:

```julia
@variable(ExModel, matrixVaribale[1:nSize,1:nSize] >= 0, Int)

for n = 1:nSize
    @constraint(ExModel, matrixVariable[n,:] in SOS1())
end

```
