asp (clingo) : why are ordered sums not working

1.1k views Asked by At

Consider the followig code, compiled in clingo.

File test.lp. Compile command: clingo 0 test.lp.

col(("rot";"blau")).

freq("rot","hell",2). freq("rot","dunkel",2). freq("rot","hell",5).
freq("blau","hell",20). freq("blau","dunkel",30). freq("blau","hell",50).

freq_sum(C,F) :- F = #sum{ X : freq(C,_,X) }, col(C).
%% does not work: >>error: syntax error, unexpected [, expecting {<<
% freq_sum(C,F) :- F = #sum[ X : freq(C,_,X) ], col(C).

#show freq_sum/2.

The code should compute the sum of frequencies for each colour. For "red", this should be 9 and for “blue" this should be 100. For "red" the value 2 is counted twice. When I replace {...}by […], which should make the list an ordered list and deliver the ordered sum, the compiler complains error: syntax error, unexpected [, expecting {. I have clingo version 4.5.4. Is there something wrong with my code or with my compiler?

Can someone please tell me, how I can perform an ordered sum in asp?

1

There are 1 answers

2
Thomas On

In case anyone comes across this issue, I found the solution. The problem is the version of clingo/gringo from version 4 does not support multisets. One can only enter in lists via {...}. Nevertheless there is a way to make prevent collapsing of multiple elements.

freq_sum(C,F) :- F = #sum{ X,H : freq(C,H,X) }, col(C).

naming the objects, over which the indexing occurs, allows each item in the list to be uniquely tagged, preventing duplicate values from being viewed as a single element. I found this solution in §2 of http://ceur-ws.org/Vol-1645/paper_9.pdf.