1 /* -*- mode: C -*- */
2 /* vim:set ts=4 sw=4 sts=4 et: */
3 /*
4 IGraph library.
5 Copyright (C) 2011-2012 Gabor Csardi <csardi.gabor@gmail.com>
6 334 Harvard st, Cambridge MA, 02139 USA
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 02110-1301 USA
22
23 */
24
25 #include <igraph.h>
26 #include <string.h>
27
main()28 int main() {
29 igraph_t g;
30 igraph_vector_t weights, result;
31 igraph_bool_t dag;
32
33 igraph_vector_init(&result, 0);
34
35 /***********************************************************************/
36 /* Approximation with Eades' method */
37 /***********************************************************************/
38
39 /* Simple unweighted graph */
40 igraph_small(&g, 0, IGRAPH_DIRECTED, 0, 1, 1, 2, 2, 0, 2, 3, 2, 4, 0, 4, 4, 3, 5, 0, 6, 5, -1);
41 igraph_feedback_arc_set(&g, &result, 0, IGRAPH_FAS_APPROX_EADES);
42 igraph_vector_print(&result);
43 igraph_delete_edges(&g, igraph_ess_vector(&result));
44 igraph_is_dag(&g, &dag);
45 if (!dag) {
46 return 1;
47 }
48 igraph_destroy(&g);
49
50 /* Simple weighted graph */
51 igraph_small(&g, 0, IGRAPH_DIRECTED, 0, 1, 1, 2, 2, 0, 2, 3, 2, 4, 0, 4, 4, 3, 5, 0, 6, 5, -1);
52 igraph_vector_init_int_end(&weights, -1, 1, 1, 3, 1, 1, 1, 1, 1, 1, -1);
53 igraph_feedback_arc_set(&g, &result, &weights, IGRAPH_FAS_APPROX_EADES);
54 igraph_vector_print(&result);
55 igraph_delete_edges(&g, igraph_ess_vector(&result));
56 igraph_is_dag(&g, &dag);
57 if (!dag) {
58 return 2;
59 }
60 igraph_vector_destroy(&weights);
61 igraph_destroy(&g);
62
63 /* Simple unweighted graph with loops */
64 igraph_small(&g, 0, IGRAPH_DIRECTED, 0, 1, 1, 2, 2, 0, 2, 3, 2, 4, 0, 4, 4, 3, 5, 0, 6, 5, 1, 1, 4, 4, -1);
65 igraph_feedback_arc_set(&g, &result, 0, IGRAPH_FAS_APPROX_EADES);
66 igraph_vector_print(&result);
67 igraph_delete_edges(&g, igraph_ess_vector(&result));
68 igraph_is_dag(&g, &dag);
69 if (!dag) {
70 return 3;
71 }
72 igraph_destroy(&g);
73
74 igraph_vector_destroy(&result);
75
76 return 0;
77 }
78