1 /* -*- mode: C -*-  */
2 /*
3    IGraph library.
4    Copyright (C) 2006-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 #include <stdlib.h>
26 
27 #include "test_utilities.inc"
28 
free_complist(igraph_vector_ptr_t * complist)29 void free_complist(igraph_vector_ptr_t *complist) {
30     long int i;
31     for (i = 0; i < igraph_vector_ptr_size(complist); i++) {
32         igraph_destroy(VECTOR(*complist)[i]);
33         igraph_free(VECTOR(*complist)[i]);
34     }
35 }
36 
main()37 int main() {
38 
39     igraph_t ring, g;
40     igraph_vector_ptr_t complist;
41     long int i;
42 
43     /* A directed ring, a single strongly connected component */
44     igraph_ring(&ring, 10, IGRAPH_DIRECTED, 0, 1);
45 
46     igraph_vector_ptr_init(&complist, 0);
47     igraph_decompose(&ring, &complist, IGRAPH_STRONG, -1, 0);
48     igraph_write_graph_edgelist(VECTOR(complist)[0], stdout);
49     free_complist(&complist);
50     igraph_destroy(&ring);
51 
52     /* a toy graph, three components maximum, with at least 2 vertices each */
53     /* 0 >->  1 >-> 3 >-> 4
54        ^      v
55        \< 2 < /           */
56     igraph_small(&g, 5, IGRAPH_DIRECTED,
57                  0, 1, 1, 2, 2, 0,
58                  1, 3,
59                  3, 4,
60                  -1);
61     igraph_decompose(&g, &complist, IGRAPH_STRONG, 3, 2);
62     for (i = 0; i < igraph_vector_ptr_size(&complist); i++) {
63         igraph_write_graph_edgelist(VECTOR(complist)[i], stdout);
64     }
65     free_complist(&complist);
66     igraph_destroy(&g);
67 
68     igraph_vector_ptr_destroy(&complist);
69 
70     VERIFY_FINALLY_STACK();
71 
72     return 0;
73 }
74