I am trying to model some constraints through constraint programming, by using CPLEXCP.jl. But I am having some issues with regards to translating the constraints into functions available by the library. So, the constraint I am trying to model is this:
if x = 10 then p + 5 = q
However, I am struggling to find a way to express this by using the functions given by library. One straightforward solution, would be to create a variable
r = q - p if x = 10 then r = 5
The above logic could be implemented as below:
# r - (q - p) = r - q + p r_eq = MOI.ScalarAffineFunction(MOI.ScalarAffineTerm.([1, -1, 1], [r, q, p]), 0) # r - q + p = 0 MOI.add_constraint(model, r_eq, MOI.EqualsTo(0)) # if x = 10 then r = 5 MOI.add_constraint(model, MOI.VectorOfVariables([x, r]), CP.Implication(MOI.EqualTo(10), MOI.EqualTo(5)) # github.com/JuliaConstraints/ConstraintProgrammingExtensions.jl/blob/master/src/Test/test_implication.jl#L16 )
However, by doing so, for each
q we want to impose such constraint, we would have to create another variable
r. I would like to know other ways of doing this without imposing a new variable to the model.
Case there is any confusing point, please, let me know. Thanks and regards.