| [1e7dd4] | 1 | /*
 | 
|---|
 | 2 |  * OrthogonalSummation_impl.hpp
 | 
|---|
 | 3 |  *
 | 
|---|
 | 4 |  *  Created on: Jun 25, 2012
 | 
|---|
 | 5 |  *      Author: heber
 | 
|---|
 | 6 |  */
 | 
|---|
 | 7 | 
 | 
|---|
 | 8 | #ifndef ORTHOGONALSUMMATION_IMPL_HPP_
 | 
|---|
 | 9 | #define ORTHOGONALSUMMATION_IMPL_HPP_
 | 
|---|
 | 10 | 
 | 
|---|
 | 11 | 
 | 
|---|
 | 12 | // include config.h
 | 
|---|
 | 13 | #ifdef HAVE_CONFIG_H
 | 
|---|
 | 14 | #include <config.h>
 | 
|---|
 | 15 | #endif
 | 
|---|
 | 16 | 
 | 
|---|
 | 17 | #include "CodePatterns/IteratorAdaptors.hpp"
 | 
|---|
 | 18 | #include "CodePatterns/Log.hpp"
 | 
|---|
 | 19 | 
 | 
|---|
| [beb16e] | 20 | #include "Fragmentation/Summation/ZeroInstance.hpp"
 | 
|---|
| [1b5a40] | 21 | #include "Fragmentation/Summation/printKeyNames.hpp"
 | 
|---|
| [beb16e] | 22 | 
 | 
|---|
| [1e7dd4] | 23 | /** Constructor of class OrthogonalSummation.
 | 
|---|
 | 24 |  *
 | 
|---|
 | 25 |  */
 | 
|---|
 | 26 | template <class T>
 | 
|---|
 | 27 | OrthogonalSummation<T>::OrthogonalSummation(
 | 
|---|
 | 28 |     InputSets_t &indices,
 | 
|---|
 | 29 |     InputValues_t& values,
 | 
|---|
 | 30 |     SubsetMap::ptr _subsetmap) :
 | 
|---|
 | 31 |   subsetmap(_subsetmap)
 | 
|---|
 | 32 | {
 | 
|---|
 | 33 |   ASSERT( indices.size() == values.size(),
 | 
|---|
 | 34 |       "OrthogonalSummation<T>::OrthogonalSummation() - indices and values mismatch in size: "
 | 
|---|
 | 35 |       +toString(indices.size())+" != "+toString(values.size())+".");
 | 
|---|
 | 36 |   /// place each index
 | 
|---|
 | 37 |   /// create own map if none is given
 | 
|---|
 | 38 |   if (!subsetmap) {
 | 
|---|
 | 39 |     typename InputSets_t::iterator iter = indices.begin();
 | 
|---|
 | 40 |     IndexSetContainer container(*iter);
 | 
|---|
 | 41 |     for (; iter != indices.end(); ++iter)
 | 
|---|
 | 42 |       container.insert(*iter);
 | 
|---|
 | 43 |     subsetmap.reset(new SubsetMap(container));
 | 
|---|
 | 44 |   } else {
 | 
|---|
| [a3fc46] | 45 |     LOG(2, "DEBUG: Using given SubsetMap.");
 | 
|---|
| [1e7dd4] | 46 |   }
 | 
|---|
 | 47 |   /// instantiate all SubSetValue's by requesting the IndexSet from the Subsetmap
 | 
|---|
 | 48 |   typename InputSets_t::iterator indexiter = indices.begin();
 | 
|---|
 | 49 |   typename InputValues_t::iterator valueiter = values.begin();
 | 
|---|
 | 50 |   for (;valueiter != values.end(); ++indexiter, ++valueiter) {
 | 
|---|
| [1b5a40] | 51 |     LOG(2, "DEBUG: Adding set " << **indexiter << " with value " << *valueiter << ".");
 | 
|---|
| [1e7dd4] | 52 |     setvalues.addValue( *indexiter, *valueiter );
 | 
|---|
 | 53 |   }
 | 
|---|
 | 54 |   /// bind static lookup functions for SetValue<T>
 | 
|---|
 | 55 |   SetValue<T>::lookupSubset =
 | 
|---|
 | 56 |       boost::bind(&SubsetMap::getSubsets, boost::ref(*subsetmap), _1);
 | 
|---|
 | 57 |   SetValue<T>::lookupValue =
 | 
|---|
 | 58 |       boost::bind(&SetValueMap<T>::getValue, boost::ref(setvalues), _1);
 | 
|---|
 | 59 | }
 | 
|---|
 | 60 | 
 | 
|---|
 | 61 | template <class T>
 | 
|---|
| [ff9963] | 62 | T OrthogonalSummation<T>::operator()(const size_t level) const
 | 
|---|
| [1e7dd4] | 63 | {
 | 
|---|
| [ff9963] | 64 |   return Sum(level);
 | 
|---|
| [1e7dd4] | 65 | }
 | 
|---|
 | 66 | 
 | 
|---|
 | 67 | template <class T>
 | 
|---|
| [ff9963] | 68 | T OrthogonalSummation<T>::Sum(const size_t level) const
 | 
|---|
| [1e7dd4] | 69 | {
 | 
|---|
 | 70 |   typename SetValueMap<T>::const_iterator iter = setvalues.begin();
 | 
|---|
| [beb16e] | 71 |   T sum(ZeroInstance<T>());
 | 
|---|
| [ff9963] | 72 |   if (iter->first->size() <= level)
 | 
|---|
 | 73 |     sum = (iter->second)->getContribution();
 | 
|---|
| [1b5a40] | 74 |   LOG(3, "DEBUG: Contribution from subset "+toString(*(iter->second->getIndexSet()))
 | 
|---|
| [1e7dd4] | 75 |       +" is "+toString(sum)+".");
 | 
|---|
| [ff9963] | 76 |   for(++iter;(iter != setvalues.end()) && (iter->first->size() <= level); ++iter) {
 | 
|---|
| [1e7dd4] | 77 |     const T tempvalue = (iter->second)->getContribution();
 | 
|---|
 | 78 |     sum += tempvalue;
 | 
|---|
| [1b5a40] | 79 |     LOG(3, "DEBUG: Contribution from subset "+toString(*(iter->second->getIndexSet()))
 | 
|---|
| [1e7dd4] | 80 |         +" is "+toString(tempvalue)+".");
 | 
|---|
 | 81 |   }
 | 
|---|
 | 82 |   return sum;
 | 
|---|
 | 83 | }
 | 
|---|
 | 84 | 
 | 
|---|
 | 85 | 
 | 
|---|
 | 86 | #endif /* ORTHOGONALSUMMATION_IMPL_HPP_ */
 | 
|---|