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 #include <math.h>
26 #include <stdlib.h>
27
28 #include "test_utilities.inc"
29
main()30 int main() {
31 igraph_t g, extd_g;
32 igraph_matrix_t coords;
33 igraph_vector_t edgelist, extd_edgelist, extd_to_orig_eids;
34 igraph_vector_t layers;
35
36 igraph_matrix_init(&coords, 0, 0);
37 igraph_vector_init(&extd_to_orig_eids, 0);
38
39 /* Layout on simple graph with predefined layers */
40 igraph_vector_init_int_end(&layers, -1, 0, 1, 1, 2, 3, 3, 4, 4, 5, -1);
41 igraph_vector_init_int_end(&edgelist, -1,
42 0, 1, 0, 2, 0, 3, 1, 2, 2, 2, 1, 4, 2, 5, 4, 6, 5, 7, 6, 8, 7, 8,
43 3, 8, 8, 1, 8, 2, -1);
44 igraph_create(&g, &edgelist, 0, 1);
45
46 igraph_layout_sugiyama(&g, &coords, 0, 0, &layers,
47 /* hgap = */ 1,
48 /* vgap = */ 1,
49 /* maxiter = */ 100,
50 /* weights = */ 0);
51 igraph_matrix_print(&coords);
52 printf("===\n");
53
54 /* Same, but this time also return the extended graph */
55 igraph_layout_sugiyama(&g, &coords, &extd_g, &extd_to_orig_eids, &layers,
56 /* hgap = */ 1,
57 /* vgap = */ 1,
58 /* maxiter = */ 100,
59 /* weights = */ 0);
60 igraph_matrix_print(&coords);
61 printf("===\n");
62 igraph_vector_init(&extd_edgelist, 0);
63 igraph_get_edgelist(&extd_g, &extd_edgelist, 0);
64 igraph_vector_print(&extd_edgelist);
65 igraph_vector_destroy(&extd_edgelist);
66 igraph_destroy(&extd_g);
67 printf("===\n");
68 igraph_vector_print(&extd_to_orig_eids);
69 printf("===\n");
70
71 igraph_vector_destroy(&layers);
72
73 /* Same, but with automatic layering */
74 igraph_layout_sugiyama(&g, &coords, 0, 0, 0,
75 /* hgap = */ 1,
76 /* vgap = */ 1,
77 /* maxiter = */ 100,
78 /* weights = */ 0);
79 igraph_matrix_print(&coords);
80 printf("===\n");
81
82 /* Layering with gaps in it */
83 igraph_vector_init_int_end(&layers, -1, 0, 2, 2, 4, 6, 6, 12, 12, 15, -1);
84 igraph_layout_sugiyama(&g, &coords, 0, 0, &layers,
85 /* hgap = */ 1,
86 /* vgap = */ 1,
87 /* maxiter = */ 100,
88 /* weights = */ 0);
89 igraph_matrix_print(&coords);
90 igraph_vector_destroy(&layers);
91 printf("===\n");
92
93 igraph_vector_destroy(&edgelist);
94 igraph_matrix_destroy(&coords);
95 igraph_vector_destroy(&extd_to_orig_eids);
96 igraph_destroy(&g);
97
98 VERIFY_FINALLY_STACK();
99
100 return 0;
101 }
102