From 1e2e048bfc9343cde3700232dee7447a3c0eddce Mon Sep 17 00:00:00 2001 From: alexgutteridge Date: Tue, 2 Oct 2007 07:47:10 +0000 Subject: [PATCH] --- ext/cIGraph_generators_random.c | 72 +++++++++++++++++++++++++++++++++ test/tc_generators_random.rb | 26 ++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 ext/cIGraph_generators_random.c create mode 100644 test/tc_generators_random.rb diff --git a/ext/cIGraph_generators_random.c b/ext/cIGraph_generators_random.c new file mode 100644 index 0000000..373c5db --- /dev/null +++ b/ext/cIGraph_generators_random.c @@ -0,0 +1,72 @@ +#include "igraph.h" +#include "ruby.h" +#include "cIGraph.h" + +VALUE cIGraph_grg_game(VALUE self, VALUE nodes, VALUE radius, VALUE torus){ + + igraph_t *graph; + VALUE new_graph; + + new_graph = cIGraph_alloc(cIGraph); + Data_Get_Struct(new_graph, igraph_t, graph); + + igraph_destroy(graph); + igraph_grg_game(graph, NUM2INT(nodes), NUM2DBL(radius), + torus == Qtrue ? 1: 0); + + return new_graph; + +} + +VALUE cIGraph_barabasi_game(VALUE self, VALUE nodes, VALUE m, VALUE outpref, VALUE directed){ + + igraph_t *graph; + VALUE new_graph; + + new_graph = cIGraph_alloc(cIGraph); + Data_Get_Struct(new_graph, igraph_t, graph); + + igraph_destroy(graph); + igraph_barabasi_game(graph, NUM2INT(nodes), NUM2INT(m), NULL, + outpref == Qtrue ? 1: 0, directed == Qtrue ? 1: 0); + + return new_graph; + +} + +VALUE cIGraph_nonlinear_barabasi_game(VALUE self, VALUE nodes, VALUE power, VALUE m, VALUE outpref, VALUE zeroappeal, VALUE directed){ + + igraph_t *graph; + VALUE new_graph; + + new_graph = cIGraph_alloc(cIGraph); + Data_Get_Struct(new_graph, igraph_t, graph); + + igraph_destroy(graph); + igraph_nonlinear_barabasi_game(graph, NUM2INT(nodes), NUM2DBL(power), + NUM2INT(m), NULL, + outpref == Qtrue ? 1: 0, + NUM2DBL(zeroappeal), + directed == Qtrue ? 1: 0); + + return new_graph; + +} + +VALUE cIGraph_erdos_renyi_game(VALUE self, VALUE type, VALUE nodes, VALUE mp, VALUE directed, VALUE loops){ + + igraph_t *graph; + VALUE new_graph; + + new_graph = cIGraph_alloc(cIGraph); + Data_Get_Struct(new_graph, igraph_t, graph); + + igraph_destroy(graph); + igraph_erdos_renyi_game(graph, NUM2INT(type), NUM2INT(nodes), + NUM2DBL(mp), + directed == Qtrue ? 1: 0, + loops == Qtrue ? 1: 0); + + return new_graph; + +} diff --git a/test/tc_generators_random.rb b/test/tc_generators_random.rb new file mode 100644 index 0000000..c3ae114 --- /dev/null +++ b/test/tc_generators_random.rb @@ -0,0 +1,26 @@ +require 'test/unit' +require 'igraph' + +class TestGraph < Test::Unit::TestCase + def test_grg + g = IGraph.grg_game(10,0.1,false) + assert_equal 10, g.vertices.size + end + def test_barabasi + g = IGraph.barabasi_game(10,3,false,false) + assert_equal 10, g.vertices.size + end + def test_nonlinear_barabasi + g = IGraph.nonlinear_barabasi_game(10,1.9,3,false,0.1,false) + assert_equal 10, g.vertices.size + end + def test_erdos_renyi + g = IGraph.erdos_renyi_game(IGraph::ERDOS_RENYI_GNP,10,0.5,false,false) + assert_equal 10, g.vertices.size + g = IGraph.erdos_renyi_game(IGraph::ERDOS_RENYI_GNM,10,0.5,false,false) + assert_equal 10, g.vertices.size + end + def test_watts_strogatz + + end +end