source: src/Graph/BoostGraphCreator.hpp@ 3dedfbd

ForceAnnealing_oldresults IndependentFragmentGrids_IntegrationTest
Last change on this file since 3dedfbd was 3dedfbd, checked in by Frederik Heber <frederik.heber@…>, 8 years ago

Moved BoostGraphCreator::createFromRange into extra impl module.

  • Property mode set to 100644
File size: 4.3 KB
Line 
1/*
2 * BoostGraphCreator.hpp
3 *
4 * Created on: May 17, 2017
5 * Author: heber
6 */
7
8
9#ifndef GRAPH_BOOSTGRAPHCREATOR_HPP_
10#define GRAPH_BOOSTGRAPHCREATOR_HPP_
11
12// include config.h
13#ifdef HAVE_CONFIG_H
14#include <config.h>
15#endif
16
17#include <map>
18#include <vector>
19
20#include <boost/function.hpp>
21#include <boost/graph/adjacency_list.hpp>
22
23#include "types.hpp"
24
25class atom;
26class bond;
27class molecule;
28
29class BreadthFirstSearchGathererTest;
30
31/** This is a helper class that contains functions to create a boost::graph
32 * from the present bond graph of molecules.
33 */
34struct BoostGraphCreator
35{
36 //!> grant unit test access to private parts that use BoostGraphCreator's internal graph
37 friend class BreadthFirstSearchGathererTest;
38
39public:
40 //!> typedef for an undirected graph using boost::graph
41 typedef boost::adjacency_list < boost::vecS, boost::vecS, boost::undirectedS,
42 boost::property<boost::vertex_name_t, atomId_t>, boost::no_property > UndirectedGraph;
43 //!> typedef for a map of graph node indices
44 typedef boost::property_map < UndirectedGraph, boost::vertex_index_t >::type index_map_t;
45 typedef boost::property_map < UndirectedGraph, boost::vertex_index_t >::const_type const_index_map_t;
46 //!> typedef for a map of graph node indices
47 typedef boost::property_map < UndirectedGraph, boost::vertex_name_t >::type name_map_t;
48 typedef boost::property_map < UndirectedGraph, boost::vertex_name_t >::const_type const_name_map_t;
49 //!> typedef for the predicate to evaluate for adding the current edge or not
50 typedef boost::function<bool (const bond &)> predicate_t;
51 //!> typedef for a Vertex
52 typedef boost::graph_traits<UndirectedGraph>::vertex_descriptor Vertex;
53 //!> typedef for vertex iterator
54 typedef boost::graph_traits<UndirectedGraph>::vertex_iterator vertex_iter;
55
56 //!> typedef for a node id
57 typedef size_t nodeId_t;
58 //!> typedef for map converting between node id in graph and the associated atomic id
59 typedef std::map<atomId_t, nodeId_t> atomids_nodeids_t;
60
61 /** Creates the boost::graph using all atoms and bonds in the given \a _mol.
62 *
63 * \param _mol molecule whose bond graph to construct
64 * \param _pred predicate to evaluate on adding each edge/bond
65 */
66 void createFromMolecule(
67 const molecule &_mol,
68 const predicate_t &_pred);
69
70 /** Creates the boost::graph using all atoms and bonds in the given vector
71 * of \a _atoms
72 *
73 * \param _atoms vector of _atoms whose bond graph to construct
74 * \param _pred predicate to evaluate on adding each edge/bond
75 */
76 void createFromAtoms(
77 const std::vector<atom *> &_atoms,
78 const predicate_t &_pred);
79
80 /** Getter for the created graph.
81 *
82 * \return graph
83 */
84 UndirectedGraph get() const
85 { return graph; }
86
87 /** Getter for the index map of the created graph.
88 *
89 * \return indexmap
90 */
91 index_map_t getIndexMap() const {
92 return boost::get(boost::vertex_index, graph);
93 }
94
95 /** Return the number of vertices contained in the created graph.
96 *
97 * \return number of vertices
98 */
99 size_t getNumVertices() const {
100 return boost::num_vertices(graph);
101 }
102
103 /** Return the number of edges contained in the created graph.
104 *
105 * \return number of edges
106 */
107 size_t getNumEdges() const {
108 return boost::num_edges(graph);
109 }
110
111 /** Returns the node id to a given atom id \a _atomid.
112 *
113 * \param _atomid atom id
114 * \return node id
115 */
116 nodeId_t getNodeId(const atomId_t &_atomid) const;
117
118 /** General purpose function that contains the internal logic of walking the
119 * bonds of a set of atoms given by \a _begin and \a _end iterators and
120 * adding its edges to a graph based on the evaluation of a given predicate
121 * \a _pred.
122 *
123 * \note We need \a _no_nodes because molecule::iterator does not work with
124 * std::distance.
125 *
126 * \param _begin begin iterator
127 * \param _end end iterator
128 * \param _no_nodes number of nodes
129 * \param _pred predicate
130 */
131 template <typename iterator>
132 void createFromRange(
133 const iterator &_begin,
134 const iterator &_end,
135 const size_t &_no_nodes,
136 const predicate_t &_pred
137 );
138
139private:
140 //!> internal graph that is created by creator functions
141 UndirectedGraph graph;
142 //!> external property map for all the atomic ids of each graph node
143 atomids_nodeids_t atomids_nodeids;
144};
145
146#include "BoostGraphCreator_impl.hpp"
147
148
149#endif /* GRAPH_BOOSTGRAPHCREATOR_HPP_ */
Note: See TracBrowser for help on using the repository browser.