1
votes

I have a graph with edges in Prolog. I'm representing the graph as a set of prolog facts. Where e.g. s(a,b,2). = b is the successor of a. Here are my facts in prolog for this graph.

Graph rep

Facts:

s(a,b,2).
s(a,c,1).
s(b,e,4).
s(b,g,2).
s(c,d,1).
s(c,x,3).
s(x,g,1).
goal(g).

Am I missing a fact here? s(e,g,1). Where g is the successor of e? Or does it even get searched on this node as "b" only has 2 branches "e" & "g". Can someone please explain this to me? Thanks

1
After typing it here, I think I understand why. Node "b" gets fully explored/visited, so no need to move to next node "e"? As it's explored fully?cala
if you want your facts to faithfully reflect the picture, they should faithfully reflect the picture. s(b,g,2). s(e,g,1). is in the picture. s(b,g,1) is not in the picture.Will Ness
@WillNess good spot. Matching up nowcala

1 Answers

1
votes

We can enumerate the graph for example in a breadth-first [Wiki] fashion, and thus determine that the edges are:

s(a, b, 2).
s(a, c, 1).
s(b, e, 4).
s(b, g, 2),
s(c, d, 1).
s(c, x, 3).
s(e, g, 1).
s(x, g, 1).
goal(g).

If we look at the original source code. The s(e, g, 1). part was missing.