module RGL::MutableGraph

def add_edge(u, v)


to u and u will be adjacent to v.
will appear in the out-edges of v. Put another way, v will be adjacent
will appear in the out-edges of u and (u,v) (or equivalently (v,u))
after a call to the function #add_edge, this implies that edge (u,v)
Note that for undirected graphs, (u,v) is the same edge as (v,u), so

Inserts the edge (u,v) into the graph.
def add_edge(u, v)
  raise NotImplementedError
end

def add_edges(*edges)


{Edge::UnDirectedEdge}.
array can be both two-element arrays or instances of {Edge::DirectedEdge} or
Add all edges in the _edges_ array to the edge set. Elements of the
def add_edges(*edges)
  edges.each { |edge| add_edge(edge[0], edge[1]) }
end

def add_vertex(v)


graph (tested via eql?), the method does nothing.
Add a new vertex _v_ to the graph. If the vertex is already in the
def add_vertex(v)
  raise NotImplementedError
end

def add_vertices(*a)


Add all objects in _a_ to the vertex set.
def add_vertices(*a)
  a.each { |v| add_vertex v }
end

def cycles

Returns:
  • (Array) - of all minimum cycles in a graph
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

def cycles_with_vertex(vertex)

Returns:
  • (Array[Array]) -
def cycles_with_vertex(vertex)
  cycles_with_vertex_helper(vertex, vertex, [])
end

def cycles_with_vertex_helper(vertex, start, visited)

def cycles_with_vertex_helper(vertex, start, visited)
  adjacent_vertices(start).reject { |x| visited.include?(x) }.inject([]) do |acc, adj|
    local_visited = Array.new(visited) << adj
    acc << local_visited if (adj==vertex)
    acc = acc + cycles_with_vertex_helper(vertex, adj, local_visited)
  end
end

def from_graphxml(source)


+source+ (see https://graphml.graphdrawing.org/).
Initializes an RGL graph from a subset of the GraphML format given in
def from_graphxml(source)
  listener = MutableGraphParser.new(self)
  REXML::Document.parse_stream(source, listener)
  self
end

def remove_edge(u, v)


Postcondition: (u,v) is no longer in the edge set for g.
Precondition: u and v are vertices in the graph.

edges, this removes all occurrences of (u,v).
Remove the edge (u,v) from the graph. If the graph allows parallel
def remove_edge(u, v)
  raise NotImplementedError
end

def remove_vertex(v)


vertex set of the graph, and there no edge with source or target _v_.
Postcondition: num_vertices is one less, _v_ no longer appears in the

_v_ are also removed from the edge set of the graph.
Remove u from the vertex set of the graph. All edges whose target is
def remove_vertex(v)
  raise NotImplementedError
end

def remove_vertices(*a)


{#remove_vertex}.
Remove all vertices specified by the array a from the graph by calling
def remove_vertices(*a)
  a.each { |v| remove_vertex v }
end