1 /* -*- mode: C -*-  */
2 /* vim:set ts=4 sw=4 sts=4 et: */
3 /*
4    IGraph library.
5    Copyright (C) 2007-2020  The igraph development team <igraph@igraph.org>
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, see <https://www.gnu.org/licenses/>.
19 */
20 
21 #include <igraph.h>
22 #include <stdio.h>
23 
main()24 int main() {
25     igraph_t graph;
26     igraph_vector_t membership;
27     igraph_real_t modularity;
28 
29     igraph_famous(&graph, "Zachary"); /* We use Zachary's karate club network. */
30 
31     /* Label propagation is a stochastic method; the result will depend on the random seed. */
32     igraph_rng_seed(igraph_rng_default(), 123);
33 
34     /* All igraph functions that returns their result in an igraph_vector_t must be given
35        an already initialized vector. */
36     igraph_vector_init(&membership, 0);
37     igraph_community_label_propagation(
38                 &graph, &membership,
39                 /* weights= */ NULL, /* initial= */ NULL, /* fixed= */ NULL,
40                 &modularity);
41 
42     printf("%ld communities found; modularity score is %g.\n",
43            (long int) (igraph_vector_max(&membership) + 1),
44            modularity);
45 
46     /* Destroy data structures at the end. */
47     igraph_vector_destroy(&membership);
48     igraph_destroy(&graph);
49 
50     return 0;
51 }
52