离散数学之图

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} EV×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} EV×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×VR 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×VR 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).


原文链接:图与网络

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值