Browse Source

tags/0.3.3
alexgutteridge 19 years ago
parent
commit
1e2e048bfc
2 changed files with 98 additions and 0 deletions
  1. +72
    -0
      ext/cIGraph_generators_random.c
  2. +26
    -0
      test/tc_generators_random.rb

+ 72
- 0
ext/cIGraph_generators_random.c View File

@@ -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;

}

+ 26
- 0
test/tc_generators_random.rb View File

@@ -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

Loading…
Cancel
Save