1 
2 #include <igraph.h>
3 
main()4 int main() {
5     igraph_t graph;
6     igraph_vector_int_t colors;
7 
8     /* Setting a seed makes the result of erdos_renyi_game deterministic. */
9     igraph_rng_seed(igraph_rng_default(), 42);
10 
11     /* IGRAPH_UNDIRECTED and IGRAPH_NO_LOOPS are both equivalent to 0/FALSE, but
12        communicate intent better in this context. */
13     igraph_erdos_renyi_game(&graph, IGRAPH_ERDOS_RENYI_GNM, 1000, 10000, IGRAPH_UNDIRECTED, IGRAPH_NO_LOOPS);
14 
15     /* As with all igraph functions, the vector in which the result is returned must
16        be initialized in advance. */
17     igraph_vector_int_init(&colors, 0);
18     igraph_vertex_coloring_greedy(&graph, &colors, IGRAPH_COLORING_GREEDY_COLORED_NEIGHBORS);
19 
20     /* Verify that the colouring is valid, i.e. no two adjacent vertices have the same colour. */
21     {
22         long int i;
23         /* Store the edge count to avoid the overhead from igraph_ecount in the for loop. */
24         long int no_of_edges = igraph_ecount(&graph);
25         for (i = 0; i < no_of_edges; ++i) {
26             if ( VECTOR(colors)[ IGRAPH_FROM(&graph, i) ] == VECTOR(colors)[ IGRAPH_TO(&graph, i) ]  ) {
27                 printf("Inconsistent coloring! Vertices %ld and %ld are adjacent but have the same color.\n",
28                        (long) IGRAPH_FROM(&graph, i), (long) IGRAPH_TO(&graph, i));
29                 abort();
30             }
31         }
32     }
33 
34     /* Destroy data structure when we are done. */
35     igraph_vector_int_destroy(&colors);
36     igraph_destroy(&graph);
37 
38     return 0;
39 }
40