library(ugraphs)
Nicos Angelopoulos <[email protected]>
| Newsgroups | gmane.comp.ai.prolog.swi |
|---|---|
| Organization | stoics.org.uk |
| Message-ID | <[email protected]> |
Dear all, 1. library(ugraphs) seems to have lost documentation for a number of its predicates- http://www.swi-prolog.org/pldoc/doc/swi/library/ugraphs.pl probably due to a very recent change as my local spuds server had full documentation until the last update from pl-devel 2. i am not sure if this is of general enough interest to be included in the library, but i recently coded a sub_graphs/2 predicate this includes a use case for the ord_select/3 predicate discussed previously Regards, Nicos Angelopoulos --- http://stoics.org.uk/~nicos/ :- requires(ord_select/3). %% sub_graphs(+Graph, -Subs). % % Subs is all disconnected subgraphs in Graph % % == % sub_graphs([1-[2,3],2-[3],3-[4],4-[],5-[6,7],6-[],7-[6]], Subs). % % Subs = [[1-[2, 3], 2-[3], 3-[4], 4-[]], [5-[6, 7], 6-[], 7-[6]]]. % == % % @author nicos angelopoulos % @version 0.1 2014/02/12 % sub_graphs([], []). sub_graphs(Graph, [Removed|TSubs]) :- \+ var(Graph), % can be moved to an outer wrapper, or removed Graph = [Vertex-_|_], reachable(Vertex, Graph, Vertices), select_vertex_entries(Graph, Vertices, Removed, Reduced), sub_graphs(Reduced, TSubs). %% del_vertex_entries(+Graph, +Vertices, -Removed, -Reduced). % % Delete the entries for a set of Vertices from Graph. % This differs from del_vertices/3, in that it does not remove edges and also % returns what was removed. The main use case for this predicate, % is for when we are removing whole isolated sub graphs. % It probably best, it should be kept away from library interfaces. % This version fails if one of the Vertices is not in Graph. % % @author nicos angelopoulos % @version 0.1 2014/02/12 % select_vertex_entries([], [], [], []). % test 2nd arg if you want to throw error. select_vertex_entries([V-Edged|T], Vertices, Removed, Reduced) :- ord_select(Vertices, V, RemVertices), !, Removed = [V-Edged|TRemoved], select_vertex_entries(T, RemVertices, TRemoved, Reduced). select_vertex_entries([V-Edged|T], Vertices, Removed, [V-Edged|TReduced]) :- select_vertex_entries(T, Vertices, Removed, TReduced).