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, cl1, cl2;
52     igraph_vector_int_t v1, v2;
53     igraph_integer_t n, n1, n2;
54 
55     igraph_rng_seed(igraph_rng_default(), 42);
56     igraph_erdos_renyi_game(&graph, IGRAPH_ERDOS_RENYI_GNP,
57                             /*n=*/ 100, /*p=*/ 0.5, /*directed=*/ 0,
58                             /*loops=*/ 0);
59 
60     igraph_vector_ptr_init(&cliques, 0);
61 
62     igraph_maximal_cliques_subset(&graph, /*subset=*/ 0,
63                                   &cliques, &n, /*outfile=*/ 0,
64                                   /*min_size=*/ 9, /*max_size=*/ 0);
65 
66     igraph_vector_int_init_seq(&v1,  0, 12);
67     igraph_vector_int_init_seq(&v2, 13, 99);
68     igraph_vector_ptr_init(&cl1, 0);
69     igraph_vector_ptr_init(&cl2, 0);
70     igraph_maximal_cliques_subset(&graph, &v1, &cl1, &n1, /*outfile=*/ 0,
71                                   /*min_size=*/ 9, /*max_size=*/ 0);
72     igraph_maximal_cliques_subset(&graph, &v2, &cl2, &n2, /*outfile=*/ 0,
73                                   /*min_size=*/ 9, /*max_size=*/ 0);
74 
75     igraph_vector_int_destroy(&v1);
76     igraph_vector_int_destroy(&v2);
77 
78     if (n1 + n2 != n) {
79         return 1;
80     }
81     if (n1 != igraph_vector_ptr_size(&cl1)) {
82         return 2;
83     }
84     if (n2 != igraph_vector_ptr_size(&cl2)) {
85         return 3;
86     }
87 
88     print_and_destroy(&cliques);
89     printf("---\n");
90     print_and_destroy(&cl1);
91     printf("+\n");
92     print_and_destroy(&cl2);
93 
94     igraph_destroy(&graph);
95 
96     VERIFY_FINALLY_STACK();
97 
98     return 0;
99 }
100