reachable/3
git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@330 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
parent
6e18479ee2
commit
601a7d2480
13
docs/yap.tex
13
docs/yap.tex
@ -8215,6 +8215,19 @@ Generate the graph @var{Closure} as the transitive closure of graph
|
||||
L = [1-[2,3,4,5,6],2-[4,5,6],4-[6]]
|
||||
@end example
|
||||
|
||||
@item reachable(+@var{Node}, +@var{Graph}, -@var{Vertices})
|
||||
@findex reachable/3
|
||||
@syindex reachable/3
|
||||
@cnindex reachable/3
|
||||
Unify @var{Vertices} with the set of all vertices in graph
|
||||
@var{Graph that are reachable from @var{Node}. In the next example:
|
||||
@example
|
||||
?- reachable(1,[1-[3,5],2-[4],3-[],4-[5],5-[]],V).
|
||||
|
||||
|
||||
V = [1,3,5]
|
||||
@end example
|
||||
|
||||
@end table
|
||||
|
||||
@node Extensions,Debugging,Library,Top
|
||||
|
@ -31,20 +31,21 @@
|
||||
*/
|
||||
|
||||
:- module(ugraphs, [
|
||||
vertices_edges_to_ugraph/3,
|
||||
vertices/2,
|
||||
edges/2,
|
||||
add_vertices/3,
|
||||
del_vertices/3,
|
||||
add_edges/3,
|
||||
del_edges/3,
|
||||
transpose/2,
|
||||
neighbours/3,
|
||||
neighbors/3,
|
||||
complement/2,
|
||||
compose/3,
|
||||
del_edges/3,
|
||||
del_vertices/3,
|
||||
edges/2,
|
||||
neighbours/3,
|
||||
neighbors/3,
|
||||
reachable/3,
|
||||
top_sort/2,
|
||||
transitive_closure/2
|
||||
transitive_closure/2,
|
||||
transpose/2,
|
||||
vertices/2,
|
||||
vertices_edges_to_ugraph/3
|
||||
]).
|
||||
|
||||
:- use_module(library(lists), [
|
||||
@ -54,9 +55,10 @@
|
||||
]).
|
||||
|
||||
:- use_module(library(ordsets), [
|
||||
ord_union/3,
|
||||
ord_add_element/3,
|
||||
ord_subtract/3,
|
||||
ord_add_element/3
|
||||
ord_union/3,
|
||||
ord_union/4
|
||||
]).
|
||||
|
||||
|
||||
@ -524,4 +526,13 @@ complement([V-Ns|G], Vs, [V-INs|NG]) :-
|
||||
|
||||
|
||||
|
||||
reachable(N, G, Rs) :-
|
||||
reachable([N], G, [N], Rs).
|
||||
|
||||
reachable([], _, Rs, Rs).
|
||||
reachable([N|Ns], G, Rs0, RsF) :-
|
||||
neighbours(N, G, Nei),
|
||||
ord_union(Rs0, Nei, Rs1, D),
|
||||
append(Ns, D, Nsi),
|
||||
reachable(Nsi, G, Rs1, RsF).
|
||||
|
||||
|
Reference in New Issue
Block a user