INET Framework for OMNeT++/OMNEST
inet::math::SummedFunction< R, D > Class Template Reference

#include <AlgebraicOperations.h>

Inheritance diagram for inet::math::SummedFunction< R, D >:
inet::math::FunctionBase< R, D > inet::math::IFunction< R, D >

Public Member Functions

 SummedFunction ()
 
 SummedFunction (const std::vector< Ptr< const IFunction< R, D >>> &functions)
 
const std::vector< Ptr< const IFunction< R, D > > > & getElements () const
 
virtual void addElement (const Ptr< const IFunction< R, D >> &f)
 
virtual void removeElement (const Ptr< const IFunction< R, D >> &f)
 
virtual D::I getDomain () const override
 Returns the valid domain of the function as an interval. More...
 
virtual R getValue (const typename D::P &p) const override
 Returns the value of the function at the given point. More...
 
virtual void partition (const typename D::I &i, const std::function< void(const typename D::I &, const IFunction< R, D > *)> callback) const override
 Subdivides the provided domain and calls back f with the subdomains and the corresponding potentially simpler domain limited functions. More...
 
virtual void partition (int index, const typename D::I &i, const std::function< void(const typename D::I &, const IFunction< R, D > *)> callback, const IFunction< R, D > *f) const
 
virtual bool isFinite (const typename D::I &i) const override
 Returns true if the function value is finite in the given domain. More...
 
virtual void printStructure (std::ostream &os, int level=0) const override
 Prints the internal data structure of this function in a human readable form to the provided stream. More...
 
- Public Member Functions inherited from inet::math::FunctionBase< R, D >
virtual Interval< R > getRange () const override
 Returns the valid range of the function as an interval. More...
 
virtual Interval< R > getRange (const typename D::I &i) const override
 Returns the valid range of the function as an interval for the given domain. More...
 
virtual bool isFinite () const override
 Returns true if the function value is finite in the whole domain. More...
 
virtual bool isNonZero () const override
 Returns true if the function value is non-zero in the whole domain. More...
 
virtual bool isNonZero (const typename D::I &i) const override
 Returns true if the function value is non-zero in the given domain. More...
 
virtual R getMin () const override
 Returns the minimum value for the whole domain. More...
 
virtual R getMin (const typename D::I &i) const override
 Returns the minimum value for the given domain. More...
 
virtual R getMax () const override
 Returns the maximum value for the whole domain. More...
 
virtual R getMax (const typename D::I &i) const override
 Returns the maximum value for the given domain. More...
 
virtual R getMean () const override
 Returns the mean value for the whole domain. More...
 
virtual R getMean (const typename D::I &i) const override
 Returns the mean value for the given domain. More...
 
virtual R getIntegral () const override
 Returns the integral value for the whole domain. More...
 
virtual R getIntegral (const typename D::I &i) const override
 Returns the integral value for the given domain. More...
 
virtual const Ptr< const IFunction< R, D > > add (const Ptr< const IFunction< R, D >> &o) const override
 Adds the provided function to this function. More...
 
virtual const Ptr< const IFunction< R, D > > subtract (const Ptr< const IFunction< R, D >> &o) const override
 Substracts the provided function from this function. More...
 
virtual const Ptr< const IFunction< R, D > > multiply (const Ptr< const IFunction< double, D >> &o) const override
 Multiplies the provided function with this function. More...
 
virtual const Ptr< const IFunction< double, D > > divide (const Ptr< const IFunction< R, D >> &o) const override
 Divides this function with the provided function. More...
 
virtual std::ostream & printOn (std::ostream &os) const override
 
virtual void print (std::ostream &os, int level=0) const override
 Prints this function in human readable form to the provided stream for the whole domain. More...
 
virtual void print (std::ostream &os, const typename D::I &i, int level=0) const override
 Prints this function in a human readable form to the provided stream for the given domain. More...
 
virtual void printPartitioning (std::ostream &os, const typename D::I &i, int level) const override
 Prints the partitioning of this function in a human readable form to the provided stream for the given domain. More...
 
