Engee
Engee

Reputation: 63

Google Or-tools disjunction of constraints

I would like to use the Google or-tools Java api and I can't make disjunction of constraints. I try to implement like this: (A==1 OR B==1) AND ((C==1 OR D==1))... How can I do that?

And the other question is how can I implement the makeSumLessOrEqual(IntVar[] VARS, IntVar limit) because there is only makeSumLessOrEqual(IntVar[] VARS, int limit) function.

Thank you for your help!

Upvotes: 3

Views: 1295

Answers (1)

Laurent Perron
Laurent Perron

Reputation: 11064

I would like to use the Google or-tools Java api and I can't make disjunction of constraints. I try to implement like this: (A==1 OR B==1) AND ((C==1 OR D==1))... How can I do that?

Create boolean variables with solver.makeIsEqualCstVar(A, 1)

The OR is solver.makeMax(boolvar_1, boolvar_2) and AND is solver.makeMin();

And the other question is how can I implement the makeSumLessOrEqual(IntVar[] VARS, IntVar limit) because there is only makeSumLessOrEqual(IntVar[] VARS, int limit) function.

You need to use the makeScalProd API with [1, .., 1, -1] and vars + [limit].

Upvotes: 2

Related Questions