# MethodError: no method matching isless(::Int64, ::AffExpr)

**URL:** <https://discourse.julialang.org/t/methoderror-no-method-matching-isless-int64-affexpr/69731>\
**Category:** Optimization (Mathematical)\
**Tags:** question, jump\
**Created:** [October 14, 2021, 6:39am UTC](https://discourse.julialang.org/t/methoderror-no-method-matching-isless-int64-affexpr/69731 "2021-10-14T06:39:36Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ali9266](https://avatars.discourse-cdn.com/v4/letter/a/7ab992/32.png) [@Ali9266](https://discourse.julialang.org/u/Ali9266)\
**Post date:** [October 14, 2021, 6:39am UTC](https://discourse.julialang.org/t/methoderror-no-method-matching-isless-int64-affexpr/69731/1 "2021-10-14T06:39:36Z")

</div>

I’m receiving an error **MethodError: no method matching isless(::Int64, ::AffExpr)** while trying to run my code in the constraints “@constraint(model, con8[k in 1:n,i in 1:m; i==m], T\_k[k]==max(C\_ki[k,i]-U\_k[k],0))”

---

<div class="post-metadata">

**Author:** ![vinicius\_de\_lima](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vinicius_de_lima/32/28717_2.png) [@vinicius\_de\_lima](https://discourse.julialang.org/u/vinicius_de_lima)\
**Post date:** [October 14, 2021, 10:27pm UTC](https://discourse.julialang.org/t/methoderror-no-method-matching-isless-int64-affexpr/69731/2 "2021-10-14T22:27:29Z")

</div>

Please see [this link](https://discourse.julialang.org/t/problem-using-jump-with-user-defined-function/68835), I believe that you have to register the function `max` before using it in a model.

---

<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:** [October 15, 2021, 1:09am UTC](https://discourse.julialang.org/t/methoderror-no-method-matching-isless-int64-affexpr/69731/3 "2021-10-15T01:09:45Z")

</div>

@vinicius_de_lima is correct. You cannot use arbitrary Julia functions in `@constraint`. You must formulate a mixed-integer linear program.

Instead of

```julia
model = Model()
@variable(model, x)
@variable(model, t)
@constraint(model, t == max(x, 0))

```

do

```julia
model = Model()
@variable(model, x)
@variable(model, t >= 0)
@constraint(model, t >= x)

```

or

```julia
model = Model()
@variable(model, x)
@variable(model, t)
register(model, :max, 2, max; autodiff = true)
@NLconstraint(model, t == max(x, 0))

```

---

<div class="post-metadata">

**Author:** ![Ali9266](https://avatars.discourse-cdn.com/v4/letter/a/7ab992/32.png) [@Ali9266](https://discourse.julialang.org/u/Ali9266)\
**Post date:** [October 18, 2021, 12:12pm UTC](https://discourse.julialang.org/t/methoderror-no-method-matching-isless-int64-affexpr/69731/4 "2021-10-18T12:12:12Z")

</div>

Thank you so much for the reply. I will follow your lead and let you know if this is working or not.

---

<div class="post-metadata">

**Author:** ![Ali9266](https://avatars.discourse-cdn.com/v4/letter/a/7ab992/32.png) [@Ali9266](https://discourse.julialang.org/u/Ali9266)\
**Post date:** [December 16, 2021, 6:22am UTC](https://discourse.julialang.org/t/methoderror-no-method-matching-isless-int64-affexpr/69731/5 "2021-12-16T06:22:14Z")

</div>

Thank you for your help, it worked. Now, I’m facing one more problem in which there are n non-negative numbers (i.e., tn\>=0) and I want to find out how many numbers out of n are positive (i.e., tn\>0). Please tell me how to calculate these numbers in JULIA as an expression in my MILP model.

---

<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 16, 2021, 6:26am UTC](https://discourse.julialang.org/t/methoderror-no-method-matching-isless-int64-affexpr/69731/6 "2021-12-16T06:26:32Z")

</div>

The mosek modeling cookbook covers this:  
[https://docs.mosek.com/modeling-cookbook/mio.html#implication-of-positivity](https://docs.mosek.com/modeling-cookbook/mio.html#implication-of-positivity)

If you have trouble, start a new post with code of what you’ve tried.

---

<div class="post-metadata">

**Author:** ![Ali9266](https://avatars.discourse-cdn.com/v4/letter/a/7ab992/32.png) [@Ali9266](https://discourse.julialang.org/u/Ali9266)\
**Post date:** [December 16, 2021, 8:37am UTC](https://discourse.julialang.org/t/methoderror-no-method-matching-isless-int64-affexpr/69731/7 "2021-12-16T08:37:56Z")

</div>

Thanks for the help.
