~ubuntu-branches/ubuntu/lucid/igraph/lucid

« back to all changes in this revision

Viewing changes to examples/simple/igraph_mincut.c

  • Committer: Bazaar Package Importer
  • Author(s): Mathieu Malaterre
  • Date: 2009-11-16 18:12:42 UTC
  • Revision ID: james.westby@ubuntu.com-20091116181242-mzv9p5fz9uj57xd1
Tags: upstream-0.5.3
ImportĀ upstreamĀ versionĀ 0.5.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- mode: C -*-  */
 
2
/* 
 
3
   IGraph library.
 
4
   Copyright (C) 2007  Gabor Csardi <csardi@rmki.kfki.hu>
 
5
   MTA RMKI, Konkoly-Thege Miklos st. 29-33, Budapest 1121, Hungary
 
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
int print_vector(const igraph_vector_t *v) {
 
27
  long int i, size=igraph_vector_size(v);
 
28
  for (i=0; i<size; i++) {
 
29
    printf("%g ", (double) VECTOR(*v)[i]);
 
30
  }
 
31
  printf("\n");
 
32
}
 
33
 
 
34
int main() {
 
35
  
 
36
  igraph_t g;
 
37
  igraph_vector_t weights, partition, partition2, cut;
 
38
  igraph_integer_t value;
 
39
  long int i;
 
40
  
 
41
  igraph_small(&g, 0, IGRAPH_UNDIRECTED, 
 
42
               0,1, 0,4, 1,2, 1,4, 1,5, 2,3, 2,6, 3,6, 3,7, 4,5, 5,6, 6,7,
 
43
               -1);
 
44
  
 
45
  igraph_vector_init_int_end(&weights, -1, 2,3,3,2,2, 4,2,2,2,3, 1,3, -1);
 
46
  
 
47
  igraph_vector_init(&partition, 0);
 
48
  igraph_vector_init(&partition2, 0);
 
49
  igraph_vector_init(&cut, 0);
 
50
  
 
51
  igraph_mincut(&g, &value, &partition, &partition2, &cut, &weights);
 
52
  
 
53
  printf("mincut value: %g\n", (double) value);
 
54
  
 
55
  printf("first partition:  ");
 
56
  igraph_vector_sort(&partition);
 
57
  print_vector(&partition);
 
58
  printf("second partition: ");
 
59
  igraph_vector_sort(&partition2);
 
60
  print_vector(&partition2);
 
61
  printf("edges in the cut: ");
 
62
  for (i=0; i<igraph_vector_size(&cut); i++) {
 
63
    igraph_integer_t from, to;
 
64
    igraph_edge(&g, VECTOR(cut)[i], &from, &to);
 
65
    if (from > to) {
 
66
      igraph_integer_t tmp=from;
 
67
      from=to;
 
68
      to=tmp;
 
69
    }
 
70
    printf("%li-%li ", (long int)from, (long int)to);
 
71
  }
 
72
  printf("\n");
 
73
 
 
74
  igraph_vector_destroy(&cut);
 
75
  igraph_vector_destroy(&partition2);
 
76
  igraph_vector_destroy(&partition);
 
77
  igraph_vector_destroy(&weights);
 
78
  igraph_destroy(&g);
 
79
 
 
80
  return 0;
 
81
}