Module: RGL::MutableGraph

### Home Classes Methods

### In Files

- lib/rgl/graphxml.rb
- lib/rgl/mutable.rb

### Namespace

- CLASS RGL::MutableGraph::MutableGraphParser

### Methods

- #add_edge
- #add_edges
- #add_vertex
- #add_vertices
- #cycles
- #cycles_with_vertex
- #from_graphxml
- #remove_edge
- #remove_vertex
- #remove_vertices

### Included Modules

- RGL::Graph

### Class/Module Index

Quicksearch

- RGL
- RGL::AdjacencyGraph
- RGL::BFSIterator
- RGL::BellmanFordAlgorithm
- RGL::BellmanFordVisitor
- RGL::BidirectionalGraph
- RGL::BipartiteBFSIterator
- RGL::DFSIterator
- RGL::DFSVisitor
- RGL::DOT
- RGL::DOT::Digraph
- RGL::DOT::DirectedEdge
- RGL::DOT::Edge
- RGL::DOT::Element
- RGL::DOT::Graph
- RGL::DOT::Node
- RGL::DOT::Port
- RGL::DOT::Subgraph
- RGL::DijkstraAlgorithm
- RGL::DijkstraVisitor
- RGL::DirectedAdjacencyGraph
- RGL::Edge
- RGL::Edge::DirectedEdge
- RGL::Edge::UnDirectedEdge
- RGL::EdgePropertiesMap
- RGL::EdmondsKarpAlgorithm
- RGL::EdmondsKarpAlgorithm::EdmondsKarpBFSIterator
- RGL::Graph
- RGL::Graph::TarjanSccVisitor
- RGL::GraphIterator
- RGL::GraphVisitor
- RGL::GraphVisitor::ClassMethods
- RGL::GraphVisitor::DistanceMapSupport
- RGL::ImplicitGraph
- RGL::MutableGraph
- RGL::MutableGraph::MutableGraphParser
- RGL::NoEdgeError
- RGL::NoVertexError
- RGL::NonNegativeEdgePropertiesMap
- RGL::NotDirectedError
- RGL::NotUndirectedError
- RGL::PrimAlgorithm
- RGL::TopsortIterator
- Enumerable
- Object

No matching classes.

# RGL::MutableGraph

A MutableGraph can be changed via the addition or removal of edges and vertices.

### Public Instance Methods

add_edge(u, v) click to toggle source

Inserts the edge (u,v) into the graph.

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

    # File lib/rgl/mutable.rb, line 29
    def add_edge(u, v)
      raise NotImplementedError
    end

add_edges(*edges) click to toggle source

Add all edges in the edges array to the edge set. Elements of the array can be both two-element arrays or instances of DirectedEdge or UnDirectedEdge.

    # File lib/rgl/mutable.rb, line 43
    def add_edges(*edges)
      edges.each { |edge| add_edge(edge[0], edge[1]) }
    end

add_vertex(v) click to toggle source

Add a new vertex v to the graph. If the vertex is already in the graph (tested via eql?), the method does nothing.

    # File lib/rgl/mutable.rb, line 17
    def add_vertex(v)
      raise NotImplementedError
    end

add_vertices(*a) click to toggle source

Add all objects in a to the vertex set.

    # File lib/rgl/mutable.rb, line 35
    def add_vertices(*a)
      a.each { |v| add_vertex v }
    end

cycles() click to toggle source

Returns an array of all minimum cycles in a graph

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

    # 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

cycles_with_vertex(vertex) click to toggle source

Returns all minimum cycles that pass through a give vertex. The format is an Array of cycles, with each cycle being an Array of vertices in the cycle.

    # File lib/rgl/mutable.rb, line 78
    def cycles_with_vertex(vertex)
      cycles_with_vertex_helper(vertex, vertex, [])
    end

from_graphxml(source) click to toggle source

Initializes an RGL graph from a subset of the GraphML format given in `source` (see www.graphdrawing.org/graphml).

    # File lib/rgl/graphxml.rb, line 53
    def from_graphxml(source)
      listener = MutableGraphParser.new(self)
      REXML::Document.parse_stream(source, listener)
      self
    end

remove_edge(u, v) click to toggle source

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

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

    # File lib/rgl/mutable.rb, line 63
    def remove_edge(u, v)
      raise NotImplementedError
    end

remove_vertex(v) click to toggle source

Remove u from the vertex set of the graph. All edges whose target is v are also removed from the edge set of the graph.

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

    # File lib/rgl/mutable.rb, line 53
    def remove_vertex(v)
      raise NotImplementedError
    end

remove_vertices(*a) click to toggle source

Remove all vertices specified by the array a from the graph by calling remove_vertex.

    # File lib/rgl/mutable.rb, line 70
    def remove_vertices(*a)
      a.each { |v| remove_vertex v }
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.