ruby-igraph
Ruby bindings for the igraph library - a collection of network analysis tools.
Installation
Install the igraph C library first:
# macOS
brew install igraph
# Ubuntu/Debian
sudo apt-get install libigraph-dev
# Other systems: see https://igraph.org/c/doc/igraph-Installation.html
Then install the gem:
gem install ruby-igraph
Usage
require 'igraph'
# Create a simple graph
graph = IGraph::LibIGraph::Graph.new
IGraph::LibIGraph.igraph_empty(graph.pointer, 3, false)
# Add edges
edges = IGraph::LibIGraph::VectorIntStruct.new
IGraph::LibIGraph.igraph_vector_int_init(edges.pointer, 4)
IGraph::LibIGraph.igraph_vector_int_set(edges.pointer, 0, 0)
IGraph::LibIGraph.igraph_vector_int_set(edges.pointer, 1, 1)
IGraph::LibIGraph.igraph_vector_int_set(edges.pointer, 2, 1)
IGraph::LibIGraph.igraph_vector_int_set(edges.pointer, 3, 2)
IGraph::LibIGraph.igraph_create(graph.pointer, edges.pointer, 3, false)
# Get basic properties
vcount = IGraph::LibIGraph.igraph_vcount(graph.pointer) # => 3
ecount = IGraph::LibIGraph.igraph_ecount(graph.pointer) # => 2
# Clean up
IGraph::LibIGraph.igraph_vector_int_destroy(edges.pointer)
IGraph::LibIGraph.igraph_destroy(graph.pointer)
Development
git clone https://github.com/kojix2/ruby-igraph
cd ruby-igraph
bundle install
rake test
Contributing
Bug reports and pull requests are welcome on GitHub.
License
This project was built with love using the vibe coding method.