new dgraph path predicate

This commit is contained in:
Vitor Santos Costa 2013-03-24 09:12:55 -05:00
parent bda5d56bdf
commit a599699f0c
2 changed files with 30 additions and 5 deletions

View File

@ -12840,6 +12840,13 @@ vertices in @var{Vs} map to vertices in @var{NewVs}.
The path @var{Path} is a path starting at vertex @var{Vertex} in graph
@var{Graph}.
@item dgraph_path(+@var{Vertex}, +@var{Vertex1}, +@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} and ending at path @var{Vertex2}.
@item dgraph_reachable(+@var{Vertex}, +@var{Graph}, ?@var{Edges})
@findex dgraph_path/3
@snindex dgraph_path/3

View File

@ -32,6 +32,7 @@
dgraph_min_paths/3,
dgraph_isomorphic/4,
dgraph_path/3,
dgraph_path/4,
dgraph_leaves/2,
dgraph_reachable/3
]).
@ -40,7 +41,8 @@
[rb_new/1 as dgraph_new]).
:- use_module(library(rbtrees),
[rb_empty/1,
[rb_new/1,
rb_empty/1,
rb_lookup/3,
rb_apply/4,
rb_insert/4,
@ -361,10 +363,21 @@ dgraph_min_paths(V1, Graph, Paths) :-
dgraph_to_wdgraph(Graph, WGraph),
wdgraph_min_paths(V1, WGraph, Paths).
dgraph_path(V, G, [V|P]) :-
rb_lookup(V, Children, G),
ord_del_element(Children, V, Ch),
do_path(Ch, G, [V], P).
dgraph_path(V1, V2, Graph, Path) :-
rb_new(E0),
rb_lookup(V1, Children, Graph),
dgraph_path_children(Children, V2, E0, Graph, Path).
dgraph_path_children([V1|_], V2, _E1, _Graph, []) :- V1 == V2.
dgraph_path_children([V1|_], V2, E1, Graph, [V1|Path]) :-
V2 \== V1,
\+ rb_lookup(V1, _, E0),
rb_insert(E0, V2, [], E1),
rb_lookup(V1, Children, Graph),
dgraph_path_children(Children, V2, E1, Graph, Path).
dgraph_path_children([_|Children], V2, E1, Graph, Path) :-
dgraph_path_children(Children, V2, E1, Graph, Path).
do_path([], _, _, []).
do_path([C|Children], G, SoFar, Path) :-
@ -378,6 +391,11 @@ do_children([V|_], G, SoFar, [V|Path]) :-
do_children([_|Children], G, SoFar, Path) :-
do_children(Children, G, SoFar, Path).
dgraph_path(V, G, [V|P]) :-
rb_lookup(V, Children, G),
ord_del_element(Children, V, Ch),
do_path(Ch, G, [V], P).
dgraph_isomorphic(Vs, Vs2, G1, G2) :-
rb_new(Map0),