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

« back to all changes in this revision

Viewing changes to src/bliss_utils.cc

  • 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
/*
 
2
Copyright (C) 2003-2006 Tommi Junttila
 
3
 
 
4
 This program is free software; you can redistribute it and/or modify
 
5
 it under the terms of the GNU General Public License version 2
 
6
 as published by the Free Software Foundation.
 
7
 
 
8
 This program is distributed in the hope that it will be useful,
 
9
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
 GNU General Public License for more details.
 
12
 
 
13
 You should have received a copy of the GNU General Public License
 
14
 along with this program; if not, write to the Free Software
 
15
 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
 
16
*/
 
17
 
 
18
/* FSF address fixed in the above notice on 1 Oct 2009 by Tamas Nepusz */
 
19
 
 
20
#include <assert.h>
 
21
#include "bliss_utils.hh"
 
22
 
 
23
namespace igraph {
 
24
 
 
25
void print_permutation(FILE *fp,
 
26
                       const unsigned int N,
 
27
                       const unsigned int *perm)
 
28
{
 
29
  assert(N > 0);
 
30
  assert(perm);
 
31
  for(unsigned int i = 0; i < N; i++) {
 
32
    unsigned int j = perm[i];
 
33
    if(j == i)
 
34
      continue;
 
35
    bool is_first = true;
 
36
    while(j != i) {
 
37
      if(j < i) {
 
38
        is_first = false;
 
39
        break;
 
40
      }
 
41
      j = perm[j];
 
42
    }
 
43
    if(!is_first)
 
44
      continue;
 
45
    fprintf(fp, "(%u,", i);
 
46
    j = perm[i];
 
47
    while(j != i) {
 
48
      fprintf(fp, "%u", j);
 
49
      j = perm[j];
 
50
      if(j != i)
 
51
        fprintf(fp, ",");
 
52
    }
 
53
    fprintf(fp, ")");
 
54
  }
 
55
}
 
56
 
 
57
}