Public Types | Static Public Member Functions | Static Private Member Functions | Static Private Attributes

MappingUtils Class Reference
[mapping - classes representing mathematical mappings]

Provides several utility methods for Mappings. More...

#include <MappingUtils.h>

List of all members.

Public Types

typedef std::list< ConstMapping * > MappingBuffer

Static Public Member Functions

static MappingcreateMapping (const DimensionSet &domain=DimensionSet(Dimension::time_static()), Mapping::InterpolationMethod intpl=Mapping::LINEAR)
 Returns an appropriate changeable Mapping with the specified domain and the specified interpolation method.
static MappingcreateMapping (double outOfRangeValue, const DimensionSet &domain=DimensionSet(Dimension::time_static()), Mapping::InterpolationMethod intpl=Mapping::LINEAR)
 Returns an appropriate changeable Mapping with the specified domain and the specified interpolation method.
template<class Operator >
static MappingapplyElementWiseOperator (ConstMapping &f1, ConstMapping &f2, const Argument &intvlStart, const Argument &intvlEnd, Operator op)
template<class Operator >
static MappingapplyElementWiseOperator (ConstMapping &f1, ConstMapping &f2, Operator op, double outOfRangeVal=0.0, bool contOutOfRange=true)
static Mappingmultiply (ConstMapping &f1, ConstMapping &f2)
 Multiplies the passed functions element-wise with each other and returns the result in a new Function.
static Mappingadd (ConstMapping &f1, ConstMapping &f2)
static Mappingsubtract (ConstMapping &f1, ConstMapping &f2)
static Mappingdivide (ConstMapping &f1, ConstMapping &f2)
static Mappingmultiply (ConstMapping &f1, ConstMapping &f2, double outOfRangeVal)
static Mappingadd (ConstMapping &f1, ConstMapping &f2, double outOfRangeVal)
static Mappingsubtract (ConstMapping &f1, ConstMapping &f2, double outOfRangeVal)
static Mappingdivide (ConstMapping &f1, ConstMapping &f2, double outOfRangeVal)
static double findMax (ConstMapping &m)
 Iterates over the passed mapping and returns value at the key entry with the highest value.
static double findMax (ConstMapping &m, const Argument &min, const Argument &max)
 Iterates over the passed mapping and returns the value at the key entry with the highest value in the range defined by the passed min and max parameter.
static double findMin (ConstMapping &m)
 Iterates over the passed mapping and returns value at the key entry with the smallest value.
static double findMin (ConstMapping &m, const Argument &min, const Argument &max)
 Iterates over the passed mapping and returns the value at the key entry with the smallest value in the range defined by the passed min and max parameter.
static void addDiscontinuity (Mapping *m, const Argument &pos, double value, simtime_t limitTime, double limitValue)
 Adds a discontinuity in time-dimension, i.e. its representation, to a passed mapping.
static simtime_t pre (simtime_t t)
 returns the closest value of simtime before passed value
static simtime_t post (simtime_t t)
 returns the closest value of simtime after passed values

Static Private Member Functions

static void freeMappingBuffer (ConstMapping *m)
static ConstMappingsetMappingBuffer (ConstMapping *mapping)
static ConstMappingcreateCompatibleMapping (ConstMapping &src, ConstMapping &dst)
static bool iterateToNext (ConstMappingIterator *it1, ConstMappingIterator *it2)

Static Private Attributes

static MappingBuffer mappingBuffer

Detailed Description

Provides several utility methods for Mappings.

Author:
Karl Wessel

Definition at line 1743 of file MappingUtils.h.


Member Function Documentation

void MappingUtils::addDiscontinuity ( Mapping m,
const Argument pos,
double  value,
simtime_t  limitTime,
double  limitValue 
) [static]

Adds a discontinuity in time-dimension, i.e. its representation, to a passed mapping.

This is done by setting a regular entry and a limit-entry. The limit-entry shall be very close to the regular entry (on its left or right).

The implementation works simply by adding the limit-value as a separate entry at the position of the limit-time. This means that this methods adds a total of two entries to the passed mapping.

Note: One should use the methods 'pre' or 'post' provided by MappingUtils to calculate the limit-time for the discontinuity.

Parameters:
m The mapping the discontinuity will be added to.
pos The position of the regular entry.
value The value of the regular entry.
limitTime The time-point of the limit-entry.
limitValue The value of the limit-entry.

