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))”

Please see this link, I believe that you have to register the function `max`

before using it in a model.

@vinicius_de_lima is correct. You cannot use arbitrary Julia functions in `@constraint`

. You must formulate a mixed-integer linear program.

Instead of

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

do

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

or

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

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

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.

The mosek modeling cookbook covers this:

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.

Thanks for the help.