source: src/Graph/BreadthFirstSearchGatherer.hpp@ fba720

Candidate_v1.6.1 ChemicalSpaceEvaluator TremoloParser_IncreasedPrecision
Last change on this file since fba720 was 4a6ef3, checked in by Frederik Heber <frederik.heber@…>, 8 years ago

Moved AlwaysTruePredicate from BoostGraphCreatorUnitTest into BreadthFirstSearchGatherer.

  • Property mode set to 100644
File size: 1.8 KB
Line 
1/*
2 * BreadthFirstSearchGatherer.hpp
3 *
4 * Created on: May 17, 2017
5 * Author: heber
6 */
7
8
9#ifndef GRAPH_BREADTHFIRSTSEARCHGATHERER_HPP_
10#define GRAPH_BREADTHFIRSTSEARCHGATHERER_HPP_
11
12// include config.h
13#ifdef HAVE_CONFIG_H
14#include <config.h>
15#endif
16
17#include <map>
18#include <stddef.h>
19#include <vector>
20
21#include "types.hpp"
22
23class bond;
24struct BoostGraphCreator;
25
26/** This struct performs a BFS on a given boost::graph and finds
27 * all nodes, i.e. atoms, up to a given limit.
28 */
29struct BreadthFirstSearchGatherer
30{
31 //!> typedef for the distance map to the obtained atomic id set.
32 typedef std::map<atomId_t, size_t> distance_map_t;
33
34 /** Cstor of class BreadthFirstSearchGatherer.
35 *
36 * \param _graph graph to work on
37 */
38 BreadthFirstSearchGatherer(BoostGraphCreator &_graph);
39
40 /** Discovers all nodes from the given \a _discoverfrom and returns
41 * the vector of ids.
42 *
43 * \param _discoverfrom node to start BFS from
44 * \param _max_distance max distance to discover (negative means all)
45 */
46 std::vector<atomId_t> operator()(
47 const atomId_t &_discoverfrom,
48 const int &_max_distance = -1);
49
50 /** Getter to the internal map of distances of each atomic id.
51 *
52 * \return ref to distance map
53 */
54 const distance_map_t& getDistances() const
55 { return distance_map; }
56
57 /** This is a default predicate which returns always true.
58 *
59 * \return true
60 */
61 static bool AlwaysTruePredicate(const bond &_bond) { return true; }
62
63private:
64 //!> typedef for a vector of BFS discovery distances
65 typedef std::vector<size_t> distances_t;
66
67 //!> BFS discovery distances for the returned atomic id set
68 distance_map_t distance_map;
69
70 //!> graph to operate on
71 BoostGraphCreator &BGcreator;
72};
73
74
75#endif /* GRAPH_BREADTHFIRSTSEARCHGATHERER_HPP_ */
Note: See TracBrowser for help on using the repository browser.