4
Copyright (C) 2006 Gabor Csardi <csardi@rmki.kfki.hu>
5
MTA RMKI, Konkoly-Thege Miklos st. 29-33, Budapest 1121, Hungary
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.
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.
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
27
void free_complist(igraph_vector_ptr_t *complist) {
29
for (i=0; i<igraph_vector_ptr_size(complist); i++) {
30
igraph_destroy(VECTOR(*complist)[i]);
31
free(VECTOR(*complist)[i]);
38
igraph_vector_ptr_t complist;
40
igraph_real_t edges[]= { 0,1,1,2,2,0,
44
igraph_vector_t idvect;
46
/* A ring, a single component */
47
igraph_ring(&ring, 10, IGRAPH_UNDIRECTED, 0, 1);
49
igraph_vector_ptr_init(&complist, 0);
50
igraph_decompose(&ring, &complist, IGRAPH_WEAK, -1, 0);
51
igraph_write_graph_edgelist(VECTOR(complist)[0], stdout);
52
free_complist(&complist);
53
igraph_destroy(&ring);
55
/* random graph with a giant component */
56
igraph_erdos_renyi_game(&g, IGRAPH_ERDOS_RENYI_GNP, 100, 4.0/100,
57
IGRAPH_UNDIRECTED, 0);
58
igraph_decompose(&g, &complist, IGRAPH_WEAK, -1, 20);
59
if (igraph_vector_ptr_size(&complist) != 1) {
62
free_complist(&complist);
65
/* a toy graph, three components maximum, with at least 2 vertices each */
67
igraph_vector_view(&v, edges, sizeof(edges)/sizeof(igraph_real_t)),
69
igraph_decompose(&g, &complist, IGRAPH_WEAK, 3, 2);
70
for (i=0; i<igraph_vector_ptr_size(&complist); i++) {
71
igraph_write_graph_edgelist(VECTOR(complist)[i], stdout);
73
free_complist(&complist);
76
/* The same graph, this time with vertex attributes */
77
/* igraph_vector_init_seq(&idvect, 0, igraph_vcount(&g)-1); */
78
/* igraph_add_vertex_attribute(&g, "id", IGRAPH_ATTRIBUTE_NUM); */
79
/* igraph_set_vertex_attributes(&g, "id", IGRAPH_VS_ALL(&g), &idvect); */
80
/* igraph_vector_destroy(&idvect); */
82
/* igraph_decompose(&g, &complist, IGRAPH_WEAK, 3, 2); */
83
/* for (i=0; i<igraph_vector_ptr_size(&complist); i++) { */
84
/* igraph_t *comp=VECTOR(complist)[i]; */
86
/* igraph_es_all(comp, &es); */
87
/* while (!igraph_es_end(comp, &es)) { */
88
/* igraph_real_t *from, *to; */
89
/* igraph_get_vertex_attribute(comp, "id", igraph_es_from(comp, &es), */
90
/* (void**) &from, 0); */
91
/* igraph_get_vertex_attribute(comp, "id", igraph_es_to(comp, &es), */
92
/* (void**) &to, 0); */
93
/* printf("%li %li\n", (long int) *from, (long int) *to); */
94
/* igraph_es_next(comp, &es); */
98
/* free_complist(&complist); */
99
/* igraph_destroy(&g); */
101
igraph_vector_ptr_destroy(&complist);