1 /* -*- mode: C -*-  */
2 /*
3    IGraph library.
4    Copyright (C) 2006-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 
26 #include "test_utilities.inc"
27 
igraph_warnings_ignore(const char * reason,const char * file,int line,int igraph_errno)28 void igraph_warnings_ignore(const char *reason, const char *file,
29                             int line, int igraph_errno) {
30     /* Do nothing */
31 }
32 
main()33 int main() {
34     igraph_t g;
35     igraph_vector_t vpath, epath;
36     igraph_vector_t w;
37 
38     /* Unweighted */
39 
40     igraph_small(&g, 5, IGRAPH_DIRECTED,
41                  0, 1, 1, 2, 2, 3, 3, 4, 0, 3,
42                  -1);
43     igraph_vector_init(&vpath, 0);
44     igraph_vector_init(&epath, 0);
45     igraph_get_shortest_path(&g, &vpath, &epath, 0, 4, IGRAPH_OUT);
46     igraph_vector_print(&vpath);
47     igraph_vector_print(&epath);
48 
49     igraph_get_shortest_path(&g, &vpath, &epath, 0, 0, IGRAPH_OUT);
50     igraph_vector_print(&vpath);
51     igraph_vector_print(&epath);
52 
53     igraph_set_warning_handler(igraph_warnings_ignore);
54     igraph_get_shortest_path(&g, &vpath, &epath, 4, 0, IGRAPH_OUT);
55     igraph_vector_print(&vpath);
56     igraph_vector_print(&epath);
57     igraph_set_warning_handler(igraph_warning_handler_print);
58 
59     igraph_get_shortest_path(&g, &vpath, &epath, 4, 0, IGRAPH_ALL);
60     igraph_vector_print(&vpath);
61     igraph_vector_print(&epath);
62 
63     /* Weighted */
64 
65     igraph_vector_init(&w, 5);
66     VECTOR(w)[0] = 1;
67     VECTOR(w)[1] = 1;
68     VECTOR(w)[2] = 1;
69     VECTOR(w)[3] = 1;
70     VECTOR(w)[4] = 3.1;
71 
72     igraph_get_shortest_path_dijkstra(&g, &vpath, &epath, 0, 4, &w, IGRAPH_OUT);
73     igraph_vector_print(&vpath);
74     igraph_vector_print(&epath);
75 
76     igraph_vector_destroy(&w);
77     igraph_vector_destroy(&epath);
78     igraph_vector_destroy(&vpath);
79     igraph_destroy(&g);
80 
81     VERIFY_FINALLY_STACK();
82 
83     return 0;
84 }
85