| [4694df] | 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 | 
 | 
|---|
| [12a24c] | 17 | #include <boost/serialization/export.hpp>
 | 
|---|
 | 18 | #include <boost/serialization/map.hpp>
 | 
|---|
 | 19 | #include <boost/serialization/vector.hpp>
 | 
|---|
 | 20 | 
 | 
|---|
| [e15ffe] | 21 | #include <iosfwd>
 | 
|---|
| [4694df] | 22 | #include <map>
 | 
|---|
| [77b350] | 23 | #include <vector>
 | 
|---|
| [4694df] | 24 | 
 | 
|---|
| [77b350] | 25 | #include "Fragmentation/Homology/HomologyGraph.hpp"
 | 
|---|
| [79ac03] | 26 | #include "Fragmentation/SetValues/Fragment.hpp"
 | 
|---|
| [12a24c] | 27 | 
 | 
|---|
 | 28 | class HomologyContainerTest;
 | 
|---|
 | 29 | 
 | 
|---|
| [4694df] | 30 | /** This class takes all KeySets in a Graph, checks for those that homologues
 | 
|---|
 | 31 |  * of one another and places them together.
 | 
|---|
 | 32 |  *
 | 
|---|
 | 33 |  * This is meant as a storage for key, value pairs, where the key is the KeySet
 | 
|---|
 | 34 |  * and the value is the energy associated to the fragment this keyset
 | 
|---|
 | 35 |  * represents.
 | 
|---|
 | 36 |  * Afterwards this can then be used as training data for a high-dimensional
 | 
|---|
 | 37 |  * approximation to the Born-Oppenheimer-surface decomposed into lower-
 | 
|---|
 | 38 |  * dimensional terms in an ANOVA-like fashion.
 | 
|---|
 | 39 |  *
 | 
|---|
 | 40 |  */
 | 
|---|
 | 41 | class HomologyContainer
 | 
