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
set_options_fast(igraph_layout_drl_options_t * options)22 void set_options_fast(igraph_layout_drl_options_t *options) {
23 options->edge_cut = 4.0/5.0;
24
25 options->init_iterations = 10;
26 options->init_temperature = 2000;
27 options->init_attraction = 10;
28 options->init_damping_mult = 1.0;
29
30 options->liquid_iterations = 10;
31 options->liquid_temperature = 2000;
32 options->liquid_attraction = 10;
33 options->liquid_damping_mult = 1.0;
34
35 options->expansion_iterations = 10;
36 options->expansion_temperature = 2000;
37 options->expansion_attraction = 2;
38 options->expansion_damping_mult = 1.0;
39
40 options->cooldown_iterations = 10;
41 options->cooldown_temperature = 2000;
42 options->cooldown_attraction = 1;
43 options->cooldown_damping_mult = .1;
44
45 options->crunch_iterations = 10;
46 options->crunch_temperature = 250;
47 options->crunch_attraction = 1;
48 options->crunch_damping_mult = 0.25;
49
50 options->simmer_iterations = 10;
51 options->simmer_temperature = 250;
52 options->simmer_attraction = .5;
53 options->simmer_damping_mult = 1;
54 }
55
check_and_destroy(igraph_matrix_t * result,igraph_real_t half_size)56 void check_and_destroy(igraph_matrix_t *result, igraph_real_t half_size) {
57 igraph_real_t min, max;
58 igraph_matrix_minmax(result, &min, &max);
59 IGRAPH_ASSERT(min >= -half_size);
60 IGRAPH_ASSERT(max <= half_size);
61 igraph_matrix_destroy(result);
62 }
63
main()64 int main() {
65 igraph_t g;
66 igraph_matrix_t result;
67 igraph_layout_drl_options_t options;
68 int i;
69 igraph_real_t *damping_muls[6] = {&options.init_damping_mult, &options.liquid_damping_mult, &options.expansion_damping_mult, &options.cooldown_damping_mult, &options.crunch_damping_mult, &options.simmer_damping_mult};
70
71 igraph_rng_seed(igraph_rng_default(), 42);
72
73 set_options_fast(&options);
74
75 printf("The Zachary karate club.\n");
76 igraph_famous(&g, "zachary");
77 igraph_matrix_init(&result, 0, 0);
78 IGRAPH_ASSERT(igraph_layout_drl(&g, &result, /*use_seed*/ 0, &options,
79 /*weights*/ NULL, /*fixed*/ 0) == IGRAPH_SUCCESS);
80 check_and_destroy(&result, 50);
81
82 VERIFY_FINALLY_STACK();
83 igraph_set_error_handler(igraph_error_handler_ignore);
84
85 printf("Negative damping.\n");
86 igraph_matrix_init(&result, 0, 0);
87 for (i = 0; i < 6; i++) {
88 *damping_muls[i] *= -1.0;
89 IGRAPH_ASSERT(igraph_layout_drl(&g, &result, /*use_seed*/ 0, &options,
90 /*weights*/ NULL, /*fixed*/ 0) == IGRAPH_EINVAL);
91 *damping_muls[i] *= -1.0;
92 }
93 igraph_matrix_destroy(&result);
94 igraph_destroy(&g);
95
96 VERIFY_FINALLY_STACK();
97 return 0;
98 }
99