1 /* -*- mode: C -*- */
2 /*
3 IGraph library.
4 Copyright (C) 2013 Gabor Csardi <csardi.gabor@gmail.com>
5 334 Harvard st, Cambridge MA, 02139 USA
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, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 02110-1301 USA
21
22 */
23
24 #include <igraph.h>
25
26 #include "test_utilities.inc"
27
sort_cliques(igraph_vector_ptr_t * cliques)28 void sort_cliques(igraph_vector_ptr_t *cliques) {
29 int i, n = igraph_vector_ptr_size(cliques);
30 for (i = 0; i < n; i++) {
31 igraph_vector_t *v = VECTOR(*cliques)[i];
32 igraph_vector_sort(v);
33 }
34 igraph_vector_ptr_sort(cliques, igraph_vector_lex_cmp);
35 }
36
print_and_destroy(igraph_vector_ptr_t * cliques)37 int print_and_destroy(igraph_vector_ptr_t *cliques) {
38 int i, n = igraph_vector_ptr_size(cliques);
39 sort_cliques(cliques);
40 for (i = 0; i < n; i++) {
41 igraph_vector_t *v = VECTOR(*cliques)[i];
42 igraph_vector_print(v);
43 igraph_vector_destroy(v);
44 }
45 igraph_vector_ptr_destroy_all(cliques);
46 return 0;
47 }
48
main()49 int main() {
50 igraph_t graph;
51 igraph_vector_ptr_t cliques;
52 igraph_integer_t no;
53
54 igraph_rng_seed(igraph_rng_default(), 42);
55
56 igraph_ring(&graph, /*n=*/ 10, /*directed=*/ 0,
57 /*mutual=*/ 0, /*circular=*/ 1);
58 igraph_vector_ptr_init(&cliques, 0);
59
60 igraph_maximal_cliques(&graph, &cliques, /*min_size=*/ 0,
61 /*max_size=*/ 0);
62 igraph_maximal_cliques_count(&graph, &no, /*min_size=*/ 0,
63 /*max_size=*/ 0 /*no limit*/);
64 IGRAPH_ASSERT(no == igraph_vector_ptr_size(&cliques));
65
66 print_and_destroy(&cliques);
67 igraph_destroy(&graph);
68
69 printf("---\n");
70 /* ----------------------------------------------------------- */
71
72 igraph_erdos_renyi_game(&graph, IGRAPH_ERDOS_RENYI_GNP,
73 /*n=*/ 50, /*p=*/ 0.5, /*directed=*/ 0,
74 /*loops=*/ 0);
75
76 igraph_vector_ptr_init(&cliques, 0);
77
78 igraph_maximal_cliques(&graph, &cliques, /*min_size=*/ 8,
79 /*max_size=*/ 0);
80 igraph_maximal_cliques_count(&graph, &no, /*min_size=*/ 8,
81 /*max_size=*/ 0 /*no limit*/);
82 IGRAPH_ASSERT(no == igraph_vector_ptr_size(&cliques));
83
84 print_and_destroy(&cliques);
85 igraph_destroy(&graph);
86
87 VERIFY_FINALLY_STACK();
88
89 return 0;
90 }
91