29 #ifndef CDPL_CHEM_TOPOLOGICALENTITYALIGNMENT_HPP
30 #define CDPL_CHEM_TOPOLOGICALENTITYALIGNMENT_HPP
36 #include <boost/iterator/indirect_iterator.hpp>
80 typedef boost::indirect_iterator<typename EntitySet::const_iterator, const EntityType>
ConstEntityIterator;
188 typedef std::vector<Util::STPair> CompatGraphNodeArray;
193 CompatGraphNodeArray compatGraphNodes;
206 template <
typename T>
209 entityMatchFunc = func;
213 template <
typename T>
217 return entityMatchFunc;
220 template <
typename T>
223 entityPairMatchFunc = func;
227 template <
typename T>
231 return entityPairMatchFunc;
234 template <
typename T>
237 return (first_set ? firstEntities : secondEntities).size();
240 template <
typename T>
243 (first_set ? firstEntities : secondEntities).push_back(&entity);
247 template <
typename T>
250 (first_set ? firstEntities : secondEntities).clear();
254 template <
typename T>
258 return (first_set ? firstEntities : secondEntities).begin();
261 template <
typename T>
265 return (first_set ? firstEntities : secondEntities).end();
268 template <
typename T>
272 const EntitySet& entity_set = (first_set ? firstEntities : secondEntities);
274 if (idx >= entity_set.size())
275 throw Base::IndexError(
"TopologicalEntityAlignment: entity index out of bounds");
277 return *entity_set[idx];
280 template <
typename T>
283 compatGraphNodes.clear();
285 if (entityMatchFunc) {
288 for (
typename EntitySet::const_iterator it1 = firstEntities.begin(), end1 = firstEntities.end(); it1 != end1; ++it1, i++) {
289 const EntityType* ent1 = *it1;
292 for (
typename EntitySet::const_iterator it2 = secondEntities.begin(), end2 = secondEntities.end(); it2 != end2; ++it2, j++)
293 if (entityMatchFunc(*ent1, **it2))
298 for (std::size_t i = 0, num_ents1 = firstEntities.size(); i < num_ents1; i++)
299 for (std::size_t j = 0, num_ents2 = secondEntities.size(); j < num_ents2; j++)
303 std::size_t num_nodes = compatGraphNodes.size();
305 adjMatrix.resize(num_nodes);
307 for (std::size_t i = 0; i < num_nodes; i++) {
308 adjMatrix[i].resize(num_nodes);
309 adjMatrix[i].
reset();
312 for (std::size_t i = 0; i < num_nodes; i++) {
315 for (std::size_t j = i + 1; j < num_nodes; j++) {
318 if (p1.first == p2.first)
321 if (p1.second == p2.second)
324 if (!entityPairMatchFunc || entityPairMatchFunc(*firstEntities[p1.first], *firstEntities[p2.first],
325 *secondEntities[p1.second], *secondEntities[p2.second])) {
332 bkAlgorithm.init(adjMatrix);
337 template <
typename T>
343 if (!bkAlgorithm.nextClique(clique))
348 for (std::size_t i = clique.find_first(); i != Util::BitSet::npos; i = clique.find_next(i))
354 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 entities by reducing the alignment problem to a ...
Definition: TopologicalEntityAlignment.hpp:64
bool nextAlignment(Util::STPairArray &mapping)
Searches for the next alignment solution and stores the corresponding mapping of the entities in the ...
Definition: TopologicalEntityAlignment.hpp:338
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:90
const EntityPairMatchFunction & getEntityPairMatchFunction() const
Returns the function that was registered for checking the compatibility of entity-pairs.
Definition: TopologicalEntityAlignment.hpp:229
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:256
TopologicalEntityAlignment()
Constructs the TopologicalEntityAlignment instance.
Definition: TopologicalEntityAlignment.hpp:95
void addEntity(const EntityType &entity, bool first_set)
Adds an entity to the specified alignment entity set.
Definition: TopologicalEntityAlignment.hpp:241
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:263
T EntityType
The actual entity type.
Definition: TopologicalEntityAlignment.hpp:70
virtual ~TopologicalEntityAlignment()
Virtual destructor.
Definition: TopologicalEntityAlignment.hpp:101
std::vector< const EntityType * > EntitySet
The container storing the entities to align.
Definition: TopologicalEntityAlignment.hpp:75
void setEntityMatchFunction(const EntityMatchFunction &func)
Specifies a function for restricting allowed entity mappings in the search for alignment solutions.
Definition: TopologicalEntityAlignment.hpp:207
void reset()
Discards the current alignment-search state so that the next call to nextAlignment() restarts the com...
Definition: TopologicalEntityAlignment.hpp:355
boost::indirect_iterator< typename EntitySet::const_iterator, const EntityType > ConstEntityIterator
A constant iterator over the stored entities.
Definition: TopologicalEntityAlignment.hpp:80
void setEntityPairMatchFunction(const EntityPairMatchFunction &func)
Specifies a function for checking the compatibility of entity-pairs in the search for alignment solut...
Definition: TopologicalEntityAlignment.hpp:221
std::function< bool(const EntityType &, const EntityType &)> EntityMatchFunction
Generic wrapper class used to store a user-defined entity match constraint function.
Definition: TopologicalEntityAlignment.hpp:85
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:270
const EntityMatchFunction & getEntityMatchFunction() const
Returns the function that was registered for restricting allowed entity mappings.
Definition: TopologicalEntityAlignment.hpp:215
void clearEntities(bool first_set)
Removes all entities in the specified alignment entity set.
Definition: TopologicalEntityAlignment.hpp:248
std::size_t getNumEntities(bool first_set) const
Returns the number of entities in the specified alignment entity set.
Definition: TopologicalEntityAlignment.hpp:235
Dynamic array class providing amortized constant time access to arbitrary elements.
Definition: Array.hpp:92
void clear()
Erases all elements.
Definition: Array.hpp:740
void addElement(const ValueType &value=ValueType())
Inserts a new element at the end of the array.
Definition: Array.hpp:765
Implementation of the Bron-Kerbosch clique-detection algorithm [BKA].
Definition: BronKerboschAlgorithm.hpp:49
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:605
std::pair< std::size_t, std::size_t > STPair
Pair of unsigned integers of type std::size_t.
Definition: Array.hpp:585
The namespace of the Chemical Data Processing Library.