Sid Datta
Sid Datta

Reputation: 1109

lparse/clingo: How to say AllOf(a,b,c) :- condition?

The following makes one or more literals true:

a,b,c :- condition.
a;b;c :- condition.

In the above a,b,c,condition is a valid model, but also (a,condition), (a,b,condition), etc. I want all of a, b, c to be true, always, if condition is true.

I can write the following to force a,b,c to be always true together.

:- condition, a, not b.
:- condition, b, not c.
:- condition, c, not a.

but these become very verbose and bug prone for complex rules.

Upvotes: 1

Views: 397

Answers (1)

peschü
peschü

Reputation: 1359

You can write

3 { a ; b ; c } 3 :- condition.

That means that at least 3 and at most 3 atoms in the curly brackets are defined as true if the condition is true.

The constraints which you wrote have a very different meaning, for example the first constraint requires that some other rule must not define truth of condition and a unless there is also a rule that defines b to be true.

Upvotes: 2

Related Questions