-
Notifications
You must be signed in to change notification settings - Fork 83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A recursion ends unexpectedly. #532
Comments
Your program can choose between 1 and 2 moves; 1 from the first rule and up to one from the second rule. So the output looks correct. Maybe you are aiming for something more like this? time(1..3).
move( a, b).
move( b, c).
move( c, d).
{ p( 0, A, B) : move( A, B) } = 1 .
0 { p( T, B, C) : p( T-1, A, B), move( B, C) } 1 :- time(T). If your graph is acyclic, you can also write move(a, b).
move(b, c).
move(c, d).
{ p(0, A, B) : move(A, B) } = 1 .
0 { p(T, B, C) : move(B, C) } 1 :- p(T-1, A, B). Grounding will not terminate if there is a cycle, though. |
Thanks for the solutions. btw. this also seems to work:
But this doesn't really explain why the first variation did't recurse properly. Where can I find an explanation for this behaviour? |
You have to move your p/3 condition from inside the choice rule to the body of the rule. Otherwise you will restrict the whole set of all predicates p(N+1,*,*) for all N to atmost 1. But you want to have this restriction for each N. So at most one move p(N+1,*,*) for each N.
Also use the --text option of clingo to get a better understanding of the grounding of your rule (like you tried manually).
|
I tried to explain here:
One move here:
Up to one move here:
So there can be at most two moves in a solution. The rule
will work. In practice, it is often best to keep conditions of head aggregates domain. |
I think I get it. The choise operator don't seem to recurse on its own created facts. At least in the aforementioned examples. But this here don't stop recursing:
So it seems to be that it can under some circumstances reprocess its own output. I am not 100% sure because this also cannot finish:
And here is no new fact created. And btw. There is another solution for my example:
I assume the choice operator gets reprocessed when the cardinality has changed. As soon it is prolog like I can understand it easily but this choice operator needs more exercises. |
Maybe check #504 (comment) for some introductory material to ASP. While Prolog and ASP share some similarities, they are still very different languages. |
Is this a bug or normal?
https://stackoverflow.com/questions/79314787/i-am-encountering-an-early-recursion-termination-in-clingo
Thanks in advance.
The text was updated successfully, but these errors were encountered: