potassco / clingo

🤔 A grounder and solver for logic programs.
https://potassco.org/clingo
MIT License
599 stars 79 forks source link

Weak Constraints Clingo DLV #439

Closed jackban99 closed 1 year ago

jackban99 commented 1 year ago

Hi, i'm pretty new to Clingo and in the last couple of days i was really struggling with the following problem. I want to implement the DLV Code of the following Paper http://www.kr.tuwien.ac.at/events/taasp22/papers/TAASP_2022_paper_15.pdf which implements Deontic Logic via weak constraints. My code looks like this:

`1{ obl(X) ; -obl(X) }1 :- act(X). 1{ forb(X) ; -forb(X) }1 :- act(X). -diamond(X) :- -do(X), act(X). :- obl(X), -do(X). :- obl(X), -diamond(X). :- obl(X), forb(X). 1{ do(X) ; -do(X) }1 :- act(X).
:- forb(X), do(X). happens(X) :- do(X). :- do(X), -diamond(X).

:~ obl(X). [1@1] :~ forb(X). [1@1]

act(help). `

The problem is now that the only Answer Set is: act(mail) -diamond(mail) -do(mail) -obl(mail) -forb(mail) and i fail to understand why there isn't another one where he chooses do(mail)(like in the paper). My confusion got only bigger when i discovered that with clingo--opt-mode=optN Deontic.lp 0 i get three answer sets

Answer: 1 act(help) -diamond(help) -do(help) -obl(help) -forb(help) Optimization: 0 Answer: 1 act(help) do(help) happens(help) -obl(help) -forb(help) Optimization: 0 Answer: 2 act(help) -diamond(help) -do(help) -obl(help) -forb(help) Optimization: 0

Why are there two answer sets 1? Why does adding the weak constraints delete Answer sets (without them i get the same Answer Sets as in the paper before adding them)? It seems to me that the weak constraints work different then in DLV, but how? Also, adding :~ -obl(help). [1@2] which should filter out Answer Sets without the obligation to help through minimisation at the higher level still contains the Answer Set described above. I really look forward to some clarification. –forb(help).

rkaminsk commented 1 year ago

Optimize statements and weak constraints optimize the sum of weights of a set of tuples. Check https://potassco.org/doc/faq/2016/09/20/how-do-optimization-statements-work.html for some background info. In your example there is just one singleton tuple: (1,) with priority 1.

You probably want to write:

:~ obl(X). [1@1,X]
:~ forb(X). [1@1,X]
jackban99 commented 1 year ago

Hi, thank you very much for the quick answer. Unfortunately this doesn‘t change the Output in any of the cases. I think the problem lies within the three or-Statements somehow there is no AS where the do(help) gets chosen.

rkaminsk commented 1 year ago

Why are there two answer sets 1? Why does adding the weak constraints delete Answer sets (without them i get the same Answer Sets as in the paper before adding them)? It seems to me that the weak constraints work different then in DLV, but how?

Sorry, I did not read too closely. The clingo output differs from dlv. When enumerating, clingo first reports intermediate answer sets and then optimal ones. You can suppress the intermediate ones using option --quiet:

clingo test.lp --opt-mode=optN --quiet=1

Check the output of --help for possible values.

jackban99 commented 1 year ago

That‘s it!! Thank you very very much for your help Mr. Kaminski.