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 <stdlib.h>
26
print_vector(igraph_vector_t * v)27 void print_vector(igraph_vector_t *v) {
28 long int i, n = igraph_vector_size(v);
29 for (i = 0; i < n; i++) {
30 printf(" %li", (long int) VECTOR(*v)[i]);
31 }
32 printf("\n");
33 }
34
warning_handler_ignore(const char * reason,const char * file,int line,int e)35 void warning_handler_ignore(const char* reason, const char* file, int line, int e) {
36 }
37
main()38 int main() {
39
40 igraph_t g;
41 igraph_vector_ptr_t result;
42 long int i, j, n;
43 igraph_integer_t alpha;
44 const int params[] = {4, -1, 2, 2, 0, 0, -1, -1};
45
46 igraph_set_warning_handler(warning_handler_ignore);
47 igraph_vector_ptr_init(&result, 0);
48
49 igraph_tree(&g, 5, 2, IGRAPH_TREE_OUT);
50 for (j = 0; j < sizeof(params) / (2 * sizeof(params[0])); j++) {
51 if (params[2 * j + 1] != 0) {
52 igraph_independent_vertex_sets(&g, &result, params[2 * j], params[2 * j + 1]);
53 } else {
54 igraph_largest_independent_vertex_sets(&g, &result);
55 }
56 n = igraph_vector_ptr_size(&result);
57 printf("%ld independent sets found\n", (long)n);
58 for (i = 0; i < n; i++) {
59 igraph_vector_t* v;
60 v = igraph_vector_ptr_e(&result, i);
61 print_vector((igraph_vector_t*)v);
62 igraph_vector_destroy(v);
63 igraph_free(v);
64 }
65 }
66 igraph_destroy(&g);
67
68 igraph_tree(&g, 10, 2, IGRAPH_TREE_OUT);
69 igraph_maximal_independent_vertex_sets(&g, &result);
70 n = igraph_vector_ptr_size(&result);
71 printf("%ld maximal independent sets found\n", (long)n);
72 for (i = 0; i < n; i++) {
73 igraph_vector_t* v;
74 v = igraph_vector_ptr_e(&result, i);
75 print_vector((igraph_vector_t*)v);
76 igraph_vector_destroy(v);
77 igraph_free(v);
78 }
79 igraph_vector_ptr_destroy(&result);
80
81 igraph_independence_number(&g, &alpha);
82 printf("alpha=%ld\n", (long)alpha);
83
84 igraph_destroy(&g);
85
86 return 0;
87 }
88