Directed Graph Model

The Directed Graph Model

A directed graph G consists of a set of vertices V and an edge set E of ordered pairs of vertices. For our purposes, each vertex corresponds to an artist. If ( Y , X ) ∈ E (Y,X) \in E (Y,X)E then there is an arrow pointing from Y Y Y to X X X, called edge.

For instance, V = { i n f l u e n c e r , f o l l o w e r } , E = { ( i n f l u e n c e r , f o l l o w e r ) } V=\{influencer,follower\}, E = \{(influencer,follower)\} V={influencer,follower},E={(influencer,follower)}, The relationship between influencers and followers can be represented in the graph G consist of V and E.

Construct a Directed Graph

In the directed graph G, each edge (arrow) represents a binary relation where a vertex points to another.
An example will explain this modeling process in more detail:

In Figure:G(Example), the vertex set contains 1 , 2 , 3 , 4 , 5 , 6 1, 2, 3, 4, 5, 6 1,2,3,4,5,6 .
The relationship of vertex includes:

  • 6 points to 1,
  • 1 points to 2 and 5,
  • 2 points to 3,
  • 3 points to 4,
  • 4 points to 2 and 7.

Strongly Connected Component(SCC)

Strongly Connected: A directed graph is strongly connected if each vertex is reachable from other vertex.
Strongly Connected Components: Strongly connected is a binary equivalence relation, and the induced subgraphs of its equivalence classes are called strongly connected components.
s c c ( G ) scc(G) scc(G): The set of strongly connected components in graph G.
In Figure: G(Eample), s c c ( G ) = { [ 2 , 3 , 4 ] } scc(G) = \{[2,3,4]\} scc(G)={[2,3,4]}

Directed Acyclic Graph(DAG)

If each strongly connected component of the original graph contract to a single vertex, the resulting graph is a directed acyclic graph called directed acyclic graph(DAG).

Find the strongly connected components( s c c ( G ) scc(G) scc(G)) in a directed graph G, replace the circle in G with the strongly connected components as a vertex, and get new directed graph C(must be DAG).

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
使用C++实现有向图的邻接矩阵,以及可达矩阵的计算算法。 请完成Project05.cpp中DirectedGraph类的成员函数,具体要求如下: DirectedGraph类: 用来表示一个有向图。 成员变量: m_AdjMat:邻接矩阵 m_ReachabilityMat:可达矩阵 成员函数: DirectedGraph():默认构造函数,构造一个空图。 ~DirectedGraph():析构函数 DirectedGraph(string filepath):解析文件filepath,构造一个DirectedGraph对象。 filepath文件格式与项目四相同,但本项目的图为有向图。 DirectedGraph(const Graph & graph):复制构造函数 operator=(const Graph & graph):赋值运算符 ClearGraph():清空图的邻接矩阵和可达矩阵。 OutputGraph():输出图的邻接矩阵 operator*(const DirectedGraph & graph): 乘法运算符,用于实现可达矩阵运算中的矩阵逻辑乘 DirectedGraph Pow(int power):邻接矩阵的整数次幂。 用法如下: DirectedGraph a; a = a.Pow(5); 即a的5次幂,相当于a = a * a * a * a * a; 注意要考虑0次幂的情况。 该函数适合以递归实现。 DirectedGraph MatOr(DirectedGraph graph):矩阵逐元素的逻辑或运算。 例如: 1 0 0 1 与 0 1 1 0 运算后的结果为 1 1 1 1 void CalcReachabilityMat():计算可达矩阵,要求该函数基于*运算符和Pow函数实现 void OutputReachabilityMat():输出可达矩阵 IsConnected(int src, int dst):基于可达矩阵判断从节点src与dst之间是否存在通路,如存在返回真,否则返回假
05-30
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值