1 /* -*- mode: C -*- */
2 /*
3 IGraph library.
4 Copyright (C) 2010-2021 The igraph development team
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301 USA
20
21 */
22
23 #include <igraph.h>
24
main()25 int main() {
26
27 igraph_t g, g2;
28 igraph_attribute_combination_t comb;
29
30 igraph_set_attribute_table(&igraph_cattribute_table);
31
32 igraph_small(&g, 4, IGRAPH_DIRECTED,
33 0, 1, 0, 1, 0, 1,
34 1, 2, 2, 3,
35 -1);
36
37 SETEAS(&g, "color", 0, "green");
38 SETEAS(&g, "color", 1, "red");
39 SETEAS(&g, "color", 2, "blue");
40 SETEAS(&g, "color", 3, "white");
41 SETEAS(&g, "color", 4, "black");
42
43 /* ****************************************************** */
44 igraph_copy(&g2, &g);
45 igraph_attribute_combination(&comb,
46 "weight", IGRAPH_ATTRIBUTE_COMBINE_SUM,
47 "color", IGRAPH_ATTRIBUTE_COMBINE_FIRST,
48 "", IGRAPH_ATTRIBUTE_COMBINE_IGNORE,
49 IGRAPH_NO_MORE_ATTRIBUTES);
50 igraph_simplify(&g2, /*multiple=*/ 1, /*loops=*/ 1, &comb);
51 igraph_attribute_combination_destroy(&comb);
52 igraph_write_graph_graphml(&g2, stdout, /*prefixattr=*/ 1);
53 igraph_destroy(&g2);
54 /* ****************************************************** */
55
56 /* ****************************************************** */
57 igraph_copy(&g2, &g);
58 igraph_attribute_combination(&comb,
59 "", IGRAPH_ATTRIBUTE_COMBINE_LAST,
60 IGRAPH_NO_MORE_ATTRIBUTES);
61 igraph_simplify(&g2, /*multiple=*/ 1, /*loops=*/ 1, &comb);
62 igraph_attribute_combination_destroy(&comb);
63 igraph_write_graph_graphml(&g2, stdout, /*prefixattr=*/ 1);
64 igraph_destroy(&g2);
65 /* ****************************************************** */
66
67 /* ****************************************************** */
68 igraph_copy(&g2, &g);
69 igraph_attribute_combination(&comb,
70 "", IGRAPH_ATTRIBUTE_COMBINE_IGNORE,
71 "color", IGRAPH_ATTRIBUTE_COMBINE_CONCAT,
72 IGRAPH_NO_MORE_ATTRIBUTES);
73 igraph_simplify(&g2, /*multiple=*/ 1, /*loops=*/ 1, &comb);
74 igraph_attribute_combination_destroy(&comb);
75 igraph_write_graph_graphml(&g2, stdout, /*prefixattr=*/ 1);
76 igraph_destroy(&g2);
77 /* ****************************************************** */
78
79 igraph_destroy(&g);
80
81 return 0;
82 }
83