Search code examples
answer-set-programmingclingo

Clingo answer set programming line intersection


I have a rule that generates the following

route(5,1,5,3) 
route(5,2,5,3) 
route(5,3,5,3) 
route(3,1,3,1) 
route(2,3,5,3) 
route(3,3,5,3) 
route(4,3,5,3) 
route(4,1,3,1) 
route(5,1,3,1) 
route(3,2,3,1) 
route(3,3,3,1) 
route(3,4,3,1) 
route(3,5,3,1)

in which the following part is a route starting at 5,1 and ending at 5,3

route(5,1,5,3) 
route(5,2,5,3) 
route(5,3,5,3)

in route(x1,y1,x2,y2)

  • x1 = x coordinate of first point
  • y1 = y coordinate of first point
  • x2 = x coordinate of second point
  • y2 = y coordinate of second point

I want to write a constraint so that these routes do not cross each other but I am not sure how to approach this problem. I would appreciate any help in this matter.


Solution

  • I used the following rule to prevent crossing of routes.

    (X',Y') = (X'',Y'') :- route(X,Y,X',Y'), route(X,Y,X'',Y'').