source: src/Fragmentation/Homology/HomologyContainer.hpp@ 5196ca

Candidate_v1.7.0 stable
Last change on this file since 5196ca was ff2c52, checked in by Frederik Heber <frederik.heber@…>, 5 years ago

ParseHomologies action lists values and their energy range per key.

  • i.e. we get how many values are stored per homology graph.
  • DOCU: Added note in userguide.
  • Property mode set to 100644
File size: 6.4 KB
Line 
1/*
2 * HomologyContainer.hpp
3 *
4 * Created on: Sep 22, 2012
5 * Author: heber
6 */
7
8#ifndef HOMOLOGYCONTAINER_HPP_
9#define HOMOLOGYCONTAINER_HPP_
10
11
12// include config.h
13#ifdef HAVE_CONFIG_H
14#include <config.h>
15#endif
16
17#include <boost/serialization/export.hpp>
18#include <boost/serialization/map.hpp>
19#include <boost/serialization/split_member.hpp>
20#include <boost/serialization/vector.hpp>
21#include <boost/serialization/version.hpp>
22
23#include <iosfwd>
24#include <map>
25#include <vector>
26
27#include "CodePatterns/IteratorAdaptors.hpp"
28#include "CodePatterns/Observer/Observable.hpp"
29
30#include "Fragmentation/EdgesPerFragment.hpp"
31#include "Fragmentation/Homology/HomologyGraph.hpp"
32#include "Fragmentation/Summation/SetValues/Fragment.hpp"
33#include "Fragmentation/Summation/SetValues/SamplingGrid.hpp"
34
35class HomologyContainerTest;
36
37/** This class takes all KeySets in a Graph, checks for those that homologues
38 * of one another and places them together.
39 *
40 * This is meant as a storage for key, value pairs, where the key is the KeySet
41 * and the value is the energy associated to the fragment this keyset
42 * represents.
43 * Afterwards this can then be used as training data for a high-dimensional
44 * approximation to the Born-Oppenheimer-surface decomposed into lower-
45 * dimensional terms in an ANOVA-like fashion.
46 *
47 */
48class HomologyContainer : public Observable
49{
50 //!> grant access to output operator
51 friend std::ostream& operator<<(std::ostream &out, const HomologyContainer &container);
52 //!> grant unit test access
53 friend class HomologyContainerTest;
54
55public:
56 /** This structure represents all values associated to a specific homology
57 * that we wish to store in this container for later reference.
58 */
59 struct value_t {
60 Fragment fragment;
61 FragmentationEdges::edges_t edges;
62 double energy;
63 bool containsGrids;
64 SamplingGrid charge_distribution;
65 SamplingGrid potential_distribution;
66
67 value_t() :
68 energy(0.),
69 containsGrids(false)
70 {}
71
72 bool operator==(const value_t &othervalue) const;
73
74 private:
75 friend class boost::serialization::access;
76 // serialization
77 template <typename Archive>
78 void serialize(Archive& ar, const unsigned int version)
79 {
80 ar & fragment;
81 if (version > 1)
82 ar & edges;
83 ar & energy;
84 if (version > 0) {
85 ar & containsGrids;
86 if (containsGrids) {
87 ar & charge_distribution;
88 ar & potential_distribution;
89 }
90 }
91 }
92 };
93
94 static bool compareEnergyContribution(
95 const std::pair<const HomologyGraph, HomologyContainer::value_t> &a,
96 const std::pair<const HomologyGraph, HomologyContainer::value_t> &b);
97
98public:
99 typedef std::multimap< HomologyGraph, value_t> container_t;
100 typedef container_t::const_iterator const_iterator;
101 typedef MapKeyConstIterator<container_t::const_iterator> const_key_iterator;
102 typedef std::pair< const_iterator, const_iterator> range_t;
103
104public:
105 /** Default Constructor of class HomologyContainer.
106 *
107 */
108 HomologyContainer();
109
110 /** Constructor of class HomologyContainer.
111 *
112 * @param values values with with to initially fill the container
113 */
114 HomologyContainer(const container_t &values);
115
116 /** Destructor of class HomologyContainer.
117 *
118 */
119 ~HomologyContainer() {}
120
121 /** Equality comparator.
122 *
123 * Sadly, the insertion order of a std::multimap's values is not guaranteed
124 * by the standard and boost::serialization does not heed the ordering of
125 * the values associated to the same key. Hence, we implement a weaker
126 * comparator for this class in order for the unit test to pass as we don't
127 * actuallty care about the order of the homologous fragments.
128 *
129 * @param other instance to compare to
130 * @return true - each container contains all elements of the other
131 */
132 bool operator==(const HomologyContainer &other) const {
133 return ((*this >= other) && (other >= *this));
134 }
135 bool operator!=(const HomologyContainer& other) const {
136 return !(*this == other);
137 }
138
139 /** Greater equal comparator, i.e. subset comparator
140 *
141 * @param other container to check if it's subset
142 * @return true - \a other is a subset of this
143 */
144 bool operator>=(const HomologyContainer &other) const;
145
146 /** Inserter for more graphs along with values.
147 *
148 * @param values graph and values to insert
149 */
150 void insert(const container_t &values);
151
152 /** Returns iterator range with all contained graphs homologous to the given \a graph.
153 *
154 * @param graph graph to match
155 * @return iterator range with all matches
156 */
157 range_t getHomologousGraphs(const HomologyGraph &graph) const {
158 return container.equal_range(graph);
159 }
160
161 /** Getter for constant iterator to begin of homologous graph container.
162 *
163 * @return begin constant iterator
164 */
165 const_iterator begin() const {
166 return container.begin();
167 }
168
169 /** Getter for constant iterator to past end of homologous graph container.
170 *
171 * @return past end constant iterator
172 */
173 const_iterator end() const {
174 return container.end();
175 }
176
177 const_key_iterator key_begin() const
178 { return const_key_iterator(container.begin()); }
179
180 const_key_iterator key_end() const
181 { return const_key_iterator(container.end()); }
182
183 const_key_iterator getNextKey(const_key_iterator &iter) const
184 { return const_key_iterator(container.upper_bound(*iter)); }
185
186 /** Clears all homologies from container.
187 *
188 */
189 void clear();
190
191 /** Returns the number of keys in the container.
192 *
193 * \return size of internal container
194 */
195 const size_t size()
196 { return container.size(); }
197
198private:
199 //!> multimap containing all homologous graph under same key but each with its value
200 container_t container;
201
202private:
203 friend class boost::serialization::access;
204 // serialization
205 template <typename Archive>
206 void load(Archive& ar, const unsigned int version)
207 {
208 OBSERVE;
209 ar & container;
210 }
211 template <typename Archive>
212 void save(Archive& ar, const unsigned int version) const
213 {
214 ar & container;
215 }
216 BOOST_SERIALIZATION_SPLIT_MEMBER()
217};
218
219/** Output operator for HomologyContainer.
220 *
221 * \param out output stream
222 * \param container container to print
223 * \return output stream for concatenation
224 */
225std::ostream& operator<<(std::ostream &out, const HomologyContainer &container);
226
227// we need to give this class a unique key for serialization
228BOOST_CLASS_EXPORT_KEY(HomologyContainer)
229
230// version for serialized information associated to HomologyGraph
231BOOST_CLASS_VERSION(HomologyContainer::value_t, 2)
232
233#endif /* HOMOLOGYCONTAINER_HPP_ */
Note: See TracBrowser for help on using the repository browser.