1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
|
/*
igraph library.
Copyright (C) 2024 The igraph development team <igraph@igraph.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <igraph.h>
#include "bench.h"
/* Benchmarks related to biconnected components. */
void run_bench(igraph_int_t vcount, igraph_real_t meandeg, igraph_int_t rep) {
igraph_t g;
igraph_bool_t b;
igraph_vector_int_t ivec;
char msg[128];
igraph_erdos_renyi_game_gnm(&g, vcount, round(meandeg * vcount / 2), IGRAPH_DIRECTED, IGRAPH_LOOPS_SW, IGRAPH_EDGE_UNLABELED);
igraph_vector_int_init(&ivec, igraph_vcount(&g));
snprintf(msg, sizeof(msg) / sizeof(msg[0]),
" 1 Weakly connected? vcount=%" IGRAPH_PRId ", meandeg=%g, %" IGRAPH_PRId "x",
vcount, meandeg, 10*rep);
igraph_invalidate_cache(&g);
BENCH(msg, REPEAT(igraph_is_connected(&g, &b, IGRAPH_WEAK), rep));
snprintf(msg, sizeof(msg) / sizeof(msg[0]),
" 2 Weak components. vcount=%" IGRAPH_PRId ", meandeg=%g, %" IGRAPH_PRId "x",
vcount, meandeg, rep);
igraph_invalidate_cache(&g);
BENCH(msg, REPEAT(igraph_connected_components(&g, &ivec, NULL, NULL, IGRAPH_WEAK), rep));
snprintf(msg, sizeof(msg) / sizeof(msg[0]),
" 3 Strongly connected? vcount=%" IGRAPH_PRId ", meandeg=%g, %" IGRAPH_PRId "x",
vcount, meandeg, 10*rep);
igraph_invalidate_cache(&g);
BENCH(msg, REPEAT(igraph_is_connected(&g, &b, IGRAPH_STRONG), rep));
snprintf(msg, sizeof(msg) / sizeof(msg[0]),
" 4 Strong components. vcount=%" IGRAPH_PRId ", meandeg=%g, %" IGRAPH_PRId "x",
vcount, meandeg, rep);
igraph_invalidate_cache(&g);
BENCH(msg, REPEAT(igraph_connected_components(&g, &ivec, NULL, NULL, IGRAPH_STRONG), rep));
snprintf(msg, sizeof(msg) / sizeof(msg[0]),
" 5 Biconnected? vcount=%" IGRAPH_PRId ", meandeg=%g, %" IGRAPH_PRId "x",
vcount, meandeg, rep);
igraph_invalidate_cache(&g);
BENCH(msg, REPEAT(igraph_is_biconnected(&g, &b), rep));
snprintf(msg, sizeof(msg) / sizeof(msg[0]),
" 6 Bridges. vcount=%" IGRAPH_PRId ", meandeg=%g, %" IGRAPH_PRId "x",
vcount, meandeg, rep);
igraph_invalidate_cache(&g);
BENCH(msg, REPEAT(igraph_bridges(&g, &ivec), rep));
snprintf(msg, sizeof(msg) / sizeof(msg[0]),
" 7 Articulation pts. vcount=%" IGRAPH_PRId ", meandeg=%g, %" IGRAPH_PRId "x",
vcount, meandeg, rep);
igraph_invalidate_cache(&g);
BENCH(msg, REPEAT(igraph_articulation_points(&g, &ivec), rep));
igraph_vector_int_destroy(&ivec);
igraph_destroy(&g);
printf("\n");
}
int main(void) {
igraph_rng_seed(igraph_rng_default(), 137);
BENCH_INIT();
// Note that whether these random graphs end up being connected
// with high probability depends not only on their mean degree,
// but also their vertex count.
run_bench(10000, 0.5, 100); // no giant component
run_bench(10000, 3, 100); // not weakly connected
run_bench(10000, 10, 100); // not strongly connected
run_bench(10000, 20, 100); // strongly connnected
run_bench(100000, 0.5, 100); // no giant component
run_bench(100000, 3, 100); // not weakly connected
run_bench(100000, 10, 100); // not strongly connected
run_bench(100000, 20, 100); // strongly connnected
return 0;
}
|