Algorithm for finding minimal cycles in a graph

前端 未结 2 711
时光说笑
时光说笑 2020-12-05 19:33

I\'m looking for an algorithm that given a graph it returns all the minimal cycles in it.
To make clear what I want, I need the algorithm to return exactly the followin

相关标签:
2条回答
  • 2020-12-05 20:05

    This Algorithm only works for un-weighted graph:

    Example:

    INPUT GRAPH: A, B, C, D, E
    
    A: B, C, E
    B: A, C
    C: A, B, D
    D: C, E
    E: A, D
    

    Algorithm:

    Initialization

    [LIST] = { }
    
    LIST[A] = { A }
    LIST[B] = { B }
    LIST[C] = { C }
    LIST[D] = { D }
    LIST[E] = { E }
    
    DISTANCE = 0
    
    SOLVED = FALSE
    
    SOLUTION = { }
    

    Search

    WHILE NOT SOLVED DO
    
        DISTANCE = DISTANCE + 1
    
        FOR EVERY LIST[X] IN [LIST]
            TEMP = LIST[X]
            LIST[X] = { }
            FOR EVERY VERTEX IN TEMP
                LIST[X] += NEIGHBORS(VERTEX)
            END-FOR
        END-FOR
    
        FOR EVERY LIST[X] IN [LIST]
            FOR EVERY VERTEX IN LIST[X]
                IF VERTEX = X THEN
                    SOLUTION = { X, DISTANCE }
                    SOLVED = TRUE
                END-IF
            END-FOR
        END-FOR
    
    END-WHILE
    
    0 讨论(0)
  • 2020-12-05 20:11

    This paper describes algorithm used in geometric tools library (written ic C++ i think). It's basically a modified DFS algorithm with addition of some algebra. The pseudocode is to big to post it here, so here is the link:

    http://www.geometrictools.com/Documentation/MinimalCycleBasis.pdf

    I'm currently working on javascript implementation. If you're interested you can view it here:

    http://jsbin.com/igujuz/8/edit

    0 讨论(0)
提交回复
热议问题