title: Trying to obtain cost for a given path
body: <p>I am new to Prolog</p>
  
  <p>I am trying in Prolog a rule that gives me a given path from a node to another and also gives me the total weight of the path.</p>
  
  <p>I have succeeded to get all the edges of the path but I am not able to show the weight of the path. I debbuged it and it is seen that variable S adds up to the whole weight of the path but in the way back, deletes all the elements. My idea is to add the total weight to P.</p>
  
  <p>Code:</p>
  
  <pre><code>notIn(A,[]).
  notIn(A,[H|T]):- A\==H,notIn(A,T).
  
  path(X,X,_,[], S, P).
  path(X,Y,[X|Cs], S, P) :-
      path(X,Y,[X],Cs, S, P), P is S+W.
  path(X,Y,Visited,[Z|Cs], S, P) :-
      connection(X,Z,W),
      notIn(Z,Visited),
      path(Z,Y,[Z|Visited],Cs, S+W, P).
  
  ? path(ori, dest, X, 0, P).
  </code></pre>