1 /* -*- mode: C -*- */
2 /*
3 IGraph library.
4 Copyright (C) 2006-2012 Gabor Csardi <csardi.gabor@gmail.com>
5 334 Harvard street, Cambridge, MA 02139 USA
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 02110-1301 USA
21
22 */
23
24 #include <igraph.h>
25
print_vector(igraph_vector_t * v)26 void print_vector(igraph_vector_t *v) {
27 long int i, n = igraph_vector_size(v);
28 for (i = 0; i < n; i++) {
29 printf(" %li", (long int) VECTOR(*v)[i]);
30 }
31 printf("\n");
32 }
33
main()34 int main() {
35
36 igraph_t g;
37 igraph_real_t result;
38 igraph_integer_t from, to;
39 igraph_vector_t path;
40
41 igraph_barabasi_game(&g, 30, /*power=*/ 1, 30, 0, 0, /*A=*/ 1,
42 IGRAPH_DIRECTED, IGRAPH_BARABASI_BAG,
43 /*start_from=*/ 0);
44 igraph_diameter(&g, &result, 0, 0, 0, IGRAPH_UNDIRECTED, 1);
45
46 /* printf("Diameter: %li\n", (long int) result); */
47
48 igraph_destroy(&g);
49
50 igraph_ring(&g, 10, IGRAPH_DIRECTED, 0, 0);
51 igraph_vector_init(&path, 0);
52 igraph_diameter(&g, &result, &from, &to, &path, IGRAPH_DIRECTED, 1);
53 printf("diameter: %li, from %li to %li\n", (long int) result,
54 (long int) from, (long int) to);
55 print_vector(&path);
56
57 igraph_vector_destroy(&path);
58 igraph_destroy(&g);
59
60 return 0;
61 }
62