1

enter image description here

Hello, I have basic knowledge about prolog and I am facing problems in writing the prolog code for the following problem: Write the fact about the above figure and write the following prolog rule: pos_path.

Sample run of the rule:

?- pos_path(n1, nx, L). 
L = [n1,n3,n7,nx] ? ; 
L = [n1,n3,n4,n5,nx] ? ; 
L = [n1,n3,n4,n6,nx] ? ; 
no
false
  • 10,264
  • 13
  • 101
  • 209
KikoPayet
  • 11
  • 4
  • 1
    Please show what you've tried so far and ask a more specific question about where you're stuck. – lurker Apr 23 '16 at 04:10

1 Answers1

2
edge(ne,n1).
edge(n1,n2).
edge(n1,n3).
edge(n3,n7).
edge(n7,nx).
edge(n3,n4).
edge(n4,n5).
edge(n5,nx).
edge(n4,n6).
edge(n6,nx).

pos_path(A, B, Path) :-
   path(edge, Path, A, B).

using path/4 defined in another question.

Community
  • 1
  • 1
false
  • 10,264
  • 13
  • 101
  • 209
  • how can I add an extra edge that connects n6 to n3. How should the representation of this fact be ? and how pos_path should be modified ? – KikoPayet Apr 23 '16 at 20:39
  • 1
    Simply add `edge(n6,n3)`. No modification is needed for above definition! – false Apr 23 '16 at 20:56