improve graphs a bit.
git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@2285 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
parent
bcfa65e227
commit
0dd1ed933e
106
Makefile.in
106
Makefile.in
@ -562,17 +562,17 @@ mycb: $(srcdir)/mycb.c
|
||||
$(CC) $(CFLAGS) $(srcdir)/mycb.c -o mycb
|
||||
|
||||
all: startup
|
||||
@INSTALL_DLLS@ (cd library/random; make)
|
||||
@INSTALL_DLLS@ (cd library/regex; make)
|
||||
@INSTALL_DLLS@ (cd library/rltree; make)
|
||||
@INSTALL_DLLS@ (cd library/system; make)
|
||||
@INSTALL_DLLS@ (cd library/tries; make)
|
||||
@INSTALL_DLLS@ (cd library/rltree; make)
|
||||
@INSTALL_DLLS@ (cd library/lammpi; make)
|
||||
@INSTALL_DLLS@ (cd library/matrix; make)
|
||||
@INSTALL_MATLAB@ (cd library/matlab; make)
|
||||
@ENABLE_JPL@ @INSTALL_DLLS@ (cd LGPL/JPL/src; make)
|
||||
@ENABLE_CPLINT@ (cd cplint; make)
|
||||
@INSTALL_DLLS@ (cd library/random; $(MAKE))
|
||||
@INSTALL_DLLS@ (cd library/regex; $(MAKE))
|
||||
@INSTALL_DLLS@ (cd library/rltree; $(MAKE))
|
||||
@INSTALL_DLLS@ (cd library/system; $(MAKE))
|
||||
@INSTALL_DLLS@ (cd library/tries; $(MAKE))
|
||||
@INSTALL_DLLS@ (cd library/rltree; $(MAKE))
|
||||
@INSTALL_DLLS@ (cd library/lammpi; $(MAKE))
|
||||
@INSTALL_DLLS@ (cd library/matrix; $(MAKE))
|
||||
@INSTALL_MATLAB@ (cd library/matlab; $(MAKE))
|
||||
@ENABLE_JPL@ @INSTALL_DLLS@ (cd LGPL/JPL/src; $(MAKE))
|
||||
@ENABLE_CPLINT@ (cd cplint; $(MAKE))
|
||||
|
||||
startup: yap@EXEC_SUFFIX@ $(PL_SOURCES)
|
||||
-rm -f startup
|
||||
@ -603,18 +603,18 @@ install_unix: startup libYap.a
|
||||
mkdir -p $(DESTDIR)$(SHAREDIR)/Yap/pl
|
||||
mkdir -p $(DESTDIR)$(SHAREDIR)/Yap/swi
|
||||
for f in $(PL_SOURCES); do $(INSTALL) $$f $(DESTDIR)$(SHAREDIR)/Yap/pl; done
|
||||
@INSTALL_DLLS@ (cd library/random; make install)
|
||||
@INSTALL_DLLS@ (cd library/regex; make install)
|
||||
@INSTALL_DLLS@ (cd library/rltree; make install)
|
||||
@INSTALL_DLLS@ (cd library/system; make install)
|
||||
@INSTALL_DLLS@ (cd library/tries; make install)
|
||||
@INSTALL_DLLS@ (cd library/lammpi; make install)
|
||||
@INSTALL_DLLS@ (cd library/matrix; make install)
|
||||
@INSTALL_MATLAB@ (cd library/matlab; make install)
|
||||
@ENABLE_JPL@ @INSTALL_DLLS@ (cd LGPL/JPL/src; make install)
|
||||
@INSTALL_DLLS@ (cd library/random; $(MAKE) install)
|
||||
@INSTALL_DLLS@ (cd library/regex; $(MAKE) install)
|
||||
@INSTALL_DLLS@ (cd library/rltree; $(MAKE) install)
|
||||
@INSTALL_DLLS@ (cd library/system; $(MAKE) install)
|
||||
@INSTALL_DLLS@ (cd library/tries; $(MAKE) install)
|
||||
@INSTALL_DLLS@ (cd library/lammpi; $(MAKE) install)
|
||||
@INSTALL_DLLS@ (cd library/matrix; $(MAKE) install)
|
||||
@INSTALL_MATLAB@ (cd library/matlab; $(MAKE) install)
|
||||
@ENABLE_JPL@ @INSTALL_DLLS@ (cd LGPL/JPL/src; $(MAKE) install)
|
||||
mkdir -p $(DESTDIR)$(INCLUDEDIR)
|
||||
for h in $(INTERFACE_HEADERS); do $(INSTALL) $$h $(DESTDIR)$(INCLUDEDIR); done
|
||||
@ENABLE_CPLINT@ (cd cplint; make install)
|
||||
@ENABLE_CPLINT@ (cd cplint; $(MAKE) install)
|
||||
|
||||
|
||||
install_win32: startup
|
||||
@ -633,34 +633,34 @@ install_win32: startup
|
||||
$(INSTALL) $(HEADERS) $(DESTDIR)$(INCLUDEDIR)
|
||||
for h in $(INTERFACE_HEADERS); do $(INSTALL) $$h $(DESTDIR)$(INCLUDEDIR); done
|
||||
$(INSTALL) config.h $(INCLUDEDIR)/config.h
|
||||
(cd library/random; make install)
|
||||
(cd library/matrix; make install)
|
||||
(cd library/regex; make install)
|
||||
(cd library/rltree; make install)
|
||||
(cd library/system; make install)
|
||||
@ENABLE_WINCONSOLE@ (cd LGPL/swi_console; make install)
|
||||
@INSTALL_MATLAB@ (cd library/matlab; make install)
|
||||
(cd library/tries; make install)
|
||||
@ENABLE_CPLINT@ (cd cplint; make install)
|
||||
(cd library/random; $(MAKE) install)
|
||||
(cd library/matrix; $(MAKE) install)
|
||||
(cd library/regex; $(MAKE) install)
|
||||
(cd library/rltree; $(MAKE) install)
|
||||
(cd library/system; $(MAKE) install)
|
||||
@ENABLE_WINCONSOLE@ (cd LGPL/swi_console; $(MAKE) install)
|
||||
@INSTALL_MATLAB@ (cd library/matlab; $(MAKE) install)
|
||||
(cd library/tries; $(MAKE) install)
|
||||
@ENABLE_CPLINT@ (cd cplint; $(MAKE) install)
|
||||
|
||||
install_library: @YAPLIB@
|
||||
mkdir -p $(DESTDIR)$(INCLUDEDIR)
|
||||
for h in $(HEADERS); do $(INSTALL) $$h $(DESTDIR)$(INCLUDEDIR); done
|
||||
|
||||
install_data:
|
||||
(cd library ; make install)
|
||||
(cd LGPL ; make install)
|
||||
(cd GPL ; make install)
|
||||
@ENABLE_JPL@ (cd LGPL/JPL ; make install)
|
||||
@ENABLE_JPL@ (cd LGPL/JPL/java; make install)
|
||||
(cd library ; $(MAKE) install)
|
||||
(cd LGPL ; $(MAKE) install)
|
||||
(cd GPL ; $(MAKE) install)
|
||||
@ENABLE_JPL@ (cd LGPL/JPL ; $(MAKE) install)
|
||||
@ENABLE_JPL@ (cd LGPL/JPL/java; $(MAKE) install)
|
||||
$(INSTALL_DATA) $(srcdir)/LGPL/pillow/icon_address.pl $(DESTDIR)$(SHAREDIR)/Yap/
|
||||
$(INSTALL_DATA) $(srcdir)/LGPL/pillow/pillow.pl $(DESTDIR)$(SHAREDIR)/Yap/
|
||||
# (cd CLPQR ; make install)
|
||||
@INSTALLCLP@(cd LGPL/clp ; make install)
|
||||
@INSTALLCLP@(cd GPL/clpqr ; make install)
|
||||
# (cd CHR ; make install)
|
||||
@INSTALLCLP@(cd LGPL/chr ; make install)
|
||||
@INSTALLCLP@(cd CLPBN ; make install)
|
||||
# (cd CLPQR ; $(MAKE) install)
|
||||
@INSTALLCLP@(cd LGPL/clp ; $(MAKE) install)
|
||||
@INSTALLCLP@(cd GPL/clpqr ; $(MAKE) install)
|
||||
# (cd CHR ; $(MAKE) install)
|
||||
@INSTALLCLP@(cd LGPL/chr ; $(MAKE) install)
|
||||
@INSTALLCLP@(cd CLPBN ; $(MAKE) install)
|
||||
|
||||
|
||||
##########
|
||||
@ -677,16 +677,16 @@ depend: $(HEADERS) $(C_SOURCES)
|
||||
|
||||
clean: clean_docs
|
||||
rm -f *.o *~ *.BAK *.a
|
||||
@INSTALL_DLLS@ (cd library/matrix; make clean)
|
||||
@INSTALL_DLLS@ (cd library/random; make clean)
|
||||
@INSTALL_DLLS@ (cd library/regex; make clean)
|
||||
@INSTALL_DLLS@ (cd library/system; make clean)
|
||||
@INSTALL_DLLS@ (cd library/rltree; make clean)
|
||||
@INSTALL_DLLS@ (cd library/tries; make clean)
|
||||
@INSTALL_DLLS@ (cd library/lammpi; make clean)
|
||||
@INSTALL_MATLAB@ (cd library/matlab; make clean)
|
||||
@ENABLE_JPL@ @INSTALL_DLLS@ (cd LGPL/JPL/src; make clean)
|
||||
@ENABLE_CPLINT@ (cd cplint; make clean)
|
||||
@INSTALL_DLLS@ (cd library/matrix; $(MAKE) clean)
|
||||
@INSTALL_DLLS@ (cd library/random; $(MAKE) clean)
|
||||
@INSTALL_DLLS@ (cd library/regex; $(MAKE) clean)
|
||||
@INSTALL_DLLS@ (cd library/system; $(MAKE) clean)
|
||||
@INSTALL_DLLS@ (cd library/rltree; $(MAKE) clean)
|
||||
@INSTALL_DLLS@ (cd library/tries; $(MAKE) clean)
|
||||
@INSTALL_DLLS@ (cd library/lammpi; $(MAKE) clean)
|
||||
@INSTALL_MATLAB@ (cd library/matlab; $(MAKE) clean)
|
||||
@ENABLE_JPL@ @INSTALL_DLLS@ (cd LGPL/JPL/src; $(MAKE) clean)
|
||||
@ENABLE_CPLINT@ (cd cplint; $(MAKE) clean)
|
||||
|
||||
|
||||
|
||||
@ -712,7 +712,7 @@ yap.dll: libYap.a
|
||||
-Wl,--no-whole-archive $(LIBS) $(LDFLAGS)
|
||||
|
||||
install_info:
|
||||
make info; \
|
||||
$(MAKE) info; \
|
||||
$(INSTALL) yap.info* $(DESTDIR)$(INFODIR); \
|
||||
if test -e $(DESTDIR)$(INFODIR)/emacs.bz2; then \
|
||||
bzip2 --quiet --force $(DESTDIR)$(INFODIR)/yap.info*; \
|
||||
@ -765,7 +765,7 @@ realclean_docs: clean_docs
|
||||
rm -f yap.ps yap.html yap_toc.html yap.pdf yap.info*
|
||||
|
||||
installcheck:
|
||||
@ENABLE_CPLINT@ (cd cplint; make installcheck)
|
||||
@ENABLE_CPLINT@ (cd cplint; $(MAKE) installcheck)
|
||||
|
||||
# DO NOT DELETE THIS LINE -- make depend depends on it.
|
||||
|
||||
|
@ -15,8 +15,9 @@
|
||||
|
||||
<h1>Changes in YAP-5.1</h1>
|
||||
|
||||
<h2>Yap-5.1.3:</h2>
|
||||
<h2>Yap-5.1.4:</h2>
|
||||
<ul>
|
||||
<li> NEW: dgraph_reachable/3 and friends.</li>
|
||||
</ul>
|
||||
|
||||
|
||||
|
116
docs/yap.tex
116
docs/yap.tex
@ -11197,6 +11197,13 @@ Edge @var{N1}-@var{N2} is an edge in directed graph @var{Graph}.
|
||||
Unify @var{Edges} with all edges appearing in graph
|
||||
@var{Graph}.
|
||||
|
||||
@item dgraph_add_vertices(+@var{Graph}, +@var{Vertex}, -@var{NewGraph})
|
||||
@findex dgraph_add_vertex/3
|
||||
@snindex dgraph_add_vertex/3
|
||||
@cnindex dgraph_add_vertex/3
|
||||
Unify @var{NewGraph} with a new graph obtained by adding
|
||||
vertex @var{Vertex} to the graph @var{Graph}.
|
||||
|
||||
@item dgraph_add_vertices(+@var{Graph}, +@var{Vertices}, -@var{NewGraph})
|
||||
@findex dgraph_add_vertices/3
|
||||
@snindex dgraph_add_vertices/3
|
||||
@ -11204,7 +11211,15 @@ Unify @var{Edges} with all edges appearing in graph
|
||||
Unify @var{NewGraph} with a new graph obtained by adding the list of
|
||||
vertices @var{Vertices} to the graph @var{Graph}.
|
||||
|
||||
@item dgraph_del_vertices(+@var{Vertices}, +@var{Graph}, -@var{NewGraph})
|
||||
@item dgraph_del_vertex(+@var{Graph}, +@var{Vertex}, -@var{NewGraph})
|
||||
@findex dgraph_del_vertex/3
|
||||
@syindex dgraph_del_vertex/3
|
||||
@cnindex dgraph_del_vertex/3
|
||||
Unify @var{NewGraph} with a new graph obtained by deleting vertex
|
||||
@var{Vertex} and all the edges that start from or go to @var{Vertex} to
|
||||
the graph @var{Graph}.
|
||||
|
||||
@item dgraph_del_vertices(+@var{Graph}, +@var{Vertices}, -@var{NewGraph})
|
||||
@findex dgraph_del_vertices/3
|
||||
@syindex dgraph_del_vertices/3
|
||||
@cnindex dgraph_del_vertices/3
|
||||
@ -11212,6 +11227,13 @@ Unify @var{NewGraph} with a new graph obtained by deleting the list of
|
||||
vertices @var{Vertices} and all the edges that start from or go to a
|
||||
vertex in @var{Vertices} to the graph @var{Graph}.
|
||||
|
||||
@item dgraph_add_edge(+@var{Graph}, +@var{N1}, +@var{N2}, -@var{NewGraph})
|
||||
@findex dgraph_add_edge/4
|
||||
@snindex dgraph_add_edge/4
|
||||
@cnindex dgraph_add_edge/4
|
||||
Unify @var{NewGraph} with a new graph obtained by adding the edge
|
||||
@var{N1}-@var{N2} to the graph @var{Graph}.
|
||||
|
||||
@item dgraph_add_edges(+@var{Graph}, +@var{Edges}, -@var{NewGraph})
|
||||
@findex dgraph_add_edges/3
|
||||
@snindex dgraph_add_edges/3
|
||||
@ -11219,6 +11241,14 @@ vertex in @var{Vertices} to the graph @var{Graph}.
|
||||
Unify @var{NewGraph} with a new graph obtained by adding the list of
|
||||
edges @var{Edges} to the graph @var{Graph}.
|
||||
|
||||
@item dgraph_del_edge(+@var{Graph}, +@var{N1}, +@var{N2}, -@var{NewGraph})
|
||||
@findex dgraph_del_edge/4
|
||||
@snindex dgraph_del_edge/4
|
||||
@cnindex dgraph_del_edge/4
|
||||
Succeeds if @var{NewGraph} unifies with a new graph obtained by
|
||||
removing the edge @var{N1}-@var{N2} from the graph @var{Graph}. Notice
|
||||
that no vertices are deleted.
|
||||
|
||||
@item dgraph_del_edges(+@var{Graph}, +@var{Edges}, -@var{NewGraph})
|
||||
@findex dgraph_del_edges/3
|
||||
@snindex dgraph_del_edges/3
|
||||
@ -11227,6 +11257,23 @@ Unify @var{NewGraph} with a new graph obtained by removing the list of
|
||||
edges @var{Edges} from the graph @var{Graph}. Notice that no vertices
|
||||
are deleted.
|
||||
|
||||
@item dgraph_to_ugraph(+@var{Graph}, -@var{UGraph})
|
||||
@findex dgraph_to_ugraph/2
|
||||
@snindex dgraph_to_ugraph/2
|
||||
@cnindex dgraph_to_ugraph/2
|
||||
Unify @var{UGraph} with the representation used by the @var{ugraphs}
|
||||
unweighted graphs library, that is, a list of the form
|
||||
@var{V-Neighbors}, where @var{V} is a node and @var{Neighbors} the nodes
|
||||
children.
|
||||
|
||||
@item ugraph_to_dgraph( +@var{UGraph}, -@var{Graph})
|
||||
@findex ugraph_to_dgraph/2
|
||||
@snindex ugraph_to_dgraph/2
|
||||
@cnindex ugraph_to_dgraph/2
|
||||
Unify @var{Graph} with the directed graph obtain from @var{UGraph},
|
||||
represented in the form used in the @var{ugraphs} unweighted graphs
|
||||
library.
|
||||
|
||||
@item dgraph_neighbors(+@var{Vertex}, +@var{Graph}, -@var{Vertices})
|
||||
@findex dgraph_neighbors/3
|
||||
@snindex dgraph_neighbors/3
|
||||
@ -11255,7 +11302,7 @@ Unify @var{NewGraph} with a new graph obtained from @var{Graph} by
|
||||
replacing all edges of the form @var{V1-V2} by edges of the form
|
||||
@var{V2-V1}.
|
||||
|
||||
@item dgraph_close(+@var{Graph1}, +@var{Graph2}, -@var{ComposedGraph})
|
||||
@item dgraph_compose(+@var{Graph1}, +@var{Graph2}, -@var{ComposedGraph})
|
||||
@findex dgraph_compose/3
|
||||
@snindex dgraph_compose/3
|
||||
@cnindex dgraph_compose/3
|
||||
@ -11284,22 +11331,57 @@ contain the edge @var{V-U}.
|
||||
@cnindex dgraph_top_sort/2
|
||||
Unify @var{Vertices} with the topological sort of graph @var{Graph}.
|
||||
|
||||
@item dgraph_to_ugraph(+@var{Graph}, -@var{UGraph})
|
||||
@findex dgraph_to_ugraph/2
|
||||
@snindex dgraph_to_ugraph/2
|
||||
@cnindex dgraph_to_ugraph/2
|
||||
Unify @var{UGraph} with the representation used by the @var{ugraphs}
|
||||
unweighted graphs library, that is, a list of the form
|
||||
@var{V-Neighbors}, where @var{V} is a node and @var{Neighbors} the nodes
|
||||
children.
|
||||
@item dgraph_top_sort(+@var{Graph}, -@var{Vertices}, ?@var{Vertices0})
|
||||
@findex dgraph_top_sort/3
|
||||
@snindex dgraph_top_sort/3
|
||||
@cnindex dgraph_top_sort/3
|
||||
Unify the difference list @var{Vertices}-@var{Vertices0} with the
|
||||
topological sort of graph @var{Graph}.
|
||||
|
||||
@item dgraph_min_path(+@var{V1}, +@var{V1}, +@var{Graph}, -@var{Path}, ?@var{Costt})
|
||||
@findex dgraph_min_path/5
|
||||
@snindex dgraph_min_path/5
|
||||
@cnindex dgraph_min_path/5
|
||||
Unify the list @var{Path} with the minimal cost path between nodes
|
||||
@var{N1} and @var{N2} in graph @var{Graph}. Path @var{Path} has cost
|
||||
@var{Cost}.
|
||||
|
||||
@item dgraph_max_path(+@var{V1}, +@var{V1}, +@var{Graph}, -@var{Path}, ?@var{Costt})
|
||||
@findex dgraph_max_path/5
|
||||
@snindex dgraph_max_path/5
|
||||
@cnindex dgraph_max_path/5
|
||||
Unify the list @var{Path} with the maximal cost path between nodes
|
||||
@var{N1} and @var{N2} in graph @var{Graph}. Path @var{Path} has cost
|
||||
@var{Cost}.
|
||||
|
||||
@item dgraph_min_paths(+@var{V1}, +@var{Graph}, -@var{Paths})
|
||||
@findex dgraph_min_paths/3
|
||||
@snindex dgraph_min_paths/3
|
||||
@cnindex dgraph_min_paths/3
|
||||
Unify the list @var{Paths} with the minimal cost paths from node
|
||||
@var{N1} to the nodes in graph @var{Graph}.
|
||||
|
||||
@item dgraph_isomorphic(+@var{Vs}, +@var{NewVs}, +@var{G0}, -@var{GF})
|
||||
@findex dgraph_isomorphic/4
|
||||
@snindex dgraph_isomorphic/4
|
||||
@cnindex dgraph_isomorphic/4
|
||||
Unify the list @var{GF} with the graph isomorphic to @var{G0} where
|
||||
vertices in @var{Vs} map to vertices in @var{NewVs}.
|
||||
|
||||
@item dgraph_path(+@var{Vertex}, +@var{Graph}, ?@var{Path})
|
||||
@findex dgraph_path/3
|
||||
@snindex dgraph_path/3
|
||||
@cnindex dgraph_path/3
|
||||
The path @var{Path} is a path starting at vertex @var{Vertex} in graph
|
||||
@var{Graph}.
|
||||
|
||||
@item dgraph_reachable(+@var{Vertex}, +@var{Graph}, ?@var{Edges})
|
||||
@findex dgraph_path/3
|
||||
@snindex dgraph_path/3
|
||||
@cnindex dgraph_path/3
|
||||
The path @var{Path} is a path starting at vertex @var{Vertex} in graph
|
||||
@var{Graph}.
|
||||
|
||||
@item ugraph_to_dgraph( +@var{UGraph}, -@var{Graph})
|
||||
@findex ugraph_to_dgraph/2
|
||||
@snindex ugraph_to_dgraph/2
|
||||
@cnindex ugraph_to_dgraph/2
|
||||
Unify @var{Graph} with the directed graph obtain from @var{UGraph},
|
||||
represented in the form used in the @var{ugraphs} unweighted graphs
|
||||
library.
|
||||
@end table
|
||||
|
||||
@node UnDGraphs, LAM , DGraphs, Library
|
||||
|
@ -5,17 +5,17 @@
|
||||
|
||||
:- module( dgraphs,
|
||||
[
|
||||
dgraph_add_edge/4,
|
||||
dgraph_add_edges/3,
|
||||
dgraph_add_vertex/3,
|
||||
dgraph_add_vertices/3,
|
||||
dgraph_del_edge/4,
|
||||
dgraph_del_edges/3,
|
||||
dgraph_del_vertex/3,
|
||||
dgraph_del_vertices/3,
|
||||
dgraph_vertices/2,
|
||||
dgraph_edge/3,
|
||||
dgraph_edges/2,
|
||||
dgraph_vertices/2,
|
||||
dgraph_add_vertex/3,
|
||||
dgraph_add_vertices/3,
|
||||
dgraph_del_vertex/3,
|
||||
dgraph_del_vertices/3,
|
||||
dgraph_add_edge/4,
|
||||
dgraph_add_edges/3,
|
||||
dgraph_del_edge/4,
|
||||
dgraph_del_edges/3,
|
||||
dgraph_to_ugraph/2,
|
||||
ugraph_to_dgraph/2,
|
||||
dgraph_neighbors/3,
|
||||
@ -31,7 +31,8 @@
|
||||
dgraph_max_path/5,
|
||||
dgraph_min_paths/3,
|
||||
dgraph_isomorphic/4,
|
||||
dgraph_path/3]).
|
||||
dgraph_path/3,
|
||||
dgraph_reachable/3]).
|
||||
|
||||
:- reexport(library(rbtrees),
|
||||
[rb_new/1 as dgraph_new]).
|
||||
@ -191,7 +192,7 @@ dgraph_del_vertex(Vs0, V, Vsf) :-
|
||||
delete_edge(Edges0, V, Edges) :-
|
||||
ord_del_element(Edges0, V, Edges).
|
||||
|
||||
dgraph_del_vertices(G0, Vs, GF) -->
|
||||
dgraph_del_vertices(G0, Vs, GF) :-
|
||||
sort(Vs,SortedVs),
|
||||
delete_all(SortedVs, G0, G1),
|
||||
delete_remaining_edges(SortedVs, G1, GF).
|
||||
@ -362,7 +363,7 @@ dgraph_max_path(V1, V2, Graph, Path, Cost) :-
|
||||
|
||||
dgraph_min_paths(V1, Graph, Paths) :-
|
||||
dgraph_to_wdgraph(Graph, WGraph),
|
||||
wdgraph_min_path(V1, WGraph, Paths).
|
||||
wdgraph_min_paths(V1, WGraph, Paths).
|
||||
|
||||
dgraph_path(V, G, [V|P]) :-
|
||||
rb_lookup(V, Children, G),
|
||||
@ -403,3 +404,18 @@ translate_edges([V1-V2|Edges],Map,[NV1-NV2|TEdges]) :-
|
||||
rb_lookup(V1,NV1,Map),
|
||||
rb_lookup(V2,NV2,Map),
|
||||
translate_edges(Edges,Map,TEdges).
|
||||
|
||||
dgraph_reachable(V, G, Edges) :-
|
||||
rb_lookup(V, Children, G),
|
||||
ord_list_to_rbtree([V-[]],Done0),
|
||||
reachable(Children, Done0, _, G, Edges, []).
|
||||
|
||||
reachable([], Done, Done, _, Edges, Edges).
|
||||
reachable([V|Vertices], Done0, DoneF, G, EdgesF, Edges0) :-
|
||||
rb_lookup(V,_, Done0), !,
|
||||
reachable(Vertices, Done0, DoneF, G, EdgesF, Edges0).
|
||||
reachable([V|Vertices], Done0, DoneF, G, [V|EdgesF], Edges0) :-
|
||||
rb_lookup(V, Kids, G),
|
||||
rb_insert(Done0, V, [], Done1),
|
||||
reachable(Kids, Done1, DoneI, G, EdgesF, EdgesI),
|
||||
reachable(Vertices, DoneI, DoneF, G, EdgesI, Edges0).
|
||||
|
@ -29,7 +29,8 @@
|
||||
dgraph_vertices/2 as undgraph_vertices,
|
||||
dgraph_complement/2 as undgraph_complement,
|
||||
dgraph_symmetric_closure/2 as dgraph_to_undgraph,
|
||||
dgraph_edge/3 as undgraph_edge
|
||||
dgraph_edge/3 as undgraph_edge,
|
||||
dgraph_reachable/3 as undgraph_reachable
|
||||
]).
|
||||
|
||||
|
||||
|
@ -18,6 +18,8 @@
|
||||
dgraph_to_wdgraph/2,
|
||||
wdgraph_neighbors/3,
|
||||
wdgraph_neighbours/3,
|
||||
wdgraph_wneighbors/3,
|
||||
wdgraph_wneighbours/3,
|
||||
wdgraph_transpose/2,
|
||||
wdgraph_transitive_closure/2,
|
||||
wdgraph_symmetric_closure/2,
|
||||
@ -25,7 +27,8 @@
|
||||
wdgraph_min_path/5,
|
||||
wdgraph_min_paths/3,
|
||||
wdgraph_max_path/5,
|
||||
wdgraph_path/3]).
|
||||
wdgraph_path/3,
|
||||
wdgraph_reachable/3]).
|
||||
|
||||
:- reexport(library(dgraphs),
|
||||
[dgraph_add_vertex/3 as wdgraph_add_vertex,
|
||||
@ -279,13 +282,19 @@ cvt_neighbs([V|WEs], [V-1|Es]) :-
|
||||
cvt_neighbs(WEs, Es).
|
||||
|
||||
wdgraph_neighbors(V, WG, Neighbors) :-
|
||||
rb_lookup(V, WG, EdgesList0),
|
||||
rb_lookup(V, EdgesList0, WG),
|
||||
cvt_wneighbs(EdgesList0, Neighbors).
|
||||
|
||||
wdgraph_neighbours(V, WG, Neighbors) :-
|
||||
rb_lookup(V, WG, EdgesList0),
|
||||
rb_lookup(V, EdgesList0, WG),
|
||||
cvt_wneighbs(EdgesList0, Neighbors).
|
||||
|
||||
wdgraph_wneighbors(V, WG, Neighbors) :-
|
||||
rb_lookup(V, Neighbors, WG).
|
||||
|
||||
wdgraph_wneighbours(V, WG, Neighbors) :-
|
||||
rb_lookup(V, Neighbors, WG).
|
||||
|
||||
wdgraph_transpose(Graph, TGraph) :-
|
||||
rb_visit(Graph, Edges),
|
||||
rb_clone(Graph, TGraph, NewNodes),
|
||||
@ -433,3 +442,17 @@ wdgraph_path(V, WG, P) :-
|
||||
wdgraph_to_dgraph(WG, G),
|
||||
dgraph_path(V, G, P).
|
||||
|
||||
wdgraph_reachable(V, G, Edges) :-
|
||||
rb_lookup(V, Children, G),
|
||||
ord_list_to_rbtree([V-[]],Done0),
|
||||
reachable(Children, Done0, _, G, Edges, []).
|
||||
|
||||
reachable([], Done, Done, _, Edges, Edges).
|
||||
reachable([V-_|Vertices], Done0, DoneF, G, EdgesF, Edges0) :-
|
||||
rb_lookup(V,_, Done0), !,
|
||||
reachable(Vertices, Done0, DoneF, G, EdgesF, Edges0).
|
||||
reachable([V-_|Vertices], Done0, DoneF, G, [V|EdgesF], Edges0) :-
|
||||
rb_lookup(V, Kids, G),
|
||||
rb_insert(Done0, V, [], Done1),
|
||||
reachable(Kids, Done1, DoneI, G, EdgesF, EdgesI),
|
||||
reachable(Vertices, DoneI, DoneF, G, EdgesI, Edges0).
|
||||
|
@ -13,6 +13,8 @@
|
||||
wundgraph_edges/2,
|
||||
wundgraph_neighbors/3,
|
||||
wundgraph_neighbours/3,
|
||||
wundgraph_wneighbors/3,
|
||||
wundgraph_wneighbours/3,
|
||||
wdgraph_to_wundgraph/2,
|
||||
wundgraph_to_undgraph/2,
|
||||
wundgraph_min_tree/3,
|
||||
@ -32,7 +34,9 @@
|
||||
wdgraph_min_path/5 as wundgraph_min_path,
|
||||
wdgraph_min_paths/3 as wundgraph_min_paths,
|
||||
wdgraph_max_path/5 as wundgraph_max_path,
|
||||
wdgraph_path/3 as wundgraph_path]).
|
||||
wdgraph_path/3 as wundgraph_path,
|
||||
wdgraph_reachable/3 as wundgraph_reachable
|
||||
]).
|
||||
|
||||
:- use_module( library(wdgraphs),
|
||||
[
|
||||
@ -95,6 +99,25 @@ wundgraph_neighbours(V,Vertices,Children) :-
|
||||
).
|
||||
wundgraph_neighbors(V,Vertices,Children) :-
|
||||
wdgraph_neighbors(V,Vertices,Children0),
|
||||
(
|
||||
wdel_me(Children0,V,Children)
|
||||
->
|
||||
true
|
||||
;
|
||||
Children = Children0
|
||||
).
|
||||
|
||||
wundgraph_wneighbours(V,Vertices,Children) :-
|
||||
wdgraph_wneighbours(V,Vertices,Children0),
|
||||
(
|
||||
wdel_me(Children0,V,Children)
|
||||
->
|
||||
true
|
||||
;
|
||||
Children = Children0
|
||||
).
|
||||
wundgraph_wneighbors(V,Vertices,Children) :-
|
||||
wdgraph_wneighbors(V,Vertices,Children0),
|
||||
(
|
||||
del_me(Children0,V,Children)
|
||||
->
|
||||
@ -104,7 +127,7 @@ wundgraph_neighbors(V,Vertices,Children) :-
|
||||
).
|
||||
|
||||
del_me([], _, []).
|
||||
del_me([K-_|Children], K1, NewChildren) :-
|
||||
del_me([K|Children], K1, NewChildren) :-
|
||||
( K == K1 ->
|
||||
Children = NewChildren
|
||||
;
|
||||
@ -116,6 +139,19 @@ del_me([K-_|Children], K1, NewChildren) :-
|
||||
compact(Children, MoreChildren)
|
||||
).
|
||||
|
||||
wdel_me([], _, []).
|
||||
wdel_me([K-A|Children], K1, NewChildren) :-
|
||||
( K == K1 ->
|
||||
Children = NewChildren
|
||||
;
|
||||
K @< K1 ->
|
||||
NewChildren = [K-A|ChildrenLeft],
|
||||
wdel_me(Children, K1, ChildrenLeft)
|
||||
;
|
||||
NewChildren = [K-A|MoreChildren],
|
||||
compact(Children, MoreChildren)
|
||||
).
|
||||
|
||||
wundgraph_del_edge(Vs0,V1,V2,K,VsF) :-
|
||||
wdgraph_del_edge(Vs0,V1,V2,K,Vs1),
|
||||
wdgraph_del_edge(Vs1,V2,V1,K,VsF).
|
||||
|
Reference in New Issue
Block a user