RDKit: PartitionSet.h Source File

| RDKit Open-source cheminformatics and machine learning.

Loading...
Searching...
No Matches
PartitionSet.h
Go to the documentation of this file.
1//
2// Copyright (C) David Cosgrove 2023
3//
4// @@ All Rights Reserved @@
5// This file is part of the RDKit.
6// The contents are covered by the terms of the BSD license
7// which is included in the file license.txt, found at the root
8// of the RDKit source tree.
9//
10
11#ifndef RASCALMCES_PARTITION_SET_H
12#define RASCALMCES_PARTITION_SET_H
13
14#include <map>
15#include <vector>
16
17#include <RDGeneral/BoostStartInclude.h>
18#include <boost/dynamic_bitset.hpp>
19#include <RDGeneral/BoostEndInclude.h>
20
21namespace RDKit {
22
23 namespace RascalMCES {
24
25 class PartitionSet {
26 public:
27 // Make a partition set from the modular product and the labels
28 // of the vertices from the first graph. Each element in vtxPairs
29 // has a row/column in modProd. The partitions are sorted
30 // into descending order of sizes.
31 PartitionSet(const std::vector<boost::dynamic_bitset<>> &modProd,
32 const std::vector<std::pair<int, int>> &vtxPairs,
33 const std::vector<unsigned int> &vtx1Labels,
34 const std::vector<unsigned int> &vtx2Labels,
35 unsigned int lowerBound);
36
37 bool isEmpty() const { return d_parts.empty(); }
38
39 size_t numParts() const { return d_parts.size(); }
40
41 // Compute the upper bound on the clique that can be extracted from
42 // the current partition.
43 int upperBound();
44
45 friend std::ostream &operator<<(std::ostream &os, const PartitionSet &pt);
46
47 // removes the last element of the last partition and returns
48 // its value. Throws a runtime_error if empty.
49 unsigned int popLastVertex();
50
51 // remove from the partitions any vertex not connected to the given
52 // vertex
53 void pruneVertices(unsigned int vtx_num);
54
55 private:
56 std::shared_ptr<const std::vector<boost::dynamic_bitset<>>> d_ModProd;
57 std::shared_ptr<const std::vector<std::pair<int, int>>> d_VtxPairs;
58 std::shared_ptr<const std::vector<unsigned int>> d_vtx1Labels;
59 std::shared_ptr<const std::vector<unsigned int>> d_vtx2Labels;
60 std::vector<std::vector<unsigned int>> d_parts;
61 // counts of the number of times each vertex appears in the partitions
62 std::vector<int> d_vtx1Counts, d_vtx2Counts;
63 // counts of the number of times the d_vtx[12]_labels appear in the partitions
64 std::vector<int> d_vtx1TypeCounts, d_vtx2TypeCounts;
65
66 void sortPartitions();
67
68 void calcVtxTypeCounts();
69
70 void decrementVertexCounts(int vtxNum);
71};
72} // namespace RascalMCES
73} // namespace RDKit
74
75#endif // RASCALMCES_PARTITION_SET_H
BoostEndInclude.h
BoostStartInclude.h
RDKit::RascalMCES::PartitionSet::popLastVertex
unsigned int popLastVertex()
RDKit::RascalMCES::PartitionSet::PartitionSet
PartitionSet(const std::vector< boost::dynamic_bitset<> > &modProd, const std::vector< std::pair< int, int > > &vtxPairs, const std::vector< unsigned int > &vtx1Labels, const std::vector< unsigned int > &vtx2Labels, unsigned int lowerBound)
RDKit::RascalMCES::PartitionSet::numParts
size_t numParts() const
Definition PartitionSet.h:39
RDKit::RascalMCES::PartitionSet::isEmpty
bool isEmpty() const
Definition PartitionSet.h:37
RDKit::RascalMCES::PartitionSet::pruneVertices
void pruneVertices(unsigned int vtx_num)
RDKit::RascalMCES::PartitionSet::upperBound
int upperBound()
RDKit::RascalMCES::PartitionSet::operator<<
friend std::ostream & operator<<(std::ostream &os, const PartitionSet &pt)
RDKit::RascalMCES
Definition PartitionSet.h:23
RDKit
Std stuff.
Definition Abbreviations.h:19