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 
sort_and_print(igraph_vector_t * vec)22 void sort_and_print(igraph_vector_t *vec) {
23     igraph_vector_sort(vec);
24     print_vector_round(vec);
25 }
26 
main()27 int main() {
28 
29     igraph_t g;
30     igraph_vector_t cut, partition, partition2, capacity;
31     igraph_real_t value;
32     int source = 0;
33     int target = 4;
34 
35     igraph_vector_init(&partition, 0);
36     igraph_vector_init(&partition2, 0);
37     igraph_vector_init(&cut, 0);
38 
39     igraph_small(&g, 5, IGRAPH_DIRECTED, 0, 1, 1, 2, 1, 3, 2, 4, 3, 4, -1);
40     igraph_vector_init_int_end(&capacity, -1, 8, 2, 3, 3, 2, -1);
41 
42     /*    test without capacity    */
43 
44     igraph_st_mincut(&g, &value, &cut, &partition, &partition2, source, target, /*capacity*/ NULL);
45 
46     /* cut and partition should have only one element */
47     print_vector_round(&cut);
48     print_vector_round(&partition);
49     sort_and_print(&partition2);
50 
51     /*    test with capacity    */
52 
53     igraph_st_mincut(&g, &value, &cut, &partition, &partition2, source, target, &capacity);
54 
55     sort_and_print(&cut);
56     sort_and_print(&partition);
57     sort_and_print(&partition2);
58 
59     /*     cleanup     */
60 
61     igraph_vector_destroy(&cut);
62     igraph_vector_destroy(&partition);
63     igraph_vector_destroy(&partition2);
64     igraph_vector_destroy(&capacity);
65     igraph_destroy(&g);
66 
67     VERIFY_FINALLY_STACK();
68     return 0;
69 }
70