/src/igraph/fuzzing/misc_algos_weighted.cpp
Line | Count | Source |
1 | | /* |
2 | | igraph library. |
3 | | Copyright (C) 2024 The igraph development team |
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, write to the Free Software |
17 | | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
18 | | 02110-1301 USA |
19 | | */ |
20 | | |
21 | | #include <igraph.h> |
22 | | #include <cstdlib> |
23 | | |
24 | 1.62k | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { |
25 | 1.62k | igraph_t graph; |
26 | 1.62k | igraph_vector_int_t edges; |
27 | 1.62k | igraph_vector_t weights; |
28 | | |
29 | 1.62k | igraph_set_warning_handler(igraph_warning_handler_ignore); |
30 | | |
31 | 1.62k | if (Size % 3 == 0 || Size % 3 == 2 || Size > (3 * 256) + 1 || Size < 1) { |
32 | 14 | return 0; |
33 | 14 | } |
34 | | |
35 | 1.61k | igraph_vector_int_init(&edges, ((Size-1) / 3) * 2); |
36 | 1.61k | igraph_vector_init(&weights, (Size-1) / 3); |
37 | 60.8k | for (size_t i=0; i < ((Size-1) / 3); ++i) { |
38 | 59.1k | VECTOR(edges)[i * 2] = Data[i * 3 + 1]; |
39 | 59.1k | VECTOR(edges)[i * 2 + 1] = Data[i * 3 + 2]; |
40 | | // We keep the weights strictly positive, as this is required by some algorithms. |
41 | 59.1k | VECTOR(weights)[i] = ((double) Data[i * 3 + 3] + 1.0) / 105.0; |
42 | 59.1k | } |
43 | | |
44 | | // Turn on attribute handling. |
45 | 1.61k | igraph_set_attribute_table(&igraph_cattribute_table); |
46 | | |
47 | 1.61k | igraph_rng_seed(igraph_rng_default(), 42); |
48 | | |
49 | 1.61k | if (igraph_create(&graph, &edges, Data[0], IGRAPH_DIRECTED) == IGRAPH_SUCCESS) { |
50 | 1.61k | igraph_real_t r, r2; |
51 | 1.61k | igraph_vector_int_list_t ivl1; |
52 | 1.61k | igraph_vector_t v1, v2; |
53 | 1.61k | igraph_vector_int_t iv1, iv2; |
54 | 1.61k | igraph_matrix_t m; |
55 | | |
56 | 1.61k | igraph_vector_int_list_init(&ivl1, 0); |
57 | 1.61k | igraph_vector_init(&v1, 0); |
58 | 1.61k | igraph_vector_init(&v2, 0); |
59 | 1.61k | igraph_vector_int_init(&iv1, 0); |
60 | 1.61k | igraph_vector_int_init(&iv2, 0); |
61 | 1.61k | igraph_matrix_init(&m, 0, 0); |
62 | | |
63 | | /* Directed */ |
64 | | |
65 | 1.61k | igraph_get_adjacency(&graph, &m, IGRAPH_GET_ADJACENCY_BOTH, &weights, IGRAPH_NO_LOOPS); |
66 | 1.61k | igraph_get_laplacian(&graph, &m, IGRAPH_OUT, IGRAPH_LAPLACIAN_LEFT, &weights); |
67 | 1.61k | igraph_get_stochastic(&graph, &m, false, &weights); |
68 | 1.61k | igraph_joint_degree_matrix(&graph, &weights, &m, -1, -1); |
69 | 1.61k | igraph_joint_degree_distribution(&graph, &weights, &m, IGRAPH_IN, IGRAPH_OUT, true, true, -1, -1); |
70 | 1.61k | igraph_degree_correlation_vector(&graph, &weights, &v1, IGRAPH_OUT, IGRAPH_IN, true); |
71 | 1.61k | igraph_avg_nearest_neighbor_degree(&graph, igraph_vss_all(), IGRAPH_OUT, IGRAPH_IN, &v1, &v2, &weights); |
72 | | |
73 | 1.61k | igraph_pseudo_diameter(&graph, &weights, &r, -1, NULL, NULL, true, true); |
74 | 1.61k | igraph_diameter(&graph, &weights, &r, NULL, NULL, NULL, NULL, true, false); |
75 | 1.61k | igraph_average_path_length(&graph, &weights, &r, &r2, true, true); |
76 | 1.61k | igraph_radius(&graph, &weights, &r, IGRAPH_OUT); |
77 | | |
78 | 1.61k | igraph_feedback_arc_set(&graph, &iv1, &weights, IGRAPH_FAS_APPROX_EADES); |
79 | | |
80 | 1.61k | if (igraph_vcount(&graph) >= 1) { |
81 | 1.61k | igraph_random_walk(&graph, &weights, &iv1, &iv2, 0, IGRAPH_ALL, igraph_ecount(&graph), IGRAPH_RANDOM_WALK_STUCK_RETURN); |
82 | 1.61k | igraph_distances_dijkstra(&graph, &m, igraph_vss_1(0), igraph_vss_all(), &weights, IGRAPH_OUT); |
83 | 1.61k | igraph_distances_bellman_ford(&graph, &m, igraph_vss_1(0), igraph_vss_all(), &weights, IGRAPH_OUT); |
84 | 1.61k | igraph_widest_path_widths_dijkstra(&graph, &m, igraph_vss_1(0), igraph_vss_all(), &weights, IGRAPH_IN); |
85 | 1.61k | } |
86 | | |
87 | 1.61k | if (igraph_vcount(&graph) >= 2) { |
88 | 1.59k | igraph_get_k_shortest_paths(&graph, &weights, &ivl1, NULL, 5, 0, 1, IGRAPH_IN); |
89 | 1.59k | } |
90 | | |
91 | | /* Undirected */ |
92 | | |
93 | 1.61k | { |
94 | 1.61k | igraph_attribute_combination_t comb; |
95 | | |
96 | 1.61k | SETEANV(&graph, "weight", &weights); |
97 | 1.61k | igraph_attribute_combination(&comb, |
98 | 1.61k | "weight", IGRAPH_ATTRIBUTE_COMBINE_SUM, |
99 | 1.61k | IGRAPH_NO_MORE_ATTRIBUTES); |
100 | 1.61k | igraph_to_undirected(&graph, IGRAPH_TO_UNDIRECTED_COLLAPSE, &comb); |
101 | 1.61k | igraph_attribute_combination_destroy(&comb); |
102 | 1.61k | EANV(&graph, "weight", &weights); |
103 | 1.61k | } |
104 | | |
105 | 1.61k | igraph_get_adjacency(&graph, &m, IGRAPH_GET_ADJACENCY_BOTH, &weights, IGRAPH_LOOPS_ONCE); |
106 | 1.61k | igraph_get_laplacian(&graph, &m, IGRAPH_OUT, IGRAPH_LAPLACIAN_UNNORMALIZED, &weights); |
107 | 1.61k | igraph_get_stochastic(&graph, &m, true, &weights); |
108 | 1.61k | igraph_joint_degree_matrix(&graph, &weights, &m, -1, -1); |
109 | 1.61k | igraph_joint_degree_distribution(&graph, &weights, &m, IGRAPH_ALL, IGRAPH_ALL, false, true, -1, -1); |
110 | 1.61k | igraph_degree_correlation_vector(&graph, &weights, &v1, IGRAPH_ALL, IGRAPH_ALL, false); |
111 | 1.61k | igraph_avg_nearest_neighbor_degree(&graph, igraph_vss_all(), IGRAPH_ALL, IGRAPH_ALL, &v1, &v2, &weights); |
112 | | |
113 | 1.61k | igraph_pseudo_diameter(&graph, &weights, &r, -1, NULL, NULL, false, false); |
114 | 1.61k | igraph_diameter(&graph, &weights, &r, NULL, NULL, NULL, NULL, false, true); |
115 | 1.61k | igraph_average_path_length(&graph, &weights, &r, &r, true, true); |
116 | 1.61k | igraph_radius(&graph, &weights, &r, IGRAPH_OUT); |
117 | | |
118 | 1.61k | if (igraph_vcount(&graph) >= 1) { |
119 | 1.61k | igraph_random_walk(&graph, &weights, &iv1, &iv2, 0, IGRAPH_ALL, igraph_ecount(&graph), IGRAPH_RANDOM_WALK_STUCK_RETURN); |
120 | 1.61k | igraph_distances_dijkstra(&graph, &m, igraph_vss_1(0), igraph_vss_all(), &weights, IGRAPH_ALL); |
121 | 1.61k | igraph_distances_bellman_ford(&graph, &m, igraph_vss_1(0), igraph_vss_all(), &weights, IGRAPH_ALL); |
122 | 1.61k | igraph_widest_path_widths_dijkstra(&graph, &m, igraph_vss_1(0), igraph_vss_all(), &weights, IGRAPH_ALL); |
123 | 1.61k | } |
124 | | |
125 | 1.61k | igraph_minimum_spanning_tree(&graph, &iv1, &weights, IGRAPH_MST_PRIM); |
126 | 1.61k | igraph_minimum_spanning_tree(&graph, &iv1, &weights, IGRAPH_MST_KRUSKAL); |
127 | | |
128 | 1.61k | igraph_spanner(&graph, &iv1, 2.34, &weights); |
129 | | |
130 | 1.61k | igraph_matrix_destroy(&m); |
131 | 1.61k | igraph_vector_int_destroy(&iv2); |
132 | 1.61k | igraph_vector_int_destroy(&iv1); |
133 | 1.61k | igraph_vector_destroy(&v2); |
134 | 1.61k | igraph_vector_destroy(&v1); |
135 | 1.61k | igraph_vector_int_list_destroy(&ivl1); |
136 | | |
137 | 1.61k | igraph_destroy(&graph); |
138 | 1.61k | } |
139 | | |
140 | 1.61k | igraph_vector_int_destroy(&edges); |
141 | 1.61k | igraph_vector_destroy(&weights); |
142 | | |
143 | 1.61k | IGRAPH_ASSERT(IGRAPH_FINALLY_STACK_EMPTY); |
144 | | |
145 | 1.61k | return 0; // Non-zero return values are reserved for future use. |
146 | 1.61k | } |