| 1 | /* | 
|---|
| 2 | * MatrixContainer.hpp | 
|---|
| 3 | * | 
|---|
| 4 | *  Created on: Sep 15, 2011 | 
|---|
| 5 | *      Author: heber | 
|---|
| 6 | */ | 
|---|
| 7 |  | 
|---|
| 8 | #ifndef MATRIXCONTAINER_HPP_ | 
|---|
| 9 | #define MATRIXCONTAINER_HPP_ | 
|---|
| 10 |  | 
|---|
| 11 | // include config.h | 
|---|
| 12 | #ifdef HAVE_CONFIG_H | 
|---|
| 13 | #include <config.h> | 
|---|
| 14 | #endif | 
|---|
| 15 |  | 
|---|
| 16 | #include <vector> | 
|---|
| 17 |  | 
|---|
| 18 | #include "boost/serialization/serialization.hpp" | 
|---|
| 19 | #include <boost/serialization/split_member.hpp> | 
|---|
| 20 | #include "boost/serialization/vector.hpp" | 
|---|
| 21 |  | 
|---|
| 22 | /** Contains a sequence of matrices parsed from file. | 
|---|
| 23 | * | 
|---|
| 24 | */ | 
|---|
| 25 | class MatrixContainer { | 
|---|
| 26 | public: | 
|---|
| 27 | typedef std::vector<std::vector<double> > MatrixArray; | 
|---|
| 28 | typedef std::vector<MatrixArray> ArrayOfMatrices; | 
|---|
| 29 | typedef std::vector<std::string> StringVector; | 
|---|
| 30 | typedef std::vector<int> IntVector; | 
|---|
| 31 | typedef std::vector<IntVector> VectorOfIntVectors; | 
|---|
| 32 |  | 
|---|
| 33 | ArrayOfMatrices Matrix; | 
|---|
| 34 | VectorOfIntVectors Indices; | 
|---|
| 35 | StringVector Header; | 
|---|
| 36 | int MatrixCounter; | 
|---|
| 37 | IntVector RowCounter; | 
|---|
| 38 | IntVector ColumnCounter; | 
|---|
| 39 |  | 
|---|
| 40 | MatrixContainer(); | 
|---|
| 41 | virtual ~MatrixContainer(); | 
|---|
| 42 |  | 
|---|
| 43 | bool InitialiseIndices(class MatrixContainer *Matrix = NULL); | 
|---|
| 44 | bool ParseMatrix(std::istream &input, int skiplines, int skipcolumns, size_t MatrixNr); | 
|---|
| 45 | bool AddMatrix(const std::string &header, const MatrixArray &matrix, size_t MatrixNr); | 
|---|
| 46 | virtual bool ParseFragmentMatrix(const std::string name, const std::string prefix, std::string suffix, int skiplines, int skipcolumns); | 
|---|
| 47 | bool AllocateMatrix(StringVector GivenHeader, int MCounter, IntVector RCounter, IntVector CCounter); | 
|---|
| 48 | bool ResetMatrix(); | 
|---|
| 49 | double FindMinValue(); | 
|---|
| 50 | double FindMaxValue(); | 
|---|
| 51 | bool SetLastMatrix(double value, int skipcolumns); | 
|---|
| 52 | bool SetLastMatrix(const MatrixArray &values, int skipcolumns); | 
|---|
| 53 | //bool ParseIndices(); | 
|---|
| 54 | //bool SumSubValues(); | 
|---|
| 55 | bool SumSubManyBodyTerms(class MatrixContainer &Matrix, class KeySetsContainer &KeySets, int Order); | 
|---|
| 56 | bool WriteTotalFragments(const std::string name, const std::string prefix); | 
|---|
| 57 | bool WriteLastMatrix(const std::string name, const std::string prefix, const std::string suffix); | 
|---|
| 58 |  | 
|---|
| 59 | bool operator==(const MatrixContainer &other) const; | 
|---|
| 60 |  | 
|---|
| 61 | bool operator!=(const MatrixContainer &other) const { | 
|---|
| 62 | return !(*this == other); | 
|---|
| 63 | } | 
|---|
| 64 |  | 
|---|
| 65 | private: | 
|---|
| 66 | friend class boost::serialization::access; | 
|---|
| 67 | // serialization | 
|---|
| 68 | template <typename Archive> | 
|---|
| 69 | void load(Archive& ar, const unsigned int version) | 
|---|
| 70 | { | 
|---|
| 71 | // default cstor resizes these three to 1, serialization will add more | 
|---|
| 72 | // members instead of starting new | 
|---|
| 73 | Header.clear(); | 
|---|
| 74 | RowCounter.clear(); | 
|---|
| 75 | ColumnCounter.clear(); | 
|---|
| 76 | ar & Matrix; | 
|---|
| 77 | ar & Indices; | 
|---|
| 78 | ar & Header; | 
|---|
| 79 | ar & MatrixCounter; | 
|---|
| 80 | ar & RowCounter; | 
|---|
| 81 | ar & ColumnCounter; | 
|---|
| 82 | } | 
|---|
| 83 | template <typename Archive> | 
|---|
| 84 | void save(Archive& ar, const unsigned int version) const | 
|---|
| 85 | { | 
|---|
| 86 | ar & Matrix; | 
|---|
| 87 | ar & Indices; | 
|---|
| 88 | ar & Header; | 
|---|
| 89 | ar & MatrixCounter; | 
|---|
| 90 | ar & RowCounter; | 
|---|
| 91 | ar & ColumnCounter; | 
|---|
| 92 | } | 
|---|
| 93 |  | 
|---|
| 94 | BOOST_SERIALIZATION_SPLIT_MEMBER() | 
|---|
| 95 | }; | 
|---|
| 96 |  | 
|---|
| 97 | std::ostream & operator << (std::ostream &ost, const MatrixContainer &m); | 
|---|
| 98 |  | 
|---|
| 99 | #endif /* MATRIXCONTAINER_HPP_ */ | 
|---|