javascript - 多边无向图的循环枚举

标签 javascript algorithm math graph cycle

我正在尝试编写一个使用 Electrical Mesh Analasys 的程序。所以我有电路的节点 [A,B,C,D] 和连接节点 [0,1,2,3,4,5,6,7,8] 的分支。

如何在多边无向图中找到最短环,如下例所示?

图图像(4 个节点,9 个边/分支):

graph

周期:

0-1-0
5-6-5
6-8-6
1-4-2-1
2-7-3-2
4-7-5-4

我需要的周期数是: Cycles = Branches - (Nodes - 1),在这种情况下我需要 6 个周期。

我将这些数据存储在这样的数组中:

realNodes = [A,B,C,D];

groupBranches = [[0,1,4,5,6,8], [3,5,6,7,8], [0,1,2,3], [2,4,7]];

// groupArray[0] stores the branch numbers connected to A;
// groupArray[1] stores the branch numbers connected to B;
// groupArray[2] stores the branch numbers connected to C;
// groupArray[3] stores the branch numbers connected to D;

注意事项:

我不需要所有可能的循环,我只需要在某个循环中使用每个边(分支)。

此外,最终周期可能与示例中的不同。

我很高兴看到任何语言的算法。

最佳答案

您可以使用您喜欢的任何算法(BFS 有效)生成生成树。

然后,对于不在树中的每条边,您创建一个循环,其中包含该边加上从一端到另一端穿过树的路径。

关于javascript - 多边无向图的循环枚举,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55482573/

相关文章:

javascript - 如果另一个正在运行,jQuery 会阻止动画触发

algorithm - 为什么具有可接受的不一致启发式的 A* 会找到非最优解?

algorithm - 递归查找一组给定的不同整数的所有子集

python - 在 Python 中获取集合的子集

javascript - 将数据帧从 python 发送到 node.js 应用程序

javascript - 使用 jquery 制作图像 slider

javascript - 如何将 xsl 变量作为参数传递给脚本标记内的 javascript 函数?

algorithm - 自组织映射中神经元的位置是否取决于它的权重?

java - 我不明白 Java 上的这个算术

c++ - N 个区间的 bool 规则 (C)