If I have a list of edges for a problem like "Show me the routes from a city that is considered dangerous to one that is considered safe" as so...
dangerous(oakland).
safe(portland).
move(rome,plane,portland).
move(portland,plane,rome).
move(halifax,train,gatwick).
move(gatwick,car,rome).
move(portland,plane,newyork).
move(oakland,plane,rome).
move(oakland,plane,gatwick).
move(halifax,train,gatwick).
move(gatwick,plane,rome).
move(oakland,train,newyork).
I can get a list of Paths that lead to a safe city by using the following depth first search(found on SO)...
dfs_start(Start, Goal, Path) :- phrase(dfs(Start, [], Goal), Path).
dfs(Node, _, Goal) --> [Node], { call(Goal, Node) }.
dfs(Node0, Es, Goal) --> [Node0],
{ move(Node0,_,Node1), \+ member(Node1, Es) },
dfs(Node1, [Node0|Es], Goal).
The problem I'm trying to solve however is to find all of the Paths from dangerous cities that do NOT lead to a safe city (which in this case would only be one oakland -> newyork.) If I call the above function with...
dfs_start(oakland,safe,Path).
...I get
Path = [oakland, rome, portland] ;
Path = [oakland, gatwick, rome, portland] ;
Path = [oakland, gatwick, rome, portland] ;
...but what I'm looking to do is call something like...
dfs_start(oakland,unsafe,Path).
...and get...
Path = [oakland, newyork] ;
Any advice would be greatly appreciated!