42 template <
typename ValueType =
long unsigned int,
43 typename DecompositionValueType =
unsigned int>
61 typedef typename decomposition_type::size_type
size_type;
177 template <
typename ValueType,
typename DecompositionValueType>
192 template <
typename ValueType,
typename DecompositionValueType>
198 if (_alphabet.
size() < 2)
206 _ertable.reserve(_alphabet.
size());
207 _ertable.assign(_alphabet.
size(), std::vector<value_type>(smallestMass, _infty));
215 _witnessVector.resize(smallestMass);
218 size_type it_inc = secondMass % smallestMass, witness = 1;
226 _ertable[1][it_i] = mass;
229 _witnessVector[it_i] = std::make_pair(witness, counter);
232 if (it_i >= _ertable[1].size())
234 it_i -= _ertable[1].size();
239 _lcms[1] = secondMass * smallestMass / tmp_d;
240 _mass_in_lcms[1] = smallestMass / tmp_d;
252 _lcms[i] = currentMass * smallestMass / d;
253 _mass_in_lcms[i] = smallestMass / d;
256 if (currentMass >= _ertable[i - 1][currentMass % smallestMass])
258 _ertable[i] = _ertable[i - 1];
271 size_type p_inc = currentMass % smallestMass;
280 for (
size_type m = smallestMass; m > 0; --m)
285 if (p >= smallestMass)
289 if (n > prev_column[p])
296 _witnessVector[p] = std::make_pair(i, local_counter);
308 size_type cur = currentMass % smallestMass;
312 std::vector<decomposition_value_type> counters(smallestMass);
317 cur_column[j] = prev_column[j];
321 for (
size_type m = smallestMass / d; m > 1; m--)
328 if (cur_column[prev] + currentMass > prev_column[cur])
330 cur_column[cur] = prev_column[cur];
335 cur_column[cur] = cur_column[prev] + currentMass;
336 _witnessVector[cur] = std::make_pair(i, counters[cur]);
347 if (cur >= smallestMass)
363 if (cur_column[prev] + currentMass < cur_column[cur])
365 cur_column[cur] = cur_column[prev] + currentMass;
367 _witnessVector[cur] = std::make_pair(i, counters[cur]);
380 if (cur >= smallestMass)
390 template <
typename ValueType,
typename DecompositionValueType>
395 value_type residue = ertable_.back().at(mass % alphabet_.getWeight(0));
396 return residue != infty_ && mass >= residue;
399 template <
typename ValueType,
typename DecompositionValueType>
405 if (!this->exist(mass))
407 return decomposition;
410 decomposition.reserve(alphabet_.size());
411 decomposition.resize(alphabet_.size());
418 ((mass - m) / alphabet_.getWeight(0));
422 size_type i = witness_vector_.at(r).first;
424 decomposition.at(i) += j;
425 if (m < j * alphabet_.getWeight(i))
429 m -= j * alphabet_.getWeight(i);
430 r = m % alphabet_.getWeight(0);
432 return decomposition;
435 template <
typename ValueType,
typename DecompositionValueType>
441 collectDecompositionsRecursively_(mass, alphabet_.size() - 1, decomposition, decompositionsStore);
442 return decompositionsStore;
445 template <
typename ValueType,
typename DecompositionValueType>
450 if (alphabetMassIndex == 0)
452 value_type numberOfMasses0 = mass / alphabet_.getWeight(0);
453 if (numberOfMasses0 * alphabet_.getWeight(0) == mass)
456 decompositionsStore.push_back(decomposition);
463 const value_type lcm = lcms_[alphabetMassIndex];
464 const value_type mass_in_lcm = mass_in_lcms_[alphabetMassIndex];
466 value_type mass_mod_alphabet0 = mass % alphabet_.getWeight(0);
467 const value_type mass_mod_decrement = alphabet_.getWeight(alphabetMassIndex) % alphabet_.getWeight(0);
476 if (mass < i * alphabet_.getWeight(alphabetMassIndex))
482 value_type r = ertable_[alphabetMassIndex - 1][mass_mod_alphabet0];
487 for (
value_type m = mass - i * alphabet_.getWeight(alphabetMassIndex); m >= r; m -= lcm)
492 collectDecompositionsRecursively_(m, alphabetMassIndex - 1, decomposition, decompositionsStore);
493 decomposition[alphabetMassIndex] += mass_in_lcm;
503 if (mass_mod_alphabet0 < mass_mod_decrement)
505 mass_mod_alphabet0 += alphabet_.getWeight(0) - mass_mod_decrement;
509 mass_mod_alphabet0 -= mass_mod_decrement;
523 template <
typename ValueType,
typename DecompositionValueType>
525 DecompositionValueType>::getNumberOfDecompositions(
value_type mass)
Implements MassDecomposer interface using algorithm and data structures described in paper "Efficient...
Definition: IntegerMassDecomposer.h:46
residues_table_row_type lcms_
Definition: IntegerMassDecomposer.h:137
Weights alphabet_
Definition: IntegerMassDecomposer.h:124
value_type infty_
Definition: IntegerMassDecomposer.h:149
IntegerMassDecomposer(const Weights &alphabet)
Definition: IntegerMassDecomposer.h:178
std::vector< residues_table_row_type > residues_table_type
Definition: IntegerMassDecomposer.h:119
std::vector< std::pair< size_type, decomposition_value_type > > witness_vector_type
Definition: IntegerMassDecomposer.h:109
void collectDecompositionsRecursively_(value_type mass, size_type alphabetMassIndex, decomposition_type decomposition, decompositions_type &decompositionsStore)
Definition: IntegerMassDecomposer.h:447
decompositions_type getAllDecompositions(value_type mass) override
Definition: IntegerMassDecomposer.h:437
std::vector< value_type > residues_table_row_type
Definition: IntegerMassDecomposer.h:114
residues_table_row_type mass_in_lcms_
Definition: IntegerMassDecomposer.h:144
decomposition_type getDecomposition(value_type mass) override
Definition: IntegerMassDecomposer.h:401
MassDecomposer< ValueType, DecompositionValueType >::decomposition_type decomposition_type
Type of decomposition.
Definition: IntegerMassDecomposer.h:55
decomposition_type::size_type size_type
Type of decomposition's size.
Definition: IntegerMassDecomposer.h:61
witness_vector_type witness_vector_
Definition: IntegerMassDecomposer.h:155
bool exist(value_type mass) override
Definition: IntegerMassDecomposer.h:392
MassDecomposer< ValueType, DecompositionValueType >::decomposition_value_type decomposition_value_type
Type of decomposition value.
Definition: IntegerMassDecomposer.h:52
residues_table_type ertable_
Definition: IntegerMassDecomposer.h:131
MassDecomposer< ValueType, DecompositionValueType >::decompositions_type decompositions_type
Type of container for many decompositions.
Definition: IntegerMassDecomposer.h:58
MassDecomposer< ValueType, DecompositionValueType >::value_type value_type
Type of value to be decomposed.
Definition: IntegerMassDecomposer.h:49
decomposition_value_type getNumberOfDecompositions(value_type mass) override
Definition: IntegerMassDecomposer.h:525
void fillExtendedResidueTable_(const Weights &_alphabet, residues_table_row_type &_lcms, residues_table_row_type &_mass_in_lcms, const value_type _infty, witness_vector_type &_witness_vector, residues_table_type &_ertable)
Definition: IntegerMassDecomposer.h:193
An interface to handle decomposing of integer values/masses over a set of integer weights (alphabet).
Definition: MassDecomposer.h:42
DecompositionValueType decomposition_value_type
Definition: MassDecomposer.h:52
ValueType value_type
Definition: MassDecomposer.h:47
std::vector< decomposition_type > decompositions_type
Definition: MassDecomposer.h:62
std::vector< decomposition_value_type > decomposition_type
Definition: MassDecomposer.h:57
Represents a set of weights (double values and scaled with a certain precision their integer counterp...
Definition: Weights.h:42
size_type size() const
Definition: Weights.h:98
weight_type getWeight(size_type i) const
Definition: Weights.h:109
T gcd(T a, T b)
Returns the greatest common divisor (gcd) of two numbers by applying the Euclidean algorithm.
Definition: MathFunctions.h:215
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:22