1 /* -*- mode: C -*-  */
2 /*
3    IGraph library.
4    Copyright (C) 2011-2012  Gabor Csardi <csardi.gabor@gmail.com>
5    334 Harvard st, 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 
main()26 int main() {
27 
28     igraph_t g;
29     igraph_vector_t ev;
30     igraph_t scg_graph;
31     igraph_matrix_t scg_matrix;
32     igraph_sparsemat_t scg_sparsemat;
33     igraph_matrix_t L, R;
34     igraph_sparsemat_t Lsparse, Rsparse;
35     igraph_matrix_t input_matrix;
36     igraph_vector_t groups;
37     igraph_vector_t eval;
38     igraph_matrix_t evec;
39 
40     igraph_tree(&g, 10, /* children= */ 3, IGRAPH_TREE_UNDIRECTED);
41 
42     igraph_vector_init(&ev, 1);
43     igraph_matrix_init(&L, 0, 0);
44     igraph_matrix_init(&R, 0, 0);
45     igraph_matrix_init(&scg_matrix, 0, 0);
46     igraph_vector_init(&groups, 0);
47     igraph_vector_init(&eval, 0);
48     igraph_matrix_init(&evec, 0, 0);
49 
50 #define CALLSYM(algo) do {                      \
51         igraph_vector_clear(&eval);                     \
52         igraph_matrix_resize(&evec, 0, 0);                  \
53         igraph_scg_adjacency(&g, /*matrix=*/ 0, /*sparsemat=*/ 0, &ev,  \
54                              /* intervals= */ 3, /* intervals_vector= */ 0, \
55                              /* algorithm= */ algo, &eval, &evec,       \
56                              /* groups= */ &groups, /* use_arpack= */ 0,    \
57                              /* maxiter= */ 0, &scg_graph, &scg_matrix, \
58                              &scg_sparsemat, &L, &R,            \
59                              &Lsparse, &Rsparse); } while(0)
60 
61 
62 #define PRINTRES()                      \
63     do {                              \
64         printf("------------------------------------\n");       \
65         igraph_write_graph_edgelist(&scg_graph, stdout);        \
66         printf("---\n");                        \
67         igraph_vector_print(&groups);               \
68         printf("---\n");                        \
69         igraph_vector_print(&eval);                 \
70         igraph_matrix_print(&evec);                 \
71         printf("---\n");                        \
72         igraph_sparsemat_print(&scg_sparsemat, stdout);     \
73         printf("---\n");                        \
74         igraph_sparsemat_print(&Lsparse, stdout);           \
75         printf("---\n");                        \
76         igraph_sparsemat_print(&Rsparse, stdout);           \
77         printf("---\n");                        \
78     } while (0)
79 
80     VECTOR(ev)[0] = 1;
81     CALLSYM(IGRAPH_SCG_EXACT);
82     PRINTRES();
83     igraph_destroy(&scg_graph);
84     igraph_sparsemat_destroy(&scg_sparsemat);
85     igraph_sparsemat_destroy(&Lsparse);
86     igraph_sparsemat_destroy(&Rsparse);
87 
88     VECTOR(ev)[0] = 3;
89     CALLSYM(IGRAPH_SCG_EXACT);
90     PRINTRES();
91     igraph_destroy(&scg_graph);
92     igraph_sparsemat_destroy(&scg_sparsemat);
93     igraph_sparsemat_destroy(&Lsparse);
94     igraph_sparsemat_destroy(&Rsparse);
95 
96     igraph_vector_resize(&ev, 2);
97     VECTOR(ev)[0] = 1;
98     VECTOR(ev)[1] = 3;
99     CALLSYM(IGRAPH_SCG_EXACT);
100     PRINTRES();
101     igraph_destroy(&scg_graph);
102     igraph_sparsemat_destroy(&scg_sparsemat);
103     igraph_sparsemat_destroy(&Lsparse);
104     igraph_sparsemat_destroy(&Rsparse);
105 
106 #define CALLSYM2(algo) do {                     \
107         igraph_vector_clear(&eval);                     \
108         igraph_matrix_resize(&evec, 0, 0);                  \
109         igraph_scg_adjacency(/* graph=*/ 0, &input_matrix, /*sparsemat=*/ 0, \
110                                          &ev, /* intervals= */ 3,           \
111                                          /* intervals_vector= */ 0,         \
112                                          /* algorithm= */ algo, &eval, &evec,       \
113                                          /* groups= */ &groups, /* use_arpack= */ 0,    \
114                                          /* maxiter= */ 0, &scg_graph, &scg_matrix, \
115                                          &scg_sparsemat, &L, &R,            \
116                                          &Lsparse, &Rsparse); } while (0)
117 
118     igraph_matrix_init(&input_matrix, 0, 0);
119     igraph_get_adjacency(&g, &input_matrix, IGRAPH_GET_ADJACENCY_BOTH,
120                          /* eids= */ 0);
121 
122     igraph_vector_resize(&ev, 1);
123     VECTOR(ev)[0] = 1;
124     CALLSYM2(IGRAPH_SCG_EXACT);
125     PRINTRES();
126     igraph_destroy(&scg_graph);
127     igraph_sparsemat_destroy(&scg_sparsemat);
128     igraph_sparsemat_destroy(&Lsparse);
129     igraph_sparsemat_destroy(&Rsparse);
130 
131     VECTOR(ev)[0] = 3;
132     CALLSYM2(IGRAPH_SCG_EXACT);
133     PRINTRES();
134     igraph_destroy(&scg_graph);
135     igraph_sparsemat_destroy(&scg_sparsemat);
136     igraph_sparsemat_destroy(&Lsparse);
137     igraph_sparsemat_destroy(&Rsparse);
138 
139     igraph_vector_resize(&ev, 2);
140     VECTOR(ev)[0] = 1;
141     VECTOR(ev)[1] = 3;
142     CALLSYM2(IGRAPH_SCG_EXACT);
143     PRINTRES();
144     igraph_destroy(&scg_graph);
145     igraph_sparsemat_destroy(&scg_sparsemat);
146     igraph_sparsemat_destroy(&Lsparse);
147     igraph_sparsemat_destroy(&Rsparse);
148 
149     igraph_matrix_destroy(&evec);
150     igraph_vector_destroy(&eval);
151     igraph_vector_destroy(&groups);
152     igraph_matrix_destroy(&input_matrix);
153     igraph_matrix_destroy(&scg_matrix);
154     igraph_matrix_destroy(&L);
155     igraph_matrix_destroy(&R);
156     igraph_vector_destroy(&ev);
157     igraph_destroy(&g);
158 
159     /* -------------------------------------------------------------------- */
160 
161     return 0;
162 }
163