0

I'm using pydatalog to solve a path-planning problem (just an example). I want one path from the begin state to the end state, i.e. one answer. As far as I can tell, ask() yields a list of all answers and I would like to generate the answers lazily.

A second question: notice I had to define member/2 where I thought I could say

(Z in Freesquares) and
~(Z in P1) 

But I get the error

TypeError: argument of type 'bool' is not iterable

Any cleaner way to write that code? Thanks!

#  Defn of adjacent is missing. For example (r,c) is adjacent to (r+1,c), (r,c+1), (r-1,c), (r,c-1)

create_terms('path', 'Begin', 'Current', 'End', 'FreeSquares', 'Path', 'P1')

path(Begin, Current, End, FreeSquares, Path)  <= adjacent(Current, End) & (Path==[])
path(Begin, Current, End, FreeSquares, Path)  <= \
        adjacent(Current, Z) & ~(Z == Begin) & ~(Z == End) & member(Z, FreeSquares) & \
            path(Begin, Z, End, FreeSquares, P1) & ~member(Z, P1) & (Path == [Z] + P1) 

ask('path((3,3), (3,3), (1,1), [(1,1), (1,2), (2,1), (2,2), (2,3), (3,1), (3,3)], X)').answers
[(((2, 3), (2, 2), (1, 2)),), (((2, 3), (2, 2), (2, 1)),)]

0 Answers0