1 /* -*- mode: C -*-  */
2 /*
3    IGraph library.
4    Copyright (C) 2010-2012  Gabor Csardi <csardi.gabor@gmail.com>
5    334 Harvard st, 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 
main()26 int main() {
27     igraph_t g;
28     igraph_vector_t v, v2;
29     igraph_vector_t v_weighted, v2_weighted;
30     igraph_integer_t n;
31     igraph_neimode_t mode, neighbour_degree_mode;
32 
33     mode = IGRAPH_IN;
34     neighbour_degree_mode = IGRAPH_OUT;
35 
36     igraph_ring(&g, 10, /*directed=*/ 1, /*mutual=*/ 0, /*circular=*/ 1);
37     n = igraph_vcount(&g);
38     igraph_vector_init(&v, (long int)n);
39     igraph_vector_init(&v2, (long int)n);
40     igraph_avg_nearest_neighbor_degree(&g, igraph_vss_all(),
41                                        mode, neighbour_degree_mode,
42                                        &v, &v2, /*weights=*/ 0);
43 
44     igraph_vector_t weights;
45     igraph_vector_init(&weights, igraph_ecount(&g));
46     igraph_vector_fill(&weights, 2.0);
47 
48     igraph_vector_init(&v_weighted, (long int)n);
49     igraph_vector_init(&v2_weighted, (long int)n);
50     igraph_avg_nearest_neighbor_degree(&g, igraph_vss_all(),
51                                        mode, neighbour_degree_mode,
52                                        &v_weighted, &v2_weighted, &weights);
53 
54     if (!igraph_vector_all_e(&v, &v_weighted)) {
55         return 1;
56     }
57 
58     igraph_vector_destroy(&v_weighted);
59     igraph_vector_destroy(&v2_weighted);
60 
61     igraph_vector_destroy(&weights);
62 
63     igraph_vector_destroy(&v);
64     igraph_vector_destroy(&v2);
65 
66     igraph_destroy(&g);
67 
68     return 0;
69 }
70