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.
- data/Manifest.txt +14 -0
- data/Rakefile.rb +1 -1
- data/ext/cIGraph.c +40 -4
- data/ext/cIGraph.h +70 -2
- data/ext/cIGraph_attribute_handler.c +6 -0
- data/ext/cIGraph_cliques.c +178 -0
- data/ext/cIGraph_dijkstra.c +258 -0
- data/ext/cIGraph_generators_random.c +72 -0
- data/ext/cIGraph_independent_vertex_sets.c +182 -0
- data/ext/cIGraph_isomorphism.c +137 -0
- data/ext/cIGraph_layout.c +174 -2
- data/ext/cIGraph_motif.c +109 -0
- data/ext/cIGraph_spectral.c +1 -1
- data/test/tc_adj_to_distance.rb +24 -0
- data/test/tc_cliques.rb +21 -0
- data/test/tc_dijkstra.rb +11 -0
- data/test/tc_generators_random.rb +26 -0
- data/test/tc_independent_vertex_sets.rb +21 -0
- data/test/tc_isomorphic.rb +33 -0
- data/test/tc_layout.rb +35 -0
- data/test/tc_motif.rb +19 -0
- data/test/test_all.rb +8 -2
- data/test/test_draw.rb +61 -0
- metadata +16 -2
@@ -0,0 +1,72 @@
|
|
1
|
+
#include "igraph.h"
|
2
|
+
#include "ruby.h"
|
3
|
+
#include "cIGraph.h"
|
4
|
+
|
5
|
+
VALUE cIGraph_grg_game(VALUE self, VALUE nodes, VALUE radius, VALUE torus){
|
6
|
+
|
7
|
+
igraph_t *graph;
|
8
|
+
VALUE new_graph;
|
9
|
+
|
10
|
+
new_graph = cIGraph_alloc(cIGraph);
|
11
|
+
Data_Get_Struct(new_graph, igraph_t, graph);
|
12
|
+
|
13
|
+
igraph_destroy(graph);
|
14
|
+
igraph_grg_game(graph, NUM2INT(nodes), NUM2DBL(radius),
|
15
|
+
torus == Qtrue ? 1: 0);
|
16
|
+
|
17
|
+
return new_graph;
|
18
|
+
|
19
|
+
}
|
20
|
+
|
21
|
+
VALUE cIGraph_barabasi_game(VALUE self, VALUE nodes, VALUE m, VALUE outpref, VALUE directed){
|
22
|
+
|
23
|
+
igraph_t *graph;
|
24
|
+
VALUE new_graph;
|
25
|
+
|
26
|
+
new_graph = cIGraph_alloc(cIGraph);
|
27
|
+
Data_Get_Struct(new_graph, igraph_t, graph);
|
28
|
+
|
29
|
+
igraph_destroy(graph);
|
30
|
+
igraph_barabasi_game(graph, NUM2INT(nodes), NUM2INT(m), NULL,
|
31
|
+
outpref == Qtrue ? 1: 0, directed == Qtrue ? 1: 0);
|
32
|
+
|
33
|
+
return new_graph;
|
34
|
+
|
35
|
+
}
|
36
|
+
|
37
|
+
VALUE cIGraph_nonlinear_barabasi_game(VALUE self, VALUE nodes, VALUE power, VALUE m, VALUE outpref, VALUE zeroappeal, VALUE directed){
|
38
|
+
|
39
|
+
igraph_t *graph;
|
40
|
+
VALUE new_graph;
|
41
|
+
|
42
|
+
new_graph = cIGraph_alloc(cIGraph);
|
43
|
+
Data_Get_Struct(new_graph, igraph_t, graph);
|
44
|
+
|
45
|
+
igraph_destroy(graph);
|
46
|
+
igraph_nonlinear_barabasi_game(graph, NUM2INT(nodes), NUM2DBL(power),
|
47
|
+
NUM2INT(m), NULL,
|
48
|
+
outpref == Qtrue ? 1: 0,
|
49
|
+
NUM2DBL(zeroappeal),
|
50
|
+
directed == Qtrue ? 1: 0);
|
51
|
+
|
52
|
+
return new_graph;
|
53
|
+
|
54
|
+
}
|
55
|
+
|
56
|
+
VALUE cIGraph_erdos_renyi_game(VALUE self, VALUE type, VALUE nodes, VALUE mp, VALUE directed, VALUE loops){
|
57
|
+
|
58
|
+
igraph_t *graph;
|
59
|
+
VALUE new_graph;
|
60
|
+
|
61
|
+
new_graph = cIGraph_alloc(cIGraph);
|
62
|
+
Data_Get_Struct(new_graph, igraph_t, graph);
|
63
|
+
|
64
|
+
igraph_destroy(graph);
|
65
|
+
igraph_erdos_renyi_game(graph, NUM2INT(type), NUM2INT(nodes),
|
66
|
+
NUM2DBL(mp),
|
67
|
+
directed == Qtrue ? 1: 0,
|
68
|
+
loops == Qtrue ? 1: 0);
|
69
|
+
|
70
|
+
return new_graph;
|
71
|
+
|
72
|
+
}
|
@@ -0,0 +1,182 @@
|
|
1
|
+
#include "igraph.h"
|
2
|
+
#include "ruby.h"
|
3
|
+
#include "cIGraph.h"
|
4
|
+
|
5
|
+
/* call-seq:
|
6
|
+
* graph.independent_vertex_sets(min_size,max_size) -> Array
|
7
|
+
*
|
8
|
+
* Find all independent vertex sets in a graph
|
9
|
+
*
|
10
|
+
* A vertex set is considered independent if there are no edges between them.
|
11
|
+
*
|
12
|
+
* If you are interested in the size of the largest independent vertex set,
|
13
|
+
* use IGraph#independence_number() instead.
|
14
|
+
*/
|
15
|
+
|
16
|
+
VALUE cIGraph_independent_vertex_sets(VALUE self, VALUE min, VALUE max){
|
17
|
+
|
18
|
+
igraph_t *graph;
|
19
|
+
igraph_vector_ptr_t res;
|
20
|
+
igraph_vector_t *vec;
|
21
|
+
int i;
|
22
|
+
int j;
|
23
|
+
VALUE independent_vertex_set;
|
24
|
+
VALUE object;
|
25
|
+
VALUE independent_vertex_sets = rb_ary_new();
|
26
|
+
|
27
|
+
Data_Get_Struct(self, igraph_t, graph);
|
28
|
+
|
29
|
+
igraph_vector_ptr_init(&res,0);
|
30
|
+
|
31
|
+
igraph_independent_vertex_sets(graph, &res, NUM2INT(min), NUM2INT(max));
|
32
|
+
|
33
|
+
for(i=0; i<igraph_vector_ptr_size(&res); i++){
|
34
|
+
independent_vertex_set = rb_ary_new();
|
35
|
+
rb_ary_push(independent_vertex_sets,independent_vertex_set);
|
36
|
+
vec = VECTOR(res)[i];
|
37
|
+
for(j=0; j<igraph_vector_size(vec); j++){
|
38
|
+
vec = VECTOR(res)[i];
|
39
|
+
object = cIGraph_get_vertex_object(self,VECTOR(*vec)[j]);
|
40
|
+
rb_ary_push(independent_vertex_set,object);
|
41
|
+
}
|
42
|
+
}
|
43
|
+
|
44
|
+
for(i=0;i<igraph_vector_ptr_size(&res);i++){
|
45
|
+
igraph_vector_destroy(VECTOR(res)[i]);
|
46
|
+
free(VECTOR(res)[i]);
|
47
|
+
}
|
48
|
+
|
49
|
+
igraph_vector_ptr_destroy(&res);
|
50
|
+
|
51
|
+
return independent_vertex_sets;
|
52
|
+
|
53
|
+
}
|
54
|
+
|
55
|
+
/* call-seq:
|
56
|
+
* graph.largest_independent_vertex_sets() -> Array
|
57
|
+
*
|
58
|
+
* Finds the largest independent vertex set(s) in a graph.
|
59
|
+
|
60
|
+
* An independent vertex set is largest if there is no other independent
|
61
|
+
* vertex set with more vertices in the graph.
|
62
|
+
*/
|
63
|
+
|
64
|
+
VALUE cIGraph_largest_independent_vertex_sets(VALUE self){
|
65
|
+
|
66
|
+
igraph_t *graph;
|
67
|
+
igraph_vector_ptr_t res;
|
68
|
+
igraph_vector_t *vec;
|
69
|
+
int i;
|
70
|
+
int j;
|
71
|
+
VALUE independent_vertex_set;
|
72
|
+
VALUE object;
|
73
|
+
VALUE independent_vertex_sets = rb_ary_new();
|
74
|
+
|
75
|
+
Data_Get_Struct(self, igraph_t, graph);
|
76
|
+
|
77
|
+
igraph_vector_ptr_init(&res,0);
|
78
|
+
|
79
|
+
igraph_largest_independent_vertex_sets(graph, &res);
|
80
|
+
|
81
|
+
for(i=0; i<igraph_vector_ptr_size(&res); i++){
|
82
|
+
independent_vertex_set = rb_ary_new();
|
83
|
+
rb_ary_push(independent_vertex_sets,independent_vertex_set);
|
84
|
+
vec = VECTOR(res)[i];
|
85
|
+
for(j=0; j<igraph_vector_size(vec); j++){
|
86
|
+
vec = VECTOR(res)[i];
|
87
|
+
object = cIGraph_get_vertex_object(self,VECTOR(*vec)[j]);
|
88
|
+
rb_ary_push(independent_vertex_set,object);
|
89
|
+
}
|
90
|
+
}
|
91
|
+
|
92
|
+
for(i=0;i<igraph_vector_ptr_size(&res);i++){
|
93
|
+
igraph_vector_destroy(VECTOR(res)[i]);
|
94
|
+
free(VECTOR(res)[i]);
|
95
|
+
}
|
96
|
+
|
97
|
+
igraph_vector_ptr_destroy(&res);
|
98
|
+
|
99
|
+
return independent_vertex_sets;
|
100
|
+
|
101
|
+
}
|
102
|
+
|
103
|
+
/* call-seq:
|
104
|
+
* graph.maximal_independent_vertex_sets() -> Array
|
105
|
+
*
|
106
|
+
* Find all maximal independent vertex sets of a graph
|
107
|
+
*
|
108
|
+
* A maximal independent vertex set is an independent vertex set which can't
|
109
|
+
* be extended any more by adding a new vertex to it.
|
110
|
+
*
|
111
|
+
* The algorithm used here is based on the following paper: S. Tsukiyama,
|
112
|
+
* M. Ide, H. Ariyoshi and I. Shirawaka. A new algorithm for generating all
|
113
|
+
* the maximal independent sets. SIAM J Computing, 6:505--517, 1977.
|
114
|
+
*
|
115
|
+
* The implementation was originally written by Kevin O'Neill and modified
|
116
|
+
* by K M Briggs in the Very Nauty Graph Library. I simply re-wrote it to
|
117
|
+
* use igraph's data structures.
|
118
|
+
*
|
119
|
+
* If you are interested in the size of the largest independent vertex set,
|
120
|
+
* use IGraph#independence_number() instead.
|
121
|
+
*/
|
122
|
+
|
123
|
+
VALUE cIGraph_maximal_independent_vertex_sets(VALUE self){
|
124
|
+
|
125
|
+
igraph_t *graph;
|
126
|
+
igraph_vector_ptr_t res;
|
127
|
+
igraph_vector_t *vec;
|
128
|
+
int i;
|
129
|
+
int j;
|
130
|
+
VALUE independent_vertex_set;
|
131
|
+
VALUE object;
|
132
|
+
VALUE independent_vertex_sets = rb_ary_new();
|
133
|
+
|
134
|
+
Data_Get_Struct(self, igraph_t, graph);
|
135
|
+
|
136
|
+
igraph_vector_ptr_init(&res,0);
|
137
|
+
|
138
|
+
igraph_maximal_independent_vertex_sets(graph, &res);
|
139
|
+
|
140
|
+
for(i=0; i<igraph_vector_ptr_size(&res); i++){
|
141
|
+
independent_vertex_set = rb_ary_new();
|
142
|
+
rb_ary_push(independent_vertex_sets,independent_vertex_set);
|
143
|
+
vec = VECTOR(res)[i];
|
144
|
+
for(j=0; j<igraph_vector_size(vec); j++){
|
145
|
+
vec = VECTOR(res)[i];
|
146
|
+
object = cIGraph_get_vertex_object(self,VECTOR(*vec)[j]);
|
147
|
+
rb_ary_push(independent_vertex_set,object);
|
148
|
+
}
|
149
|
+
}
|
150
|
+
|
151
|
+
for(i=0;i<igraph_vector_ptr_size(&res);i++){
|
152
|
+
igraph_vector_destroy(VECTOR(res)[i]);
|
153
|
+
free(VECTOR(res)[i]);
|
154
|
+
}
|
155
|
+
|
156
|
+
igraph_vector_ptr_destroy(&res);
|
157
|
+
|
158
|
+
return independent_vertex_sets;
|
159
|
+
|
160
|
+
}
|
161
|
+
|
162
|
+
/* call-seq:
|
163
|
+
* graph.independence_number() -> Integer
|
164
|
+
*
|
165
|
+
* Find the independence number of the graph
|
166
|
+
*
|
167
|
+
* The independence number of a graph is the cardinality of the largest
|
168
|
+
* independent vertex set.
|
169
|
+
*/
|
170
|
+
|
171
|
+
VALUE cIGraph_independence_number(VALUE self){
|
172
|
+
|
173
|
+
igraph_t *graph;
|
174
|
+
igraph_integer_t res;
|
175
|
+
|
176
|
+
Data_Get_Struct(self, igraph_t, graph);
|
177
|
+
|
178
|
+
igraph_independence_number(graph, &res);
|
179
|
+
|
180
|
+
return INT2NUM(res);
|
181
|
+
|
182
|
+
}
|
@@ -0,0 +1,137 @@
|
|
1
|
+
#include "igraph.h"
|
2
|
+
#include "ruby.h"
|
3
|
+
#include "cIGraph.h"
|
4
|
+
|
5
|
+
/* call-seq:
|
6
|
+
* graph.isomorphic(graph) -> True/False
|
7
|
+
*
|
8
|
+
* Decides whether two graphs are isomorphic
|
9
|
+
*
|
10
|
+
* From Wikipedia: The graph isomorphism problem or GI problem is the graph
|
11
|
+
* theory problem of determining whether, given two graphs G1 and G2, it is
|
12
|
+
* possible to permute (or relabel) the vertices of one graph so that it is
|
13
|
+
* equal to the other. Such a permutation is called a graph isomorphism.
|
14
|
+
*/
|
15
|
+
VALUE cIGraph_isomorphic(VALUE self, VALUE g){
|
16
|
+
|
17
|
+
igraph_bool_t res = 0;
|
18
|
+
igraph_t *graph;
|
19
|
+
igraph_t *graph2;
|
20
|
+
|
21
|
+
Data_Get_Struct(self, igraph_t, graph);
|
22
|
+
Data_Get_Struct(g, igraph_t, graph2);
|
23
|
+
|
24
|
+
IGRAPH_CHECK(igraph_isomorphic(graph,graph2,&res));
|
25
|
+
|
26
|
+
return res == 0 ? Qfalse : Qtrue;
|
27
|
+
|
28
|
+
}
|
29
|
+
|
30
|
+
/* call-seq:
|
31
|
+
* graph.isomorphic_vf2(graph) -> True/False
|
32
|
+
*
|
33
|
+
* Decides whether two graphs are isomorphic
|
34
|
+
*
|
35
|
+
* This function is an implementation of the VF2 isomorphism algorithm,
|
36
|
+
* see P. Foggia, C. Sansone, M. Vento, An Improved algorithm for matching
|
37
|
+
* large graphs, Prof. of the 3rd IAPR-TC-15 International Workshop on
|
38
|
+
* Graph-based Representations, Italy, 2001.
|
39
|
+
*/
|
40
|
+
VALUE cIGraph_isomorphic_vf2(VALUE self, VALUE g){
|
41
|
+
|
42
|
+
igraph_bool_t res = 0;
|
43
|
+
igraph_t *graph;
|
44
|
+
igraph_t *graph2;
|
45
|
+
|
46
|
+
Data_Get_Struct(self, igraph_t, graph);
|
47
|
+
Data_Get_Struct(g, igraph_t, graph2);
|
48
|
+
|
49
|
+
IGRAPH_CHECK(igraph_isomorphic_vf2(graph,graph2,&res));
|
50
|
+
|
51
|
+
return res == 0 ? Qfalse : Qtrue;
|
52
|
+
|
53
|
+
}
|
54
|
+
|
55
|
+
/* call-seq:
|
56
|
+
* graph.isoclass() -> Integer
|
57
|
+
*
|
58
|
+
* Determine the isomorphism class of a graph
|
59
|
+
*
|
60
|
+
* All graphs with a given number of vertices belong to a number of
|
61
|
+
* isomorpism classes, with every graph in a given class being isomorphic
|
62
|
+
* to each other.
|
63
|
+
*
|
64
|
+
* This function gives the isomorphism class (a number) of a graph. Two
|
65
|
+
* graphs have the same isomorphism class if and only if they are isomorphic.
|
66
|
+
*
|
67
|
+
* The first isomorphism class is numbered zero and it is the empty graph,
|
68
|
+
* the last isomorphism class is the full graph. The number of isomorphism
|
69
|
+
* class for directed graphs with three vertices is 16 (between 0 and 15),
|
70
|
+
* for undirected graph it is only 4. For graphs with four vertices it is
|
71
|
+
* 218 (directed) and 11 (undirected).
|
72
|
+
*/
|
73
|
+
VALUE cIGraph_isoclass(VALUE self){
|
74
|
+
|
75
|
+
int res = 0;
|
76
|
+
igraph_t *graph;
|
77
|
+
|
78
|
+
Data_Get_Struct(self, igraph_t, graph);
|
79
|
+
|
80
|
+
IGRAPH_CHECK(igraph_isoclass(graph,&res));
|
81
|
+
|
82
|
+
return INT2NUM(res);
|
83
|
+
|
84
|
+
}
|
85
|
+
|
86
|
+
/* call-seq:
|
87
|
+
* graph.isoclass_subgraph(vs) -> Integer
|
88
|
+
*
|
89
|
+
* Determine the isomorphism class of a subgraph given by the vertices given
|
90
|
+
* in the Array vs.
|
91
|
+
*
|
92
|
+
*/
|
93
|
+
VALUE cIGraph_isoclass_subgraph(VALUE self, VALUE vs){
|
94
|
+
|
95
|
+
int res = 0;
|
96
|
+
igraph_t *graph;
|
97
|
+
igraph_vector_t vidv;
|
98
|
+
|
99
|
+
Data_Get_Struct(self, igraph_t, graph);
|
100
|
+
|
101
|
+
//Convert an array of vertices to a vector of vertex ids
|
102
|
+
igraph_vector_init_int(&vidv,0);
|
103
|
+
cIGraph_vertex_arr_to_id_vec(self,vs,&vidv);
|
104
|
+
|
105
|
+
IGRAPH_CHECK(igraph_isoclass_subgraph(graph,&vidv,&res));
|
106
|
+
|
107
|
+
igraph_vector_destroy(&vidv);
|
108
|
+
|
109
|
+
return INT2NUM(res);
|
110
|
+
|
111
|
+
}
|
112
|
+
|
113
|
+
/* call-seq:
|
114
|
+
* IGraph.isoclass_create(vn,iso,dir) -> IGraph
|
115
|
+
*
|
116
|
+
* Creates a graph with the number of vertices given by vn from the given
|
117
|
+
* isomorphism class iso and the direction boolean dir.
|
118
|
+
*
|
119
|
+
* This function is implemented only for graphs with three or four vertices.
|
120
|
+
*/
|
121
|
+
VALUE cIGraph_isoclass_create(VALUE self, VALUE vn, VALUE iso, VALUE dir){
|
122
|
+
|
123
|
+
igraph_t *graph;
|
124
|
+
VALUE new_graph;
|
125
|
+
igraph_bool_t dir_b = 0;
|
126
|
+
|
127
|
+
if(dir)
|
128
|
+
dir_b = 1;
|
129
|
+
|
130
|
+
new_graph = cIGraph_alloc(cIGraph);
|
131
|
+
Data_Get_Struct(new_graph, igraph_t, graph);
|
132
|
+
|
133
|
+
IGRAPH_CHECK(igraph_isoclass_create(graph,NUM2INT(vn),NUM2INT(iso),dir_b));
|
134
|
+
|
135
|
+
return new_graph;
|
136
|
+
|
137
|
+
}
|
data/ext/cIGraph_layout.c
CHANGED
@@ -22,7 +22,7 @@ VALUE cIGraph_layout_random(VALUE self){
|
|
22
22
|
}
|
23
23
|
|
24
24
|
/* call-seq:
|
25
|
-
* graph.
|
25
|
+
* graph.layout_circle -> IGraphMatrix
|
26
26
|
*
|
27
27
|
* Returns a layout with nodes laid out around a circle.
|
28
28
|
*/
|
@@ -41,7 +41,7 @@ VALUE cIGraph_layout_circle(VALUE self){
|
|
41
41
|
}
|
42
42
|
|
43
43
|
/* call-seq:
|
44
|
-
* graph.
|
44
|
+
* graph.layout_fruchterman_reingold -> IGraphMatrix
|
45
45
|
*
|
46
46
|
* Places the vertices on a plane according to the Fruchterman-Reingold
|
47
47
|
* algorithm.
|
@@ -75,3 +75,175 @@ VALUE cIGraph_layout_fruchterman_reingold(VALUE self,
|
|
75
75
|
return Data_Wrap_Struct(cIGraphMatrix, 0, cIGraph_matrix_free, res);
|
76
76
|
|
77
77
|
}
|
78
|
+
|
79
|
+
/* call-seq:
|
80
|
+
* graph.layout_kamada_kawai -> IGraphMatrix
|
81
|
+
*
|
82
|
+
* Places the vertices on a plane according the Kamada-Kawai algorithm.
|
83
|
+
*
|
84
|
+
* This is a force directed layout, see Kamada, T. and Kawai, S.: An
|
85
|
+
* Algorithm for Drawing General Undirected Graphs. Information Processing
|
86
|
+
* Letters, 31/1, 7--15, 1989.
|
87
|
+
*/
|
88
|
+
VALUE cIGraph_layout_kamada_kawai(VALUE self,
|
89
|
+
VALUE niter,
|
90
|
+
VALUE sigma,
|
91
|
+
VALUE initemp,
|
92
|
+
VALUE coolexp,
|
93
|
+
VALUE kkconst){
|
94
|
+
|
95
|
+
igraph_t *graph;
|
96
|
+
igraph_matrix_t *res = malloc(sizeof(igraph_matrix_t));
|
97
|
+
|
98
|
+
Data_Get_Struct(self, igraph_t, graph);
|
99
|
+
|
100
|
+
igraph_matrix_init(res,0,0);
|
101
|
+
igraph_layout_kamada_kawai(graph,res,
|
102
|
+
NUM2INT(niter),
|
103
|
+
NUM2DBL(sigma),
|
104
|
+
NUM2DBL(initemp),
|
105
|
+
NUM2DBL(coolexp),
|
106
|
+
NUM2DBL(kkconst));
|
107
|
+
|
108
|
+
return Data_Wrap_Struct(cIGraphMatrix, 0, cIGraph_matrix_free, res);
|
109
|
+
|
110
|
+
}
|
111
|
+
|
112
|
+
/* call-seq:
|
113
|
+
* graph.layout_reingold_tilford -> IGraphMatrix
|
114
|
+
*
|
115
|
+
* Reingold-Tilford layout for tree graphs
|
116
|
+
*
|
117
|
+
* Arranges the nodes in a tree where the given node is used as the root.
|
118
|
+
* The tree is directed downwards and the parents are centered above its
|
119
|
+
* children. For the exact algorithm, see:
|
120
|
+
*
|
121
|
+
* Reingold, E and Tilford, J: Tidier drawing of trees. IEEE Trans. Softw.
|
122
|
+
* Eng., SE-7(2):223--228, 1981
|
123
|
+
*
|
124
|
+
* If the given graph is not a tree, a breadth-first search is executed
|
125
|
+
* first to obtain a possible spanning tree.
|
126
|
+
*/
|
127
|
+
VALUE cIGraph_layout_reingold_tilford(VALUE self,
|
128
|
+
VALUE root){
|
129
|
+
|
130
|
+
igraph_t *graph;
|
131
|
+
igraph_matrix_t *res = malloc(sizeof(igraph_matrix_t));
|
132
|
+
|
133
|
+
Data_Get_Struct(self, igraph_t, graph);
|
134
|
+
|
135
|
+
igraph_matrix_init(res,0,0);
|
136
|
+
igraph_layout_reingold_tilford(graph,res,
|
137
|
+
cIGraph_get_vertex_id(self, root));
|
138
|
+
|
139
|
+
return Data_Wrap_Struct(cIGraphMatrix, 0, cIGraph_matrix_free, res);
|
140
|
+
|
141
|
+
}
|
142
|
+
|
143
|
+
/* call-seq:
|
144
|
+
* graph.layout_reingold_tilford_circular -> IGraphMatrix
|
145
|
+
*
|
146
|
+
* Reingold-Tilford layout for tree graphs, drawn in a circular style
|
147
|
+
*
|
148
|
+
* Arranges the nodes in a tree where the given node is used as the root.
|
149
|
+
* The tree is directed downwards and the parents are centered above its
|
150
|
+
* children. For the exact algorithm, see:
|
151
|
+
*
|
152
|
+
* Reingold, E and Tilford, J: Tidier drawing of trees. IEEE Trans. Softw.
|
153
|
+
* Eng., SE-7(2):223--228, 1981
|
154
|
+
*
|
155
|
+
* If the given graph is not a tree, a breadth-first search is executed
|
156
|
+
* first to obtain a possible spanning tree.
|
157
|
+
*/
|
158
|
+
VALUE cIGraph_layout_reingold_tilford_circular(VALUE self,
|
159
|
+
VALUE root){
|
160
|
+
|
161
|
+
igraph_t *graph;
|
162
|
+
igraph_matrix_t *res = malloc(sizeof(igraph_matrix_t));
|
163
|
+
|
164
|
+
Data_Get_Struct(self, igraph_t, graph);
|
165
|
+
|
166
|
+
igraph_matrix_init(res,0,0);
|
167
|
+
igraph_layout_reingold_tilford_circular(graph,res,
|
168
|
+
cIGraph_get_vertex_id(self, root));
|
169
|
+
|
170
|
+
return Data_Wrap_Struct(cIGraphMatrix, 0, cIGraph_matrix_free, res);
|
171
|
+
|
172
|
+
}
|
173
|
+
|
174
|
+
/* call-seq:
|
175
|
+
* graph.layout_grid_fruchterman_reingold -> IGraphMatrix
|
176
|
+
*
|
177
|
+
* Places the vertices on a plane according to the Fruchterman-Reingold
|
178
|
+
* algorithm.
|
179
|
+
*
|
180
|
+
* This is a force-directed layout, see Fruchterman, T.M.J. and Reingold,
|
181
|
+
* E.M.: Graph Drawing by Force-directed Placement. Software -- Practice and
|
182
|
+
* Experience, 21/11, 1129--1164, 1991.
|
183
|
+
*/
|
184
|
+
VALUE cIGraph_layout_grid_fruchterman_reingold(VALUE self,
|
185
|
+
VALUE niter,
|
186
|
+
VALUE maxdelta,
|
187
|
+
VALUE area,
|
188
|
+
VALUE coolexp,
|
189
|
+
VALUE repulserad,
|
190
|
+
VALUE cellsize,
|
191
|
+
VALUE use_seed){
|
192
|
+
|
193
|
+
igraph_t *graph;
|
194
|
+
igraph_matrix_t *res = malloc(sizeof(igraph_matrix_t));
|
195
|
+
|
196
|
+
Data_Get_Struct(self, igraph_t, graph);
|
197
|
+
|
198
|
+
igraph_matrix_init(res,0,0);
|
199
|
+
igraph_layout_grid_fruchterman_reingold(graph,res,
|
200
|
+
NUM2INT(niter),
|
201
|
+
NUM2DBL(maxdelta),
|
202
|
+
NUM2DBL(area),
|
203
|
+
NUM2DBL(coolexp),
|
204
|
+
NUM2DBL(repulserad),
|
205
|
+
NUM2DBL(cellsize),
|
206
|
+
use_seed == Qtrue ? 1: 0);
|
207
|
+
|
208
|
+
return Data_Wrap_Struct(cIGraphMatrix, 0, cIGraph_matrix_free, res);
|
209
|
+
|
210
|
+
}
|
211
|
+
|
212
|
+
/* call-seq:
|
213
|
+
* graph.layout_lgl -> IGraphMatrix
|
214
|
+
*
|
215
|
+
* Places the vertices on a plane according to the Fruchterman-Reingold
|
216
|
+
* algorithm.
|
217
|
+
*
|
218
|
+
* This is a force-directed layout, see Fruchterman, T.M.J. and Reingold,
|
219
|
+
* E.M.: Graph Drawing by Force-directed Placement. Software -- Practice and
|
220
|
+
* Experience, 21/11, 1129--1164, 1991.
|
221
|
+
*/
|
222
|
+
VALUE cIGraph_layout_lgl(VALUE self,
|
223
|
+
VALUE maxit,
|
224
|
+
VALUE maxdelta,
|
225
|
+
VALUE area,
|
226
|
+
VALUE coolexp,
|
227
|
+
VALUE repulserad,
|
228
|
+
VALUE cellsize,
|
229
|
+
VALUE proot){
|
230
|
+
|
231
|
+
igraph_t *graph;
|
232
|
+
igraph_matrix_t *res = malloc(sizeof(igraph_matrix_t));
|
233
|
+
|
234
|
+
Data_Get_Struct(self, igraph_t, graph);
|
235
|
+
|
236
|
+
igraph_matrix_init(res,0,0);
|
237
|
+
igraph_layout_lgl(graph,res,
|
238
|
+
NUM2INT(maxit),
|
239
|
+
NUM2DBL(maxdelta),
|
240
|
+
NUM2DBL(area),
|
241
|
+
NUM2DBL(coolexp),
|
242
|
+
NUM2DBL(repulserad),
|
243
|
+
NUM2DBL(cellsize),
|
244
|
+
cIGraph_get_vertex_id(self, proot));
|
245
|
+
|
246
|
+
return Data_Wrap_Struct(cIGraphMatrix, 0, cIGraph_matrix_free, res);
|
247
|
+
|
248
|
+
}
|
249
|
+
|