[英]adjacency matrix of weighted directed graph
A) Suppose A
be a adjacency matrix of weighted directed graph G
with n
vertex in which A[i,j]
be a weight of edge i
to j
. A)假设
A
是具有n
顶点的加权有向图G
的邻接矩阵,其中A[i,j]
是边i
到j
的权重。 if there is no such edge A[i ,i]=0
. 如果没有这样的边
A[i ,i]=0
。 Matrix A^K= A*A*A*...A
. 矩阵
A^K= A*A*A*...A
if we use + instead of * and use min
instead of +, Slot A^k [i,j]
not describe weight of path i
to j
with at most k
edge. 如果我们用+代替*并用
min
代替+,则插槽A^k [i,j]
不会描述路径i
到j
权重(最多k
边)。 I want to find this problem show what things? 我想找到这个问题显示什么东西?
B) Suppose A
be a adjacency matrix of weighted directed graph (wihout loop and multiple edge) G
with n
vertex in which A[i,j]
be a weight of edge i
to j
. B)假设
A
是具有n
顶点的加权有向图(无循环和多边) G
的邻接矩阵,其中A[i,j]
是边i
到j
的权重。 if there is no such edge A[i ,j]=infinity
, and for evrey i
we have A[i, i]=0
. 如果没有这样的边
A[i ,j]=infinity
,并且对于evrey i
我们有A[i, i]=0
。 Matrix A^K= A*A*A*...A
. 矩阵
A^K= A*A*A*...A
Slot A^k [i,j]
Show what things? 插槽
A^k [i,j]
显示什么? min weight? 最小体重? or...?
要么...?
any idea? 任何想法?
Edit: i means these algorithm find which in graph? 编辑:我的意思是这些算法在图中找到哪个? find maximum weight?
找到最大的重量? min weight?
最小体重? find nothing?
什么都没找到?
Let B = A^K
设
B = A^K
B[i, j]
would represent shortest path from i .. j
that takes exactly k
steps. B[i, j]
代表距i .. j
最短路径,它正好花了k
步。 How ? 怎么样 ?
Given a Matrix A
what happens if we multiple A
with itself ? 给定一个矩阵
A
,如果我们A
与自身相乘会发生什么?
// Initialize a matrix result which would be the matrix obtained by A*A
vector< N, vector<int> (N, INF) > result;
REP(i,0,N) REP(j,0,N) REP(k,0,N)
result[i][j] = min(result[i][j], (A[i][k] + A[k][j]));
Initially A[i, j]
had the direct cost of going to j
from i
. 最初,
A[i, j]
具有直接从i
转到j
的直接成本。 As you can see that result[i, j]
is minimum
of result[i, j]
and A[i, k] + A[k, j]
, So we conclude that result[i, j]
contains path going from i .. j
using one intermediate vertex k
. 如您所见,
result[i, j]
是result[i, j]
和A[i, k] + A[k, j]
minimum
,因此我们得出结论, result[i, j]
包含从i .. j
出发的路径i .. j
使用一个中间顶点k
。 And since we iterate this for all k's
, result[i, j]
contains the minimum cost path that traverses exactly two edges. 并且由于我们针对所有
k's
进行了迭代, result[i, j]
包含恰好穿越两个边的最小成本路径。 We can now generalize for A^k
. 现在我们可以归纳为
A^k
。
What if we set A[i, i]
to 0
? 如果将
A[i, i]
为0
怎样?
This allows self loops. 这允许自循环。 In the above code when
k == i
, 在上面的代码中,当
k == i
,
result[i, j] = min(result[i,j], A[i, i] + A[i, j])
result[i, j] = min(result[i,j], A[i,j)] // since A[i, i] = 0;
This means that now result[i, j]
would denote the shortest path to reach from i .. j
if we can use either one or two edges. 这意味着现在
result[i, j]
就表示从到达的最短路径i .. j
如果我们可以用一个或两个边缘。
So Now B[i, j]
would represent shortest path from i .. j
that takes almost k
steps. 因此,现在
B[i, j]
代表距i .. j
最短路径,需要近k
步。
Similarly, We can use the same concept to calculate no of paths from i .. j
that take exactly k
steps. 同样,我们可以使用相同的概念来计算没有路径从
i .. j
是采取完全相同k
步骤。 What you can do is that initialize A[i, j]
as 1
if we have an edge between i
and j
else 0
. 您可以做的是,如果
i
和j
之间的边为0
则将A[i, j]
初始化为1
。
A^k
would give you the desired result. A^k
会给您想要的结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.