cala
cala

Reputation: 1421

Prolog graph representation missing fact

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

Upvotes: 1

Views: 77

Answers (1)

willeM_ Van Onsem
willeM_ Van Onsem

Reputation: 476503

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.

Upvotes: 1

Related Questions