1 /* -*- mode: C -*- */
2 /*
3 IGraph library.
4 Copyright (C) 2011-2012 Gabor Csardi <csardi.gabor@gmail.com>
5 334 Harvard st, Cambridge, MA, 02138 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 #define SIZE (1000)
27
main()28 int main() {
29
30 igraph_matrix_t M, M2;
31 igraph_vector_t lambda;
32 igraph_matrix_t V;
33 igraph_vector_t groups;
34 igraph_vector_t ivec;
35 int i, j;
36 int n;
37
38 igraph_rng_seed(igraph_rng_default(), 42);
39
40 /* Symmetric matrix, exponentially distributed elements */
41
42 igraph_matrix_init(&M, SIZE, SIZE);
43 n = igraph_matrix_nrow(&M);
44 for (i = 0; i < n; i++) {
45 for (j = 0; j < n; j++) {
46 MATRIX(M, i, j) = igraph_rng_get_exp(igraph_rng_default(), 1);
47 }
48 }
49 igraph_matrix_init(&M2, n, n);
50 igraph_matrix_update(&M2, &M);
51 igraph_matrix_transpose(&M2);
52 igraph_matrix_add(&M, &M2);
53 igraph_matrix_scale(&M, 0.5);
54 igraph_matrix_destroy(&M2);
55
56 /* Get first (most positive) two eigenvectors */
57
58 igraph_vector_init(&lambda, 0);
59 igraph_matrix_init(&V, 0, 0);
60 igraph_lapack_dsyevr(&M, IGRAPH_LAPACK_DSYEV_SELECT, /*vl=*/ 0, /*vu=*/ 0,
61 /*vestimate=*/ 0, /*il=*/ n - 1, /*iu=*/ n,
62 /*abstol=*/ 0.0, /*values=*/ &lambda, /*vectors=*/ &V,
63 /*support=*/ 0);
64
65 /* Grouping */
66
67 igraph_vector_init(&groups, 0);
68 igraph_vector_init(&ivec, 2);
69 VECTOR(ivec)[0] = 2;
70 VECTOR(ivec)[1] = 3;
71 igraph_scg_grouping(&V, &groups, /*invervals=*/ 0,
72 /*intervals_vector=*/ &ivec, IGRAPH_SCG_SYMMETRIC,
73 IGRAPH_SCG_OPTIMUM, /*p=*/ 0, /*maxiter=*/ 100);
74
75 igraph_vector_print(&groups);
76
77 igraph_vector_destroy(&ivec);
78 igraph_vector_destroy(&groups);
79 igraph_vector_destroy(&lambda);
80 igraph_matrix_destroy(&V);
81 igraph_matrix_destroy(&M);
82
83 return 0;
84 }
85