Definition at line 335 of file MappingUtils.cc.

References Argument::getTime(), Argument::setTime(), and Mapping::setValue().

Referenced by BaseMacLayer::createRectangleMapping().

{
  // asserts/preconditions
  // make sure the time really differs at the discontinuity
  assert(limitTime != pos.getTime());

  // add (pos, value) to mapping
  m->setValue(pos, value);

  // create Argument limitPos for the limit-position, i.e. copy pos and set limitTime as its time
  Argument limitPos = pos;
  limitPos.setTime(limitTime);

  // add (limitPos, limitValue) to mapping
  m->setValue(limitPos, limitValue);
}

Mapping * MappingUtils::createMapping ( const DimensionSet domain = DimensionSet(Dimension::time_static()),
Mapping::InterpolationMethod  intpl = Mapping::LINEAR 
) [static]

Returns an appropriate changeable Mapping with the specified domain and the specified interpolation method.

Note: The interpolation method is always linear, at the moment.

Definition at line 90 of file MappingUtils.cc.

References DimensionSet::hasDimension(), Mapping::LINEAR, Mapping::NEAREST, Mapping::STEPS, and Dimension::time.

Referenced by BaseDecider::calculateRSSIMapping(), BaseMacLayer::createConstantMapping(), BaseMacLayer::createRectangleMapping(), Mac80211::createSignal(), BaseMacLayer::createSingleFrequencyMapping(), LogNormalShadowing::filterSignal(), RandomFrequencyOnlyModel::filterSignal(), and RandomFreqTimeModel::filterSignal().

                                                    {
  assert(domain.hasDimension(Dimension::time));

  if(domain.size() == 1){
    switch(intpl){
    case Mapping::LINEAR:
      return new TimeMapping<Linear>(intpl);
      break;
    case Mapping::NEAREST:
      return new TimeMapping<Nearest>(intpl);
      break;
    case Mapping::STEPS:
      return new TimeMapping<NextSmaller>(intpl);
      break;
    }
    return 0;
  } else {
    switch(intpl){
    case Mapping::LINEAR:
      return new MultiDimMapping<Linear>(domain, intpl);
      break;
    case Mapping::NEAREST:
      return new MultiDimMapping<Nearest>(domain, intpl);
      break;
    case Mapping::STEPS:
      return new MultiDimMapping<NextSmaller>(domain, intpl);
      break;
    }
    return 0;
  }
}

Mapping * MappingUtils::createMapping ( double  outOfRangeValue,
const DimensionSet domain = DimensionSet(Dimension::time_static()),
Mapping::InterpolationMethod  intpl = Mapping::LINEAR 
) [static]

Returns an appropriate changeable Mapping with the specified domain and the specified interpolation method.

Note: The interpolation method is always linear, at the moment.

Definition at line 123 of file MappingUtils.cc.

References DimensionSet::hasDimension(), Mapping::LINEAR, Mapping::NEAREST, Mapping::STEPS, and Dimension::time.

                                                  {
  assert(domain.hasDimension(Dimension::time));

  if(domain.size() == 1){
    switch(intpl){
    case Mapping::LINEAR:
      return new TimeMapping<Linear>(outOfRangeVal, intpl);
      break;
    case Mapping::NEAREST:
      return new TimeMapping<Nearest>(outOfRangeVal, intpl);
      break;
    case Mapping::STEPS:
      return new TimeMapping<NextSmaller>(outOfRangeVal, intpl);
      break;
    }
    return 0;
  } else {
    switch(intpl){
    case Mapping::LINEAR:
      return new MultiDimMapping<Linear>(domain, outOfRangeVal, intpl);
      break;
    case Mapping::NEAREST:
      return new MultiDimMapping<Nearest>(domain, outOfRangeVal, intpl);
      break;
    case Mapping::STEPS:
      return new MultiDimMapping<NextSmaller>(domain, outOfRangeVal, intpl);
      break;
    }
    return 0;
  }
}

double MappingUtils::findMax ( ConstMapping m,
const Argument min,
const Argument max 
) [static]

Iterates over the passed mapping and returns the value at the key entry with the highest value in the range defined by the passed min and max parameter.

