Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Ruby binding for the igraph library.
C Ruby
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
ext Fixed bug in coreness.


== Introduction

IGraph is a Ruby extension for interfacing with the C igraph library ( igraph is a library for creating and manipulating graphs with a particular emphasis on network analysis functions.

IGraph is currently in beta status and the API should be considered stable. The main documentation can be found at though it is incomplete in places. you can also see the test suite for examples of how to use the various functions.

All bug reports, feature requests and patches are welcome. Please email alexg (at) or use the rubyforge forums:

== Installation

A working igraph library installation is required. Please see the igraph homepage ( for details on installing igraph.

IGraph is only available as a gem. The installation requires the location of your igraph headers and library to compile the extension. For example, under Ubuntu linux the following command succesfully compiles and installs (you may need to be root):

  gem install igraph -- --with-igraph-include=/usr/local/include/igraph

== Documentation

Graph objects are represented in the IGraph class. See the IGraph class documentation for a list of available methods available to build and query graph objects. The graph generators will use simple Integers as the vertices, but you can use any object as a vertex and edges can also be annotated with any kind of object.

Note that many functions require 'mode' constants to tell igraph how you want certain calculations to be made. The constants are listed under the IGraph documentation and should also be made explicit in each methods documentation.

Here are three examples which translate the C tutorial programs from the igraph documentation (

= 1.

  require 'igraph'

  g = IGraph::GenerateRandom.erdos_renyi_game(IGraph::ERDOS_RENYI_GNP, 
					      1000, 5.0/1000,
					      false, false)

  d = g.diameter(false,true).size-1
  puts "Diameter of a random graph with average degree 5: #{d}"

= 2.

  require 'igraph'

  graph = IGraph::Generate.lattice([30,30],false,false,true)
  puts "Average path (lattice): #{graph.average_path_length(false,true)}"

  puts "Average path (randomised): #{graph.average_path_length(false,true)}"

= 3.

  require 'igraph'

  edges = [
    0,  1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8,
    0, 10, 0,11, 0,12, 0,13, 0,17, 0,19, 0,21, 0,31,
    1,  2, 1, 3, 1, 7, 1,13, 1,17, 1,19, 1,21, 1,30,
    2,  3, 2, 7, 2,27, 2,28, 2,32, 2, 9, 2, 8, 2,13,
    3,  7, 3,12, 3,13, 4, 6, 4,10, 5, 6, 5,10, 5,16,
    6, 16, 8,32, 8,32, 8,33, 9,33,13,33,14,32,14,33,

  g =,false)
  vs = g.vertices

  max =,IGraph::ALL,true)).max{|a,b| a[1] <=> b[1]}
  puts "Maximum degree is      #{sprintf("%10i",max[1])}, vertex #{max[0]}."

  max =,IGraph::ALL)).max{|a,b| a[1] <=> b[1]}
  puts "Maximum closeness is   #{sprintf("%10f",max[1])}, vertex  #{max[0]}."

  max =,IGraph::ALL)).max{|a,b| a[1] <=> b[1]}
  puts "Maximum betweenness is #{sprintf("%10f",max[1])}, vertex  #{max[0]}."

== License

Copyright (C) 2006 Alex Gutteridge

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
Something went wrong with that request. Please try again.