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