Method: RGL::MutableGraph#cycles

Defined in:
lib/rgl/mutable.rb

#cyclesArray

This is not an efficient implementation O(n^4) and could be done using Minimum Spanning Trees. Hint. Hint.

Returns:

  • (Array)

    of all minimum cycles in a graph



99
100
101
102
103
104
105
# File 'lib/rgl/mutable.rb', line 99

def cycles
  g = self.clone
  self.inject([]) do |acc, v|
    acc = acc.concat(g.cycles_with_vertex(v))
    g.remove_vertex(v); acc
  end
end