1
2 #include <igraph.h>
3
main()4 int main() {
5 igraph_t graph;
6 igraph_vector_t component_sizes;
7
8 igraph_rng_seed(igraph_rng_default(), 42); /* make program deterministic */
9
10 /* Sample a graph from the Erdős-Rényi G(n,m) model */
11
12 igraph_erdos_renyi_game(
13 &graph, IGRAPH_ERDOS_RENYI_GNM,
14 /* n= */ 100, /* m= */ 100,
15 IGRAPH_UNDIRECTED, IGRAPH_NO_LOOPS);
16
17 /* Compute the fraction of vertices contained within the largest connected component */
18
19 igraph_vector_init(&component_sizes, 0);
20 igraph_clusters(&graph, NULL, &component_sizes, NULL, IGRAPH_STRONG);
21
22 printf("Fraction of vertices in giant component: %g\n", (double) igraph_vector_max(&component_sizes) / igraph_vcount(&graph));
23
24 /* Clean up data structures when no longer needed */
25
26 igraph_vector_destroy(&component_sizes);
27 igraph_destroy(&graph);
28
29 return 0;
30 }
31