29 #ifndef CDPL_CHEM_TOPOLOGICALENTITYALIGNMENT_HPP
30 #define CDPL_CHEM_TOPOLOGICALENTITYALIGNMENT_HPP
36 #include <boost/iterator/indirect_iterator.hpp>
81 typedef boost::indirect_iterator<typename EntitySet::const_iterator, const EntityType>
ConstEntityIterator;
189 typedef std::vector<Util::STPair> CompatGraphNodeArray;
194 CompatGraphNodeArray compatGraphNodes;
207 template <
typename T>
210 entityMatchFunc = func;
214 template <
typename T>
218 return entityMatchFunc;
221 template <
typename T>
224 entityPairMatchFunc = func;
228 template <
typename T>
232 return entityPairMatchFunc;
235 template <
typename T>
238 return (first_set ? firstEntities : secondEntities).size();
241 template <
typename T>
244 (first_set ? firstEntities : secondEntities).push_back(&entity);
248 template <
typename T>
251 (first_set ? firstEntities : secondEntities).clear();
255 template <
typename T>
259 return (first_set ? firstEntities : secondEntities).begin();
262 template <
typename T>
266 return (first_set ? firstEntities : secondEntities).end();
269 template <
typename T>
273 const EntitySet& entity_set = (first_set ? firstEntities : secondEntities);
275 if (idx >= entity_set.size())
276 throw Base::IndexError(
"TopologicalEntityAlignment: entity index out of bounds");
278 return *entity_set[idx];
281 template <
typename T>
284 compatGraphNodes.clear();
286 if (entityMatchFunc) {
289 for (
typename EntitySet::const_iterator it1 = firstEntities.begin(), end1 = firstEntities.end(); it1 != end1; ++it1, i++) {
290 const EntityType* ent1 = *it1;
293 for (
typename EntitySet::const_iterator it2 = secondEntities.begin(), end2 = secondEntities.end(); it2 != end2; ++it2, j++)
294 if (entityMatchFunc(*ent1, **it2))
299 for (std::size_t i = 0, num_ents1 = firstEntities.size(); i < num_ents1; i++)
300 for (std::size_t j = 0, num_ents2 = secondEntities.size(); j < num_ents2; j++)
304 std::size_t num_nodes = compatGraphNodes.size();
306 adjMatrix.resize(num_nodes);
308 for (std::size_t i = 0; i < num_nodes; i++) {
309 adjMatrix[i].resize(num_nodes);
310 adjMatrix[i].
reset();
313 for (std::size_t i = 0; i < num_nodes; i++) {
316 for (std::size_t j = i + 1; j < num_nodes; j++) {
319 if (p1.first == p2.first)
322 if (p1.second == p2.second)
325 if (!entityPairMatchFunc || entityPairMatchFunc(*firstEntities[p1.first], *firstEntities[p2.first],
326 *secondEntities[p1.second], *secondEntities[p2.second])) {
333 bkAlgorithm.init(adjMatrix);
338 template <
typename T>
344 if (!bkAlgorithm.nextClique(clique))
349 for (std::size_t i = clique.find_first(); i != Util::BitSet::npos; i = clique.find_next(i))
355 template <
typename T>
Definition of class CDPL::Util::Array.
Definition of exception classes.
Implementation of the Bron-Kerbosch algorithm.
Thrown to indicate that an index is out of range.
Definition: Base/Exceptions.hpp:152
Computes a topological alignment between two sets of arbitrary entities by performing a maximum commo...
Definition: TopologicalEntityAlignment.hpp:65
bool nextAlignment(Util::STPairArray &mapping)
Searches for the next alignment solution and stores the corresponding mapping of the entities in the ...
Definition: TopologicalEntityAlignment.hpp:339
std::function< bool(const EntityType &, const EntityType &, const EntityType &, const EntityType &)> EntityPairMatchFunction
Generic wrapper class used to store a user-defined entity pair match constraint function.
Definition: TopologicalEntityAlignment.hpp:91
const EntityPairMatchFunction & getEntityPairMatchFunction() const
Returns the function that was registered for checking the compatibility of entity pairs.
Definition: TopologicalEntityAlignment.hpp:230
ConstEntityIterator getEntitiesBegin(bool first_set) const
Returns a constant iterator pointing to the beginning of the entities stored in the specified set.
Definition: TopologicalEntityAlignment.hpp:257
TopologicalEntityAlignment()
Constructs the TopologicalEntityAlignment instance.
Definition: TopologicalEntityAlignment.hpp:96
void addEntity(const EntityType &entity, bool first_set)
Adds an entity to the specified alignment entity set.
Definition: TopologicalEntityAlignment.hpp:242
ConstEntityIterator getEntitiesEnd(bool first_set) const
Returns a constant iterator pointing to the end of the entities stored in the specified set.
Definition: TopologicalEntityAlignment.hpp:264
T EntityType
The actual entity type.
Definition: TopologicalEntityAlignment.hpp:71
virtual ~TopologicalEntityAlignment()
Virtual destructor.
Definition: TopologicalEntityAlignment.hpp:102
std::vector< const EntityType * > EntitySet
The container storing the entities to align.
Definition: TopologicalEntityAlignment.hpp:76
void setEntityMatchFunction(const EntityMatchFunction &func)
Specifies a function for restricting allowed entity mappings in the search for alignment solutions.
Definition: TopologicalEntityAlignment.hpp:208
void reset()
Discards the current alignment search state so that the next call to nextAlignment() restarts the com...
Definition: TopologicalEntityAlignment.hpp:356
boost::indirect_iterator< typename EntitySet::const_iterator, const EntityType > ConstEntityIterator
A constant iterator over the stored entities.
Definition: TopologicalEntityAlignment.hpp:81
void setEntityPairMatchFunction(const EntityPairMatchFunction &func)
Specifies a function for checking the compatibility of entity pairs in the search for alignment solut...
Definition: TopologicalEntityAlignment.hpp:222
std::function< bool(const EntityType &, const EntityType &)> EntityMatchFunction
Generic wrapper class used to store a user-defined entity match constraint function.
Definition: TopologicalEntityAlignment.hpp:86
const EntityType & getEntity(std::size_t idx, bool first_set) const
Returns a non-const reference to the stored entity at index idx in the specified set.
Definition: TopologicalEntityAlignment.hpp:271
const EntityMatchFunction & getEntityMatchFunction() const
Returns the function that was registered for restricting allowed entity mappings.
Definition: TopologicalEntityAlignment.hpp:216
void clearEntities(bool first_set)
Removes all entities in the specified alignment entity set.
Definition: TopologicalEntityAlignment.hpp:249
std::size_t getNumEntities(bool first_set) const
Returns the number of entities in the specified alignment entity set.
Definition: TopologicalEntityAlignment.hpp:236
Dynamic array class providing amortized constant time access to arbitrary elements.
Definition: Array.hpp:92
void clear()
Erases all elements.
Definition: Array.hpp:743
void addElement(const ValueType &value=ValueType())
Inserts a new element at the end of the array.
Definition: Array.hpp:768
Implementation of the Bron-Kerbosch clique-detection algorithm [BKA].
Definition: BronKerboschAlgorithm.hpp:51
constexpr unsigned int T
Specifies Hydrogen (Tritium).
Definition: AtomType.hpp:67
boost::dynamic_bitset BitSet
Dynamic bitset class.
Definition: BitSet.hpp:46
Array< BitSet > BitSetArray
Array storing Util::BitSet objects.
Definition: Array.hpp:608
std::pair< std::size_t, std::size_t > STPair
Pair of unsigned integers of type std::size_t.
Definition: Array.hpp:588
The namespace of the Chemical Data Processing Library.