Search code examples
answer-set-programmingclingo

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


A processor 'a' takes care the header 'a' of a message 'a_b_c_d' and passes the payload 'b_c_d' to the another processor in the next level as following:

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 list 'a_b_c_d' in ASP, and change the above to general cases?


Solution

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

    The way you implement a list, the list itself cannot be used as a term and thus what if you want to bind between variables in the list and other elements of a rule? Perhaps you would like something such as p(t, [q(X), q(Y)]) :- X != Y.

    You can try implementing a list as (a, b, c) and an append predicate but the problem is ASP requires grounding before computing answer-sets. Consequently a list defined in this way whilst more like lists in Prolog would mean the ground-program contains all ground-instances of all possible lists (explosion) regardless of whether they are used or not.

    I therefore come back to my first point, try using DLV instead of Clingo if possible (for this task, at least).