File: implicit.rb [rgl-0.5.0 Documentation]

Last Modified
  2015-05-23 12:33:40 +0000
Requires
  - rgl/base

## Description

implicit.rb

This file contains the definition of the class RGL::ImplicitGraph, which defines vertex and edge iterators using blocks (which again call blocks).

An ImplicitGraph provides a handy way to define graphs on the fly, using two blocks for the two iterators defining a graph. A directed cyclic graph, with five vertices can be created as follows:

    g = RGL::ImplicitGraph.new do |g|
      g.vertex_iterator { |b| 0.upto(4,&b) }
      g.adjacent_iterator { |x, b| b.call((x+1)%5) }
      g.directed = true
    end

    g.to_s # => "(0-1)(1-2)(2-3)(3-4)(4-0)"

Other examples are given by the methods vertices_filtered_by and edges_filtered_by, which can be applied to any graph.