1
2 #include <igraph.h>
3 #include <stdio.h>
4
main()5 int main() {
6 igraph_t graph;
7 igraph_vector_ptr_t cliques;
8 long int i, n;
9
10 /* Set a random seed to make the program deterministic */
11 igraph_rng_seed(igraph_rng_default(), 31415);
12
13 /* Create a random graph with a given number of vertices and edges */
14 igraph_erdos_renyi_game(&graph, IGRAPH_ERDOS_RENYI_GNM, 15, 80, IGRAPH_UNDIRECTED, IGRAPH_NO_LOOPS);
15
16 /* Find all maximal cliques in the graph */
17 igraph_vector_ptr_init(&cliques, 0);
18 igraph_maximal_cliques(&graph, &cliques, -1, -1);
19
20 /* Print the cliques in lexicographical order */
21 printf("Maximal cliques in lexicographical order:\n");
22 igraph_vector_ptr_sort(&cliques, igraph_vector_lex_cmp);
23 n = igraph_vector_ptr_size(&cliques);
24 for (i=0; i < n; ++i) {
25 igraph_vector_print(VECTOR(cliques)[i]);
26 }
27
28 /* Print the cliques in colexicographical order */
29 printf("\nMaximal cliques in colexicographical order:\n");
30 igraph_vector_ptr_sort(&cliques, igraph_vector_colex_cmp);
31 n = igraph_vector_ptr_size(&cliques);
32 for (i=0; i < n; ++i) {
33 igraph_vector_print(VECTOR(cliques)[i]);
34 }
35
36 /* Destroy data structures when we no longer need them */
37
38 IGRAPH_VECTOR_PTR_SET_ITEM_DESTRUCTOR(&cliques, igraph_vector_destroy);
39 igraph_vector_ptr_destroy_all(&cliques);
40
41 igraph_destroy(&graph);
42
43 return 0;
44 }
45