File: igraph_regular_tree.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 (30 lines) | stat: -rw-r--r-- 839 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

#include <igraph.h>

int main(void) {
    igraph_t tree;
    igraph_vector_t eccentricity;
    igraph_bool_t is_tree;

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

    /* Create a Bethe lattice with 5 levels, i.e. height 4. */
    igraph_regular_tree(&tree, 4, 3, IGRAPH_TREE_UNDIRECTED);

    /* Bethe lattices are trees. */
    igraph_is_tree(&tree, &is_tree, NULL, IGRAPH_ALL);
    printf("Is it a tree? %s\n", is_tree ? "Yes." : "No.");

    /* Compute and print eccentricities. The root is the most central. */
    igraph_vector_init(&eccentricity, 0);
    igraph_eccentricity(&tree, NULL, &eccentricity, igraph_vss_all(), IGRAPH_ALL);
    printf("Vertex eccentricities:\n");
    igraph_vector_print(&eccentricity);
    igraph_vector_destroy(&eccentricity);

    /* Clean up. */
    igraph_destroy(&tree);

    return 0;
}