Supporting onlyEnforceIf() on addExactlyOne()

595 views
Skip to first unread message

Marichi Gupta

unread,
Apr 23, 2022, 11:01:04 AM4/23/22
to or-tools-discuss
I am trying to place an addExactlyOne() constraint, only enforced upon another literal:

>>  model.addExactlyOne(workers).onlyEnforceIf(timeIsAfterStepStart);

Including this line causes the following "INVALID MODEL" status:

>> Starting CP-SAT solver v9.3.10497 
>> Parameters: log_search_progress: true 
>> Setting number of workers to 4 
>> Invalid model: Enforcement literal not supported in constraint: enforcement_literal: 24 exactly_one { literals: 0 }

It appears that the constraint addExactlyOne() - which was added in the most recent release (March '22) -  does not support onlyEnforceIf(). Is this by design? Are there any workarounds? What I'm trying to do seems like a reasonable use of the API.

This is a crosspost for this StackOverflow question, a minimum reproducible example is there. If resolved here I will update/answer that question.

Laurent Perron

unread,
Apr 23, 2022, 1:37:47 PM4/23/22
to or-tools-discuss
Sum()==1 only enforce if (literal)


--
You received this message because you are subscribed to the Google Groups "or-tools-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to or-tools-discu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/or-tools-discuss/dd9dc2d8-3c70-42a7-88ee-5dc2d40bdbf3n%40googlegroups.com.

Marichi Gupta

unread,
Apr 23, 2022, 2:24:23 PM4/23/22
to or-tools-discuss
Thanks, Laurent.

Java Code for future readers:
>> LinearArgument sumLinearArgument = LinearExpr.sum(workers); 
>> model.addEquality(sumLinearArgument, 1).onlyEnforceIf(timeIsAfterStepStart);

Reply all
Reply to author
Forward
0 new messages