0

Im new at Prolog , and I am trying some manipulation on graphs .

I have a problem in my implementation, and since it is very long and complicated to expose , I will give a simple and similar problem .

Let say we have the following graph :

edge(a,e).
edge(e,d).
edge(d,c).
edge(c,b).
edge(b,a).
edge(d,a).
edge(e,c).
edge(f,b).

And I wanted to make this graph bidirected . I use the following code :

graph(Graph):-findall(A-B, edge(A,B), L),
    findall(B-A, edge(A,B), L1),
    append(L, L1, Graph).

when executing the query I get this result :

?- graph(Graph).
Graph = [a-e, b-a, c-b, d-a, d-c, e-c, e-d, f-b, ... - ...|...].

My problem is not in the code my problem is in the results as you can see I don't get the complete results, its always giving me only 8 edges and the rest are not shown.

How to solve this ?

false
  • 10,264
  • 13
  • 101
  • 209
StamDad
  • 135
  • 8

1 Answers1

0
graph(Graph),writeln(Graph).

writeln/1 writes out the entire variable to the output.

From @WillemVanOnsem

If you write graph(G);true. then the program will pause after the first statement. Next you can hit W and it will again write the answer but now in full.

Jim Ashworth
  • 765
  • 6
  • 17
  • ` ?- graph(Graph),writeln(Graph).` `[a-e,b-a,c-b,d-a,d-c,e-c,e-d,f-b,a-b,a-d,b-c,b-f,c-d,c-e,d-e,e-a]` `Graph = [a-e, b-a, c-b, d-a, d-c, e-c, e-d, f-b, ... - ...|...]. ` – StamDad Mar 09 '17 at 17:10
  • Thank you for the answer – StamDad Mar 09 '17 at 17:12
  • yes problem solved .... I just want to ask this , is there any way to get or to trnsform the results from prolog into a graphic representation (get the nodes and the connexions edges ) ? – StamDad Mar 09 '17 at 17:54
  • @StambouliA.ouadoud That would be a new question, but I think there is? Ask a new question and someone will know. – Jim Ashworth Mar 09 '17 at 17:56