1 /* -*- mode: C -*- */
2 /*
3 IGraph library.
4 Copyright (C) 2012 Gabor Csardi <csardi.gabor@gmail.com>
5 334 Harvard street, Cambridge, MA 02139 USA
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 02110-1301 USA
21
22 */
23
24 #include <igraph.h>
25
26 #include "test_utilities.inc"
27
28
main()29 int main() {
30
31 igraph_t g;
32 igraph_matrix_t merges;
33 igraph_vector_t membership;
34 igraph_vector_t x;
35 igraph_arpack_options_t options;
36 igraph_vector_t weights;
37
38 /* Zachary Karate club */
39 igraph_small(&g, 0, IGRAPH_UNDIRECTED,
40 0, 1, 0, 2, 0, 3, 0, 4, 0, 5,
41 0, 6, 0, 7, 0, 8, 0, 10, 0, 11,
42 0, 12, 0, 13, 0, 17, 0, 19, 0, 21,
43 0, 31, 1, 2, 1, 3, 1, 7, 1, 13,
44 1, 17, 1, 19, 1, 21, 1, 30, 2, 3,
45 2, 7, 2, 8, 2, 9, 2, 13, 2, 27,
46 2, 28, 2, 32, 3, 7, 3, 12, 3, 13,
47 4, 6, 4, 10, 5, 6, 5, 10, 5, 16,
48 6, 16, 8, 30, 8, 32, 8, 33, 9, 33,
49 13, 33, 14, 32, 14, 33, 15, 32, 15, 33,
50 18, 32, 18, 33, 19, 33, 20, 32, 20, 33,
51 22, 32, 22, 33, 23, 25, 23, 27, 23, 29,
52 23, 32, 23, 33, 24, 25, 24, 27, 24, 31,
53 25, 31, 26, 29, 26, 33, 27, 33, 28, 31,
54 28, 33, 29, 32, 29, 33, 30, 32, 30, 33,
55 31, 32, 31, 33, 32, 33,
56 -1);
57
58 igraph_matrix_init(&merges, 0, 0);
59 igraph_vector_init(&membership, 0);
60 igraph_vector_init(&x, 0);
61 igraph_arpack_options_init(&options);
62 igraph_vector_init(&weights, igraph_ecount(&g));
63 igraph_vector_fill(&weights, 1);
64
65 igraph_community_leading_eigenvector(&g, &weights, &merges,
66 &membership, 1,
67 &options, /*modularity=*/ 0,
68 /*start=*/ 0, /*eigenvalues=*/ 0,
69 /*eigenvectors=*/ 0, /*history=*/ 0,
70 /*callback=*/ 0,
71 /*callback_extra=*/ 0);
72
73 print_matrix_round(&merges);
74 print_vector_round(&membership);
75
76 printf("\n");
77
78 /* Make all the steps */
79 igraph_community_leading_eigenvector(&g, &weights, &merges,
80 &membership, igraph_vcount(&g),
81 &options, /*modularity=*/ 0,
82 /*start=*/ 0, /*eigenvalues=*/ 0,
83 /*eigenvectors=*/ 0, /*history=*/ 0,
84 /*callback=*/ 0,
85 /*callback_extra=*/ 0);
86
87 print_matrix_round(&merges);
88 print_vector_round(&membership);
89
90 igraph_vector_destroy(&weights);
91 igraph_vector_destroy(&x);
92 igraph_vector_destroy(&membership);
93 igraph_matrix_destroy(&merges);
94 igraph_destroy(&g);
95
96 VERIFY_FINALLY_STACK();
97
98 return 0;
99 }
100