Search code examples
logicanswer-set-programmingclingogringo

clingo apply a variable range


I do not know much about clingo, i hope i can share the problem clearly.

Currently i've

cellUseCount(X,Y,C) :- C = #count{cell(X,Y)}, target(X,Y,XX,YY).

which returns results for each X,Y value. How can i get for X-XX and Y-YY range.

For instance: the rule generates cellUseCount(1,5,1) for target(1,5,1,1). However, i'd like to have cellUseCount(1,1,1), cellUseCount(1,2,1), cellUseCount(1,3,1), cellUseCount(1,4,1), cellUseCount(1,5,1) for target(1,5,1,1). How can i implement that?

Thanks in advance.


Solution

  • Try:

    % instance
    target(1,5,1,1).
    
    % encoding
    cellUseCount(X,1..Y,C) :- C = #count{cell(X,Y)}, target(X,Y,XX,YY).
    

    Output:

    enter image description here