implicit.rb

Path: lib/rgl/implicit.rb
Last Update: Tue Jun 08 07:59:04 +0000 2010

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 { |g|
    g.vertex_iterator { |b| 0.upto(4,&b) }
    g.adjacent_iterator { |x, b| b.call((x+1)%5) }
    g.directed = true
  }

  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.

Required files

rgl/base  

[Validate]