1 /* -*- mode: C -*-  */
2 /*
3    IGraph library.
4    Copyright (C) 2006-2012  Gabor Csardi <csardi.gabor@gmail.com>
5    334 Harvard street, 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 
28     igraph_t g1, g2, res;
29     igraph_vector_t v;
30     igraph_vector_t map1, map2;
31 
32     igraph_vector_init(&map1, 0);
33     igraph_vector_init(&map2, 0);
34 
35     /* composition with the empty graph */
36     igraph_empty(&g1, 5, IGRAPH_DIRECTED);
37     igraph_full(&g2, 5, IGRAPH_DIRECTED, IGRAPH_NO_LOOPS);
38     igraph_compose(&res, &g1, &g2, &map1, &map2);
39     if (igraph_ecount(&res) != 0) {
40         return 1;
41     }
42     if (igraph_vector_size(&map1) != 0 || igraph_vector_size(&map2) != 0) {
43         return 11;
44     }
45     igraph_destroy(&res);
46     igraph_compose(&res, &g2, &g1, &map1, &map2);
47     if (igraph_ecount(&res) != 0) {
48         return 2;
49     }
50     if (igraph_vector_size(&map1) != 0 || igraph_vector_size(&map2) != 0) {
51         return 12;
52     }
53     igraph_destroy(&res);
54     igraph_destroy(&g1);
55     igraph_destroy(&g2);
56 
57     /* same but undirected */
58     igraph_empty(&g1, 5, IGRAPH_UNDIRECTED);
59     igraph_full(&g2, 5, IGRAPH_UNDIRECTED, IGRAPH_NO_LOOPS);
60     igraph_compose(&res, &g1, &g2, &map1, &map2);
61     if (igraph_ecount(&res) != 0) {
62         return 1;
63     }
64     if (igraph_vector_size(&map1) != 0 || igraph_vector_size(&map2) != 0) {
65         return 11;
66     }
67     igraph_destroy(&res);
68     igraph_compose(&res, &g2, &g1, &map1, &map2);
69     if (igraph_ecount(&res) != 0) {
70         return 2;
71     }
72     if (igraph_vector_size(&map1) != 0 || igraph_vector_size(&map2) != 0) {
73         return 12;
74     }
75     igraph_destroy(&res);
76     igraph_destroy(&g1);
77     igraph_destroy(&g2);
78 
79     /* proper directed graph */
80     igraph_vector_init_int_end(&v, -1, 0, 1, 1, 2, 5, 6, -1);
81     igraph_create(&g1, &v, 0, IGRAPH_DIRECTED);
82     igraph_vector_destroy(&v);
83 
84     igraph_vector_init_int_end(&v, -1, 0, 1, 2, 4, 5, 6, -1);
85     igraph_create(&g2, &v, 0, IGRAPH_DIRECTED);
86     igraph_vector_destroy(&v);
87 
88     igraph_compose(&res, &g1, &g2, &map1, &map2);
89     igraph_write_graph_edgelist(&res, stdout);
90     igraph_vector_print(&map1);
91     igraph_vector_print(&map2);
92     igraph_destroy(&res);
93     igraph_destroy(&g1);
94     igraph_destroy(&g2);
95 
96     /* undirected graph */
97     igraph_vector_init_int_end(&v, -1, 0, 1, 1, 2, 5, 6, -1);
98     igraph_create(&g1, &v, 0, IGRAPH_UNDIRECTED);
99     igraph_vector_destroy(&v);
100 
101     igraph_vector_init_int_end(&v, -1, 0, 1, 0, 4, 5, 6, -1);
102     igraph_create(&g2, &v, 0, IGRAPH_UNDIRECTED);
103     igraph_vector_destroy(&v);
104 
105     igraph_compose(&res, &g1, &g2, &map1, &map2);
106     igraph_write_graph_edgelist(&res, stdout);
107     igraph_vector_print(&map1);
108     igraph_vector_print(&map2);
109     igraph_destroy(&res);
110     igraph_destroy(&g1);
111     igraph_destroy(&g2);
112 
113     igraph_vector_destroy(&map2);
114     igraph_vector_destroy(&map1);
115 
116     return 0;
117 }
118