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

« back to all changes in this revision

Viewing changes to examples/simple/igraph_cliques.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) 2006  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
#include <stdlib.h>
 
26
 
 
27
int 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
 
 
35
void warning_handler_ignore(const char* reason,const char* file,int line,int e) {
 
36
}
 
37
 
 
38
int main() {
 
39
  
 
40
  igraph_t g;
 
41
  igraph_vector_ptr_t result;
 
42
  igraph_es_t es;
 
43
  igraph_integer_t omega;
 
44
  long int i, j, n;
 
45
  const int params[] = {4, -1, 2, 2, 0, 0, -1, -1};
 
46
 
 
47
  igraph_set_warning_handler(warning_handler_ignore);
 
48
 
 
49
  igraph_vector_ptr_init(&result, 0);
 
50
  igraph_full(&g, 6, 0, 0);
 
51
  igraph_es_pairs_small(&es, 0, 0, 1, 0, 2, 3, 5, -1);
 
52
  igraph_delete_edges(&g, es);
 
53
  igraph_es_destroy(&es);
 
54
  
 
55
  for (j=0; j<sizeof(params)/(2*sizeof(params[0])); j++) {
 
56
    if (params[2*j+1] != 0) {
 
57
      igraph_cliques(&g, &result, params[2*j], params[2*j+1]);  
 
58
    } else {
 
59
      igraph_largest_cliques(&g, &result);
 
60
    }
 
61
    n = igraph_vector_ptr_size(&result);
 
62
    printf("%ld cliques found\n", (long)n);
 
63
    for (i=0; i<n; i++) {
 
64
      igraph_vector_t* v;
 
65
      v=igraph_vector_ptr_e(&result,i);
 
66
      print_vector((igraph_vector_t*)v);
 
67
      igraph_vector_destroy(v);
 
68
      free(v);
 
69
    }
 
70
  }
 
71
   
 
72
  igraph_clique_number(&g, &omega);
 
73
  printf("omega=%ld\n", (long)omega);
 
74
 
 
75
  igraph_destroy(&g);
 
76
 
 
77
  igraph_tree(&g, 5, 2, IGRAPH_TREE_OUT);
 
78
  igraph_cliques(&g, &result, 5, 5);
 
79
  if (igraph_vector_ptr_size(&result) != 0) return 1;
 
80
 
 
81
  igraph_destroy(&g);
 
82
  igraph_vector_ptr_destroy(&result);
 
83
 
 
84
  return 0;
 
85
}