~ubuntu-branches/ubuntu/trusty/igraph/trusty-proposed

1 by Mathieu Malaterre
Import upstream version 0.5.3
1
/* -*- mode: C -*-  */
2
/* 
3
   IGraph library.
1.1.2 by Mathieu Malaterre
Import upstream version 0.6.5
4
   Copyright (C) 2006-2012  Gabor Csardi <csardi.gabor@gmail.com>
5
   334 Harvard st, Cambridge MA, 02139 USA
1 by Mathieu Malaterre
Import upstream version 0.5.3
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
26
#include <stdlib.h>
27
#include <stdio.h>
28
29
int print_vector(igraph_vector_t *v) {
30
  long int i, l=igraph_vector_size(v);
31
  for (i=0; i<l; i++) {
32
    printf(" %li", (long int) VECTOR(*v)[i]);
33
  }
34
  printf("\n");
35
}
36
37
int main() {
38
  
39
  igraph_t left, right, uni;
40
  igraph_vector_t v;
41
  igraph_vector_ptr_t glist;
42
  long int i;
43
44
  igraph_vector_init_int_end(&v, -1, 0,1, 1,2, 2,2, 2,3, -1);
45
  igraph_create(&left, &v, 0, IGRAPH_DIRECTED);
46
  igraph_vector_destroy(&v);
47
  
48
  igraph_vector_init_int_end(&v, -1, 0,1, 1,2, 2,2, 2,4, -1); 
49
  igraph_create(&right, &v, 0, IGRAPH_DIRECTED);
50
  igraph_vector_destroy(&v);
51
  
52
  igraph_union(&uni, &left, &right);
53
  igraph_write_graph_edgelist(&uni, stdout);
54
55
  igraph_destroy(&uni);
56
  igraph_destroy(&left);
57
  igraph_destroy(&right);
58
59
  /* Empty graph list */
60
  igraph_vector_ptr_init(&glist, 0);
61
  igraph_union_many(&uni, &glist);
62
  if (!igraph_is_directed(&uni) || igraph_vcount(&uni) != 0) {
63
    return 1;
64
  }
65
  igraph_vector_ptr_destroy(&glist);
66
  igraph_destroy(&uni);  
67
68
  /* Non-empty graph list */
69
  igraph_vector_ptr_init(&glist, 10); 
70
  for (i=0; i<igraph_vector_ptr_size(&glist); i++) {
71
    VECTOR(glist)[i]=calloc(1, sizeof(igraph_t));
72
    igraph_vector_init_int_end(&v, -1, 0,1, 1,0, -1);
73
    igraph_create(VECTOR(glist)[i], &v, 0, IGRAPH_DIRECTED);    
74
    igraph_vector_destroy(&v);
75
  }
76
77
  igraph_union_many(&uni, &glist);
78
  igraph_write_graph_edgelist(&uni, stdout);
79
80
  for (i=0; i<igraph_vector_ptr_size(&glist); i++) {
81
    igraph_destroy(VECTOR(glist)[i]);
82
    free(VECTOR(glist)[i]);
83
  }
84
  igraph_vector_ptr_destroy(&glist);
85
  igraph_destroy(&uni);  
86
87
  /* Another non-empty graph list */
88
  igraph_vector_ptr_init(&glist, 10); 
89
  for (i=0; i<igraph_vector_ptr_size(&glist); i++) {
90
    VECTOR(glist)[i]=calloc(1, sizeof(igraph_t));
91
    igraph_vector_init_int_end(&v, -1, i,i+1, 1,0, -1);
92
    igraph_create(VECTOR(glist)[i], &v, 0, IGRAPH_DIRECTED);    
93
    igraph_vector_destroy(&v);
94
  }
95
96
  igraph_union_many(&uni, &glist);
97
  igraph_write_graph_edgelist(&uni, stdout);
98
99
  for (i=0; i<igraph_vector_ptr_size(&glist); i++) {
100
    igraph_destroy(VECTOR(glist)[i]);
101
    free(VECTOR(glist)[i]);
102
  }
103
  igraph_vector_ptr_destroy(&glist);
104
  igraph_destroy(&uni);  
105
  
106
  /* Undirected graph list*/
107
  igraph_vector_ptr_init(&glist, 10); 
108
  for (i=0; i<igraph_vector_ptr_size(&glist); i++) {
109
    VECTOR(glist)[i]=calloc(1, sizeof(igraph_t));
110
    igraph_vector_init_int_end(&v, -1, i,i+1, 1,0, -1);
111
    igraph_create(VECTOR(glist)[i], &v, 0, IGRAPH_UNDIRECTED);    
112
    igraph_vector_destroy(&v);
113
  }
114
115
  igraph_union_many(&uni, &glist);
116
  igraph_write_graph_edgelist(&uni, stdout);
117
118
  for (i=0; i<igraph_vector_ptr_size(&glist); i++) {
119
    igraph_destroy(VECTOR(glist)[i]);
120
    free(VECTOR(glist)[i]);
121
  }
122
  igraph_vector_ptr_destroy(&glist);
123
  igraph_destroy(&uni);  
124
125
  return 0;
126
}