dwolter_SparQ/Calculi/cardir.lisp
;;;
;;; Frank's / Ligozat's cardinal direction calculus 
;;;

(def-calculus "Cardinal direction calculus (cardir)"
  :arity :binary
  :parametric? nil
  :basis-entity :2d-point
  :consistency :a-closure
  :qualifier #'(lambda (p1 p2)
		 (let ((x1 (car p1))
		       (y1 (second p1))
		       (x2 (car p2))
		       (y2 (second p2)))
		   (cond ((= x1 x2) (cond ((> y1 y2) 'N)
					  ((= y1 y2) 'EQ)
					  (t 'S)))
			 ((< x1 x2) (cond ((> y1 y2) 'NW)
					  ((= y1 y2) 'W)
					  (t 'SW)))
			 (t (cond ((> y1 y2) 'NE)
				  ((= y1 y2) 'E)
				  (t 'SE))))))


  :identity-relation EQ
  :converse-operation ((N S)
		       (NE  SW)
		       (E W)
		       (SE  NW)
		       (S N)
		       (SW  NE)
		       (W E)
		       (NW  SE)
		       (EQ EQ))
  
  :base-relations (N NE E SE S SW W NW EQ)
  :composition-operation ((N N N)
			  (N S (N EQ S))
			  (N E NE)
			  (N W NW)
			  (N NE NE)
			  (N NW NW)
			  (N SE (SE E NE))
			  (N SW (SW W NW))
			  (N EQ N)
			  (S N (S EQ N))
			  (S S S)
			  (S E SE)
			  (S W SW)
			  (S NE (SE E NE))
			  (S NW (SW W NW))
			  (S SE SE)
			  (S SW SW)
			  (S EQ S)
			  (E N NE)
			  (E S SE)
			  (E E E)
			  (E W (W EQ E))
			  (E NE NE)
			  (E NW (NW N NE))
			  (E SE SE)
			  (E SW (SW S SE))
			  (E EQ E)
			  (W N NW)
			  (W S SW)
			  (W E (W EQ E))
			  (W W W)
			  (W NE (NW N NE))
			  (W NW NW)
			  (W SE (SW S SE))
			  (W SW SW)
			  (W EQ W)
			  (NE N NE)
			  (NE S (SE E NE))
			  (NE E NE)
			  (NE W (NW N NE))
			  (NE NE NE)
			  (NE NW (NW N NE))
			  (NE SE (SE E NE))
			  (NE SW (N S E W NE NW SE SW EQ))
			  (NE EQ NE)
			  (NW N NW)
			  (NW S (SW W NW))
			  (NW E (NW N NE))
			  (NW W NW)
			  (NW NE (NW N NE))
			  (NW NW NW)
			  (NW SE (N S E W NE NW SE SW EQ))
			  (NW SW (SW W NW))
			  (NW EQ NW)
			  (SE N (SE E NE))
			  (SE S SE)
			  (SE E SE)
			  (SE W (SW S SE))
			  (SE NE (SE E NE))
			  (SE NW (N S E W NE NW SE SW EQ))
			  (SE SE SE)
			  (SE SW (SW S SE))
			  (SE EQ SE)
			  (SW N (SW W NW))
			  (SW S SW)
			  (SW E (SW S SE))
			  (SW W SW)
			  (SW NE (N S E W NE NW SE SW EQ))
			  (SW NW (SW W NW))
			  (SW SE (SW S SE))
			  (SW SW SW)
			  (SW EQ SW)
			  (EQ N N)
			  (EQ S S)
			  (EQ E E)
			  (EQ W W)
			  (EQ NE NE)
			  (EQ NW NW)
			  (EQ SE SE)
			  (EQ SW SW)
			  (EQ EQ EQ)
			  )

  ;; THIS IS NOT A GOOD TRACTABLE SUBSET: TRACTABLE BUT NOT MAXIMAL
  :tractable-subsets ((() (e) (eq) (n) (ne) (nw) (n ne nw) (s) (eq n s) (se) (e ne se) (sw) (s se sw) (w) (e eq w) (nw sw w) (e eq n ne nw s se sw w))) 

  :cnhs ( ((default def 8neighbor 8nb)
	   ( (N  (EQ NE NW))
	     (NW (EQ N W))
	     (W  (EQ NW SW))
	     (SW (EQ W S))
	     (S  (EQ SW SE))
	     (SE (EQ S E))
	     (E  (EQ SE NE))
	     (NE (EQ E N))
	     (EQ (N NW W SW S SE E NE)) ))
	 
	  ((goyal condotta 4neighbor 4nb)
	   ( (N  (EQ NE NW))
	     (NW (N W))
	     (W  (EQ NW SW))
	     (SW (W S))
	     (S  (EQ SW SE))
	     (SE (S E))
	     (E  (EQ SE NE))
	     (NE (E N))
	     (EQ (N W S E)) )) )
)


