File: igraph_betweenness.c

package info (click to toggle)
igraph 1.0.1%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 22,436 kB
  • sloc: ansic: 155,759; cpp: 32,544; xml: 2,960; python: 411; makefile: 168; javascript: 20; sh: 9
file content (84 lines) | stat: -rw-r--r-- 3,807 bytes parent folder | download | duplicates (2)
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
/*
   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"

int main(void) {
    igraph_t graph;
    igraph_vector_t betweenness;

    BENCH_INIT();
    igraph_rng_seed(igraph_rng_default(), 42);

    igraph_vector_init(&betweenness, 0);

    /* Kautz and De Bruijn graphs are connected, therefore there should not be a dramatic difference
     * in the performance of the directed and undirected calculations. */

    igraph_kautz(&graph, 4, 5);
    BENCH(" 1 Betweenness, Kautz(4,5), directed",
          igraph_betweenness(&graph, NULL, &betweenness, igraph_vss_all(), IGRAPH_DIRECTED, false));
    BENCH(" 2 Betweenness, Kautz(4,5), undirected",
          igraph_betweenness(&graph, NULL, &betweenness, igraph_vss_all(), IGRAPH_UNDIRECTED, false));
    igraph_destroy(&graph);

    igraph_de_bruijn(&graph, 6, 5);
    BENCH(" 3 Betweenness, DeBruijn(6,5), directed",
          igraph_betweenness(&graph, NULL, &betweenness, igraph_vss_all(), IGRAPH_DIRECTED, false));
    igraph_destroy(&graph);

    {
        igraph_vector_int_t dims;

        igraph_vector_int_init_int_end(&dims, -1, 8, 8, 8, 8, -1);
        igraph_square_lattice(&graph, &dims, 1, IGRAPH_UNDIRECTED, /* mutual */ 0, /* periodic */ 0);
        BENCH(" 4 Betweenness, Grid(8,8,8,8), undirected",
              igraph_betweenness(&graph, NULL, &betweenness, igraph_vss_all(), IGRAPH_UNDIRECTED, false));
        igraph_destroy(&graph);
        igraph_vector_int_destroy(&dims);

        igraph_vector_int_init_int_end(&dims, -1, 10, 10, 10, 10, -1);
        igraph_square_lattice(&graph, &dims, 1, IGRAPH_UNDIRECTED, /* mutual */ 0, /* periodic */ 0);
        BENCH(" 5 Betweenness, Grid(10,10,10,10), cutoff 5",
              igraph_betweenness_cutoff(&graph, NULL, &betweenness, igraph_vss_all(), IGRAPH_UNDIRECTED, false, 5));
        BENCH(" 6 Betweenness, Grid(10,10,10,10), cutoff 8",
              igraph_betweenness_cutoff(&graph, NULL, &betweenness, igraph_vss_all(), IGRAPH_UNDIRECTED, false, 8));
        igraph_destroy(&graph);
        igraph_vector_int_destroy(&dims);
    }

    igraph_barabasi_game(&graph, 8000, 1, 1, NULL, 1, 0, IGRAPH_UNDIRECTED, IGRAPH_BARABASI_PSUMTREE, NULL);
    BENCH(" 7 Betweenness, Barabasi n=8000 m=1, undirected",
          igraph_betweenness(&graph, NULL, &betweenness, igraph_vss_all(), IGRAPH_UNDIRECTED, false));
    BENCH(" 8 Betweenness, Barabasi n=8000 m=1, undirected, cutoff 6",
          igraph_betweenness_cutoff(&graph, NULL, &betweenness, igraph_vss_all(), IGRAPH_UNDIRECTED, false, 6));
    igraph_destroy(&graph);

    igraph_barabasi_game(&graph, 30000, 1, 5, NULL, 1, 0, IGRAPH_DIRECTED, IGRAPH_BARABASI_PSUMTREE, NULL);
    BENCH(" 9 Betweenness, Barabasi n=30000 m=5, directed",
          igraph_betweenness(&graph, NULL, &betweenness, igraph_vss_all(), IGRAPH_DIRECTED, false));
    BENCH("10 Betweenness, Barabasi n=30000 m=5, directed, cutoff 5",
          igraph_betweenness_cutoff(&graph, NULL, &betweenness, igraph_vss_all(), IGRAPH_DIRECTED, false, 5));
    igraph_destroy(&graph);

    igraph_vector_destroy(&betweenness);

    return 0;
}