Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

member predicate 1

Status
Not open for further replies.

misoijnr

Programmer
Nov 17, 2010
32
BE
hi, help me put this predicate into perspective, was trying to make one to find path on the facts attached.

findpath(Dest,L) :-
find_route(node(NodeID), Dest, L.
findpath(S, Dest, Sol) :-
way(S, Dest, , Path),
invert(Path, Sol).

path( P, P, L, L).
path( Node, Goal, Path, Sol) :-
route( Node, WayID), not( way(WayID) ),
not( member( WayID, Path)),
path( WayID, Goal, [WayID | Path], Sol).

member(X,[X|Xs]).
member(X,[_|Ys]) :- member(X,Ys).

node(NodeID) :- member(NodeID, [lat,long]).
node_tag(NodeID) :- member(NodeID,[name,highway,add:street,crossing,crossing_ref]).
way(WayID) :- member(WayID, Nodelist).
way_tag(WayID):-member(WayID,[name,highway,foot,maxspeed,lanes,oneway,bridge])
 
hi kahleen,

i am re-writing the get_path predicate below to take into account iterative deepening also to avoid loop or for loop detection, also, am trying to include lenght as a cost to the search space. however, can i use the edge facts i generated earlier ? check the code below, it tries to analyse paths that have been visited so that it does not loop. advise.

% depth-first search with loop detection
get_path([Path|Rest],Visited,Path):-
path(Path).
get_path([Current|Rest],Visited,Path):-
node(X,Y),
add_path(Y,Rest,Visited,NewPaths),
get_path(NewPaths,[Current|Visited],Path).
add_path([],Paths,Visited,Paths).
add_path([X|Rest],OldPaths,Visited,[X|NewPath]):-
not edge(X,OldPaths),
not edge(X,Visited),
add_path(Rest,OldPaths,Visited,NewPaths).
add_path([X|Rest],OldPaths,Visited,NewPaths):-
edge(X,OldPaths),
add_path(Rest,Oldpaths,Visited,NewPaths).
add_path([X|Rest],OldPaths,Visited,NewPaths):-
edge(X,Visited),
add_path(Rest,OldPaths,Visited,NewPaths).
 
how should i avoid singleton variables from the above code, seems am getting that error
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top