Re: Recursion and how to construct a graph? (What is the boundary condition?)

Carlo Capelli <[email protected]>
Newsgroups gmane.comp.ai.prolog.swi
Message-ID <CABty9wxH6AszdSRR2iUdnEDh6MOBxEBJ3C1S5SOANUm-yZP9hA@mail.gmail.com>
Hi Ben

take a look at library(ugraph), specifically
vertices_edges_to_ugraph<http://www.swi-prolog.org/pldoc/doc_for?object=vertices_edges_to_ugraph/3>
.

I have a loosely related note: you graph is already 'built', just in an
alternative format.
Which format to prefer depends from the task: for instance RDF more
resembles the edge/2 representation than a list.


bye Carlo


2013/8/30 Ben Engbers <[email protected]>

> I have found lots of examples on how to construct a path through a
> graph, but I didn't find any examples on how to construct the graph
> itselfand that's exactly what I need to do..
>
> I have a set of edges, all in the form edge( from, to, value) and I want
> to construct a graph (list) for which 'from' is member.
> Length(Graph) has to be >2.
>
> In pseudocode I wanted to do this:
>
> construct_graph( X, Graph) :-
>   If \+member(X, Graph) Then construct_graph(X, [X|Graph]). /* Add X to
> the graph, Recursion */
>
> construct_graph( X, Graph) :-
>    edge( X, To, Value), construct_graph( To, Graph), /* all the edges
> for which X is starting point
>    edge( To, X, Value), construct_graph( To, Graph). /* all the edges
> for which X is end point
>
> construct_graph( X, Graph) :-
>    \+edge( X, _, _). /* X is not starting point for other edges.
>
>
> In all the examples that I see for recursion, the ending boundary
> condition is the first clause.
> In my pseudocode, the ending boundary condition is the last clause.
>
> My question is if this approach will work?
>
> Ben Engbers
> _______________________________________________
> SWI-Prolog mailing list
> [email protected]
> https://lists.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog
>
-------------- next part --------------
HTML attachment scrubbed and removed
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.