簡體   English   中英

具有多邊的無向圖的循環枚舉

[英]Cycle enumeration of an undirected graph with multi edges

我正在嘗試編寫一個使用Electrical Mesh Analasys的程序。 因此,我具有電路[A,B,C,D]的節點和鏈接節點[0,1,2,3,4,5,6,7,8]的分支。

我如何在具有多個邊的無向圖中找到最短的周期,例如下面的波紋管?

圖形圖像(4個節點,9個邊緣/分支):

圖形

周期數:

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

我需要的周期數是:周期=分支-(節點-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可以工作)。

然后,對於不在樹中的每個邊緣,進行一個循環,其中包含該邊緣以及從一端到另一端的穿過樹的路徑。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM