Chemical Data Processing Library C++ API - Version 1.4.0
BronKerboschAlgorithm.hpp
Go to the documentation of this file.
1 /*
2  * BronKerboschAlgorithm.hpp
3  *
4  * This file is part of the Chemical Data Processing Toolkit
5  *
6  * Copyright (C) 2003 Thomas Seidel <thomas.seidel@univie.ac.at>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License
19  * along with this library; see the file COPYING. If not, write to
20  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  */
23 
29 #ifndef CDPL_UTIL_BRONKERBOSCHALGORITHM_HPP
30 #define CDPL_UTIL_BRONKERBOSCHALGORITHM_HPP
31 
32 #include <cstddef>
33 #include <vector>
34 
35 #include "CDPL/Util/APIPrefix.hpp"
36 #include "CDPL/Util/BitSet.hpp"
37 #include "CDPL/Util/Array.hpp"
39 
40 
41 namespace CDPL
42 {
43 
44  namespace Util
45  {
46 
51  {
52 
53  public:
58 
64 
70 
75  void init(const BitSetArray& adj_mtx);
76 
82  bool nextClique(BitSet& clique);
83 
90 
91  private:
92  struct State
93  {
94 
95  BitSet curr;
96  BitSet pool;
97  BitSet excl;
98  std::size_t u;
99  std::size_t v;
100  };
101 
102  typedef std::vector<std::size_t> NodeDegreeTable;
103  typedef std::vector<State*> StateStack;
104  typedef Util::ObjectStack<State> StateCache;
105 
106  const BitSetArray* adjMatrix;
107  StateCache stateCache;
108  NodeDegreeTable nodeDegrees;
109  StateStack states;
110  BitSet pivotCandSet;
111  };
112  } // namespace Util
113 } // namespace CDPL
114 
115 #endif // CDPL_UTIL_BRONKERBOSCHALGORITHM_HPP
Definition of class CDPL::Util::Array.
Declaration of type CDPL::Util::BitSet.
Definition of class CDPL::Util::ObjectStack.
Definition of the preprocessor macro CDPL_UTIL_API.
#define CDPL_UTIL_API
Tells the compiler/linker which classes, functions and variables are part of the library API.
Implementation of the Bron-Kerbosch clique-detection algorithm [BKA].
Definition: BronKerboschAlgorithm.hpp:51
void init(const BitSetArray &adj_mtx)
(Re-)initializes the algorithm with the adjacency matrix adj_mtx and resets the clique iterator.
BronKerboschAlgorithm()
Constructs the BronKerboschAlgorithm instance without an associated adjacency matrix.
Definition: BronKerboschAlgorithm.hpp:57
bool nextClique(BitSet &clique)
Advances the clique iterator and writes the next maximal clique into clique.
BronKerboschAlgorithm(const BitSetArray &adj_mtx)
Constructs the BronKerboschAlgorithm instance and immediately initializes it with the adjacency matri...
BronKerboschAlgorithm(const BronKerboschAlgorithm &bka)
Constructs a copy of the BronKerboschAlgorithm instance bka.
BronKerboschAlgorithm & operator=(const BronKerboschAlgorithm &bka)
Copy assignment operator.
boost::dynamic_bitset BitSet
Dynamic bitset class.
Definition: BitSet.hpp:46
Array< BitSet > BitSetArray
Array storing Util::BitSet objects.
Definition: Array.hpp:608
The namespace of the Chemical Data Processing Library.