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

« back to all changes in this revision

Viewing changes to src/walktrap_heap.h

  • 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
/* The original version of this file was written by Pascal Pons
 
25
   The original copyright notice follows here. The FSF address was
 
26
   fixed by Tamas Nepusz */
 
27
 
 
28
// File: heap.h
 
29
//-----------------------------------------------------------------------------
 
30
// Walktrap v0.2 -- Finds community structure of networks using random walks
 
31
// Copyright (C) 2004-2005 Pascal Pons
 
32
//
 
33
// This program is free software; you can redistribute it and/or modify
 
34
// it under the terms of the GNU General Public License as published by
 
35
// the Free Software Foundation; either version 2 of the License, or
 
36
// (at your option) any later version.
 
37
//
 
38
// This program is distributed in the hope that it will be useful,
 
39
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
40
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
41
// GNU General Public License for more details.
 
42
//
 
43
// You should have received a copy of the GNU General Public License
 
44
// along with this program; if not, write to the Free Software
 
45
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 
 
46
// 02110-1301 USA
 
47
//-----------------------------------------------------------------------------
 
48
// Author   : Pascal Pons 
 
49
// Email    : pons@liafa.jussieu.fr
 
50
// Web page : http://www.liafa.jussieu.fr/~pons/
 
51
// Location : Paris, France
 
52
// Time     : June 2005
 
53
//-----------------------------------------------------------------------------
 
54
// see readme.txt for more details
 
55
 
 
56
#ifndef HEAP_H
 
57
#define HEAP_H
 
58
 
 
59
class Neighbor {
 
60
public:
 
61
  int community1;   // the two adjacent communities
 
62
  int community2;   // community1 < community2
 
63
 
 
64
  float delta_sigma;    // the delta sigma between the two communities
 
65
  float weight;         // the total weight of the edges between the two communities
 
66
  bool exact;           // true if delta_sigma is exact, false if it is only a lower bound
 
67
  
 
68
  Neighbor* next_community1;        // pointers of two double
 
69
  Neighbor* previous_community1;    // chained lists containing
 
70
  Neighbor* next_community2;        // all the neighbors of
 
71
  Neighbor* previous_community2;    // each communities.
 
72
 
 
73
  int heap_index;       // 
 
74
  
 
75
  Neighbor();
 
76
};
 
77
 
 
78
 
 
79
class Neighbor_heap {  
 
80
private:
 
81
  int size;
 
82
  int max_size;
 
83
 
 
84
  Neighbor** H;   // the heap that contains a pointer to each Neighbor object stored
 
85
 
 
86
  void move_up(int index);
 
87
  void move_down(int index);
 
88
  
 
89
public:
 
90
  void add(Neighbor* N);            // add a new distance
 
91
  void update(Neighbor* N);         // update a distance 
 
92
  void remove(Neighbor* N);         // remove a distance
 
93
  Neighbor* get_first();            // get the first item
 
94
  long memory();
 
95
  bool is_empty();
 
96
  
 
97
  Neighbor_heap(int max_size);
 
98
  ~Neighbor_heap();
 
99
};
 
100
 
 
101
 
 
102
class Min_delta_sigma_heap {
 
103
private:
 
104
  int size;
 
105
  int max_size;
 
106
 
 
107
  int* H;   // the heap that contains the number of each community
 
108
  int* I;   // the index of each community in the heap (-1 = not stored)
 
109
 
 
110
  void move_up(int index);
 
111
  void move_down(int index);
 
112
 
 
113
public:
 
114
  int get_max_community();                          // return the community with the maximal delta_sigma
 
115
  void remove_community(int community);             // remove a community;
 
116
  void update(int community);                       // update (or insert if necessary) the community
 
117
  long memory();                                    // the memory used in Bytes.
 
118
  bool is_empty();
 
119
 
 
120
  float* delta_sigma;                                // the delta_sigma of the stored communities
 
121
  
 
122
  Min_delta_sigma_heap(int max_size);
 
123
  ~Min_delta_sigma_heap();
 
124
};
 
125
#endif
 
126