source: src/Fragmentation/Summation/Summation_impl.hpp@ fba720

Candidate_v1.6.1 ChemicalSpaceEvaluator TremoloParser_IncreasedPrecision
Last change on this file since fba720 was 3d444a, checked in by Frederik Heber <heber@…>, 9 years ago

(Orthogonal)Summation's Sum() can be further simplified now.

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