virtual void printPartition (std::ostream &os, const typename D::I &i, int level=0) const override
 Prints a single partition of this function in a human readable form to the provided stream for the given domain. More...
 
- Public Member Functions inherited from inet::math::IFunction< R, D >
virtual ~IFunction ()
 

Protected Attributes

std::vector< Ptr< const IFunction< R, D > > > functions
 

Constructor & Destructor Documentation

◆ SummedFunction() [1/2]

template<typename R , typename D >
inet::math::SummedFunction< R, D >::SummedFunction ( )
inline
344 {}

◆ SummedFunction() [2/2]

template<typename R , typename D >
inet::math::SummedFunction< R, D >::SummedFunction ( const std::vector< Ptr< const IFunction< R, D >>> &  functions)
inline
345 : functions(functions) {}

Member Function Documentation

◆ addElement()

template<typename R , typename D >
virtual void inet::math::SummedFunction< R, D >::addElement ( const Ptr< const IFunction< R, D >> &  f)
inlinevirtual
349  {
350  functions.push_back(f);
351  }

◆ getDomain()

template<typename R , typename D >
virtual D::I inet::math::SummedFunction< R, D >::getDomain ( ) const
inlineoverridevirtual

Returns the valid domain of the function as an interval.

Reimplemented from inet::math::FunctionBase< R, D >.

357  {
358  typename D::I domain(D::P::getLowerBounds(), D::P::getUpperBounds(), 0, 0, 0);
359  for (const auto& f : functions)
360  domain = domain.getIntersected(f->getDomain());
361  return domain;
362  }

◆ getElements()

template<typename R , typename D >
const std::vector<Ptr<const IFunction<R, D> > >& inet::math::SummedFunction< R, D >::getElements ( ) const
inline
347 { return functions; }

◆ getValue()

template<typename R , typename D >
virtual R inet::math::SummedFunction< R, D >::getValue ( const typename D::P &  p) const
inlineoverridevirtual

Returns the value of the function at the given point.

The returned value falls into the range of the function. The provided point must fall into the domain of the function.

Implements inet::math::IFunction< R, D >.

364  {
365  R sum = R(0);
366  for (const auto& f : functions)
367  sum += f->getValue(p);
368  return sum;
369  }

◆ isFinite()

template<typename R , typename D >
virtual bool inet::math::SummedFunction< R, D >::isFinite ( const typename D::I &  i) const
inlineoverridevirtual

Returns true if the function value is finite in the given domain.

Reimplemented from inet::math::FunctionBase< R, D >.

415  {
416  for (const auto& f : functions)
417  if (!f->isFinite(i))
418  return false;
419  return true;
420  }

◆ partition() [1/2]

template<typename R , typename D >
virtual void inet::math::SummedFunction< R, D >::partition ( const typename D::I &  i,
const std::function< void(const typename D::I &, const IFunction< R, D > *)>  f 
) const
inlineoverridevirtual

Subdivides the provided domain and calls back f with the subdomains and the corresponding potentially simpler domain limited functions.

Reimplemented from inet::math::FunctionBase< R, D >.

371  {
372  ConstantFunction<R, D> g(R(0));
373  partition(0, i, callback, &g);
374  }

◆ partition() [2/2]

template<typename R , typename D >
virtual void inet::math::SummedFunction< R, D >::partition ( int  index,
const typename D::I &  i,
const std::function< void(const typename D::I &, const IFunction< R, D > *)>  callback,
const IFunction< R, D > *  f 
) const
inlinevirtual
376  {
377  if (index == (int)functions.size())
378  simplifyAndCall(i, f, callback);
379  else {
380  functions[index]->partition(i, [&] (const typename D::I& i1, const IFunction<R, D> *f1) {
381  if (auto fc = dynamic_cast<const ConstantFunction<R, D> *>(f)) {
382  if (auto f1c = dynamic_cast<const ConstantFunction<R, D> *>(f1)) {
383  ConstantFunction<R, D> g(fc->getConstantValue() + f1c->getConstantValue());
384  partition(index + 1, i1, callback, &g);
385  }
386  else if (auto f1l = dynamic_cast<const UnilinearFunction<R, D> *>(f1)) {
387  UnilinearFunction<R, D> g(i1.getLower(), i1.getUpper(), f1l->getValue(i1.getLower()) + fc->getConstantValue(), f1l->getValue(i1.getUpper()) + fc->getConstantValue(), f1l->getDimension());
388  partition(index + 1, i1, callback, &g);
389  }
390  else
391  throw cRuntimeError("TODO");
392  }
393  else if (auto fl = dynamic_cast<const UnilinearFunction<R, D> *>(f)) {
394  if (auto f1c = dynamic_cast<const ConstantFunction<R, D> *>(f1)) {
395  UnilinearFunction<R, D> g(i1.getLower(), i1.getUpper(), fl->getValue(i1.getLower()) + f1c->getConstantValue(), fl->getValue(i1.getUpper()) + f1c->getConstantValue(), fl->getDimension());
396  partition(index + 1, i1, callback, &g);
397  }
398  else if (auto f1l = dynamic_cast<const UnilinearFunction<R, D> *>(f1)) {
399  if (fl->getDimension() == f1l->getDimension()) {
400  UnilinearFunction<R, D> g(i1.getLower(), i1.getUpper(), fl->getValue(i1.getLower()) + f1l->getValue(i1.getLower()), fl->getValue(i1.getUpper()) + f1l->getValue(i1.getUpper()), fl->getDimension());
401  partition(index + 1, i1, callback, &g);
402  }
403  else
404  throw cRuntimeError("TODO");
405  }
406  else
407  throw cRuntimeError("TODO");
408  }
409  else
410  throw cRuntimeError("TODO");
411  });
412  }
413  }

◆ printStructure()

template<typename R , typename D >
virtual void inet::math::SummedFunction< R, D >::printStructure ( std::ostream &  os,
int  level = 0 
) const
inlineoverridevirtual

Prints the internal data structure of this function in a human readable form to the provided stream.

Reimplemented from inet::math::FunctionBase< R, D >.

422  {
423  os << "(Σ ";
424  bool first = true;
425  for (const auto& f : functions) {
426  if (first)
427  first = false;
428  else
429  os << "\n" << std::string(level + 3, ' ');
430  f->printStructure(os, level + 3);
431  }
432  os << ")";
433  }

◆ removeElement()

template<typename R , typename D >
virtual void inet::math::SummedFunction< R, D >::removeElement ( const Ptr< const IFunction< R, D >> &  f)
inlinevirtual
353  {
354  functions.erase(std::remove(functions.begin(), functions.end(), f), functions.end());
355  }

Member Data Documentation

◆ functions

template<typename R , typename D >
std::vector<Ptr<const IFunction<R, D> > > inet::math::SummedFunction< R, D >::functions
protected

The documentation for this class was generated from the following file:
inet::remove
void remove(std::vector< T > &v, const Tk &a)
Definition: stlutils.h:107
inet::units::units::g
milli< kg >::type g
Definition: Units.h:1071
inet::units::constants::R
const value< double, compose< units::J, compose< pow< units::mol, -1 >, pow< units::kg, -1 > > > > R(8.314472)
inet::math::SummedFunction::functions
std::vector< Ptr< const IFunction< R, D > > > functions
Definition: AlgebraicOperations.h:341
inet::math::simplifyAndCall
void simplifyAndCall(const typename D::I &i, const IFunction< R, D > *f, const std::function< void(const typename D::I &, const IFunction< R, D > *)> callback)
Definition: PrimitiveFunctions.h:776
inet::math::SummedFunction::partition
virtual void partition(const typename D::I &i, const std::function< void(const typename D::I &, const IFunction< R, D > *)> callback) const override
Subdivides the provided domain and calls back f with the subdomains and the corresponding potentially...
Definition: AlgebraicOperations.h:371