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.

1 Like

@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.

1 Like