source: src/Graph/BoostGraphCreator.hpp@ d6192a3

ForceAnnealing_goodresults ForceAnnealing_tocheck
Last change on this file since d6192a3 was d6192a3, 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.2 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
29/** This is a helper class that contains functions to create a boost::graph
30 * from the present bond graph of molecules.
31 */
32struct BoostGraphCreator
33{
34public:
35 //!> typedef for an undirected graph using boost::graph
36 typedef boost::adjacency_list < boost::vecS, boost::vecS, boost::undirectedS,
37 boost::property<boost::vertex_name_t, atomId_t>, boost::no_property > UndirectedGraph;
38 //!> typedef for a map of graph node indices
39 typedef boost::property_map < UndirectedGraph, boost::vertex_index_t >::type index_map_t;
40 typedef boost::property_map < UndirectedGraph, boost::vertex_index_t >::const_type const_index_map_t;
41 //!> typedef for a map of graph node indices
42 typedef boost::property_map < UndirectedGraph, boost::vertex_name_t >::type name_map_t;
43 typedef boost::property_map < UndirectedGraph, boost::vertex_name_t >::const_type const_name_map_t;
44 //!> typedef for the predicate to evaluate for adding the current edge or not
45 typedef boost::function<bool (const bond &)> predicate_t;
46 //!> typedef for a Vertex
47 typedef boost::graph_traits<UndirectedGraph>::vertex_descriptor Vertex;
48 //!> typedef for vertex iterator
49 typedef boost::graph_traits<UndirectedGraph>::vertex_iterator vertex_iter;
50
51 //!> typedef for a node id
52 typedef size_t nodeId_t;
53 //!> typedef for map converting between node id in graph and the associated atomic id
54 typedef std::map<atomId_t, nodeId_t> atomids_nodeids_t;
55
56 /** Creates the boost::graph using all atoms and bonds in the given \a _mol.
57 *
58 * \param _mol molecule whose bond graph to construct
59 * \param _pred predicate to evaluate on adding each edge/bond
60 */
61 void createFromMolecule(
62 const molecule &_mol,
63 const predicate_t &_pred);
64
65 /** Creates the boost::graph using all atoms and bonds in the given vector
66 * of \a _atoms
67 *
68 * \param _atoms vector of _atoms whose bond graph to construct
69 * \param _pred predicate to evaluate on adding each edge/bond
70 */
71 void createFromAtoms(
72 const std::vector<atom *> &_atoms,
73 const predicate_t &_pred);
74
75 /** Getter for the created graph.
76 *
77 * \return graph
78 */
79 UndirectedGraph get() const
80 { return graph; }
81
82 /** Getter for the index map of the created graph.
83 *
84 * \return indexmap
85 */
86 index_map_t getIndexMap() const {
87 return boost::get(boost::vertex_index, graph);
88 }
89
90 /** Return the number of vertices contained in the created graph.
91 *
92 * \return number of vertices
93 */
94 size_t getNumVertices() const {
95 return boost::num_vertices(graph);
96 }
97
98 /** Return the number of edges contained in the created graph.
99 *
100 * \return number of edges
101 */
102 size_t getNumEdges() const {
103 return boost::num_edges(graph);
104 }
105
106 /** Returns the node id to a given atom id \a _atomid.
107 *
108 * \param _atomid atom id
109 * \return node id
110 */
111 nodeId_t getNodeId(const atomId_t &_atomid) const;
112
113 /** General purpose function that contains the internal logic of walking the
114 * bonds of a set of atoms given by \a _begin and \a _end iterators and
115 * adding its edges to a graph based on the evaluation of a given predicate
116 * \a _pred.
117 *
118 * \note We need \a _no_nodes because molecule::iterator does not work with
119 * std::distance.
120 *
121 * \param _begin begin iterator
122 * \param _end end iterator
123 * \param _no_nodes number of nodes
124 * \param _pred predicate
125 */
126 template <typename iterator>
127 void createFromRange(
128 const iterator &_begin,
129 const iterator &_end,
130 const size_t &_no_nodes,
131 const predicate_t &_pred
132 );
133
134private:
135 //!> internal graph that is created by creator functions
136 UndirectedGraph graph;
137 //!> external property map for all the atomic ids of each graph node
138 atomids_nodeids_t atomids_nodeids;
139};
140
141#include "BoostGraphCreator_impl.hpp"
142
143
144#endif /* GRAPH_BOOSTGRAPHCREATOR_HPP_ */
Note: See TracBrowser for help on using the repository browser.