IloIfThen constraints for CPLEX in Julia

Hello,

I need to use the conditional constraints for a JuMP model with CPLEX, that would be IloIfThen in C++. Like if I have three variables x, y and z, a constraint like:

If (x >= 1) && (y <= 2) then z == 1

I am using JuMP, and have tried to use the indicator constraints, with something like this:
@constraint(m, name, ((x >= 1) && (y <= 2)) => { z == 1})

However it does not work, it seems that I can’t use a JuMP decision variable in a logical expression, therefore I can only use a binary decision variable to trigger the constraint instead of a more complex logical expression.

Of course I could linearize the conditional constraints, but that is not possible in my case: I need to implement this model (found in the literature) to benchmark an algorithm I developped. The model uses a lot of conditional constraints, and I fear that the workaround of linearizing everything might affect the performances.

So, is there a way for JuMP to model this constraint ? Otherwise, is it possible to do that using the low-level CPLEX API ? What would be the syntax in this case ?

Thanks!

Of course I could linearize the conditional constraints

Yes, this is what you will need to do.

is there a way for JuMP to model this constraint ?

No. JuMP supports only indicator constraints of the form z => { ... } where z is a binary variable.

Otherwise, is it possible to do that using the low-level CPLEX API ? What would be the syntax in this case ?

you can call any functions in the CPLEX C API: https://github.com/jump-dev/CPLEX.jl/blob/master/src/gen2210/libcpx_api.jl

But this is usually non-trivial, and requires a detailed understanding of the C API.

It sounds like you’re looking to do constraint programming. There is a nice blog post about the relationship between JuMP and this topic here:

In particular, the package ConstraintProgrammingExtensions.jl can interact with CPLEXCP.jl, which wraps the Java interface rather than the C++ version; see, for example, this list of exported functions here.

There is probably some more work to do with introductory tutorials and docs for getting started.

1 Like

Or have a look here on reformulation ideas:
https://docs.mosek.com/modeling-cookbook/mio.html

1 Like