digraph
Directed Graphs
The digraph
module implements a version of labeled
directed graphs. What makes the graphs implemented here
non-proper directed graphs is that multiple edges between
vertices are allowed. However, the customary definition of
directed graphs will be used in the text that follows.
digraph
模块实现了一个有标签的有向图. 允许顶点之间有多条边使这里实现的图为不完全有向图. 然而, the customary definition of directed graphs will be used in the text that follows.
A
Digraphs can be annotated with additional information. Such
information may be attached to the vertices and to the edges of
the digraph. A digraph which has been annotated is called a
labeled digraph, and the information attached to a
vertex or an edge is called a
有向图可以通过额外的信息来注释. 这样的信息可以加到顶点或者边上. 注释过的图称为标记有向图, 附加到顶点或者边的信息称为
An edge e = (v, w) is said to
e = (v, w) 表示从顶点v
A digraph as returned by new/0,1
.
一个由new/0,1
返回的图.
Functions:
add_edge(G, V1, V2) -> edge() | {'error', add_edge_err_rsn()}
V1 = vertex(),
V2 = vertex()
add_edge(G, V1, V2, Label) -> edge() | {'error', add_edge_err_rsn()}
V1 = vertex(),
V2 = vertex(),
Label = label()
add_edge(G, E, V1, V2, Label) -> edge() | {'error', add_edge_err_rsn()}
E = edge(),
V1 = vertex(),
V2 = vertex(),
Label = label()
add_edge/5
creates (or modifies) the edge
of the digraph
, using
as the (new)
label of the edge. The
edge is emanating from
and incident
on
. Returns
.
add_edge/5
使用
作为(新) 标签 创建(或修改)图
的边
. 这条边从
发出 并且 传入 到
. 返回
.
add_edge(
is
equivalent to
add_edge(
,
where
is a created edge. The created edge is
represented by the term ['$e' | N]
, where N
is an integer >= 0.
add_edge(
等同于
add_edge(
,
where
is a created edge. 创建的边由项['$e' | N]
代表, 其中N是大于等于0的整数.
add_edge(
is equivalent to
add_edge(
.
add_edge(
等同于add_edge(
.
If the edge would create a cycle in
an acyclic digraph,
then {error, {bad_edge,
is returned. If
either of
or
is not a vertex of the
digraph
, then
{error, {bad_vertex,
}}
is
returned,
or
.
如果要边在一个无环图中产生环, 那么返回{error, {bad_edge,
. 如果
或
不是
的顶点, 则返回{error, {bad_vertex,
}}
,
或
.
add_vertex(G) -> vertex()
add_vertex(G, V) -> vertex()
V = vertex()
add_vertex(G, V, Label) -> vertex()
V = vertex(),
Label = label()
add_vertex/3
creates (or modifies) the vertex
of the digraph
, using
as the (new)
label of the
vertex. Returns
.
add_vertex/3
创建(或修改)图
的顶点
, using
as the (new)
label of the
vertex. Returns
.
add_vertex(
is equivalent to
add_vertex(
.
add_vertex(
等同于add_vertex(
.
add_vertex/1
creates a vertex using the empty list
as label, and returns the created vertex. The created vertex
is represented by the term ['$v' | N]
,
where N is an integer >= 0.
add_vertex/1
使用空列表作为标签创建一个顶点, 并且返回创建好的顶点. 新顶点由项['$v' | N]
表示, 其中N是一个大于等于零的整数.
del_edge(G, E) -> 'true'
E = edge()
Deletes the edge
from the digraph
.
从图
.
del_edges(G, Edges) -> 'true'
Edges = [edge()]
Deletes the edges in the list
from the digraph
.
从图
中删除列表
从的边 .
del_path(G, V1, V2) -> 'true'
V1 = vertex(),
V2 = vertex()
Deletes edges from the digraph
until there are no
paths from the vertex
to the vertex
.
从图
中删除边直到从顶点
到顶点
不再有路径 .
A sketch of the procedure employed: Find an arbitrary
simple path
v[1], v[2], ..., v[k] from
to
in
. Remove all edges of
emanating from v[i]
and incident to v[i+1] for
1 <= i < k (including multiple
edges). Repeat until there is no path between
and
.
del_vertex(G, V) -> 'true'
V = vertex()
del_vertices(G, Vertices) -> 'true'
Vertices = [vertex()]
Deletes the vertices in the list
from the
digraph
.
从图
中删除列表
里的顶点.
delete(G) -> 'true'
Deletes the digraph
. This call is important
because digraphs are implemented with ETS
. There is
no garbage collection of ETS
tables. The digraph
will, however, be deleted if the process that created the
digraph terminates.
删除图
. 这个调用很重要,因为图是通过ETS
实现的. 没有针对ETS
表的垃圾回收. 然而,如果创建图的进程终止,那么图也自然被删除.
edge(G, E) -> {E, V1, V2, Label} | 'false'
E = edge(),
V1 = vertex(),
V2 = vertex(),
Label = label()
edges(G) -> Edges
Edges = [edge()]
Returns a list of all edges of the digraph
, in
some unspecified order.
以一个列表的形式返回图
的所有边.(列表元素顺序未指定)
edges(G, V) -> Edges
V = vertex(),
Edges = [edge()]
get_cycle(G, V) -> Vertices | 'false'
V = vertex(),
Vertices = [vertex(),...]
If there is
a simple cycle of
length two or more through the vertex
, then the cycle is returned as a list
[
of vertices, otherwise if there
is a loop through
, then the loop is returned as a list [
. If
there are no cycles through
, then false
is
returned.
如果有一个长度大于等于2的简单环通过顶点
, 那么环以一个顶点的列表[
返回, 否则如果有一个自环 通过
, 那么自环以一个列表[
返回. 如果没有环通过
, 则返回false
.
get_path/3
is used for finding a simple cycle
through
.
get_path/3
用于寻找一个通过
.
get_path(G, V1, V2) -> Vertices | 'false'
V1 = vertex(),
V2 = vertex(),
Vertices = [vertex(),...]
Tries to find
a simple path from
the vertex
to the vertex
of the digraph
. Returns the path as a
list [
of vertices, or
false
if no simple path from
to
of length one or more exists.
在图
中尝试寻找一个从顶点
到顶点
的简单路径. 以一个顶点列表[
的形式返回路径, 或者如果没有从
到
长度大于等于1的简单路径则返回false
.
The digraph
is traversed in a depth-first manner,
and the first path found is returned.
以深度优先的方式遍历图
, 并且返回找到的第一条路径.
get_short_cycle(G, V) -> Vertices | 'false'
V = vertex(),
Vertices = [vertex(),...]
Tries to find an as short as
possible simple cycle through
the vertex
of the digraph G
. Returns the cycle
as a list [
of vertices, or
false
if no simple cycle through
exists.
Note that a loop through
is returned as the list [
.
在图
中尝试寻找一个通过
且尽可能短的简单环. 以一个顶点列表[
的形式返回路径, 或者如果没有从
到
长度大于等于1的简单路径则返回false
.
注意,一个通过
的自环 以列表[
的形式返回.
get_short_path/3
is used for finding a simple cycle
through
.
get_short_path/3
用以寻找一个通过
的简单环.
get_short_path(G, V1, V2) -> Vertices | 'false'
V1 = vertex(),
V2 = vertex(),
Vertices = [vertex(),...]
Tries to find an as short as
possible simple path from
the vertex
to the vertex
of the digraph
.
Returns the path as a list [
of
vertices, or false
if no simple path from
to
of length one or more exists.
在图
中尝试寻找一个从顶点
到顶点
尽可能短的简单路径. 以一个顶点列表[
的形式返回路径, 或者如果没有从
到
长度大于等于1的简单路径则返回false
.
The digraph
is traversed in a breadth-first
manner, and the first path found is returned.
以广度优先的方式遍历图
, 并且返回找到的第一条路径.
in_degree(G, V) -> non_neg_integer()
V = vertex()
in_edges(G, V) -> Edges
V = vertex(),
Edges = [edge()]
in_neighbours(G, V) -> Vertex
V = vertex(),
Vertex = [vertex()]
Returns a list of
all in-neighbours of
of the digraph
, in some unspecified order.
以列表的形式,返回在图
中顶点
的所有内邻点.(列表元素顺序未指定).
info(G) -> InfoList
InfoList = [{'cyclicity', Cyclicity = d_cyclicity()} |
{'memory', NoWords = non_neg_integer()} |
{'protection', Protection = d_protection()}]
Returns a list of {Tag, Value}
pairs describing the
digraph
. The following pairs are returned:
返回一个{Tag, Value}
对的列表来描述图
. 返回下列对:
{cyclicity,
, where
is cyclic
or acyclic
, according to the
options given to new
.
{cyclicity,
, 其中, 根据给new
的选项,
是 cyclic
或 acyclic
.
{memory,
, where
is
the number of words allocated to the ETS
tables.
{memory,
, 其中
是分配给该ETS
表"字"的数量(内存大小).
{protection,
, where
is protected
or private
, according
to the options given to new
.
{protection,
, 其中, 根据给new
的选项,
是 protected
或 private
.
new() -> digraph()
Equivalent to new([])
.
等同于new([])
.
new(Type) -> digraph()
Returns
an empty digraph with
properties according to the options in
:
根据以下在
中的选项返回一个具有相关特性的空图:
cyclic
Allow cycles in the digraph (default).
在图中有环(默认).
acyclic
The digraph is to be kept acyclic.
图将会一直保持无环.
protected
Other processes can read the digraph (default).
其他进程可以读取该图(默认).
private
The digraph can be read and modified by the creating process only.
该图只能由创建它的进程读取和修改.
If an unrecognized type option T
is given or
is not a proper list, there will be a badarg
exception.
如果给定一个不可识别的选项T
或者
不是一个[TODO]完全列表, 将会产生一个badarg
异常.
no_edges(G) -> non_neg_integer()
Returns the number of edges of the digraph
.
返回图
中边的数量.
no_vertices(G) -> non_neg_integer()
Returns the number of vertices of the digraph
.
返回图
中顶点的数量.
out_degree(G, V) -> non_neg_integer()
V = vertex()
Returns the out-degree of the vertex
of the digraph
.
返回图
中顶点
的出度.
out_edges(G, V) -> Edges
V = vertex(),
Edges = [edge()]
out_neighbours(G, V) -> Vertices
V = vertex(),
Vertices = [vertex()]
Returns a list of
all of
of the digraph
, in some unspecified order.
以列表的形式, 返回图
中的
所有外邻点.(列表元素顺序未指定)
vertex(G, V) -> {V, Label} | 'false'
V = vertex(),
Label = label()
vertices(G) -> Vertices
Vertices = [vertex()]
Returns a list of all vertices of the digraph
, in
some unspecified order.
以列表的形式, 返回图
的所有顶点.(列表元素顺序未指定)