
ugraphs.pl -- Graph manipulation libraryThe S-representation of a graph is a list of (vertex-neighbours) pairs, where the pairs are in standard order (as produced by keysort) and the neighbours of each vertex are also in standard order (as produced by sort). This form is convenient for many calculations.
A new UGraph from raw data can be created using vertices_edges_to_ugraph/3.
Adapted to support some of the functionality of the SICStus ugraphs library by Vitor Santos Costa.
Ported from YAP 5.0.1 to SWI-Prolog by Jan Wielemaker.
vertices(+S_Graph, -Vertices) is det
vertices_edges_to_ugraph(+Vertices, +Edges, -UGraph) is det?- vertices_edges_to_ugraph([],[1-3,2-4,4-5,1-5], L). L = [1-[3,5], 2-[4], 3-[], 4-[5], 5-[]]
In this case all vertices are defined implicitly. The next example shows three unconnected vertices:
?- vertices_edges_to_ugraph([6,7,8],[1-3,2-4,4-5,1-5], L). L = [1-[3,5], 2-[4], 3-[], 4-[5], 5-[], 6-[], 7-[], 8-[]]
del_vertices(+Graph, +Vertices, -NewGraph) is det
?- del_vertices([1-[3,5],2-[4],3-[],4-[5],5-[],6-[],7-[2,6],8-[]],
[2,1],
NL).
NL = [3-[],4-[5],5-[],6-[],7-[6],8-[]]
ugraph_union(+Set1, +Set2, ?Union)
edges(+UGraph, -Edges) is det
transpose_ugraph(Graph, NewGraph) is det
?- transpose([1-[3,5],2-[4],3-[],4-[5],
5-[],6-[],7-[],8-[]], NL).
NL = [1-[],2-[],3-[1],4-[2],5-[1,4],6-[],7-[],8-[]]
compose(G1, G2, Composition)
top_sort(+Graph, -Sorted) is semidet
top_sort(+Graph, -Sorted, ?Tail) is semidet?- top_sort([1-[2], 2-[3], 3-[]], L). L = [1, 2, 3]
The predicate top_sort/3 is a difference list version of top_sort/2.
neighbors(+Vertex, +Graph, -Neigbours) is det
neighbours(+Vertex, +Graph, -Neigbours) is det
top_sort(+Graph, -Sorted) is semidet
top_sort(+Graph, -Sorted, ?Tail) is semidet?- top_sort([1-[2], 2-[3], 3-[]], L). L = [1, 2, 3]
The predicate top_sort/3 is a difference list version of top_sort/2.
neighbors(+Vertex, +Graph, -Neigbours) is det
neighbours(+Vertex, +Graph, -Neigbours) is detThe following predicates are exported, but not or incorrectly documented.
transitive_closure(Arg1, Arg2)
reachable(Arg1, Arg2, Arg3)
del_edges(Arg1, Arg2, Arg3)
add_vertices(Arg1, Arg2, Arg3)
complement(Arg1, Arg2)
add_edges(Arg1, Arg2, Arg3)