File: igraph_diameter.c

package info (click to toggle)
igraph 0.10.2%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 16,176 kB
  • sloc: ansic: 121,500; cpp: 21,699; xml: 2,734; python: 411; makefile: 147; javascript: 20; sh: 9
file content (45 lines) | stat: -rw-r--r-- 1,282 bytes parent folder | download | duplicates (4)
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
/* -*- mode: C -*-  */

#include <igraph.h>

void print_vector_int(igraph_vector_int_t *v) {
    igraph_integer_t i, n = igraph_vector_int_size(v);
    for (i = 0; i < n; i++) {
        printf(" %" IGRAPH_PRId, VECTOR(*v)[i]);
    }
    printf("\n");
}

int main(void) {

    igraph_t g;
    igraph_real_t result;
    igraph_integer_t from, to;
    igraph_vector_int_t path, path_edge;

    igraph_barabasi_game(&g, 30, /*power=*/ 1, 30, 0, 0, /*A=*/ 1,
                         IGRAPH_DIRECTED, IGRAPH_BARABASI_BAG,
                         /*start_from=*/ 0);
    igraph_diameter(&g, &result, 0, 0, 0, 0, IGRAPH_UNDIRECTED, 1);

    /*   printf("Diameter: %" IGRAPH_PRId "\n", (igraph_integer_t) result); */

    igraph_destroy(&g);

    igraph_ring(&g, 10, IGRAPH_DIRECTED, 0, 0);
    igraph_vector_int_init(&path, 0);
    igraph_vector_int_init(&path_edge, 0);
    igraph_diameter(&g, &result, &from, &to, &path, &path_edge, IGRAPH_DIRECTED, 1);
    printf(
        "diameter: %" IGRAPH_PRId ", from %" IGRAPH_PRId " to %" IGRAPH_PRId "\n",
        (igraph_integer_t) result, from, to
    );
    print_vector_int(&path);
    print_vector_int(&path_edge);

    igraph_vector_int_destroy(&path);
    igraph_vector_int_destroy(&path_edge);
    igraph_destroy(&g);

    return 0;
}