Computational Philosophy / Continuing On

Continuing On

Planning should be done to ensure the health of an individual.
The following algorithm lists a particular safe route from a point to ensure health is protected. Given a starting point, a destination point, list of paths from that point, it chooses the path reaching the desired point.
%% findpath(Start,End,Max_steps,Path_links,Path)
%% Finds a Path from Start to End in under Max_steps using the Path_links

%% findpath([0,0],[1,1],3,[[[0,0],[1,0]],[[1,0],[1,1]]],Path).
%% Path = [[0, 0], [1, 0], [1, 1]] ;

findpath(Start,End,Max_steps,Path_links,Path) :-
findpath(Start,End,Path_links,_,[Start],Path),
length(Path,Steps), Max_steps>=Steps.

%% findpath(Start,End,Path_links1,Pathlinks2,Path1,Path2)
%% Finds a Path from Start to End using the given Path_links1, returning the new
%% Path_links, is given Path1, and returns Path2

findpath(End,End,_,_,Path,Path).
findpath(Start,End,Path_links1,Path_links3,Path1,Path2) :-
findnextstep(Path_links1,Start,Next,Path_links2),
append(Path1,[Next],Path3),
findpath(Next,End,Path_links2,Path_links3,Path3,Path2).

%% findnextstep(Path_links,Start,Next,Pathlinks2)
%% Finds the next possible step, Next, starting at Start, from Path_links and returns
%% Path_links2

findnextstep(Path_links1,Start,Next,Path_links2) :-
delete(Path_links1,[Start,Next],Path_links2).
findnextstep(Path_links,Start,Next,Pathlinks2) :-
delete(Path_links1,[Next,Start],Path_links2).

A thought is an object could have dropped on the ground. The following algorithm finds where the object is on the ground. If an object matching the given object�s area is found, it returns true.

%% find_object(Descriptions,Area,Identity)
%% Finds an object's number for an object with a certain Area from Descriptions, which is a list of object number, bottom-left corner and top-right corner
%% find_object([[0,[0,0],[1,1]],[1,[0,2],[1,4]]],1,Identity).
%% Identity = 0;

find_object(Descriptions,Area,Identity) :-
find_areas(Descriptions,[],Areas),
member([Identity,Area],Areas).

%% find_areas(Descriptions,Areas1,Areas2)
%% Calculates the areas of object described in Descriptions, adds them to Areas1 and
%% returns Areas2

find_areas([],Areas,Areas).
find_areas([[Identity,[X1,Y1],[X2,Y2]]|Descriptions],Areas1,Areas2) :-
Area is (X2-X1)*(Y2-Y1), append(Areas1,[[Identity,Area]],Areas3),
find_areas(Descriptions,Areas3,Areas2).


Hosted by www.Geocities.ws

1