igraph 0.3.2 → 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,109 @@
1
+ #include "igraph.h"
2
+ #include "ruby.h"
3
+ #include "cIGraph.h"
4
+
5
+ /* call-seq:
6
+ * igraph.motifs_randesu(size,cut)
7
+ *
8
+ */
9
+ VALUE cIGraph_motifs_randesu(VALUE self, VALUE size, VALUE cuts){
10
+
11
+ igraph_t *graph;
12
+ igraph_vector_t cutsv;
13
+ igraph_vector_t res;
14
+ int i;
15
+ VALUE hist = rb_ary_new();
16
+
17
+ Data_Get_Struct(self, igraph_t, graph);
18
+
19
+ igraph_vector_init(&res,0);
20
+
21
+ //Convert an array of vertices to a vector of vertex ids
22
+ igraph_vector_init(&cutsv,0);
23
+ for(i=0;i<RARRAY(cuts)->len;i++){
24
+ igraph_vector_push_back(&cutsv,NUM2DBL(RARRAY(cuts)->ptr[i]));
25
+ }
26
+
27
+ igraph_motifs_randesu(graph,&res,NUM2INT(size),&cutsv);
28
+
29
+ for(i=0; i<igraph_vector_size(&res); i++){
30
+ rb_ary_push(hist,INT2NUM(VECTOR(res)[i]));
31
+ }
32
+
33
+ igraph_vector_destroy(&cutsv);
34
+ igraph_vector_destroy(&res);
35
+
36
+ return hist;
37
+
38
+ }
39
+
40
+ /* call-seq:
41
+ * igraph.motifs_randesu_no(size,cut)
42
+ *
43
+ */
44
+ VALUE cIGraph_motifs_randesu_no(VALUE self, VALUE size, VALUE cuts){
45
+
46
+ igraph_t *graph;
47
+ igraph_vector_t cutsv;
48
+ igraph_integer_t res;
49
+ int i;
50
+
51
+ Data_Get_Struct(self, igraph_t, graph);
52
+
53
+ //Convert an array of vertices to a vector of vertex ids
54
+ igraph_vector_init(&cutsv,0);
55
+ for(i=0;i<RARRAY(cuts)->len;i++){
56
+ igraph_vector_push_back(&cutsv,NUM2DBL(RARRAY(cuts)->ptr[i]));
57
+ }
58
+
59
+ igraph_motifs_randesu_no(graph,&res,NUM2INT(size),&cutsv);
60
+
61
+ igraph_vector_destroy(&cutsv);
62
+
63
+ return INT2NUM(res);
64
+
65
+ }
66
+
67
+ /* call-seq:
68
+ * igraph.motifs_randesu_estimate(size,cut,samplen,samplev)
69
+ *
70
+ */
71
+ VALUE cIGraph_motifs_randesu_estimate(VALUE self, VALUE size, VALUE cuts,
72
+ VALUE samplen, VALUE samplev){
73
+
74
+ igraph_t *graph;
75
+ igraph_vector_t cutsv;
76
+ igraph_vector_t vidv;
77
+ igraph_integer_t res;
78
+ int i;
79
+
80
+ if(samplev != Qnil){
81
+ igraph_vector_init(&vidv,0);
82
+ //Convert an array of vertices to a vector of vertex ids
83
+ igraph_vector_init_int(&vidv,0);
84
+ cIGraph_vertex_arr_to_id_vec(self,samplev,&vidv);
85
+ }
86
+
87
+ Data_Get_Struct(self, igraph_t, graph);
88
+
89
+ igraph_vector_init(&cutsv,0);
90
+ for(i=0;i<RARRAY(cuts)->len;i++){
91
+ igraph_vector_push_back(&cutsv,NUM2DBL(RARRAY(cuts)->ptr[i]));
92
+ }
93
+
94
+ if(samplev == Qnil){
95
+ igraph_motifs_randesu_estimate(graph,&res,NUM2INT(size),
96
+ &cutsv,NUM2INT(samplen),NULL);
97
+ } else {
98
+ igraph_motifs_randesu_estimate(graph,&res,NUM2INT(size),
99
+ &cutsv,NUM2INT(samplen),&vidv);
100
+ }
101
+
102
+ igraph_vector_destroy(&cutsv);
103
+ if(samplev != Qnil){
104
+ igraph_vector_destroy(&vidv);
105
+ }
106
+
107
+ return INT2NUM(res);
108
+
109
+ }
@@ -31,7 +31,7 @@ VALUE cIGraph_laplacian(VALUE self, VALUE mode){
31
31
  VALUE val;
32
32
  VALUE matrix = rb_ary_new();
33
33
 
34
- if(mode = Qtrue)
34
+ if(mode == Qtrue)
35
35
  pmode = 1;
36
36
 
37
37
  Data_Get_Struct(self, igraph_t, graph);
@@ -0,0 +1,24 @@
1
+ require 'igraph'
2
+
3
+ g = IGraph.new(['A','B','A','C','A','D','C','D'],false)
4
+
5
+ adj = g.get_adjacency(2)
6
+ g.vcount.times do |k|
7
+ adj[k][k] = 1
8
+ end
9
+
10
+ dis = Array.new(4){|i| Array.new(4)}
11
+
12
+ dis.each_with_index do |row,i|
13
+ row.each_with_index do |cell,j|
14
+ cij = 0
15
+ g.vcount.times do |k|
16
+ puts "#{i} #{j} #{k}"
17
+ cij += adj[i][k] * adj[j][k]
18
+ end
19
+ dis[i][j] = 10 - cij
20
+ end
21
+ end
22
+
23
+ p adj
24
+ p dis
@@ -0,0 +1,21 @@
1
+ require 'test/unit'
2
+ require 'igraph'
3
+
4
+ class TestGraph < Test::Unit::TestCase
5
+ def test_cliques
6
+ g = IGraph.new([1,2,3,4],false)
7
+ assert_equal [[1,2],[3,4]], g.cliques(2,0)
8
+ end
9
+ def test_largest_cliques
10
+ g = IGraph.new(['A','B','C','D','A','E','B','E'],false)
11
+ assert_equal [['A','B','E','B','E']], g.largest_cliques()
12
+ end
13
+ def test_maximal_cliques
14
+ g = IGraph.new(['A','B','C','D','A','E','B','E'],false)
15
+ assert_equal [['A','B','E'],['C','D']], g.maximal_cliques()
16
+ end
17
+ def test_clique_number
18
+ g = IGraph.new(['A','B','C','D','A','E','B','E'],false)
19
+ assert_equal 3, g.clique_number
20
+ end
21
+ end
@@ -0,0 +1,11 @@
1
+ require 'test/unit'
2
+ require 'igraph'
3
+
4
+ Infinity = 1.0/0
5
+
6
+ class TestGraph < Test::Unit::TestCase
7
+ def test_dijkstra
8
+ g = IGraph.new([1,2,3,4],false)
9
+ assert_equal [[0,1.5,Infinity,Infinity]], g.dijkstra_shortest_paths([1],[1.5,2.5],IGraph::OUT)
10
+ end
11
+ end
@@ -0,0 +1,26 @@
1
+ require 'test/unit'
2
+ require 'igraph'
3
+
4
+ class TestGraph < Test::Unit::TestCase
5
+ def test_grg
6
+ g = IGraph.grg_game(10,0.1,false)
7
+ assert_equal 10, g.vertices.size
8
+ end
9
+ def test_barabasi
10
+ g = IGraph.barabasi_game(10,3,false,false)
11
+ assert_equal 10, g.vertices.size
12
+ end
13
+ def test_nonlinear_barabasi
14
+ g = IGraph.nonlinear_barabasi_game(10,1.9,3,false,0.1,false)
15
+ assert_equal 10, g.vertices.size
16
+ end
17
+ def test_erdos_renyi
18
+ g = IGraph.erdos_renyi_game(IGraph::ERDOS_RENYI_GNP,10,0.5,false,false)
19
+ assert_equal 10, g.vertices.size
20
+ g = IGraph.erdos_renyi_game(IGraph::ERDOS_RENYI_GNM,10,0.5,false,false)
21
+ assert_equal 10, g.vertices.size
22
+ end
23
+ def test_watts_strogatz
24
+
25
+ end
26
+ end
@@ -0,0 +1,21 @@
1
+ require 'test/unit'
2
+ require 'igraph'
3
+
4
+ class TestGraph < Test::Unit::TestCase
5
+ def test_independent_vertex_sets
6
+ g = IGraph.new([1,2,3,4],true)
7
+ assert_equal [[1,3],[1,4],[2,3],[2,4]], g.independent_vertex_sets(2,0)
8
+ end
9
+ def test_largest_independent_vertex_sets
10
+ g = IGraph.new([1,2,3,4,1,5],true)
11
+ assert_equal [[2,3,5],[2,4,5]], g.largest_independent_vertex_sets
12
+ end
13
+ def test_maximal_independent_vertex_sets
14
+ g = IGraph.new([1,2,3,4],true)
15
+ assert_equal [[1,3],[1,4],[2,3],[2,4]], g.maximal_independent_vertex_sets
16
+ end
17
+ def test_independence_number
18
+ g = IGraph.new([1,2,3,4],true)
19
+ assert_equal 2, g.independence_number
20
+ end
21
+ end
@@ -0,0 +1,33 @@
1
+ require 'test/unit'
2
+ require 'igraph'
3
+
4
+ class TestGraph < Test::Unit::TestCase
5
+ def test_isomorphic
6
+ g = IGraph.new([1,2,3,4],false)
7
+ h = IGraph.new([5,6,7,8],false)
8
+ assert_equal true, g.isomorphic(h)
9
+ assert_equal true, h.isomorphic(g)
10
+ end
11
+ def test_isomorphic_vf2
12
+ g = IGraph.new([1,2,3,4],false)
13
+ h = IGraph.new([5,6,7,8],false)
14
+ assert_equal true, g.isomorphic_vf2(h)
15
+ assert_equal true, h.isomorphic_vf2(g)
16
+ end
17
+ def test_isoclass
18
+ g = IGraph.new([1,2,3,4],false)
19
+ h = IGraph.new([5,6,7,8],false)
20
+ assert g.isoclass >= 0 and g.isoclass <= 11
21
+ assert_equal h.isoclass, g.isoclass
22
+ end
23
+ def test_isoclass_subgraph
24
+ g = IGraph.new([1,2,3,4],false)
25
+ assert g.isoclass_subgraph([1,2,3]) >= 0 and g.isoclass <= 4
26
+ assert_equal g.isoclass_subgraph([1,2,3]), g.isoclass_subgraph([2,3,4])
27
+ end
28
+ def test_igraph_isoclass_create
29
+ g = IGraph.new([1,2,3,4],false)
30
+ h = IGraph.isoclass_create(4,g.isoclass,false)
31
+ assert_equal g.isoclass, h.isoclass
32
+ end
33
+ end
@@ -23,4 +23,39 @@ class TestGraph < Test::Unit::TestCase
23
23
  assert_equal g.vcount, l.nrow
24
24
  assert_equal 2, l.ncol
25
25
  end
26
+ def test_kamada_kawai
27
+ g = IGraph.new([1,2,3,4],true)
28
+ l = g.layout_kamada_kawai(10,1,1,2,1)
29
+ assert_instance_of IGraphMatrix, l
30
+ assert_equal g.vcount, l.nrow
31
+ assert_equal 2, l.ncol
32
+ end
33
+ def test_reingold_tilford
34
+ g = IGraph.new([1,2,3,4],true)
35
+ l = g.layout_reingold_tilford(1)
36
+ assert_instance_of IGraphMatrix, l
37
+ assert_equal g.vcount, l.nrow
38
+ assert_equal 2, l.ncol
39
+ end
40
+ def test_reingold_tilford_circular
41
+ g = IGraph.new([1,2,3,4],true)
42
+ l = g.layout_reingold_tilford_circular(1)
43
+ assert_instance_of IGraphMatrix, l
44
+ assert_equal g.vcount, l.nrow
45
+ assert_equal 2, l.ncol
46
+ end
47
+ def test_grid_fruchterman_reingold
48
+ g = IGraph.new([1,2,3,4],true)
49
+ l = g.layout_grid_fruchterman_reingold(10,1,1,2,1,1,false)
50
+ assert_instance_of IGraphMatrix, l
51
+ assert_equal g.vcount, l.nrow
52
+ assert_equal 2, l.ncol
53
+ end
54
+ def test_lgl
55
+ g = IGraph.new([1,2,3,4],true)
56
+ l = g.layout_lgl(10,1,1,2,1,1,1)
57
+ assert_instance_of IGraphMatrix, l
58
+ assert_equal g.vcount, l.nrow
59
+ assert_equal 2, l.ncol
60
+ end
26
61
  end
@@ -0,0 +1,19 @@
1
+ require 'test/unit'
2
+ require 'igraph'
3
+
4
+ class TestGraph < Test::Unit::TestCase
5
+ def test_motifs_randesu
6
+ g = IGraph.new(['A','B','C','D','A','C'],false)
7
+ hist = g.motifs_randesu(3,[0,0,0])
8
+ assert_equal [0,0,2,0], hist
9
+ end
10
+ def test_motifs_randesu_no
11
+ g = IGraph.new(['A','B','C','D','A','C'],false)
12
+ assert_equal 2, g.motifs_randesu_no(3,[0,0,0])
13
+ end
14
+ def test_motifs_randesu_estimate
15
+ g = IGraph.new(['A','B','C','D','A','C'],false)
16
+ assert_equal 2, g.motifs_randesu_estimate(3,[0,0,0],4,nil)
17
+ assert_equal 2, g.motifs_randesu_estimate(3,[0,0,0],0,['A','B','C','D'])
18
+ end
19
+ end
@@ -3,9 +3,8 @@
3
3
  require 'test/unit'
4
4
 
5
5
  require 'tc_attributes'
6
+ require 'tc_cliques'
6
7
  require 'tc_create'
7
- require 'tc_iterators'
8
- require 'tc_selectors'
9
8
  require 'tc_add_delete'
10
9
  require 'tc_basic_query'
11
10
  require 'tc_basic_properties'
@@ -13,12 +12,19 @@ require 'tc_centrality'
13
12
  require 'tc_components'
14
13
  require 'tc_copy'
15
14
  require 'tc_cores'
15
+ require 'tc_dijkstra'
16
16
  require 'tc_directedness'
17
17
  require 'tc_error_handling'
18
18
  require 'tc_file_read_write'
19
+ require 'tc_generators_random'
20
+ require 'tc_independent_vertex_sets'
21
+ require 'tc_isomorphic'
22
+ require 'tc_iterators'
19
23
  require 'tc_layout'
20
24
  require 'tc_matrix'
25
+ require 'tc_motif'
21
26
  require 'tc_other_ops'
27
+ require 'tc_selectors'
22
28
  require 'tc_shortest_paths'
23
29
  require 'tc_spanning'
24
30
  require 'tc_spectral'
@@ -0,0 +1,61 @@
1
+ require 'igraph'
2
+ require 'cairo'
3
+
4
+ g = IGraph.barabasi_game(100,3,false,false)
5
+
6
+ vertices = g.to_a
7
+ layout = g.send(ARGV.shift.to_sym,*ARGV.map{|a| eval(a)}).to_a
8
+
9
+ format = Cairo::FORMAT_ARGB32
10
+ width = 1000
11
+ height = 1000
12
+
13
+ surface = Cairo::ImageSurface.new(format, width, height)
14
+ cr = Cairo::Context.new(surface)
15
+
16
+ # fill background with white
17
+ cr.set_source_rgba(1.0, 1.0, 1.0, 0.8)
18
+ cr.paint
19
+
20
+ max_x = layout.map{|a| a[0]}.max
21
+ min_x = layout.map{|a| a[0]}.min
22
+ max_y = layout.map{|a| a[1]}.max
23
+ min_y = layout.map{|a| a[1]}.min
24
+
25
+ x_var = max_x - min_x
26
+ y_var = max_y - min_y
27
+
28
+ max_var = [x_var,y_var].max
29
+
30
+ layout.each_with_index do |a,i|
31
+ x,y = *a
32
+
33
+ x = (x - min_x)/max_var
34
+ y = (y - min_y)/max_var
35
+ x *= (width)
36
+ y *= (height)
37
+
38
+ layout[i] = [x,y]
39
+
40
+ puts "#{x} #{y}"
41
+
42
+ end
43
+
44
+ layout.each_with_index do |a,i|
45
+
46
+ v = vertices[i]
47
+ x,y = *a
48
+
49
+ cr.set_source_rgba(rand,rand,rand,0.5)
50
+ cr.circle(x,y,1).fill
51
+
52
+ g.adjacent_vertices(v,IGraph::OUT).each do |w|
53
+ cr.move_to(x,y)
54
+ wx,wy = *layout[vertices.index(w)]
55
+ cr.line_to(wx,wy)
56
+ cr.stroke
57
+ end
58
+
59
+ end
60
+
61
+ cr.target.write_to_png("test.png")
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.2
3
3
  specification_version: 1
4
4
  name: igraph
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.3.2
7
- date: 2007-09-03 00:00:00 +09:00
6
+ version: 0.3.3
7
+ date: 2007-10-02 00:00:00 +09:00
8
8
  summary: IGraph is a Ruby extension for interfacing with the C igraph library (http://cneurocvs.rmki.kfki.hu/igraph/). igraph is a library for creating and manipulating graphs with a particular emphasis on network analysis functions.
9
9
  require_paths:
10
10
  - test
@@ -41,14 +41,20 @@ files:
41
41
  - ext/cIGraph_basic_properties.c
42
42
  - ext/cIGraph_basic_query.c
43
43
  - ext/cIGraph_centrality.c
44
+ - ext/cIGraph_cliques.c
44
45
  - ext/cIGraph_components.c
46
+ - ext/cIGraph_dijkstra.c
45
47
  - ext/cIGraph_direction.c
46
48
  - ext/cIGraph_error_handlers.c
47
49
  - ext/cIGraph_file.c
50
+ - ext/cIGraph_generators_random.c
51
+ - ext/cIGraph_independent_vertex_sets.c
52
+ - ext/cIGraph_isomorphism.c
48
53
  - ext/cIGraph_iterators.c
49
54
  - ext/cIGraph_kcores.c
50
55
  - ext/cIGraph_layout.c
51
56
  - ext/cIGraph_matrix.c
57
+ - ext/cIGraph_motif.c
52
58
  - ext/cIGraph_operators.c
53
59
  - ext/cIGraph_other_ops.c
54
60
  - ext/cIGraph_selectors.c
@@ -61,20 +67,27 @@ files:
61
67
  - ext/cIGraph_vertex_neighbourhood.c
62
68
  - ext/extconf.rb
63
69
  - test/tc_add_delete.rb
70
+ - test/tc_adj_to_distance.rb
64
71
  - test/tc_attributes.rb
65
72
  - test/tc_basic_properties.rb
66
73
  - test/tc_basic_query.rb
67
74
  - test/tc_centrality.rb
75
+ - test/tc_cliques.rb
68
76
  - test/tc_components.rb
69
77
  - test/tc_copy.rb
70
78
  - test/tc_cores.rb
71
79
  - test/tc_create.rb
80
+ - test/tc_dijkstra.rb
72
81
  - test/tc_directedness.rb
73
82
  - test/tc_error_handling.rb
74
83
  - test/tc_file_read_write.rb
84
+ - test/tc_generators_random.rb
85
+ - test/tc_independent_vertex_sets.rb
86
+ - test/tc_isomorphic.rb
75
87
  - test/tc_iterators.rb
76
88
  - test/tc_layout.rb
77
89
  - test/tc_matrix.rb
90
+ - test/tc_motif.rb
78
91
  - test/tc_other_ops.rb
79
92
  - test/tc_selectors.rb
80
93
  - test/tc_shortest_paths.rb
@@ -85,6 +98,7 @@ files:
85
98
  - test/tc_transitivity.rb
86
99
  - test/tc_vertex_neighbourhood.rb
87
100
  - test/test_all.rb
101
+ - test/test_draw.rb
88
102
  test_files:
89
103
  - test/test_all.rb
90
104
  rdoc_options: