How should a list be presented in ASP (Answer Set Programming)?

Processor "a" takes header "a" of message "a_b_c_d" and transfers the payload "b_c_d" to another processor at the next level as follows:

msg(a, b_c_d).
pro(a;b;c;d).

msg(b, c_d) :- pro(X), msg(X, b_c_d).
msg(c, d)   :- pro(X), msg(X, c_d).
msg(d)      :- pro(X), msg(X, d).

#hide. #show msg/2. #show msg/1.

      

How should I represent the list "a_b_c_d" in ASP and modify the above in general cases?

+3


source to share


3 answers


There is no "official" way of handling lists in ASP as far as I know. But DLV has built-in list processing similar to Prolog's.

How do you implement a list, the list itself cannot be used as a term and therefore what if you want to bind between variables in the list and other elements of the rule? You may need something like p (t, [q (X), q (Y)]): - X! = Y.



You can try to implement the list as (a, b, c) and the append predicate, but the problem is that ASP needs to be grounded before evaluating response sets. Hence a list defined in this way, while the more similar lists in Prolog mean that the ground program contains all the ground instances of all possible (bang) lists, whether they are used or not.

So I'll go back to my first point, try using DLV instead of Clingo if possible (for this task at least).

0


source


No, the official way, but I think most people don't understand that you can create cons-cells in ASP. For example, here you can get items for all lists of length 5 from items 1..6

element(1..6).
listLen(empty, 0).
listLen(cons(E, L), K + 1) :- element(E); listLen(L, K); K < 5.
is5List(L) :- listLen(L, 5).

#show is5List/1.

      

resulting in



is5List(cons(1,cons(1,cons(1,cons(1,cons(1,empty))))))
is5List(cons(1,cons(1,cons(1,cons(1,cons(2,empty))))))
is5List(cons(1,cons(1,cons(1,cons(1,cons(3,empty))))))

      

...

+1


source


Using the index, I have a way to go through the list, however I don't know if this is the official way to handle a list in ASP. Can anyone have more experience with ASP, give us a hand? Thank you.

index(3,a). index(2,b). index(1,c). index(0,d). 
pro(a;b;c;d). msg(3,a).

msg(I-1,N) :- pro(P), msg(I,P), index(I,P), I>0, index(I-1,N).

#hide. #show msg/2.

      

0


source







All Articles