Re: library(graph_algorithms)

From: Andrew John Sadler <ajs2_at_icparc.ic.ac.uk>
Date: Tue 11 Nov 2003 11:13:10 AM GMT
Message-Id: <E1AJWSM-0004Z9-Lc@tempest.icparc.ic.ac.uk>
> 
> Dear all,
> 
> 
> 
> Is there anybody who has implemented (and is willing to share) predicates
> for incrementally constructing/destructing graphs that are compatible with
> the ones in the library graph_algorithms? The kind of operations that I'm
> looking for are for adding/removing nodes/arcs. I Know I can do this by
> transforming to lists of edges, modifying the edges and reconstructing the
> graph from scrathc but I was hoping for something a bit better:-)

If you only want to add/remove edges you can try these predicates.
They're reasonably efficient, though in no way supported by the
ECLiPSe team, nor are they guaranteed to work in any future (or past)
versions of ECLiPSe.

Also note, that some operations may take longer once a graph has been
modified (get_incoming_edges/3).  Also note that tools like the
Visualisation Client will NOT be notified of such changes to the graph
structure.

% add an edge
graph_add_edge(G, Edge):-
        Edge=e(S,_T,_Info),
        arg(2,G,Adj),
        SEdgesOld is Adj[S],
        SEdgesNew = [Edge|SEdgesOld],
        setarg(S,Adj,SEdgesNew),
        setarg(3,G,_),   % remove the optional incoming edges array
        true.


% remove an edge
graph_remove_edge(G, Edge):-
        Edge=e(S,_T,_Info),
        arg(2,G,Adj),
        SEdgesOld is Adj[S],
        once(delete(Edge, SEdgesOld, SEdgesNew)),
        setarg(S,Adj,SEdgesNew),
        setarg(3,G,_),   % remove the optional incoming edges array
        true.

PS. It is probably not a good idea to modify the graph in this way
whilst any resatisfiable predicates are running on the graph.


Andrew Sadler
Received on Tue Nov 11 11:18:18 2003

This archive was generated by hypermail 2.1.8 : Wed 16 Nov 2005 06:07:26 PM GMT GMT