File: igraph_average_path_length.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 (25 lines) | stat: -rw-r--r-- 775 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

#include <igraph.h>

int main(void) {
    igraph_t graph;
    igraph_real_t result;

    /* Initialize the library. */
    igraph_setup();

    /* Create a random preferential attachment graph. */
    igraph_barabasi_game(&graph, 30, /*power=*/ 1, 30, NULL, /*outpref=*/ false, /*A=*/ 1,
                         IGRAPH_DIRECTED, IGRAPH_BARABASI_BAG,
                         /*start_from=*/ NULL);

    /* Compute the average shortest path length. */
    igraph_average_path_length(&graph, /*weights=*/ NULL, &result,
                               /*unconn_pairs=*/ NULL, IGRAPH_UNDIRECTED, /*unconn=*/ true);
    printf("Average length of all-pairs shortest paths: %g\n", result);

    /* Destroy no-longer-needed objects. */
    igraph_destroy(&graph);

    return 0;
}