Directed and undirected graphs are fundamental data structures representing arbitrary relationships between data objects. This package provides a Prolog implementation of directed graphs, undirected graphs being a special case of directed graphs.
An unweighted directed graph (ugraph) is represented as a list of
(vertex-neighbors) pairs, where the pairs are in standard order (as
produced by keysort
with unique keys) and the neighbors of each
vertex are also in standard order (as produced by sort
),
every neighbor appears as a vertex even if it has no neighbors itself,
and no vertex is a neighbor to itself.
An undirected graph is represented as a directed graph where for each edge (U,V) there is a symmetric edge (V,U).
An edge (U,V) is represented as the term U-V. U and V must be distinct.
A vertex can be any term. Two vertices are distinct iff they are
not identical (==
).
A path from u to v is represented as a list of vertices, beginning with u and ending with v. A vertex cannot appear twice in a path. A path is maximal in a graph if it cannot be extended.
A tree is a tree-shaped directed graph (all vertices have a single predecessor, except the root node, which has none).
A strongly connected component of a graph is a maximal set of vertices where each vertex has a path in the graph to every other vertex.
Sets are represented as ordered lists (see Ordsets).
To load the package, enter the query
| ?- use_module(library(ugraphs)).
The following predicates are defined for directed graphs.
vertices_edges_to_ugraph(
+Vertices,
+Edges,
-Graph)
vertices(
+Graph,
-Vertices)
edges(
+Graph,
-Edges)
add_vertices(
+Graph1,
+Vertices,
-Graph2)
del_vertices(
+Graph1,
+Vertices,
-Graph2)
add_edges(
+Graph1,
+Edges,
-Graph2)
del_edges(
+Graph1,
+Edges,
-Graph2)
transpose(
+Graph,
-Transpose)
neighbors(
+Vertex,
+Graph,
-Neighbors)
neighbours(
+Vertex,
+Graph,
-Neighbors)
complement(
+Graph,
-Complement)
compose(
+G1,
+G2,
-Composition)
transitive_closure(
+Graph,
-Closure)
symmetric_closure(
+Graph,
-Closure)
top_sort(
+Graph,
-Sorted)
max_path(
+V1,
+V2,
+Graph,
-Path,
-Cost)
min_path(
+V1,
+V2,
+Graph,
-Path,
-Cost)
min_paths(
+Vertex,
+Graph,
-Tree)
path(
+Vertex,
+Graph,
-Path)
reduce(
+Graph,
-Reduced)
reachable(
+Vertex,
+Graph,
-Reachable)
random_ugraph(
+P,
+N,
-Graph)
The following predicates are defined for undirected graphs only.
min_tree(
+Graph,
-Tree,
-Cost)
clique(
+Graph,
+K,
-Clique)
independent_set(
+Graph,
+K,
-Set)
coloring(
+Graph,
+K,
-Coloring)
colouring(
+Graph,
+K,
-Coloring)