This commit is contained in:
alexgutteridge 2007-11-09 05:33:28 +00:00
parent cfe40b637e
commit a743da0276
8 changed files with 559 additions and 5 deletions

View File

@ -208,12 +208,53 @@ void Init_igraph(){
rb_define_const(cIGraph, "GET_ADJACENCY_BOTH", INT2NUM(2));
rb_define_const(cIGraph, "ERDOS_RENYI_GNP", INT2NUM(0));
rb_define_const(cIGraph, "ERDOS_RENYI_GNM", INT2NUM(1));
rb_define_const(cIGraph, "ERDOS_RENYI_GNM", INT2NUM(1));
rb_define_const(cIGraph, "ADJ_DIRECTED", INT2NUM(0));
rb_define_const(cIGraph, "ADJ_UNDIRECTED", INT2NUM(1));
rb_define_const(cIGraph, "ADJ_MAX", INT2NUM(2));
rb_define_const(cIGraph, "ADJ_MIN", INT2NUM(3));
rb_define_const(cIGraph, "ADJ_PLUS", INT2NUM(4));
rb_define_const(cIGraph, "ADJ_UPPER", INT2NUM(5));
rb_define_const(cIGraph, "ADJ_LOWER", INT2NUM(6));
rb_define_const(cIGraph, "STAR_OUT", INT2NUM(0));
rb_define_const(cIGraph, "STAR_IN", INT2NUM(1));
rb_define_const(cIGraph, "STAR_UNDIRECTED", INT2NUM(2));
rb_define_const(cIGraph, "TREE_OUT", INT2NUM(0));
rb_define_const(cIGraph, "TREE_IN", INT2NUM(1));
rb_define_const(cIGraph, "TREE_UNDIRECTED", INT2NUM(2));
rb_define_singleton_method(cIGraph, "adjacency", cIGraph_adjacency, 2); /* in cIGraph_generators_deterministic.c */
rb_define_singleton_method(cIGraph, "star", cIGraph_star, 3); /* in cIGraph_generators_deterministic.c */
rb_define_singleton_method(cIGraph, "lattice", cIGraph_lattice, 4); /* in cIGraph_generators_deterministic.c */
rb_define_singleton_method(cIGraph, "ring", cIGraph_ring, 4); /* in cIGraph_generators_deterministic.c */
rb_define_singleton_method(cIGraph, "tree", cIGraph_tree, 3); /* in cIGraph_generators_deterministic.c */
rb_define_singleton_method(cIGraph, "full", cIGraph_full, 3); /* in cIGraph_generators_deterministic.c */
rb_define_singleton_method(cIGraph, "atlas", cIGraph_atlas, 1); /* in cIGraph_generators_deterministic.c */
rb_define_singleton_method(cIGraph, "extended_chordal_ring", cIGraph_extended_chordal_ring, 2); /* in cIGraph_generators_deterministic.c */
rb_define_method(cIGraph, "connect_neighborhood", cIGraph_connect_neighborhood, 2); /* in cIGraph_generators_deterministic.c */
rb_define_singleton_method(cIGraph, "grg_game", cIGraph_grg_game, 3); /* in cIGraph_generators_random.c */
rb_define_singleton_method(cIGraph, "barabasi_game", cIGraph_barabasi_game, 4); /* in cIGraph_generators_random.c */
rb_define_singleton_method(cIGraph, "nonlinear_barabasi_game", cIGraph_nonlinear_barabasi_game, 6); /* in cIGraph_generators_random.c */
rb_define_singleton_method(cIGraph, "erdos_renyi_game", cIGraph_erdos_renyi_game, 5); /* in cIGraph_generators_random.c */
rb_define_singleton_method(cIGraph, "erdos_renyi_game", cIGraph_erdos_renyi_game, 5); /* in cIGraph_generators_random.c */
rb_define_singleton_method(cIGraph, "watts_strogatz_game", cIGraph_watts_strogatz_game, 4); /* in cIGraph_generators_random.c */
rb_define_singleton_method(cIGraph, "degree_sequence_game", cIGraph_degree_sequence_game, 2); /* in cIGraph_generators_random.c */
rb_define_singleton_method(cIGraph, "growing_random_game", cIGraph_growing_random_game, 4); /* in cIGraph_generators_random.c */
rb_define_singleton_method(cIGraph, "callaway_traits_game", cIGraph_callaway_traits_game, 6); /* in cIGraph_generators_random.c */
rb_define_singleton_method(cIGraph, "establishment_game", cIGraph_establishment_game, 6); /* in cIGraph_generators_random.c */
rb_define_singleton_method(cIGraph, "preference_game", cIGraph_preference_game, 6); /* in cIGraph_generators_random.c */
rb_define_singleton_method(cIGraph, "asymmetric_preference_game", cIGraph_asymmetric_preference_game, 5); /* in cIGraph_generators_random.c */
rb_define_singleton_method(cIGraph, "recent_degree_game", cIGraph_recent_degree_game, 7); /* in cIGraph_generators_random.c */
rb_define_singleton_method(cIGraph, "barabasi_aging_game", cIGraph_barabasi_aging_game, 11); /* in cIGraph_generators_random.c */
rb_define_singleton_method(cIGraph, "recent_degree_aging_game", cIGraph_recent_degree_aging_game, 9); /* in cIGraph_generators_random.c */
rb_define_singleton_method(cIGraph, "cited_type_game", cIGraph_cited_type_game, 5); /* in cIGraph_generators_random.c */
rb_define_singleton_method(cIGraph, "citing_cited_type_game", cIGraph_citing_cited_type_game, 5); /* in cIGraph_generators_random.c */
rb_define_method(cIGraph, "rewire_edges", cIGraph_rewire_edges, 1); /* cIGraph_randomisation.c */
rb_define_method(cIGraph, "rewire", cIGraph_rewire, 1); /* cIGraph_randomisation.c */
rb_define_method(cIGraph, "[]", cIGraph_get_edge_attr, 2); /* in cIGraph_attribute_handler.c */
rb_define_method(cIGraph, "[]=", cIGraph_set_edge_attr, 3); /* in cIGraph_attribute_handler.c */
@ -345,6 +386,14 @@ rb_define_singleton_method(cIGraph, "erdos_renyi_game", cIGraph_erdos_renyi_game
rb_define_method(cIGraph, "layout_grid_fruchterman_reingold", cIGraph_layout_grid_fruchterman_reingold, 7); /* in cIGraph_layout.c */
rb_define_method(cIGraph, "layout_lgl", cIGraph_layout_lgl, 7); /* in cIGraph_layout.c */
rb_define_method(cIGraph, "layout_random_3d", cIGraph_layout_random_3d, 0); /* in cIGraph_layout3d.c */
rb_define_method(cIGraph, "layout_sphere", cIGraph_layout_sphere, 0); /* in cIGraph_layout3d.c */
rb_define_method(cIGraph, "layout_fruchterman_reingold_3d", cIGraph_layout_fruchterman_reingold_3d, 6); /* in cIGraph_layout3d.c */
rb_define_method(cIGraph, "layout_kamada_kawai_3d", cIGraph_layout_kamada_kawai_3d, 5); /* in cIGraph_layout3d.c */
rb_define_singleton_method(cIGraph, "layout_merge_dla", cIGraph_layout_merge_dla, 2); /* in cIGraph_layout.c */
//Matrix class
cIGraphMatrix = rb_define_class("IGraphMatrix", rb_cObject);

View File

@ -30,6 +30,17 @@ VALUE cIGraph_alloc(VALUE klass);
VALUE cIGraph_initialize(int argc, VALUE *argv, VALUE self);
VALUE cIGraph_init_copy(VALUE copy, VALUE orig);
//Graph generators
VALUE cIGraph_adjacency(VALUE self, VALUE matrix, VALUE mode);
VALUE cIGraph_star (VALUE self, VALUE n, VALUE mode, VALUE center);
VALUE cIGraph_lattice (VALUE self, VALUE dim, VALUE directed, VALUE mutual, VALUE circular);
VALUE cIGraph_ring(VALUE self, VALUE n, VALUE directed, VALUE mutual, VALUE circular);
VALUE cIGraph_tree(VALUE self, VALUE n, VALUE children, VALUE type);
VALUE cIGraph_full(VALUE self, VALUE n, VALUE directed, VALUE loops);
VALUE cIGraph_atlas(VALUE self, VALUE n);
VALUE cIGraph_extended_chordal_ring(VALUE self, VALUE n, VALUE matrix);
VALUE cIGraph_connect_neighborhood(VALUE self, VALUE order, VALUE mode);
//Random graph generators
VALUE cIGraph_grg_game (VALUE self, VALUE nodes,
VALUE radius, VALUE torus);
@ -38,6 +49,21 @@ VALUE cIGraph_barabasi_game(VALUE self, VALUE nodes,
VALUE cIGraph_nonlinear_barabasi_game(VALUE self, VALUE nodes, VALUE power,
VALUE m, VALUE outpref, VALUE zeroappeal, VALUE directed);
VALUE cIGraph_erdos_renyi_game (VALUE self, VALUE type, VALUE nodes, VALUE mp, VALUE directed, VALUE loops);
VALUE cIGraph_watts_strogatz_game(VALUE self, VALUE dim, VALUE size, VALUE nei, VALUE p);
VALUE cIGraph_degree_sequence_game(VALUE self, VALUE out_deg, VALUE in_deg);
VALUE cIGraph_growing_random_game(VALUE self, VALUE n, VALUE m, VALUE directed, VALUE citation);
VALUE cIGraph_callaway_traits_game(VALUE self, VALUE nodes, VALUE types, VALUE e_per_step, VALUE type_dist, VALUE pref_matrix, VALUE directed);
VALUE cIGraph_establishment_game(VALUE self, VALUE nodes, VALUE types, VALUE k, VALUE type_dist, VALUE pref_matrix, VALUE directed);
VALUE cIGraph_preference_game(VALUE self, VALUE nodes, VALUE types, VALUE type_dist, VALUE pref_matrix, VALUE directed, VALUE loops);
VALUE cIGraph_asymmetric_preference_game(VALUE self, VALUE nodes, VALUE types, VALUE type_dist_matrix, VALUE pref_matrix, VALUE loops);
VALUE cIGraph_recent_degree_game(VALUE self, VALUE n, VALUE power, VALUE window, VALUE m, VALUE outpref, VALUE zero_appeal, VALUE directed);
VALUE cIGraph_barabasi_aging_game(VALUE self, VALUE nodes, VALUE m, VALUE outpref, VALUE pa_exp, VALUE aging_exp, VALUE aging_bin, VALUE zero_deg_appeal, VALUE zero_age_appeal, VALUE deg_coef, VALUE age_coef, VALUE directed);
VALUE cIGraph_recent_degree_aging_game(VALUE self, VALUE nodes, VALUE m, VALUE outpref, VALUE pa_exp, VALUE aging_exp, VALUE aging_bin, VALUE time_window, VALUE zero_appeal, VALUE directed);
VALUE cIGraph_cited_type_game(VALUE self, VALUE nodes, VALUE types, VALUE pref, VALUE e_per_s, VALUE directed);
VALUE cIGraph_citing_cited_type_game(VALUE self, VALUE nodes, VALUE types, VALUE pref, VALUE e_per_s, VALUE directed);
VALUE cIGraph_rewire_edges(VALUE self, VALUE prop);
VALUE cIGraph_rewire(VALUE self, VALUE n, VALUE mode);
//Attribute accessors
int replace_i(VALUE key, VALUE val, VALUE hash);
@ -216,6 +242,23 @@ VALUE cIGraph_layout_lgl(VALUE self,
VALUE cellsize,
VALUE proot);
VALUE cIGraph_layout_random_3d(VALUE self);
VALUE cIGraph_layout_sphere (VALUE self);
VALUE cIGraph_layout_fruchterman_reingold_3d(VALUE self,
VALUE niter,
VALUE maxdelta,
VALUE volume,
VALUE coolexp,
VALUE repulserad,
VALUE use_seed);
VALUE cIGraph_layout_kamada_kawai_3d (VALUE self,
VALUE niter,
VALUE sigma,
VALUE initemp,
VALUE coolexp,
VALUE kkconst);
VALUE cIGraph_layout_merge_dla(VALUE self, VALUE graphs, VALUE layouts);
//Attributes
int cIGraph_attribute_init(igraph_t *graph,

View File

@ -70,3 +70,327 @@ VALUE cIGraph_erdos_renyi_game(VALUE self, VALUE type, VALUE nodes, VALUE mp, VA
return new_graph;
}
VALUE cIGraph_watts_strogatz_game(VALUE self, VALUE dim, VALUE size, VALUE nei, VALUE p){
igraph_t *graph;
VALUE new_graph;
new_graph = cIGraph_alloc(cIGraph);
Data_Get_Struct(new_graph, igraph_t, graph);
igraph_destroy(graph);
igraph_watts_strogatz_game(graph, NUM2INT(dim), NUM2INT(size),
NUM2INT(nei), NUM2DBL(p));
return new_graph;
}
VALUE cIGraph_degree_sequence_game(VALUE self, VALUE out_deg, VALUE in_deg){
igraph_t *graph;
VALUE new_graph;
igraph_vector_t out_degv;
igraph_vector_t in_degv;
int i;
new_graph = cIGraph_alloc(cIGraph);
Data_Get_Struct(new_graph, igraph_t, graph);
igraph_vector_init(&out_degv,0);
igraph_vector_init(&in_degv,0);
for(i=0;i<RARRAY(out_deg)->len;i++){
igraph_vector_push_back(&out_degv,NUM2INT(RARRAY(out_deg)->ptr[i]));
}
for(i=0;i<RARRAY(in_deg)->len;i++){
igraph_vector_push_back(&in_degv,NUM2INT(RARRAY(in_deg)->ptr[i]));
}
igraph_destroy(graph);
igraph_degree_sequence_game(graph, &out_degv, &in_degv, 0);
igraph_vector_destroy(&out_degv);
igraph_vector_destroy(&in_degv);
return new_graph;
}
VALUE cIGraph_growing_random_game(VALUE self, VALUE n, VALUE m, VALUE directed, VALUE citation){
igraph_t *graph;
VALUE new_graph;
new_graph = cIGraph_alloc(cIGraph);
Data_Get_Struct(new_graph, igraph_t, graph);
igraph_destroy(graph);
igraph_growing_random_game(graph, NUM2INT(n), NUM2INT(m),
directed == Qtrue ? 1: 0,
citation == Qtrue ? 1: 0);
return new_graph;
}
VALUE cIGraph_callaway_traits_game(VALUE self, VALUE nodes, VALUE types, VALUE e_per_step, VALUE type_dist, VALUE pref_matrix, VALUE directed){
igraph_t *graph;
VALUE new_graph;
igraph_vector_t type_distv;
igraph_matrix_t *pref_matrixm;
int i;
new_graph = cIGraph_alloc(cIGraph);
Data_Get_Struct(new_graph, igraph_t, graph);
Data_Get_Struct(pref_matrix, igraph_matrix_t, pref_matrixm);
igraph_vector_init(&type_distv,0);
for(i=0;i<RARRAY(type_dist)->len;i++){
igraph_vector_push_back(&type_distv,NUM2DBL(RARRAY(type_dist)->ptr[i]));
}
igraph_destroy(graph);
igraph_callaway_traits_game(graph, NUM2INT(nodes), NUM2INT(types),
NUM2INT(e_per_step), &type_distv,
pref_matrixm,
directed == Qtrue ? 1: 0);
igraph_vector_destroy(&type_distv);
return new_graph;
}
VALUE cIGraph_establishment_game(VALUE self, VALUE nodes, VALUE types, VALUE k, VALUE type_dist, VALUE pref_matrix, VALUE directed){
igraph_t *graph;
VALUE new_graph;
igraph_vector_t type_distv;
igraph_matrix_t *pref_matrixm;
int i;
new_graph = cIGraph_alloc(cIGraph);
Data_Get_Struct(new_graph, igraph_t, graph);
Data_Get_Struct(pref_matrix, igraph_matrix_t, pref_matrixm);
igraph_vector_init(&type_distv,0);
for(i=0;i<RARRAY(type_dist)->len;i++){
igraph_vector_push_back(&type_distv,NUM2DBL(RARRAY(type_dist)->ptr[i]));
}
igraph_destroy(graph);
igraph_establishment_game(graph, NUM2INT(nodes), NUM2INT(types),
NUM2INT(k), &type_distv,
pref_matrixm,
directed == Qtrue ? 1: 0);
igraph_vector_destroy(&type_distv);
return new_graph;
}
VALUE cIGraph_preference_game(VALUE self, VALUE nodes, VALUE types, VALUE type_dist, VALUE pref_matrix, VALUE directed, VALUE loops){
igraph_t *graph;
VALUE new_graph;
igraph_vector_t type_distv;
igraph_matrix_t *pref_matrixm;
int i;
new_graph = cIGraph_alloc(cIGraph);
Data_Get_Struct(new_graph, igraph_t, graph);
Data_Get_Struct(pref_matrix, igraph_matrix_t, pref_matrixm);
igraph_vector_init(&type_distv,0);
for(i=0;i<RARRAY(type_dist)->len;i++){
igraph_vector_push_back(&type_distv,NUM2DBL(RARRAY(type_dist)->ptr[i]));
}
igraph_destroy(graph);
igraph_preference_game(graph, NUM2INT(nodes), NUM2INT(types),
&type_distv,
pref_matrixm,
NULL,
directed == Qtrue ? 1: 0,
loops == Qtrue ? 1 : 0);
igraph_vector_destroy(&type_distv);
return new_graph;
}
VALUE cIGraph_asymmetric_preference_game(VALUE self, VALUE nodes, VALUE types, VALUE type_dist_matrix, VALUE pref_matrix, VALUE loops){
igraph_t *graph;
VALUE new_graph;
igraph_matrix_t *type_dist_matrixm;
igraph_matrix_t *pref_matrixm;
new_graph = cIGraph_alloc(cIGraph);
Data_Get_Struct(new_graph, igraph_t, graph);
Data_Get_Struct(pref_matrix, igraph_matrix_t, pref_matrixm);
Data_Get_Struct(type_dist_matrix, igraph_matrix_t, type_dist_matrixm);
igraph_destroy(graph);
igraph_asymmetric_preference_game(graph, NUM2INT(nodes), NUM2INT(types),
type_dist_matrixm,
pref_matrixm,
NULL, NULL,
loops == Qtrue ? 1 : 0);
return new_graph;
}
VALUE cIGraph_recent_degree_game(VALUE self, VALUE n, VALUE power, VALUE window, VALUE m, VALUE outpref, VALUE zero_appeal, 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_recent_degree_game(graph, NUM2INT(n), NUM2DBL(power),
NUM2INT(window), NUM2INT(m),
NULL,
outpref == Qtrue ? 1: 0,
NUM2DBL(zero_appeal),
directed == Qtrue ? 1: 0);
return new_graph;
}
VALUE cIGraph_barabasi_aging_game(VALUE self, VALUE nodes, VALUE m, VALUE outpref, VALUE pa_exp, VALUE aging_exp, VALUE aging_bin, VALUE zero_deg_appeal, VALUE zero_age_appeal, VALUE deg_coef, VALUE age_coef, 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_aging_game(graph, NUM2INT(nodes), NUM2INT(m),
NULL,
outpref == Qtrue ? 1: 0,
NUM2DBL(pa_exp), NUM2DBL(aging_exp),
NUM2INT(aging_bin),
NUM2DBL(zero_deg_appeal),
NUM2DBL(zero_age_appeal),
NUM2DBL(deg_coef),
NUM2DBL(age_coef),
directed == Qtrue ? 1: 0);
return new_graph;
}
VALUE cIGraph_recent_degree_aging_game(VALUE self, VALUE nodes, VALUE m, VALUE outpref, VALUE pa_exp, VALUE aging_exp, VALUE aging_bin, VALUE time_window, VALUE zero_appeal, 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_recent_degree_aging_game(graph, NUM2INT(nodes), NUM2INT(m),
NULL,
outpref == Qtrue ? 1: 0,
NUM2DBL(pa_exp), NUM2DBL(aging_exp),
NUM2INT(aging_bin),
NUM2INT(time_window),
NUM2DBL(zero_appeal),
directed == Qtrue ? 1: 0);
return new_graph;
}
VALUE cIGraph_cited_type_game(VALUE self, VALUE nodes, VALUE types, VALUE pref, VALUE e_per_s, VALUE directed){
igraph_t *graph;
VALUE new_graph;
igraph_vector_t type_distv;
igraph_vector_t prefv;
int i;
new_graph = cIGraph_alloc(cIGraph);
Data_Get_Struct(new_graph, igraph_t, graph);
igraph_vector_init(&type_distv,0);
igraph_vector_init(&prefv,0);
for(i=0;i<RARRAY(types)->len;i++){
igraph_vector_push_back(&type_distv,NUM2DBL(RARRAY(types)->ptr[i]));
}
for(i=0;i<RARRAY(pref)->len;i++){
igraph_vector_push_back(&prefv,NUM2DBL(RARRAY(pref)->ptr[i]));
}
igraph_destroy(graph);
igraph_cited_type_game(graph, NUM2INT(nodes),
&type_distv,
&prefv,
NUM2INT(e_per_s),
directed == Qtrue ? 1: 0);
igraph_vector_destroy(&type_distv);
igraph_vector_destroy(&prefv);
return new_graph;
}
VALUE cIGraph_citing_cited_type_game(VALUE self, VALUE nodes, VALUE types, VALUE pref, VALUE e_per_s, VALUE directed){
igraph_t *graph;
VALUE new_graph;
igraph_vector_t typev;
igraph_matrix_t *prefm;
int i;
new_graph = cIGraph_alloc(cIGraph);
Data_Get_Struct(new_graph, igraph_t, graph);
Data_Get_Struct(pref, igraph_matrix_t, prefm);
igraph_vector_init(&typev,0);
for(i=0;i<RARRAY(types)->len;i++){
igraph_vector_push_back(&typev,NUM2INT(RARRAY(types)->ptr[i]));
}
printf("ok\n");
igraph_destroy(graph);
igraph_citing_cited_type_game(graph, NUM2INT(nodes),
&typev,
prefm,
NUM2INT(e_per_s),
directed == Qtrue ? 1: 0);
printf("death\n");
igraph_vector_destroy(&typev);
return new_graph;
}

View File

@ -247,3 +247,33 @@ VALUE cIGraph_layout_lgl(VALUE self,
}
VALUE cIGraph_layout_merge_dla(VALUE self, VALUE graphs, VALUE layouts){
igraph_vector_ptr_t thegraphs;
igraph_vector_ptr_t coords;
int i;
igraph_t *graph;
igraph_matrix_t *coord;
igraph_matrix_t *res = malloc(sizeof(igraph_matrix_t));
igraph_vector_ptr_init(&thegraphs,0);
igraph_vector_ptr_init(&coords,0);
igraph_matrix_init(res,0,0);
for(i=0;i<RARRAY(graphs)->len;i++){
Data_Get_Struct(RARRAY(graphs)->ptr[i], igraph_t, graph);
igraph_vector_ptr_push_back(&thegraphs,graph);
}
for(i=0;i<RARRAY(layouts)->len;i++){
Data_Get_Struct(RARRAY(layouts)->ptr[i], igraph_matrix_t, coord);
igraph_vector_ptr_push_back(&coords,coord);
}
igraph_layout_merge_dla(&thegraphs, &coords, res);
igraph_vector_ptr_destroy(&thegraphs);
igraph_vector_ptr_destroy(&coords);
return Data_Wrap_Struct(cIGraphMatrix, 0, cIGraph_matrix_free, res);
}

View File

@ -56,6 +56,27 @@ class TestGraph < Test::Unit::TestCase
assert_equal 1, graph.ecount
end
def test_delete_large
vs = (0..99).to_a
h = IGraph.new([],true)
vs.each do |id|
h.add_vertex(id)
end
g = h.dup
delete_ids = (0..99).to_a.sort_by{rand}[0..19]
assert_nothing_raised do
delete_ids.each do |id|
g.delete_vertex(id)
end
end
delete_ids.each do |id|
assert_equal false, g.include?(id)
end
assert_equal 80, g.vcount
end
def test_delete_edge
graph = IGraph.new(['A','B','C','D'],true)
assert_equal true, graph.are_connected?('A','B')

View File

@ -16,11 +16,85 @@ class TestGraph < Test::Unit::TestCase
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
assert_instance_of IGraph, g
g = IGraph.erdos_renyi_game(IGraph::ERDOS_RENYI_GNM,10,0.5,false,false)
assert_equal 10, g.vertices.size
assert_instance_of IGraph, g
end
def test_watts_strogatz
g = IGraph.watts_strogatz_game(10,1,2,0.6)
assert_instance_of IGraph, g
end
def test_degree_sequence_game
g = IGraph.degree_sequence_game([1,2,3],[1,2,3])
assert_instance_of IGraph, g
end
def test_growing_random_game
assert_instance_of IGraph, IGraph.growing_random_game(10,2,true,true)
end
def test_callaway_traits_game
assert_instance_of IGraph,
IGraph.callaway_traits_game(30,4,2,[0.25,0.25,0.25,0.25],
IGraphMatrix.new([0,0.5,0.25,0.25],
[0.5,0,0.25,0.25],
[0.5,0.25,0,0.25],
[0.5,0.25,0.25,0]),true)
end
def test_establishment_game
assert_instance_of IGraph,
IGraph.establishment_game(30,4,2,[0.25,0.25,0.25,0.25],
IGraphMatrix.new([0,0.5,0.25,0.25],
[0.5,0,0.25,0.25],
[0.5,0.25,0,0.25],
[0.5,0.25,0.25,0]),true)
end
def test_preference_game
assert_instance_of IGraph,
IGraph.preference_game(30,4,[0.25,0.25,0.25,0.25],
IGraphMatrix.new([0,0.5,0.25,0.25],
[0.5,0,0.25,0.25],
[0.5,0.25,0,0.25],
[0.5,0.25,0.25,0]),true,false)
end
def test_asymmetric_preference_game
assert_instance_of IGraph,
IGraph.asymmetric_preference_game(30,4,
IGraphMatrix.new([0,0.5,0.25,0.25],
[0.5,0,0.25,0.25],
[0.5,0.25,0,0.25],
[0.5,0.25,0.25,0]),
IGraphMatrix.new([0,0.5,0.25,0.25],
[0.5,0,0.25,0.25],
[0.5,0.25,0,0.25],
[0.5,0.25,0.25,0]),
false)
end
def test_recent_degree_game
assert_instance_of IGraph,
IGraph.recent_degree_game(30,2,4,5,false,0.1,true)
end
def test_barabasi_aging_game
assert_instance_of IGraph,
IGraph.barabasi_aging_game(30,2,true,0.9,-0.5,3,0.1,0.1,2,2,true)
end
def test_recent_degree_aging_game
assert_instance_of IGraph,
IGraph.recent_degree_aging_game(30,2,true,0.9,-0.5,3,4,0.1,true)
end
def test_cited_type_game
assert_instance_of IGraph,
IGraph.cited_type_game(10,(0..9).to_a,
Array.new(5,0.5)+Array.new(5,0.2),
2,true)
end
def test_citing_cited_type_Game
# assert_instance_of IGraph,
# IGraph.citing_cited_type_game(4,(0..3).to_a,
# IGraphMatrix.new([0,0.5,0.25,0.25],
# [0.5,0,0.25,0.25],
# [0.5,0.25,0,0.25],
# [0.5,0.25,0.25,0]),
# 1,
# true)
end
end

View File

@ -58,4 +58,14 @@ class TestGraph < Test::Unit::TestCase
assert_equal g.vcount, l.nrow
assert_equal 2, l.ncol
end
def test_merge
g = IGraph.new([1,2,3,4],true)
l = g.layout_lgl(10,1,1,2,1,1,1)
h = IGraph.new([1,2,3,4],true)
m = h.layout_lgl(10,1,1,2,1,1,1)
f = IGraph.layout_merge_dla([g,h],[l,m])
assert_instance_of IGraphMatrix, f
assert_equal g.vcount + h.vcount, f.nrow
assert_equal 2, f.ncol
end
end

View File

@ -16,14 +16,17 @@ require 'tc_dijkstra'
require 'tc_directedness'
require 'tc_error_handling'
require 'tc_file_read_write'
require 'tc_generators_deterministic'
require 'tc_generators_random'
require 'tc_independent_vertex_sets'
require 'tc_isomorphic'
require 'tc_iterators'
require 'tc_layout'
require 'tc_layout3d'
require 'tc_matrix'
require 'tc_motif'
require 'tc_other_ops'
require 'tc_randomisation'
require 'tc_selectors'
require 'tc_shortest_paths'
require 'tc_spanning'