|---|
 | 42 | {
 | 
|---|
| [e15ffe] | 43 |   //!> grant access to output operator
 | 
|---|
 | 44 |   friend std::ostream& operator<<(std::ostream &out, const HomologyContainer &container);
 | 
|---|
| [12a24c] | 45 |   //!> grant unit test access
 | 
|---|
 | 46 |   friend class HomologyContainerTest;
 | 
|---|
| [4694df] | 47 | public:
 | 
|---|
| [77b350] | 48 |   typedef double energy_t;
 | 
|---|
 | 49 |   typedef std::pair<Fragment, energy_t> value_t;
 | 
|---|
 | 50 |   typedef std::multimap< HomologyGraph, value_t> container_t;
 | 
|---|
 | 51 |   typedef std::pair< container_t::const_iterator, container_t::const_iterator> range_t;
 | 
|---|
 | 52 | public:
 | 
|---|
 | 53 |   /** Default Constructor of class HomologyContainer.
 | 
|---|
 | 54 |    *
 | 
|---|
 | 55 |    */
 | 
|---|
 | 56 |   HomologyContainer() {}
 | 
|---|
 | 57 | 
 | 
|---|
 | 58 |   /** Constructor of class HomologyContainer.
 | 
|---|
 | 59 |    *
 | 
|---|
 | 60 |    * @param values values with with to initially fill the container
 | 
|---|
 | 61 |    */
 | 
|---|
 | 62 |   HomologyContainer(const container_t &values) :
 | 
|---|
 | 63 |     container(values)
 | 
|---|
 | 64 |   {}
 | 
|---|
 | 65 |   /** Destructor of class HomologyContainer.
 | 
|---|
 | 66 |    *
 | 
|---|
 | 67 |    */
 | 
|---|
| [4694df] | 68 |   ~HomologyContainer() {}
 | 
|---|
 | 69 | 
 | 
|---|
| [12a24c] | 70 |   /** Equality comparator.
 | 
|---|
 | 71 |    *
 | 
|---|
 | 72 |    * Sadly, the insertion order of a std::multimap's values is not guaranteed
 | 
|---|
 | 73 |    * by the standard and boost::serialization does not heed the ordering of
 | 
|---|
 | 74 |    * the values associated to the same key. Hence, we implement a weaker
 | 
|---|
 | 75 |    * comparator for this class in order for the unit test to pass as we don't
 | 
|---|
 | 76 |    * actuallty care about the order of the homologous fragments.
 | 
|---|
 | 77 |    *
 | 
|---|
 | 78 |    * @param other instance to compare to
 | 
|---|
 | 79 |    * @return true - each container contains all elements of the other
 | 
|---|
 | 80 |    */
 | 
|---|
 | 81 |   bool operator==(const HomologyContainer &other) const {
 | 
|---|
 | 82 |     return ((*this >= other) && (other >= *this));
 | 
|---|
 | 83 |   }
 | 
|---|
 | 84 |   bool operator!=(const HomologyContainer& other) const {
 | 
|---|
 | 85 |     return !(*this == other);
 | 
|---|
 | 86 |   }
 | 
|---|
 | 87 | 
 | 
|---|
 | 88 |   /** Greater equal comparator, i.e. subset comparator
 | 
|---|
 | 89 |    *
 | 
|---|
 | 90 |    * @param other container to check if it's subset
 | 
|---|
 | 91 |    * @return true - \a other is a subset of this
 | 
|---|
 | 92 |    */
 | 
|---|
 | 93 |   bool operator>=(const HomologyContainer &other) const;
 | 
|---|
 | 94 | 
 | 
|---|
| [77b350] | 95 |   /** Inserter for more graphs along with values.
 | 
|---|
 | 96 |    *
 | 
|---|
 | 97 |    * @param values graph and values to insert
 | 
|---|
 | 98 |    */
 | 
|---|
 | 99 |   void insert(const container_t &values) {
 | 
|---|
 | 100 |     container.insert(values.begin(), values.end());
 | 
|---|
 | 101 |   }
 | 
|---|
 | 102 | 
 | 
|---|
 | 103 |   /** Returns iterator range with all contained graphs homologous to the given \a graph.
 | 
|---|
 | 104 |    *
 | 
|---|
 | 105 |    * @param graph graph to match
 | 
|---|
 | 106 |    * @return iterator range with all matches
 | 
|---|
 | 107 |    */
 | 
|---|
 | 108 |   range_t getHomologousGraphs(const HomologyGraph &graph) {
 | 
|---|
 | 109 |     return container.equal_range(graph);
 | 
|---|
 | 110 |   }
 | 
|---|
 | 111 | 
 | 
|---|
| [4694df] | 112 | private:
 | 
|---|
| [77b350] | 113 |   //!> multimap containing all homologous graph under same key but each with its value
 | 
|---|
 | 114 |   container_t container;
 | 
|---|
| [12a24c] | 115 | 
 | 
|---|
 | 116 | private:
 | 
|---|
 | 117 |   friend class boost::serialization::access;
 | 
|---|
 | 118 |   // serialization
 | 
|---|
 | 119 |   template <typename Archive>
 | 
|---|
 | 120 |   void serialize(Archive& ar, const unsigned int version)
 | 
|---|
 | 121 |   {
 | 
|---|
 | 122 |     ar & container;
 | 
|---|
 | 123 |   }
 | 
|---|
| [4694df] | 124 | };
 | 
|---|
 | 125 | 
 | 
|---|
| [e15ffe] | 126 | /** Output operator for HomologyContainer.
 | 
|---|
 | 127 |  *
 | 
|---|
 | 128 |  * \param out output stream
 | 
|---|
 | 129 |  * \param container container to print
 | 
|---|
 | 130 |  * \return output stream for concatenation
 | 
|---|
 | 131 |  */
 | 
|---|
 | 132 | std::ostream& operator<<(std::ostream &out, const HomologyContainer &container);
 | 
|---|
| [4694df] | 133 | 
 | 
|---|
| [12a24c] | 134 | // we need to give this class a unique key for serialization
 | 
|---|
 | 135 | BOOST_CLASS_EXPORT_KEY(HomologyContainer)
 | 
|---|
 | 136 | 
 | 
|---|
 | 137 | 
 | 
|---|
| [4694df] | 138 | #endif /* HOMOLOGYCONTAINER_HPP_ */
 | 
|---|