/**************************************
Buffer example:

Given a map of road I-80, given hotel's location.
Also given Exit locations on the road.

From GPS ( Global Point System) , we know that 
our car is currently at location ( 251, 377.77).

We want to ask : 
1. Which hotel is less than 25 miles
				far from us and at the south of the 
				road?
2. Which exit is the nearest exit from our current location? 

***************************************/ 

begin%road%
/*R(1, x, y):- x >= 0, x <= 500,
				y >= 0, y <= 500.

Current_Pos(Name, x,y) :- Name=1, x= 176, y=175.574.
*/

Current_Pos(Name, x,y) :- Name=1,  
                                  x>= 172, x<=180,
                                  y>=172, y <= 180.

Road(80, x, y):-  -65x + 132y = 13295,
					x >= 29, x <= 161.

Road(80, x, y):- 54x + 183y = 41634,
					x >= 161, x <= 344.

Road(80, x, y):- -164x + 140y = -38776,
				x >= 344, x <= 484.



 


Exit(409, x, y):- x = 231, y>= 152.344, y<=165.344.
Exit(410, x, y):- x = 307, y>= 130.918, y<=140.918.
Exit(411, x, y):- x = 340, y>= 120.18, y <=132.18.

Hotel(1, x, y):- x >= 174, x<=177, y >= 191.5, y <= 192.5.
Hotel(2, x, y):- x >= 248.2, x<= 250.2, y>= 176.3, y <= 177.3.
Hotel(3, x, y):- x >= 258, x<=260, y >= 126.1, y <= 128.1.
Hotel(4, x, y):- x >= 327.5, x<= 329.5, y >= 140.7, y<=143.7.
Hotel(5, x, y):- x >= 376.5, x<= 379.5, y >= 126.7, y<=129.7.

Nearest_Exit(id, MIN(x)):- x - x0 >= 0,
			   Current_Pos(id2, x0, y0),
			   Exit(id, x, y).

Buf_Nearest_Exit(id, x, y) :- 
id = 409,
x +0.41 y <= 346.45,
x +2.41 y <= 733.16,
-x +2.41 y <= 271.16,
-x +0.41 y <= -115.55,
-x -0.41 y <= -246.45,
-x -2.41 y <= -491.73,
x -2.41 y <= -29.73,
x -0.41 y <= 215.55.

Convenient_Hotel(id,x,y) :-  Hotel(id, x, y), 
                         Buf_Nearest_Exit(id1, x, y).
		   
end%road%	