1. 有向图
Definition 1:
A
directed graph
is tuple G = ( V , E ) G = (\mathbf{V}, \mathbf{E}) G=(V,E), where V \mathbf{V} V is the set of nodes, E ⊆ V × V \mathbf{E} \subseteq \mathbf{V} \times \mathbf{V} E⊆V×V is the set of arcs(弧).
- 节点集合 V = { v 1 , v 2 , … , v n } \mathbf{V} = \{v_1, v_2, \dots, v_n\} V={v1,v2,…,vn}.
- 弧(有向边)的集合 E \mathbf{E} E 本质上是 V \mathbf{V} V 上的关系.
- 弧记为 ⟨ v i , v j ⟩ \langle v_i, v_j \rangle ⟨vi,vj⟩. 有角度的括号表示有向.
- 元组 (tuple) 可以把不同类型的数据融合到一起,对应程序设计中的对象。
class Graph
{
// 节点个数
int n;
// 节点之前是否存在弧:1 表示存在,0 表示不存在。
int [][] arcs;
Graph(int paraN)
{
n = paraN;
arcs = new int[n][n];
}
// 设置边:paraValue = 1 表示添加,0 表示删除。
void setArc(int paraI, int paraJ, int paraValue)
{
arcs[paraI][paraJ] = paraValue;
}
}
2. 无向图
Definition 2:
An
undirected graph
is a tuple G = ( V , E ) G = (\mathbf{V}, \mathbf{E}) G=(V,E), where V \mathbf{V} V is the set of nodes, E ⊆ V × V \mathbf{E} \subseteq \mathbf{V} \times \mathbf{V} E⊆V×V where ( v i , v j v_i, v_j vi,vj) ∈ E \in \mathbf{E} ∈E ⇔ ( v j , v i ) ∈ E \Leftrightarrow (v_j, v_i) \in \mathbf{E} ⇔(vj,vi)∈E is the set of edges.
- 无向图用小括号 ( v i , v j ) (v_i, v_j) (vi,vj).
3. 有向网络
Definition 3:
A
directed net
is a tuple G = ( V , w ) G = (\mathbf{V}, w) G=(V,w), where V \mathbf{V} V is the set of nodes, and w : V × V → R w : \mathbf{V} \times \mathbf{V} \to \mathbb{R} w:V×V→R is the weight function where w ( v i , v j ) w(v_i, v_j) w(vi,vj) is the weight of the arc ⟨ v i , v j ⟩ \langle v_i, v_j \rangle ⟨vi,vj⟩.
注意:有向图是一种特殊的有向网络,其弧的权重均为 0 或 1.
class Nat
{
// 节点个数
int n;
// 节点之前的权重。
double[][] weights;
Net(int paraN)
{
n = paraN;
weights = new double[n][n];
}
// 设置边:paraValue = 1 表示添加,0 表示删除。
void setWeight(int paraI, int paraJ, double paraWeight)
{
weights[paraI][paraJ] = paraWeight;
}
}
4. 无向网络
Definition 4:
A
undirected net
is a tuple G = ( V , w ) G = (\mathbf{V}, w) G=(V,w), where V \mathbf{V} V is the set of nodes, and w : V × V → R w : \mathbf{V} \times \mathbf{V} \to \mathbb{R} w:V×V→R is the weight function where w ( v i , v j ) w(v_i, v_j) w(vi,vj) is the weight of the arc ⟨ v i , v j ⟩ \langle v_i, v_j \rangle ⟨vi,vj⟩, w ( v j , v i ) w(v_j, v_i) w(vj,vi) is the weight of the arc ⟨ v j , v i ⟩ \langle v_j, v_i \rangle ⟨vj,vi⟩ and w ( v i , v j ) = w ( v j , v i ) w(v_i, v_j) = w(v_j, v_i) w(vi,vj)=w(vj,vi).
原文链接:图与网络