How can I find all way to go end in undirected graph ?
Graph :
Node : S, Y, F, T visualization : S ----- Y ---- T
Edge : S --- Y \ /
Y --- F \ /
S --- F \ /
Y --- T F
Assume that
Start S
Finish F
after run go
result will be :
S F
S Y F
I do not want visit one node more than once. If I visit, this problem become one of NP problems.
EDIT:
input can be any form
example:
edge (S,Y). OR edge (Y,S).
edge (Y,F). edge (F,Y).
edge (S,F). edge (F,S).
edge (Y,T). edge (T,Y).
BUT OUTPUT MUST BE SAME
Keep a trace of the visited nodes and exclude those when adding the possible destinations in the next step.
I changed a few edges and added one, to make sure it also works when edges are listed in the ‘wrong’ order for going from S to F.
In prolog this should roughly look like this:
You can use
;to manually find all the solutions, or findall.