问题
In Clingo guide, there are two modes called cautious and brave introduced as the follows:
brave Compute the brave consequences (union of all answer sets) of a logic program.
cautious Compute the cautious consequences (intersection of all answer sets) of a logic program.
No more information is provided in the guide. I tried some examples and have trouble understanding the issue.
I tried to run the following simple ASP program:
p :- not q.
q :- not p.
Running Clingo with no mode parameter will give the right answer sets:
answer 1:{p}
answer 2:{q}
As described in the guide, if run under brave mode, which will compute union of all answer sets, I should get the result {p, q}
.
Similarly, for cautious case, empty result is expected.
However, the actual result for brave reasoning by Clingo is:
clingo version 5.3.0
Reading from test/cautious_reasoning.lp
Solving...
Answer: 1
q
Consequences: [1;2]
Answer: 2
q p
Consequences: [2;2]
SATISFIABLE
Models : 2
Brave : yes
Consequences : 2
Calls : 1
Time : 0.006s (Solving: 0.00s 1st Model: 0.00s Unsat: 0.00s)
CPU Time : 0.002s
And for the cautious case:
clingo version 5.3.0
Reading from test/cautious_reasoning.lp
Solving...
Answer: 1
q
Consequences: [0;1]
Answer: 2
Consequences: [0;0]
SATISFIABLE
Models : 2
Cautious : yes
Consequences : 0
Calls : 1
Time : 0.001s (Solving: 0.00s 1st Model: 0.00s Unsat: 0.00s)
CPU Time : 0.001s
So what does the numbers in []
represent? How to understand the cautious and brave reasoning mode in Clingo?
回答1:
When you invoke clingo with enumeration algorithm --enum-mode brave
or --enum-mode cautious
, the atoms that appear in each enumerated model "converge" to the set of brave or cautious consequences, resp. That is, in brave
mode the atoms will monotonically increase, while in cautious
mode the atoms will monotonically decrease. Think of it as a "running" union or intersection for brave and cautious consequences, resp.
The numbers inside the square brackets [d;p]
have the following meaning: clingo calls TextOutput::printMeta for each model, which prints a pair of integers [d;p]
of definite consequences d
and remaining possible consequences p
as computed by Output::numCons.
Edit: the last answer will then give you the final result, i.e., the brave/cautious consequences of the input program. If all you care about is the final result, you may invoke clingo like this to get the brave consequences (e.g., of program a | b | c | d.
):
% echo 'a|b|c|d.' | clingo -e brave | grep -A1 '^Answer:' | tail -n -1
b c d a
And for the cautious consequences of program a | b | c | d.
(i.e., the empty set), you just need to start clingo in cautious enumeration mode:
% echo 'a|b|c|d.' | clingo -e cautious | grep -A1 '^Answer:' | tail -n -1
来源:https://stackoverflow.com/questions/55675488/brave-cautious-reasoning-in-clingo