简体   繁体   English

加权有向图的邻接矩阵

[英]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]是边ij的权重。 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]不会描述路径ij权重(最多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]是边ij的权重。 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 . 您可以做的是,如果ij之间的边为0则将A[i, j]初始化为1

A^k would give you the desired result. A^k会给您想要的结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM