【问题标题】:Tarjan's circular cycle multigraph unique nodesTarjan 的循环循环多重图唯一节点
【发布时间】:2013-03-15 05:05:16
【问题描述】:

我想在一个无向多重图中列出一个从根节点(Tarjan 的索引 0)开始的循环,它在根节点处开始和结束,而不会通过以前访问过的节点返回某个循环。

我使用这些指令Cycle detection in a Multigraph 在 perl 中编写了Tarjan's strongly connected components algorithm。 这是我的图表

V   E   E   E
1   2   3   4
2   1   3   
3   1   2   
4           1

我得到了这个结果

1 root
3 2 1
------------
2 root
3 1 2
------------
3 root
2 1 3
------------
4 root
3 2 1 4
------------

When 4 is selected as index 0 or the root I would like it to return 1 4 because the path must pass through 1 twice to complete the cycle with the solution of 3 2 1 4.

谢谢

【问题讨论】:

    标签: algorithm graph


    【解决方案1】:

    使用邻居搜索更改Tarjan's strongly connected components algorithm,以确保每个节点共享一条边满足我的需求。它省略了一些解决方案。

    for each v in V do
     index := 0
     S := empty
        strongconnect(v)
    repeat
    ...
    while (w != v)
      if (loopcount = 0)
       w:=v
      else
       w := S.pop()
      end if
    while (continuation = false)
     x := S.pop()
     for each (y, x) in E do
       if (y = w) then
         continuation = true
       end if
      repeat
      if (x = v) then
       continuation = true
     S.push(v)
     loopcount := loopcount+1
    if(continuation = true)
      add x to current strongly connected component
    endif
     repeat
    
    
            2   
    
    8   3   1   6
    
        4       7
            5   
    
    1   2   5   
    2   3   6   1
    3   4   2   8
    4   3   5   
    5   4   7   1
    6   2   7   
    7   5   6   
    8           3
    
    
    
    1 list
    5 4 3 2 1 
    ------------
    2 list
    1 5 4 3 2 
    ------------
    3 list
    8 3 
    ------------
    4 list
    5 7 6 2 3 4 
    ------------
    5 list
    1 2 3 4 5 
    ------------
    6 list
    7 5 4 3 2 6 
    ------------
    7 list
    6 2 3 4 5 7 
    ------------
    8 list
    3 8 
    ------------
    

    【讨论】:

      猜你喜欢
      • 2015-03-13
      • 1970-01-01
      • 2018-03-05
      • 1970-01-01
      • 1970-01-01
      • 2012-08-10
      • 2014-09-06
      • 2021-11-08
      • 2019-08-18
      相关资源
      最近更新 更多