The area defined by the min and max parameter is the number of key entries which position in each dimension is bigger or equal than the value of the min parameter in that dimension and smaller or equal than max parameter in that dimension.

Definition at line 237 of file MappingUtils.cc.

References Argument::begin(), Argument::compare(), ConstMapping::createConstIterator(), Argument::end(), Argument::getArgValue(), Argument::getDimensions(), ConstMapping::getDimensionSet(), ConstMappingIterator::getNextPosition(), ConstMappingIterator::getPosition(), Argument::getTime(), ConstMappingIterator::getValue(), ConstMappingIterator::hasNext(), DimensionSet::isSubSet(), ConstMappingIterator::iterateTo(), and ConstMappingIterator::next().

                                                                                     {
  //the passed interval should define a value for every dimension
  //of the mapping.
  assert(min.getDimensions().isSubSet(m.getDimensionSet()));
  assert(max.getDimensions().isSubSet(m.getDimensionSet()));

  ConstMappingIterator* it = m.createConstIterator(min);

  double res = it->getValue();

  while(it->hasNext() && it->getNextPosition().compare(max, m.getDimensionSet()) < 0){
    it->next();

    const Argument& next = it->getPosition();
    bool inRange = next.getTime() >= min.getTime() && next.getTime() <= max.getTime();
    if(inRange) {
      for(Argument::const_iterator itA = next.begin(); itA != next.end(); ++itA) {
        if(itA->second < min.getArgValue(itA->first) || itA->second > max.getArgValue(itA->first)) {
          inRange = false;
          break;
        }
      }
    }

    if(inRange) {
      double val = it->getValue();
      if(val > res)
        res = val;
    }
  }
  it->iterateTo(max);
  double val = it->getValue();
  if(val > res)
    res = val;

  delete it;
  return res;
}

double MappingUtils::findMin ( ConstMapping m,
const Argument min,
const Argument max 
) [static]

Iterates over the passed mapping and returns the value at the key entry with the smallest value in the range defined by the passed min and max parameter.

The area defined by the min and max parameter is the number of key entries which position in each dimension is bigger or equal than the value of the min parameter in that dimension and smaller or equal than max parameter in that dimension.

Definition at line 295 of file MappingUtils.cc.

References Argument::begin(), Argument::compare(), ConstMapping::createConstIterator(), Argument::end(), Argument::getArgValue(), Argument::getDimensions(), ConstMapping::getDimensionSet(), ConstMappingIterator::getNextPosition(), ConstMappingIterator::getPosition(), Argument::getTime(), ConstMappingIterator::getValue(), ConstMappingIterator::hasNext(), DimensionSet::isSubSet(), ConstMappingIterator::iterateTo(), and ConstMappingIterator::next().

                                                                                     {

  //the passed interval should define a value for every dimension
  //of the mapping.
  assert(min.getDimensions().isSubSet(m.getDimensionSet()));
  assert(max.getDimensions().isSubSet(m.getDimensionSet()));

  ConstMappingIterator* it = m.createConstIterator(min);

  double res = it->getValue();

  while(it->hasNext() && it->getNextPosition().compare(max, m.getDimensionSet()) < 0){
    it->next();

    const Argument& next = it->getPosition();
    bool inRange = next.getTime() >= min.getTime() && next.getTime() <= max.getTime();
    if(inRange) {
      for(Argument::const_iterator itA = next.begin(); itA != next.end(); ++itA) {
        if(itA->second < min.getArgValue(itA->first) || itA->second > max.getArgValue(itA->first)) {
          inRange = false;
          break;
        }
      }
    }

    if(inRange) {
      double val = it->getValue();
      if(val < res)
        res = val;
    }
  }
  it->iterateTo(max);
  double val = it->getValue();
  if(val < res)
    res = val;
  delete it;
  return res;
}

Mapping * MappingUtils::multiply ( ConstMapping f1,
ConstMapping f2 
) [static]

Multiplies the passed functions element-wise with each other and returns the result in a new Function.

The domain (DimensionSet) of the result is defined by the domain of the first operand. The domain of the second Mapping has to be a subset of the domain of the first mapping.

Definition at line 157 of file MappingUtils.cc.

Referenced by ThresholdDecider::handleSignalOver().

{
  return applyElementWiseOperator(f1, f2, std::multiplies<double>());
}


The documentation for this class was generated from the following files: