1 /* -*- mode: C++ -*-  */
2 /*
3    IGraph library.
4    Copyright (C) 2011-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 #include <stdio.h>
26 
27 #include "test_utilities.inc"
28 
main()29 int main() {
30     igraph_t karate;
31     igraph_vector_t parents, weights;
32     long int i, n;
33 
34     igraph_rng_seed(igraph_rng_default(), 42);
35 
36     igraph_small(&karate, 34, IGRAPH_UNDIRECTED,
37                  0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 0, 10, 0, 11, 0, 12, 0, 13,
38                  0, 17, 0, 19, 0, 21, 0, 31,
39                  1, 2, 1, 3, 1, 7, 1, 13, 1, 17, 1, 19, 1, 21, 1, 30,
40                  2, 3, 2, 7, 2, 27, 2, 28, 2, 32, 2, 9, 2, 8, 2, 13,
41                  3, 7, 3, 12, 3, 13,
42                  4, 6, 4, 10,
43                  5, 6, 5, 10, 5, 16,
44                  6, 16,
45                  8, 30, 8, 32, 8, 33,
46                  9, 33,
47                  13, 33,
48                  14, 32, 14, 33,
49                  15, 32, 15, 33,
50                  18, 32, 18, 33,
51                  19, 33,
52                  20, 32, 20, 33,
53                  22, 32, 22, 33,
54                  23, 25, 23, 27, 23, 32, 23, 33, 23, 29,
55                  24, 25, 24, 27, 24, 31,
56                  25, 31,
57                  26, 29, 26, 33,
58                  27, 33,
59                  28, 31, 28, 33,
60                  29, 32, 29, 33,
61                  30, 32, 30, 33,
62                  31, 32, 31, 33,
63                  32, 33,
64                  -1);
65 
66     igraph_vector_init(&parents, 0);
67     igraph_vector_init(&weights, 0);
68     igraph_hrg_consensus(&karate, &parents, &weights, /* hrg= */ 0,
69                          /* start= */ 0, /* num_samples= */ 100);
70 
71     /* We do some simple validity tests on the results only; the exact results
72      * are different on i386 vs other platforms due to numerical inaccuracies */
73     if (igraph_vector_size(&weights) + igraph_vcount(&karate) != igraph_vector_size(&parents)) {
74         printf("Vector length mismatch: %ld + %ld != %ld\n",
75             (long int) igraph_vector_size(&weights), (long int) igraph_vcount(&karate),
76             (long int) igraph_vector_size(&parents)
77         );
78         abort();
79     }
80 
81     n = igraph_vector_size(&parents);
82     for (i = 0; i < n; i++) {
83         if (VECTOR(parents)[i] < -1 || VECTOR(parents)[i] >= igraph_vcount(&karate) + igraph_vector_size(&weights)) {
84             printf("Invalid parents vector:\n");
85             igraph_vector_print(&parents);
86             abort();
87         }
88     }
89 
90     igraph_vector_destroy(&parents);
91     igraph_vector_destroy(&weights);
92     igraph_destroy(&karate);
93 
94     VERIFY_FINALLY_STACK();
95 
96     return 0;
97 }
98