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
main()22 int main() {
23 igraph_t g;
24 igraph_vector_t outseq;
25 igraph_rng_seed(igraph_rng_default(), 42);
26 igraph_bool_t tree;
27
28 printf("No vertices:\n");
29 IGRAPH_ASSERT(igraph_barabasi_aging_game(
30 &g, /*nodes*/ 0, /*m: edges_per_step*/ 1,
31 /*outseq: edges per step as vector*/ NULL, /*outpref*/ 0,
32 /*pa_exp*/ 1, /*aging_exp*/ 1, /*aging_bin*/ 1,
33 /*zero_deg_appeal*/ 0, /*zero_age_appeal*/ 0, /*deg_coef*/ 1.0,
34 /*age_coef */ 1.0, /*directed*/ 0) == IGRAPH_SUCCESS);
35 print_graph(&g);
36 IGRAPH_ASSERT(igraph_vcount(&g) == 0);
37 IGRAPH_ASSERT(!igraph_is_directed(&g));
38 igraph_destroy(&g);
39
40 printf("No edges:\n");
41 IGRAPH_ASSERT(igraph_barabasi_aging_game(
42 &g, /*nodes*/ 5, /*m: edges_per_step*/ 0,
43 /*outseq: edges per step as vector*/ NULL, /*outpref*/ 0,
44 /*pa_exp*/ 1, /*aging_exp*/ 1, /*aging_bin*/ 1,
45 /*zero_deg_appeal*/ 0, /*zero_age_appeal*/ 0, /*deg_coef*/ 1.0,
46 /*age_coef */ 1.0, /*directed*/ 0) == IGRAPH_SUCCESS);
47 print_graph(&g);
48 IGRAPH_ASSERT(igraph_vcount(&g) == 5);
49 IGRAPH_ASSERT(igraph_ecount(&g) == 0);
50 IGRAPH_ASSERT(!igraph_is_directed(&g));
51 igraph_destroy(&g);
52
53 /*one edge per step makes a tree*/
54 IGRAPH_ASSERT(igraph_barabasi_aging_game(
55 &g, /*nodes*/ 10, /*m: edges_per_step*/ 1,
56 /*outseq: edges per step as vector*/ NULL, /*outpref*/ 0,
57 /*pa_exp*/ 0.5, /*aging_exp*/ -0.5, /*aging_bin*/ 2,
58 /*zero_deg_appeal*/ 0.1, /*zero_age_appeal*/ 0, /*deg_coef*/ 0.1,
59 /*age_coef */ 0.1, /*directed*/ 1) == IGRAPH_SUCCESS);
60 IGRAPH_ASSERT(igraph_vcount(&g) == 10);
61 IGRAPH_ASSERT(igraph_ecount(&g) == 9);
62 IGRAPH_ASSERT(igraph_is_directed(&g));
63 igraph_is_tree(&g, &tree, /* root*/ NULL, IGRAPH_IN);
64 IGRAPH_ASSERT(tree);
65 igraph_destroy(&g);
66
67 printf("Prefer old vertices to make a star of triple edges:\n");
68 IGRAPH_ASSERT(igraph_barabasi_aging_game(
69 &g, /*nodes*/ 5, /*m: edges_per_step*/ 3,
70 /*outseq: edges per step as vector*/ NULL, /*outpref*/ 1,
71 /*pa_exp*/ 0.0, /*aging_exp*/ 10, /*aging_bin*/ 6,
72 /*zero_deg_appeal*/ 1.0, /*zero_age_appeal*/ 0, /*deg_coef*/ 0.0,
73 /*age_coef */ 1, /*directed*/ 1) == IGRAPH_SUCCESS);
74 print_graph_canon(&g);
75 igraph_destroy(&g);
76
77 printf("Prefer new vertices to make a line of double edges:\n");
78 IGRAPH_ASSERT(igraph_barabasi_aging_game(
79 &g, /*nodes*/ 5, /*m: edges_per_step*/ 2,
80 /*outseq: edges per step as vector*/ NULL, /*outpref*/ 0,
81 /*pa_exp*/ 0.0, /*aging_exp*/ -10, /*aging_bin*/ 6,
82 /*zero_deg_appeal*/ 0.1, /*zero_age_appeal*/ 0, /*deg_coef*/ 0.1,
83 /*age_coef */ 1, /*directed*/ 1) == IGRAPH_SUCCESS);
84 print_graph_canon(&g);
85 igraph_destroy(&g);
86
87 printf("Increasing thickness of the line using outseq:\n");
88 igraph_vector_init_int(&outseq, 5, 1, 2, 3, 4, 5);
89 IGRAPH_ASSERT(igraph_barabasi_aging_game(
90 &g, /*nodes*/ 5, /*m: edges_per_step*/ 2,
91 /*outseq: edges per step as vector*/ &outseq, /*outpref*/ 0,
92 /*pa_exp*/ 0.1, /*aging_exp*/ -10, /*aging_bin*/ 6,
93 /*zero_deg_appeal*/ 0.1, /*zero_age_appeal*/ 0, /*deg_coef*/ 0.1,
94 /*age_coef */ 10, /*directed*/ 1) == IGRAPH_SUCCESS);
95 print_graph_canon(&g);
96 igraph_destroy(&g);
97 igraph_vector_destroy(&outseq);
98
99 printf("Prefer more edges to make a star:\n");
100 IGRAPH_ASSERT(igraph_barabasi_aging_game(
101 &g, /*nodes*/ 5, /*m: edges_per_step*/ 2,
102 /*outseq: edges per step as vector*/ NULL, /*outpref*/ 0,
103 /*pa_exp*/ 10.0, /*aging_exp*/ 0.0, /*aging_bin*/ 6,
104 /*zero_deg_appeal*/ 0.0, /*zero_age_appeal*/ 1.0, /*deg_coef*/ 1.0,
105 /*age_coef */ 0.0, /*directed*/ 1) == IGRAPH_SUCCESS);
106 print_graph_canon(&g);
107 igraph_destroy(&g);
108
109 VERIFY_FINALLY_STACK();
110 igraph_set_error_handler(igraph_error_handler_ignore);
111
112 /* Non-negative age coefficients are required*/
113 IGRAPH_ASSERT(igraph_barabasi_aging_game(
114 &g, /*nodes*/ 5, /*m: edges_per_step*/ 2,
115 /*outseq: edges per step as vector*/ NULL, /*outpref*/ 0,
116 /*pa_exp*/ 1.0, /*aging_exp*/ 0.0, /*aging_bin*/ 6,
117 /*zero_deg_appeal*/ 1.0, /*zero_age_appeal*/ 1.0, /*deg_coef*/ 1.0,
118 /*age_coef */ -1.0, /*directed*/ 1) == IGRAPH_EINVAL);
119
120 /* Non-negative degree coefficients are required*/
121 IGRAPH_ASSERT(igraph_barabasi_aging_game(
122 &g, /*nodes*/ 5, /*m: edges_per_step*/ 2,
123 /*outseq: edges per step as vector*/ NULL, /*outpref*/ 0,
124 /*pa_exp*/ 1.0, /*aging_exp*/ 0.0, /*aging_bin*/ 6,
125 /*zero_deg_appeal*/ 1.0, /*zero_age_appeal*/ 1.0, /*deg_coef*/ -1.0,
126 /*age_coef */ 0.0, /*directed*/ 1) == IGRAPH_EINVAL);
127
128 /* Non negative zero degree appeals are required*/
129 IGRAPH_ASSERT(igraph_barabasi_aging_game(
130 &g, /*nodes*/ 5, /*m: edges_per_step*/ 2,
131 /*outseq: edges per step as vector*/ NULL, /*outpref*/ 0,
132 /*pa_exp*/ 1.0, /*aging_exp*/ 0.0, /*aging_bin*/ 6,
133 /*zero_deg_appeal*/ -1.0, /*zero_age_appeal*/ 1.0, /*deg_coef*/ 1.0,
134 /*age_coef */ 0.0, /*directed*/ 1) == IGRAPH_EINVAL);
135
136 /* Non negative zero age appeals are required*/
137 IGRAPH_ASSERT(igraph_barabasi_aging_game(
138 &g, /*nodes*/ 5, /*m: edges_per_step*/ 2,
139 /*outseq: edges per step as vector*/ NULL, /*outpref*/ 0,
140 /*pa_exp*/ 1.0, /*aging_exp*/ 0.0, /*aging_bin*/ 6,
141 /*zero_deg_appeal*/ 1.0, /*zero_age_appeal*/ -1.0, /*deg_coef*/ 1.0,
142 /*age_coef */ 0.0, /*directed*/ 1) == IGRAPH_EINVAL);
143
144 VERIFY_FINALLY_STACK();
145 return 0;
146 }
147