1 /*
2    IGraph library.
3    Copyright (C) 2021  The igraph development team <igraph@igraph.org>
4 
5    This program is free software; you can redistribute it and/or modify
6    it under the terms of the GNU General Public License as published by
7    the Free Software Foundation; either version 2 of the License, or
8    (at your option) any later version.
9 
10    This program is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13    GNU General Public License for more details.
14 
15    You should have received a copy of the GNU General Public License
16    along with this program.  If not, see <https://www.gnu.org/licenses/>.
17 */
18 
19 #include <igraph.h>
20 #include "test_utilities.inc"
21 
call_and_print(igraph_t * graph,igraph_vector_t * alpha,igraph_vector_t * alpham1,igraph_bool_t fill,igraph_bool_t ng)22 void call_and_print(igraph_t *graph, igraph_vector_t *alpha, igraph_vector_t *alpham1,
23                     igraph_bool_t fill, igraph_bool_t ng) {
24     igraph_bool_t chordal;
25     igraph_vector_t fill_in;
26     igraph_t newgraph;
27     igraph_vector_init(&fill_in, 0);
28     IGRAPH_ASSERT(igraph_is_chordal(graph, alpha, alpham1, &chordal,
29                   fill ? &fill_in : NULL, ng? &newgraph : NULL) == IGRAPH_SUCCESS);
30     printf("Is chordal: %d\nFill in:\n", chordal);
31     print_vector(&fill_in);
32     if (ng) {
33         printf("New graph:\n");
34         print_graph_canon(&newgraph);
35         igraph_destroy(&newgraph);
36     }
37     printf("\n");
38     igraph_vector_destroy(&fill_in);
39 }
40 
41 
main()42 int main() {
43     igraph_t g_0, g_1, g_lmu;
44     igraph_bool_t chordal;
45     igraph_vector_t alpha, alpham1;
46 
47     igraph_small(&g_0, 0, 0, -1);
48     igraph_small(&g_1, 1, 0, -1);
49     igraph_small(&g_lmu, 6, 0, 0,1, 0,2, 1,1, 1,3, 2,0, 2,0, 2,3, 3,4, 3,4, -1);
50 
51     printf("No vertices:\n");
52     call_and_print(&g_0, NULL, NULL, 1, 1);
53 
54     printf("One vertex:\n");
55     call_and_print(&g_1, NULL, NULL, 1, 1);
56 
57     printf("One vertex, don't calculate anything.\n\n");
58     IGRAPH_ASSERT(igraph_is_chordal(&g_1, NULL, NULL, NULL, NULL, NULL) == IGRAPH_SUCCESS);
59 
60     printf("Disconnected graph with loops and multiple edges:\n");
61     call_and_print(&g_lmu, NULL, NULL, 1, 1);
62 
63     printf("Same graph, don't ask for fill_in vector:\n");
64     call_and_print(&g_lmu, NULL, NULL, 0, 1);
65 
66     printf("Same graph, don't ask for fill_in vector or newgraph:\n");
67     call_and_print(&g_lmu, NULL, NULL, 0, 0);
68 
69     printf("Same graph, own calculation of alpha and its inverse:\n");
70     igraph_vector_init(&alpha, 0);
71     igraph_vector_init(&alpham1, 0);
72     igraph_maximum_cardinality_search(&g_lmu, &alpha, &alpham1);
73     call_and_print(&g_lmu, &alpha, &alpham1, 1, 1);
74 
75     printf("Same graph, own calculation of alpha:\n");
76     call_and_print(&g_lmu, &alpha, NULL, 1, 1);
77 
78     printf("Same graph, own calculation of inverse alpha:\n");
79     call_and_print(&g_lmu, NULL, &alpham1, 1, 1);
80 
81     VERIFY_FINALLY_STACK();
82     igraph_set_error_handler(igraph_error_handler_ignore);
83 
84     printf("Wrong size alpha.\n");
85     igraph_vector_clear(&alpha);
86     IGRAPH_ASSERT(igraph_is_chordal(&g_lmu, &alpha, NULL, &chordal, NULL, NULL) == IGRAPH_EINVAL);
87 
88     printf("Wrong size alpham1.\n");
89     IGRAPH_ASSERT(igraph_is_chordal(&g_lmu, NULL, &alpha, &chordal, NULL, NULL) == IGRAPH_EINVAL);
90 
91     igraph_destroy(&g_0);
92     igraph_destroy(&g_1);
93     igraph_destroy(&g_lmu);
94     igraph_vector_destroy(&alpha);
95     igraph_vector_destroy(&alpham1);
96 
97     VERIFY_FINALLY_STACK();
98     return 0;
99 }
100