0

I am trying to understand how ASP (answer set programming) works. Hopefully I am asking this in the right place, otherwise I'm sorry. To be more specific, I am using Clingo, the ASP programming language of my university, but I hope somebody will still be able to help me out. I am trying to write a programm that finds the orthogonal neighbours of each of the cells in a 4x4 grid. This is what I have written so far:

row(1..4).
column(1..4).
cell(X,Y) :- row(X), column(Y).

{neighbor(X-1,Y); neighbor(X+1, Y); neighbor(X, Y-1); neighbor(X, Y+1)} = 4 :- cell(X,Y).

This way, I get the following solution:

row(1) row(2) row(3) row(4) column(1) column(2) column(3) column(4) cell(1,1) cell(2,1) cell(3,1) cell(4,1) cell(1,2) cell(2,2) cell(3,2) cell(4,2) cell(1,3) cell(2,3) cell(3,3) cell(4,3) cell(1,4) cell(2,4) cell(3,4) cell(4,4) neighbor(1,2) neighbor(1,0) neighbor(2,1) neighbor(0,1) neighbor(2,2) neighbor(2,0) neighbor(1,1) neighbor(3,1) neighbor(3,2) neighbor(3,0) neighbor(4,1) neighbor(4,2) neighbor(4,0) neighbor(5,1) neighbor(1,3) neighbor(0,2) neighbor(2,3) neighbor(3,3) neighbor(4,3) neighbor(5,2) neighbor(1,4) neighbor(0,3) neighbor(2,4) neighbor(3,4) neighbor(4,4) neighbor(5,3) neighbor(1,5) neighbor(0,4) neighbor(2,5) neighbor(3,5) neighbor(4,5) neighbor(5,4)
SATISFIABLE

This is not what I wanted because I don't want neighbours that are "outside" the 4x4 grid, like neighbour(0,3), for example. (Any neighbour that has 0 or 5 as coordinates, actually.) I tried writing the following line as constraint:

:- neighbour(0, Y).

However, this doesn't work and yields "unsatisfiable". Could anybody explain why this doesn't work?

nbro
  • 42,615
  • 12
  • 119
  • 217

0 Answers0