Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- route(a,d,1).
- route(a,h,1).
- route(a,b,1).
- route(b,e,1).
- route(b,c,1).
- route(c,f,1).
- route(c,e,1).
- route(f,i,1).
- route(f,h,1).
- route(e,d,1).
- route(d,g,1).
- route(g,j,1).
- route(g,l,1).
- route(h,k,1).
- route(i,k,1).
- route(i,l,1).
- route(j,m,1).
- route(j,o,1).
- route(k,n,1).
- route(l,m,1).
- route(l,o,1).
- route(m,n,1).
- route(n,o,1).
- ha_path(A, B) :-route(A, B, _), !.
- ha_path(A, B) :-route(A, X, _), ha_path(X, B).
- %--------------------------------------------------------
- crossing(A, B,Visited,[B|Visited]) :-route(A, B,_).
- crossing(A, B, Visited, Cam) :-route(A, C, _),
- C == B,
- + member(C, Visited),
- crossing(C, B, [C|Visited], Cam).
- %------------------------------------------------
- %Find the ways and the cost between two nodes.
- path(A, B, Cam) :- crossing(A, B, [A], Cam).
- paths(A, B, Lc) :-setof(Cam, path(A, B, Cam), Lc), !.
- paths(_,_,[]).
- costPath(A, B, Cam, Cost) :-crossingCost(A, B, [A], Cam, Cost).
- crossingCost(A, B, Visited,[B|Visited],Cost1) :-route(A, B, Cost1).
- crossingCost(A, B, Visited, Cam, Cost) :-route(A, C, Cost2)
- ,C == B,+ member(C, Visited)
- ,crossingCost(C, B, [C|Visited], Cam, CostResto)
- ,Cost is Cost2 + CostResto.
- %----------------------------------------------------
- %Find the paths and cost between two points.
- costPaths(A, B, Lc) :-
- setof(Cam/Cost,costPath(A,B,Cam,Cost), Lc), !.
- costPaths(_,_,[]).
- %---------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement