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

Useful base class for most IFunction implementations with some default behavior. More...

#include <FunctionBase.h>

Inheritance diagram for inet::math::FunctionBase< R, D >:
inet::math::IFunction< R, D > inet::math::AddedFunction< R, D > inet::math::ApproximatedFunction< R, D, DIMENSION, X > inet::math::BilinearFunction< R, D > inet::math::ConstantFunction< R, D > inet::math::DomainLimitedFunction< R, D > inet::math::DomainShiftedFunction< R, D > inet::math::LeftCurryingFunction< R, C, DIMSC, D, DIMSD, E > inet::math::MemoizedFunction< R, D > inet::math::MultipliedFunction< R, D > inet::math::SubtractedFunction< R, D > inet::math::SummedFunction< R, D > inet::math::UnilinearFunction< R, D > inet::math::UnireciprocalFunction< R, D >

Public Member Functions

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 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 D::I getDomain () const override
 Returns the valid domain of the function as an interval. More...
 
virtual bool isFinite () const override
 Returns true if the function value is finite in the whole domain. More...
 
virtual bool isFinite (const typename D::I &i) const override
 Returns true if the function value is finite in the given 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...
 
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::IFunction< R, D >
virtual ~IFunction ()
 
virtual R getValue (const typename D::P &p) const =0
 Returns the value of the function at the given point. More...
 

Detailed Description

template<typename R, typename D>
class inet::math::FunctionBase< R, D >

Useful base class for most IFunction implementations with some default behavior.

Member Function Documentation

◆ add()

template<typename R , typename D >
virtual const Ptr<const IFunction<R, D> > inet::math::FunctionBase< R, D >::add ( const Ptr< const IFunction< R, D >> &  o) const
inlineoverridevirtual

Adds the provided function to this function.

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

115  {
116  return makeShared<AddedFunction<R, D>>(const_cast<FunctionBase<R, D> *>(this)->shared_from_this(), o);
117  }

◆ divide()

template<typename R , typename D >
virtual const Ptr<const IFunction<double, D> > inet::math::FunctionBase< R, D >::divide ( const Ptr< const IFunction< R, D >> &  o) const
inlineoverridevirtual

Divides this function with the provided function.

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

127  {
128  return makeShared<DividedFunction<R, D>>(const_cast<FunctionBase<R, D> *>(this)->shared_from_this(), o);
129  }

◆ getDomain()

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

Returns the valid domain of the function as an interval.

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

Reimplemented in inet::math::SummedFunction< R, D >, inet::math::MultipliedFunction< R, D >, inet::math::SubtractedFunction< R, D >, inet::math::DomainShiftedFunction< R, D >, inet::math::DomainLimitedFunction< R, D >, and inet::math::AddedFunction< R, D >.

58  {
59  return typename D::I(D::P::getLowerBounds(), D::P::getUpperBounds(), 0b0, 0b0, 0b0);
60  }

◆ getIntegral() [1/2]

template<typename R , typename D >
virtual R inet::math::FunctionBase< R, D >::getIntegral ( ) const
inlineoverridevirtual

Returns the integral value for the whole domain.

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

103 { return getIntegral(getDomain()); }

Referenced by inet::math::FunctionBase< R, Domain< X > >::getIntegral().

◆ getIntegral() [2/2]

template<typename R , typename D >
virtual R inet::math::FunctionBase< R, D >::getIntegral ( const typename D::I &  i) const
inlineoverridevirtual

Returns the integral value for the given domain.

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

Reimplemented in inet::math::UnireciprocalFunction< R, D >, inet::math::DomainLimitedFunction< R, D >, and inet::math::ConstantFunction< R, D >.

104  {
105  R result(0);
106  this->partition(i, [&] (const typename D::I& i1, const IFunction<R, D> *f1) {
107  double volume = i1.getVolume();
108  R value = f1->getMean(i1);
109  if (!(value == R(0) && std::isinf(volume)))
110  result += volume * value;
111  });
112  return result;
113  }

◆ getMax() [1/2]

template<typename R , typename D >
virtual R inet::math::FunctionBase< R, D >::getMax ( ) const
inlineoverridevirtual

Returns the maximum value for the whole domain.

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

89 { return getMax(getDomain()); }

Referenced by inet::math::FunctionBase< R, Domain< X > >::getMax().

◆ getMax() [2/2]

template<typename R , typename D >
virtual R inet::math::FunctionBase< R, D >::getMax ( const typename D::I &  i) const
inlineoverridevirtual

Returns the maximum value for the given domain.

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

Reimplemented in inet::math::UnireciprocalFunction< R, D >, inet::math::BilinearFunction< R, D >, inet::math::UnilinearFunction< R, D >, inet::math::DomainLimitedFunction< R, D >, and inet::math::ConstantFunction< R, D >.

90  {
91  R result(getLowerBound<R>());
92  this->partition(i, [&] (const typename D::I& i1, const IFunction<R, D> *f1) {
93  result = math::maxnan(f1->getMax(i1), result);
94  });
95  return result;
96  }

◆ getMean() [1/2]

template<typename R , typename D >
virtual R inet::math::FunctionBase< R, D >::getMean ( ) const
inlineoverridevirtual

Returns the mean value for the whole domain.

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

98 { return getMean(getDomain()); }

Referenced by inet::math::FunctionBase< R, Domain< X > >::getMean().

◆ getMean() [2/2]

template<typename R , typename D >
virtual R inet::math::FunctionBase< R, D >::getMean ( const typename D::I &  i) const
inlineoverridevirtual

◆ getMin() [1/2]

template<typename R , typename D >
virtual R inet::math::FunctionBase< R, D >::getMin ( ) const
inlineoverridevirtual

Returns the minimum value for the whole domain.

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

80 { return getMin(getDomain()); }

Referenced by inet::math::FunctionBase< R, Domain< X > >::getMin().

◆ getMin() [2/2]

template<typename R , typename D >
virtual R inet::math::FunctionBase< R, D >::getMin ( const typename D::I &  i) const
inlineoverridevirtual

Returns the minimum value for the given domain.

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

Reimplemented in inet::math::UnireciprocalFunction< R, D >, inet::math::BilinearFunction< R, D >, inet::math::UnilinearFunction< R, D >, inet::math::DomainLimitedFunction< R, D >, and inet::math::ConstantFunction< R, D >.

81  {
82  R result(getUpperBound<R>());
83  this->partition(i, [&] (const typename D::I& i1, const IFunction<R, D> *f1) {
84  result = math::minnan(f1->getMin(i1), result);
85  });
86  return result;
87  }

◆ getRange() [1/2]

template<typename R , typename D >
virtual Interval<R> inet::math::FunctionBase< R, D >::getRange ( ) const
inlineoverridevirtual

Returns the valid range of the function as an interval.

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

Reimplemented in inet::math::BilinearFunction< R, D >, inet::math::UnilinearFunction< R, D >, inet::math::DomainLimitedFunction< R, D >, and inet::math::ConstantFunction< R, D >.

50  {
51  return getRange(getDomain());
52  }

◆ getRange() [2/2]

template<typename R , typename D >
virtual Interval<R> inet::math::FunctionBase< R, D >::getRange ( const typename D::I &  i) const
inlineoverridevirtual

Returns the valid range of the function as an interval for the given domain.

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

54  {
55  return Interval<R>(getLowerBound<R>(), getUpperBound<R>(), 0b1, 0b1, 0b0);
56  }

◆ isFinite() [1/2]

template<typename R , typename D >
virtual bool inet::math::FunctionBase< R, D >::isFinite ( ) const
inlineoverridevirtual

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

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

62 { return isFinite(getDomain()); }

Referenced by inet::math::FunctionBase< R, Domain< X > >::isFinite().

◆ isFinite() [2/2]

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

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

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

Reimplemented in inet::math::ApproximatedFunction< R, D, DIMENSION, X >, inet::math::SummedFunction< R, D >, inet::math::DividedFunction< R, D >, inet::math::MultipliedFunction< R, D >, inet::math::BilinearFunction< R, D >, inet::math::SubtractedFunction< R, D >, inet::math::AddedFunction< R, D >, inet::math::UnilinearFunction< R, D >, and inet::math::ConstantFunction< R, D >.

63  {
64  bool result = true;
65  this->partition(i, [&] (const typename D::I& i1, const IFunction<R, D> *f1) {
66  result &= f1->isFinite(i1);
67  });
68  return result;
69  }

◆ isNonZero() [1/2]

template<typename R , typename D >
virtual bool inet::math::FunctionBase< R, D >::isNonZero ( ) const
inlineoverridevirtual

Returns true if the function value is non-zero in the whole domain.

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

71 { return isNonZero(getDomain()); }

Referenced by inet::math::FunctionBase< R, Domain< X > >::isNonZero().

◆ isNonZero() [2/2]

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

Returns true if the function value is non-zero in the given domain.

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

Reimplemented in inet::math::BilinearFunction< R, D >, inet::math::UnilinearFunction< R, D >, and inet::math::ConstantFunction< R, D >.

72  {
73  bool result = true;
74  this->partition(i, [&] (const typename D::I& i1, const IFunction<R, D> *f1) {
75  result &= f1->isNonZero(i1);
76  });
77  return result;
78  }

◆ multiply()

template<typename R , typename D >
virtual const Ptr<const IFunction<R, D> > inet::math::FunctionBase< R, D >::multiply ( const Ptr< const IFunction< double, D >> &  o) const
inlineoverridevirtual

Multiplies the provided function with this function.

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

123  {
124  return makeShared<MultipliedFunction<R, D>>(const_cast<FunctionBase<R, D> *>(this)->shared_from_this(), o);
125  }

◆ partition()

template<typename R , typename D >
virtual void inet::math::FunctionBase< 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.

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

Reimplemented in inet::math::LeftCurryingFunction< R, C, DIMSC, D, DIMSD, E >, inet::math::SummedFunction< R, D >, inet::math::UnireciprocalFunction< R, D >, inet::math::MultipliedFunction< R, D >, inet::math::BilinearFunction< R, D >, inet::math::SubtractedFunction< R, D >, inet::math::DomainShiftedFunction< R, D >, inet::math::UnilinearFunction< R, D >, inet::math::DomainLimitedFunction< R, D >, inet::math::AddedFunction< R, D >, inet::math::ConstantFunction< R, D >, and inet::math::DividedFunction< R, D >.

39  {
40  auto m = (1 << std::tuple_size<typename D::P::type>::value) - 1;
41  if (i.getFixed() == m) {
42  ASSERT(i.getLower() == i.getUpper());
43  ConstantFunction<R, D> g(this->getValue(i.getLower()));
44  callback(i, &g);
45  }
46  else
47  throw cRuntimeError("Cannot partition %s, interval = %s", this->getClassName(), i.str().c_str());
48  }

Referenced by inet::physicallayer::SpaceAndFrequencyDependentAttenuationFunction::partition(), inet::physicallayer::SpaceDependentAttenuationFunction::partition(), inet::physicallayer::BackgroundNoisePowerFunction::partition(), and inet::physicallayer::PropagatedTransmissionPowerFunction::partition().

◆ print() [1/2]

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

Prints this function in a human readable form to the provided stream for the given domain.

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

140  {
141  os << std::string(level, ' ') << "function" << D() << " → ";
142  printUnit(os, R());
143  os << std::string(level, ' ') << " {\n domain = " << i << " → range = " << getRange() << "\n";
144  os << std::string(level, ' ') << " structure =\n ";
145  printStructure(os, level + 4);
146  os << std::string(level, ' ') << "\n";
147  os << std::string(level, ' ') << " partitioning = {\n";
148  printPartitioning(os, i, level + 4);
149  os << std::string(level, ' ') << " } min = " << getMin(i) << ", max = " << getMax(i) << ", mean = " << getMean(i) << "\n}\n";
150  }

◆ print() [2/2]

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

Prints this function in human readable form to the provided stream for the whole domain.

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

136  {
137  print(os, getDomain(), level);
138  }

◆ printOn()

template<typename R , typename D >
virtual std::ostream& inet::math::FunctionBase< R, D >::printOn ( std::ostream &  os) const
inlineoverridevirtual
131  {
132  print(os);
133  return os;
134  }

◆ printPartition()

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

Prints a single partition of this function in a human readable form to the provided stream for the given domain.

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

Reimplemented in inet::math::UnireciprocalFunction< R, D >, inet::math::BilinearFunction< R, D >, inet::math::UnilinearFunction< R, D >, and inet::math::ConstantFunction< R, D >.

159  {
160  os << "over " << i << " → {";
161  iterateCorners(i, std::function<void(const typename D::P&)>([&] (const typename D::P& p) {
162  os << "\n" << std::string(level + 2, ' ') << "at " << p << " → " << this->getValue(p);
163  }));
164  os << "\n" << std::string(level, ' ') << "} min = " << getMin(i) << ", max = " << getMax(i) << ", mean = " << getMean(i) << "\n";
165  }

◆ printPartitioning()

template<typename R , typename D >
virtual void inet::math::FunctionBase< R, D >::printPartitioning ( std::ostream &  os,
const typename D::I &  i,
int  level 
) const
inlineoverridevirtual

Prints the partitioning of this function in a human readable form to the provided stream for the given domain.

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

152  {
153  this->partition(i, [&] (const typename D::I& i1, const IFunction<R, D> *f1) {
154  os << std::string(level, ' ');
155  f1->printPartition(os, i1, level);
156  });
157  }

◆ printStructure()

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

◆ subtract()

template<typename R , typename D >
virtual const Ptr<const IFunction<R, D> > inet::math::FunctionBase< R, D >::subtract ( const Ptr< const IFunction< R, D >> &  o) const
inlineoverridevirtual

Substracts the provided function from this function.

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

119  {
120  return makeShared<SubtractedFunction<R, D>>(const_cast<FunctionBase<R, D> *>(this)->shared_from_this(), o);
121  }

The documentation for this class was generated from the following file:
inet::math::FunctionBase::getRange
virtual Interval< R > getRange() const override
Returns the valid range of the function as an interval.
Definition: FunctionBase.h:50
inet::math::FunctionBase::getMean
virtual R getMean() const override
Returns the mean value for the whole domain.
Definition: FunctionBase.h:98
inet::math::IFunction::getValue
virtual R getValue(const typename D::P &p) const =0
Returns the value of the function at the given point.
inet::math::FunctionBase::getDomain
virtual D::I getDomain() const override
Returns the valid domain of the function as an interval.
Definition: FunctionBase.h:58
inet::units::units::g
milli< kg >::type g
Definition: Units.h:1071
inet::math::maxnan
const T maxnan(const T &a, const T &b)
This function properly and symmetrically handles NaNs in contrast with std::max and std::fmax.
Definition: INETMath.h:234
inet::math::FunctionBase::isNonZero
virtual bool isNonZero() const override
Returns true if the function value is non-zero in the whole domain.
Definition: FunctionBase.h:71
inet::units::constants::R
const value< double, compose< units::J, compose< pow< units::mol, -1 >, pow< units::kg, -1 > > > > R(8.314472)
inet::math::FunctionBase::getMin
virtual R getMin() const override
Returns the minimum value for the whole domain.
Definition: FunctionBase.h:80
inet::math::FunctionBase::getIntegral
virtual R getIntegral() const override
Returns the integral value for the whole domain.
Definition: FunctionBase.h:103
inet::math::FunctionBase::printStructure
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.
Definition: FunctionBase.h:167
inet::math::FunctionBase::print
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.
Definition: FunctionBase.h:136
inet::math::FunctionBase::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: FunctionBase.h:39
inet::math::printUnit
void printUnit(std::ostream &os, T v)
Definition: Point.h:19
inet::math::FunctionBase::printPartitioning
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 give...
Definition: FunctionBase.h:152
inet::math::FunctionBase::getMax
virtual R getMax() const override
Returns the maximum value for the whole domain.
Definition: FunctionBase.h:89
inet::math::minnan
const T minnan(const T &a, const T &b)
This function properly and symmetrically handles NaNs in contrast with std::min and std::fmin.
Definition: INETMath.h:216
inet::math::iterateCorners
void iterateCorners(const Interval<> &i, const std::function< void(const Point<> &)> f)
Definition: Interval.h:186
inet::units::values::m
value< double, units::m > m
Definition: Units.h:1233
inet::math::FunctionBase::isFinite
virtual bool isFinite() const override
Returns true if the function value is finite in the whole domain.
Definition: FunctionBase.h:62