INET Framework for OMNeT++/OMNEST
inet::physicallayer::MappingUtils Class Reference

Provides several utility methods for Mappings. More...

#include <MappingUtils.h>

Public Types

typedef std::list< const ConstMapping * > MappingBuffer
 

Static Public Member Functions

static MappingcreateMapping (const DimensionSet &domain=DimensionSet(Dimension::time), Mapping::InterpolationMethod intpl=Mapping::LINEAR)
 Returns an appropriate changeable Mapping with the specified domain and the specified interpolation method. More...
 
static MappingcreateMapping (Mapping::argument_value_cref_t outOfRangeValue, const DimensionSet &domain=DimensionSet(Dimension::time), Mapping::InterpolationMethod intpl=Mapping::LINEAR)
 Returns an appropriate changeable Mapping with the specified domain and the specified interpolation method. More...
 
template<class Operator >
static MappingapplyElementWiseOperator (const ConstMapping &f1, const ConstMapping &f2, const Argument &intvlStart, const Argument &intvlEnd, Operator op)
 
template<class Operator >
static MappingapplyElementWiseOperator (const ConstMapping &f1, const ConstMapping &f2, Operator op, Mapping::argument_value_cref_t outOfRangeVal=Argument::MappedZero, bool contOutOfRange=true)
 
static Mappingmultiply (const ConstMapping &f1, const ConstMapping &f2)
 Multiplies the passed functions element-wise with each other and returns the result in a new Function. More...
 
static Mappingadd (const ConstMapping &f1, const ConstMapping &f2)
 
static Mappingsubtract (const ConstMapping &f1, const ConstMapping &f2)
 
static Mappingdivide (const ConstMapping &f1, const ConstMapping &f2)
 
static Mappingmultiply (const ConstMapping &f1, const ConstMapping &f2, Mapping::argument_value_cref_t outOfRangeVal)
 
static Mappingadd (const ConstMapping &f1, const ConstMapping &f2, Mapping::argument_value_cref_t outOfRangeVal)
 
static Mappingsubtract (const ConstMapping &f1, const ConstMapping &f2, Mapping::argument_value_cref_t outOfRangeVal)
 
static Mappingdivide (const ConstMapping &f1, const ConstMapping &f2, Mapping::argument_value_cref_t outOfRangeVal)
 
static Argument::mapped_type findMax (const ConstMapping &m, Argument::mapped_type_cref cRetNotFound=cMaxNotFound)
 Iterates over the passed mapping and returns value at the key entry with the highest value. More...
 
static Argument::mapped_type findMax (const ConstMapping &m, const Argument &min, const Argument &max, Argument::mapped_type_cref cRetNotFound=cMaxNotFound)
 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. More...
 
static Argument::mapped_type findMin (const ConstMapping &m, Argument::mapped_type_cref cRetNotFound=cMinNotFound)
 Iterates over the passed mapping and returns value at the key entry with the smallest value. More...
 
static Argument::mapped_type findMin (const ConstMapping &m, const Argument &min, const Argument &max, Argument::mapped_type_cref cRetNotFound=cMinNotFound)
 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. More...
 
static void addDiscontinuity (Mapping *m, const Argument &pos, Argument::mapped_type_cref value, simtime_t_cref limitTime, Argument::mapped_type_cref limitValue)
 Adds a discontinuity in time-dimension, i.e. More...
 
static simtime_t pre (simtime_t_cref t)
 returns the closest value of simtime before passed value More...
 
static simtime_t post (simtime_t_cref t)
 returns the closest value of simtime after passed values More...
 
static simtime_t incNextPosition (simtime_t_cref t)
 returns the incremented position point (used in RSAMConstMappingIterator::setNextPosition). More...
 

Static Public Attributes

static const Argument::mapped_type cMinNotFound = std::numeric_limits<Argument::mapped_type>::infinity()
 The default value for findMin() functions if it does not find a minimum element. More...
 
static const Argument::mapped_type cMaxNotFound = -std::numeric_limits<Argument::mapped_type>::infinity()
 The default value for findMax() functions if it does not find a maximum element. More...
 

Static Private Member Functions

static const ConstMappingcreateCompatibleMapping (const ConstMapping &src, const ConstMapping &dst)
 
static bool iterateToNext (ConstMappingIterator *it1, ConstMappingIterator *it2)
 

Detailed Description

Provides several utility methods for Mappings.

Author
Karl Wessel

Member Typedef Documentation

Member Function Documentation

Mapping * inet::physicallayer::MappingUtils::add ( const ConstMapping f1,
const ConstMapping f2 
)
static

Referenced by inet::physicallayer::operator+().

188 {
189  return applyElementWiseOperator(f1, f2, std::plus<Mapping::argument_value_t>());
190 }
static Mapping * applyElementWiseOperator(const ConstMapping &f1, const ConstMapping &f2, const Argument &intvlStart, const Argument &intvlEnd, Operator op)
Definition: MappingUtils.h:2272
Mapping * inet::physicallayer::MappingUtils::add ( const ConstMapping f1,
const ConstMapping f2,
Mapping::argument_value_cref_t  outOfRangeVal 
)
static
208 {
209  return applyElementWiseOperator(f1, f2, std::plus<Mapping::argument_value_t>(), outOfRangeVal, false);
210 }
static Mapping * applyElementWiseOperator(const ConstMapping &f1, const ConstMapping &f2, const Argument &intvlStart, const Argument &intvlEnd, Operator op)
Definition: MappingUtils.h:2272
void inet::physicallayer::MappingUtils::addDiscontinuity ( Mapping m,
const Argument pos,
Argument::mapped_type_cref  value,
simtime_t_cref  limitTime,
Argument::mapped_type_cref  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
mThe mapping the discontinuity will be added to.
posThe position of the regular entry.
valueThe value of the regular entry.
limitTimeThe time-point of the limit-entry.
limitValueThe value of the limit-entry.
410 {
411  // asserts/preconditions
412  // make sure the time really differs at the discontinuity
413  assert(limitTime != pos.getTime());
414 
415  // add (pos, value) to mapping
416  m->setValue(pos, value);
417 
418  // create Argument limitPos for the limit-position, i.e. copy pos and set limitTime as its time
419  Argument limitPos = pos;
420  limitPos.setTime(limitTime);
421 
422  // add (limitPos, limitValue) to mapping
423  m->setValue(limitPos, limitValue);
424 }
value< double, units::m > m
Definition: Units.h:1047
template<class Operator >
static Mapping* inet::physicallayer::MappingUtils::applyElementWiseOperator ( const ConstMapping f1,
const ConstMapping f2,
const Argument intvlStart,
const Argument intvlEnd,
Operator  op 
)
inlinestatic
template<class Operator >
static Mapping* inet::physicallayer::MappingUtils::applyElementWiseOperator ( const ConstMapping f1,
const ConstMapping f2,
Operator  op,
Mapping::argument_value_cref_t  outOfRangeVal = Argument::MappedZero,
bool  contOutOfRange = true 
)
inlinestatic
2284  {
2285  using std::operator<<;
2286 
2287  const ConstMapping *const f2Comp = createCompatibleMapping(f2, f1);
2288  const ConstMapping *const f1Comp = createCompatibleMapping(f1, f2);
2289 
2290  const DimensionSet& domain = f1Comp->getDimensionSet();
2291  Mapping *const result = (contOutOfRange) ? MappingUtils::createMapping(domain) : MappingUtils::createMapping(outOfRangeVal, domain);
2292 
2293  ConstMappingIterator *const itF1 = f1Comp->createConstIterator();
2294  ConstMappingIterator *const itF2 = f2Comp->createConstIterator();
2295  const bool bF1InRange = itF1->inRange();
2296  const bool bF2InRange = itF2->inRange();
2297 
2298  if (!bF1InRange && !bF2InRange) {
2299  delete itF1;
2300  delete itF2;
2301  return result;
2302  }
2303 
2304  MappingIterator *itRes = 0;
2305 
2306  if (bF1InRange && (!bF2InRange || itF1->getPosition() < itF2->getPosition())) {
2307  itF2->jumpTo(itF1->getPosition());
2308  }
2309  else {
2310  itF1->jumpTo(itF2->getPosition());
2311  }
2312 
2313  itRes = result->createIterator(itF1->getPosition());
2314 
2315  while (itF1->inRange() || itF2->inRange()) {
2316 // assert(itF1->getPosition().isSamePosition(itF2->getPosition()));
2317 
2318  Mapping::argument_value_cref_t prod = op(itF1->getValue(), itF2->getValue());
2319  //result->setValue(itF1->getPosition(), prod);
2320  itRes->setValue(prod);
2321 
2322  if (!iterateToNext(itF1, itF2))
2323  break;
2324 
2325  itRes->iterateTo(itF1->getPosition());
2326  }
2327 
2328  delete itF1;
2329  delete itF2;
2330  delete itRes;
2331 
2332  if (&f2 != f2Comp)
2333  delete (f2Comp);
2334  if (&f1 != f1Comp)
2335  delete (f1Comp);
2336 
2337  return result;
2338  }
Argument::mapped_type_cref argument_value_cref_t
Definition: MappingBase.h:875
static bool iterateToNext(ConstMappingIterator *it1, ConstMappingIterator *it2)
Definition: MappingUtils.cc:81
static const ConstMapping * createCompatibleMapping(const ConstMapping &src, const ConstMapping &dst)
Definition: MappingUtils.cc:37
static Mapping * createMapping(const DimensionSet &domain=DimensionSet(Dimension::time), Mapping::InterpolationMethod intpl=Mapping::LINEAR)
Returns an appropriate changeable Mapping with the specified domain and the specified interpolation m...
Definition: MappingUtils.cc:103
const ConstMapping * inet::physicallayer::MappingUtils::createCompatibleMapping ( const ConstMapping src,
const ConstMapping dst 
)
staticprivate
38 {
39  typedef FilledUpMapping::KeySet KeySet;
40  typedef FilledUpMapping::KeyMap KeyMap;
41 
42  KeyMap DimensionIndizes;
43 
44  const DimensionSet& srcDims = src.getDimensionSet();
45  const DimensionSet& dstDims = dst.getDimensionSet();
46 
47  const DimensionSet::const_iterator srcDimsEnd = srcDims.end();
48  const DimensionSet::const_reverse_iterator dstDimsEnd = dstDims.rend();
49  for (DimensionSet::const_reverse_iterator dstDimIt = dstDims.rbegin(); dstDimIt != dstDimsEnd; ++dstDimIt) {
50  if (srcDims.find(*dstDimIt) == srcDimsEnd) {
51  DimensionIndizes.insert(DimensionIndizes.end(), KeyMap::value_type(*dstDimIt, KeySet()));
52  }
53  }
54 
55  if (DimensionIndizes.empty())
56  return &src;
57 
58  ConstMappingIterator *dstIt = dst.createConstIterator();
59 
60  if (!dstIt->inRange()) {
61  delete dstIt;
62  return &src;
63  }
64 
65  const auto keysEnd = DimensionIndizes.end();
66  do {
67  for (auto keyDimIt = DimensionIndizes.begin(); keyDimIt != keysEnd; ++keyDimIt) {
68  keyDimIt->second.insert(dstIt->getPosition().getArgValue(keyDimIt->first));
69  }
70 
71  if (!dstIt->hasNext())
72  break;
73  dstIt->next();
74  } while (true);
75 
76  delete dstIt;
77 
78  return new FilledUpMapping(&src, dstDims, DimensionIndizes);
79 }
std::set< argument_value_t > KeySet
Definition: MappingUtils.h:2120
_Base::reverse_iterator const_reverse_iterator
Definition: MappingBase.h:152
std::map< Dimension, KeySet > KeyMap
Definition: MappingUtils.h:2121
_Base::const_iterator const_iterator
Definition: MappingBase.h:153
Mapping * inet::physicallayer::MappingUtils::createMapping ( const DimensionSet domain = DimensionSet(Dimension::time),
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.

Referenced by applyElementWiseOperator(), inet::physicallayer::DimensionalAnalogModelBase::computeNoise(), inet::physicallayer::IsotropicDimensionalBackgroundNoise::computeNoise(), inet::physicallayer::DimensionalAnalogModelBase::computeReceptionPower(), and inet::physicallayer::DimensionalTransmitterBase::createPowerMapping().

104 {
105  if (domain.size() == 1) {
106  if (domain.hasDimension(Dimension::time)) {
107  switch (intpl) {
108  case Mapping::LINEAR:
109  return new TimeMapping<Linear>();
110  case Mapping::NEAREST:
111  return new TimeMapping<Nearest>();
112  case Mapping::STEPS:
113  return new TimeMapping<NextSmaller>();
114  }
115  }
116  else if (domain.hasDimension(Dimension::frequency)) {
117  switch (intpl) {
118  case Mapping::LINEAR:
119  return new FrequencyMapping<Linear>();
120  case Mapping::NEAREST:
121  return new FrequencyMapping<Nearest>();
122  case Mapping::STEPS:
123  return new FrequencyMapping<NextSmaller>();
124  }
125  }
126  }
127  else {
128  switch (intpl) {
129  case Mapping::LINEAR:
130  return new MultiDimMapping<Linear>(domain);
131  case Mapping::NEAREST:
132  return new MultiDimMapping<Nearest>(domain);
133  case Mapping::STEPS:
134  return new MultiDimMapping<NextSmaller>(domain);
135  }
136  }
137  throw cRuntimeError("Cannot create mapping");
138 }
static const Dimension time
Shortcut to the time Dimension, same as &#39;Dimension("time")&#39;, but spares the parsing of a string...
Definition: MappingBase.h:64
interpolates with nearest entry
Definition: MappingBase.h:1253
interpolates with next lower entry
Definition: MappingBase.h:1251
interpolates linear with next lower and next upper entry constant before the first and after the last...
Definition: MappingBase.h:1256
static const Dimension frequency
Shortcut to the frequency Dimension, same as &#39;Dimension("frequency")&#39;, but spares the parsing of a st...
Definition: MappingBase.h:68
Mapping * inet::physicallayer::MappingUtils::createMapping ( Mapping::argument_value_cref_t  outOfRangeValue,
const DimensionSet domain = DimensionSet(Dimension::time),
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.

141 {
142  if (domain.size() == 1) {
143  if (domain.hasDimension(Dimension::time)) {
144  switch (intpl) {
145  case Mapping::LINEAR:
146  return new TimeMapping<Linear>(outOfRangeVal);
147  case Mapping::NEAREST:
148  return new TimeMapping<Nearest>(outOfRangeVal);
149  case Mapping::STEPS:
150  return new TimeMapping<NextSmaller>(outOfRangeVal);
151  }
152  }
153  else if (domain.hasDimension(Dimension::frequency)) {
154  switch (intpl) {
155  case Mapping::LINEAR:
156  return new FrequencyMapping<Linear>(outOfRangeVal);
157  case Mapping::NEAREST:
158  return new FrequencyMapping<Nearest>(outOfRangeVal);
159  case Mapping::STEPS:
160  return new FrequencyMapping<NextSmaller>(outOfRangeVal);
161  }
162  }
163  }
164  else {
165  switch (intpl) {
166  case Mapping::LINEAR:
167  return new MultiDimMapping<Linear>(domain, outOfRangeVal);
168  case Mapping::NEAREST:
169  return new MultiDimMapping<Nearest>(domain, outOfRangeVal);
170  case Mapping::STEPS:
171  return new MultiDimMapping<NextSmaller>(domain, outOfRangeVal);
172  }
173  }
174  throw cRuntimeError("Cannot create mapping");
175 }
static const Dimension time
Shortcut to the time Dimension, same as &#39;Dimension("time")&#39;, but spares the parsing of a string...
Definition: MappingBase.h:64
interpolates with nearest entry
Definition: MappingBase.h:1253
interpolates with next lower entry
Definition: MappingBase.h:1251
interpolates linear with next lower and next upper entry constant before the first and after the last...
Definition: MappingBase.h:1256
static const Dimension frequency
Shortcut to the frequency Dimension, same as &#39;Dimension("frequency")&#39;, but spares the parsing of a st...
Definition: MappingBase.h:68
Mapping * inet::physicallayer::MappingUtils::divide ( const ConstMapping f1,
const ConstMapping f2 
)
static

Referenced by inet::physicallayer::DimensionalSNIR::computeMin(), and inet::physicallayer::operator/().

183 {
184  return applyElementWiseOperator(f1, f2, std::divides<Mapping::argument_value_t>());
185 }
static Mapping * applyElementWiseOperator(const ConstMapping &f1, const ConstMapping &f2, const Argument &intvlStart, const Argument &intvlEnd, Operator op)
Definition: MappingUtils.h:2272
Mapping * inet::physicallayer::MappingUtils::divide ( const ConstMapping f1,
const ConstMapping f2,
Mapping::argument_value_cref_t  outOfRangeVal 
)
static
203 {
204  return applyElementWiseOperator(f1, f2, std::divides<Mapping::argument_value_t>(), outOfRangeVal, false);
205 }
static Mapping * applyElementWiseOperator(const ConstMapping &f1, const ConstMapping &f2, const Argument &intvlStart, const Argument &intvlEnd, Operator op)
Definition: MappingUtils.h:2272
Mapping::argument_value_t inet::physicallayer::MappingUtils::findMax ( const ConstMapping m,
Argument::mapped_type_cref  cRetNotFound = cMaxNotFound 
)
static

Iterates over the passed mapping and returns value at the key entry with the highest value.

Parameters
mThe map where the maximum value shall be searched.
cRetNotFoundThe value which shall be returned if no maximum was found (default MappingUtils::cMaxNotFound).
Returns
The value at the key entry with the highest value or cRetNotFound if map is empty.

Referenced by inet::physicallayer::DimensionalNoise::computeMaxPower(), inet::physicallayer::DimensionalTransmission::printToStream(), inet::physicallayer::DimensionalSignalAnalogModel::printToStream(), and inet::physicallayer::DimensionalNoise::printToStream().

238 {
239  ConstMappingIterator *it = m.createConstIterator();
240  bool bIsFirst = true;
242 
243  while (it->inRange()) {
244  Mapping::argument_value_cref_t val = it->getValue();
245  if (bIsFirst || val > res) {
246  res = val;
247  bIsFirst = false;
248  }
249 
250  //std::cerr << "findMax(): " << val << " @ " << it->getPosition() << "; max is now: " << res << std::endl;
251  if (!it->hasNext())
252  break;
253 
254  it->next();
255  }
256  delete it;
257  if (bIsFirst) {
258  // no maximum available, maybe map is empty
259  return cRetNotFound;
260  }
261  return res;
262 }
Argument::mapped_type_cref argument_value_cref_t
Definition: MappingBase.h:875
Argument::mapped_type argument_value_t
Definition: MappingBase.h:874
value< double, units::m > m
Definition: Units.h:1047
Mapping::argument_value_t inet::physicallayer::MappingUtils::findMax ( const ConstMapping m,
const Argument min,
const Argument max,
Argument::mapped_type_cref  cRetNotFound = cMaxNotFound 
)
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.

Parameters
mThe map where the maximum value shall be searched.
minThe beginning of search range.
maxThe end of search range.
cRetNotFoundThe value which shall be returned if no maximum was found (default MappingUtils::cMaxNotFound).
Returns
The value at the key entry with the highest value or cRetNotFound if map is empty or no element in range [min,max].
265 {
266  const DimensionSet& rDimSet = m.getDimensionSet();
267  //the passed interval should define a value for every dimension
268  //of the mapping.
269  assert(pRangeFrom.getDimensions().isSubSet(rDimSet));
270  assert(pRangeTo.getDimensions().isSubSet(rDimSet));
271 
272  ConstMappingIterator *it = m.createConstIterator(pRangeFrom);
273  bool bIsFirst = true;
275 
276  //std::cerr << "findMax(m, " << pRangeFrom << ", " << pRangeTo << "): Map is" << std::endl << m;
277  if (it->inRange()) {
278  res = it->getValue();
279  bIsFirst = false;
280  //std::cerr << "findMax(...): " << " @ " << it->getPosition() << "; max is at beginning: " << res << std::endl;
281  }
282  while (it->hasNext() && it->getNextPosition().compare(pRangeTo, &rDimSet) < 0) {
283  it->next();
284 
285  const Argument& next = it->getPosition();
286  bool inRange = pRangeFrom.getTime() <= next.getTime() && next.getTime() <= pRangeTo.getTime();
287  if (inRange) {
288  const Argument::const_iterator itAEnd = next.end();
289  for (Argument::const_iterator itA = next.begin(); itA != itAEnd; ++itA) {
290  if (pRangeFrom.getArgValue(itA->first) > itA->second || itA->second > pRangeTo.getArgValue(itA->first)) {
291  inRange = false;
292  break;
293  }
294  }
295  }
296  if (inRange) {
297  Mapping::argument_value_cref_t val = it->getValue();
298  if (bIsFirst || val > res) {
299  res = val;
300  bIsFirst = false;
301  }
302  //std::cerr << "findMax(...): " << val << " @ " << it->getPosition() << "; max is now: " << res << std::endl;
303  }
304  }
305  it->iterateTo(pRangeTo);
306  if (it->inRange()) {
307  Mapping::argument_value_cref_t val = it->getValue();
308  if (bIsFirst || val > res) {
309  res = val;
310  bIsFirst = false;
311  }
312  //std::cerr << "findMax(...): " << val << " @ " << it->getPosition() << "; max is finally: " << res << std::endl;
313  }
314  delete it;
315  if (bIsFirst) {
316  // no minimum available
317  return cRetNotFound;
318  }
319  return res;
320 }
Argument::mapped_type_cref argument_value_cref_t
Definition: MappingBase.h:875
Argument::mapped_type argument_value_t
Definition: MappingBase.h:874
container_type::const_iterator const_iterator
Const-iterator type for this set.
Definition: MappingBase.h:444
value< double, units::m > m
Definition: Units.h:1047
Mapping::argument_value_t inet::physicallayer::MappingUtils::findMin ( const ConstMapping m,
Argument::mapped_type_cref  cRetNotFound = cMinNotFound 
)
static

Iterates over the passed mapping and returns value at the key entry with the smallest value.

Parameters
mThe map where the minimum value shall be searched.
cRetNotFoundThe value which shall be returned if no minimum was found (default MappingUtils::cMinNotFound).
Returns
The value at the key entry with the lowest value or cRetNotFound if map is empty.

Referenced by inet::physicallayer::DimensionalSNIR::computeMin(), inet::physicallayer::DimensionalReception::computeMinPower(), inet::physicallayer::DimensionalSignalAnalogModel::computeMinPower(), inet::physicallayer::DimensionalNoise::printToStream(), inet::physicallayer::DimensionalSignalAnalogModel::printToStream(), and inet::physicallayer::DimensionalTransmission::printToStream().

323 {
324  ConstMappingIterator *it = m.createConstIterator();
325  bool bIsFirst = true;
327 
328  while (it->inRange()) {
329  Mapping::argument_value_cref_t val = it->getValue();
330  if (bIsFirst || val < res) {
331  res = val;
332  bIsFirst = false;
333  }
334 
335  //std::cerr << "findMin(): " << val << " @ " << it->getPosition() << "; min is now: " << res << std::endl;
336  if (!it->hasNext())
337  break;
338 
339  it->next();
340  }
341  delete it;
342  if (bIsFirst) {
343  // no minimum available, maybe map is empty
344  return cRetNotFound;
345  }
346  return res;
347 }
Argument::mapped_type_cref argument_value_cref_t
Definition: MappingBase.h:875
Argument::mapped_type argument_value_t
Definition: MappingBase.h:874
value< double, units::m > m
Definition: Units.h:1047
Mapping::argument_value_t inet::physicallayer::MappingUtils::findMin ( const ConstMapping m,
const Argument min,
const Argument max,
Argument::mapped_type_cref  cRetNotFound = cMinNotFound 
)
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.

Parameters
mThe map where the minimum value shall be searched.
minThe beginning of search range.
maxThe end of search range.
cRetNotFoundThe value which shall be returned if no minimum was found (default MappingUtils::cMinNotFound).
Returns
The value at the key entry with the highest value or cRetNotFound if map is empty or no element in range [min,max].
350 {
351  const DimensionSet& rDimSet = m.getDimensionSet();
352  //the passed interval should define a value for every dimension
353  //of the mapping.
354  assert(pRangeFrom.getDimensions().isSubSet(rDimSet));
355  assert(pRangeTo.getDimensions().isSubSet(rDimSet));
356 
358  bool bIsFirst = true;
359  ConstMappingIterator *it = m.createConstIterator(pRangeFrom);
360 
361  //std::cerr << "findMin(m, " << pRangeFrom << ", " << pRangeTo << "): Map is" << std::endl << m;
362  if (it->inRange()) {
363  res = it->getValue();
364  bIsFirst = false;
365  //std::cerr << "findMin(...): " << " @ " << it->getPosition() << "; min is at beginning: " << res << std::endl;
366  }
367  while (it->hasNext() && it->getNextPosition().compare(pRangeTo, &rDimSet) < 0) {
368  it->next();
369 
370  const Argument& next = it->getPosition();
371  bool inRange = pRangeFrom.getTime() <= next.getTime() && next.getTime() <= pRangeTo.getTime();
372  if (inRange) {
373  const Argument::const_iterator itAEnd = next.end();
374  for (Argument::const_iterator itA = next.begin(); itA != itAEnd; ++itA) {
375  if (pRangeFrom.getArgValue(itA->first) > itA->second || itA->second > pRangeTo.getArgValue(itA->first)) {
376  inRange = false;
377  break;
378  }
379  }
380  }
381  if (inRange) {
382  Mapping::argument_value_cref_t val = it->getValue();
383  if (bIsFirst || val < res) {
384  res = val;
385  bIsFirst = false;
386  }
387  //std::cerr << "findMin(...): " << val << " @ " << it->getPosition() << "; min is now: " << res << std::endl;
388  }
389  }
390  it->iterateTo(pRangeTo);
391  if (it->inRange()) {
392  Mapping::argument_value_cref_t val = it->getValue();
393  if (bIsFirst || val < res) {
394  res = val;
395  bIsFirst = false;
396  }
397  //std::cerr << "findMin(...): " << val << " @ " << it->getPosition() << "; min is finally: " << res << std::endl;
398  }
399  delete it;
400  if (bIsFirst) {
401  // no minimum available
402  return cRetNotFound;
403  }
404  return res;
405 }
Argument::mapped_type_cref argument_value_cref_t
Definition: MappingBase.h:875
Argument::mapped_type argument_value_t
Definition: MappingBase.h:874
container_type::const_iterator const_iterator
Const-iterator type for this set.
Definition: MappingBase.h:444
value< double, units::m > m
Definition: Units.h:1047
simtime_t inet::physicallayer::MappingUtils::incNextPosition ( simtime_t_cref  t)
static

returns the incremented position point (used in RSAMConstMappingIterator::setNextPosition).

447 {
448  //assert(SIMTIME_RAW(t) < SIMTIME_RAW(MAXTIME));
449  // original it was following formula, but I do not know why
450  // the '+1' is used here!? I think post should be enough!
451  //return t + 1;
452  return post(t);
453 }
static simtime_t post(simtime_t_cref t)
returns the closest value of simtime after passed values
Definition: MappingUtils.cc:436
bool inet::physicallayer::MappingUtils::iterateToNext ( ConstMappingIterator it1,
ConstMappingIterator it2 
)
staticprivate
82 {
83  bool it1HasNext = it1->hasNext();
84  bool it2HasNext = it2->hasNext();
85 
86  if (it1HasNext || it2HasNext) {
87  if (it1HasNext && (!it2HasNext || it1->getNextPosition() < it2->getNextPosition())) {
88  it1->next();
89  it2->iterateTo(it1->getPosition());
90  }
91  else {
92  it2->next();
93  it1->iterateTo(it2->getPosition());
94  }
95 
96  return true;
97  }
98  else {
99  return false;
100  }
101 }
Mapping * inet::physicallayer::MappingUtils::multiply ( const ConstMapping f1,
const 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.

Referenced by inet::physicallayer::operator*().

178 {
179  return applyElementWiseOperator(f1, f2, std::multiplies<Mapping::argument_value_t>());
180 }
static Mapping * applyElementWiseOperator(const ConstMapping &f1, const ConstMapping &f2, const Argument &intvlStart, const Argument &intvlEnd, Operator op)
Definition: MappingUtils.h:2272
Mapping * inet::physicallayer::MappingUtils::multiply ( const ConstMapping f1,
const ConstMapping f2,
Mapping::argument_value_cref_t  outOfRangeVal 
)
static
198 {
199  return applyElementWiseOperator(f1, f2, std::multiplies<Mapping::argument_value_t>(), outOfRangeVal, false);
200 }
static Mapping * applyElementWiseOperator(const ConstMapping &f1, const ConstMapping &f2, const Argument &intvlStart, const Argument &intvlEnd, Operator op)
Definition: MappingUtils.h:2272
simtime_t inet::physicallayer::MappingUtils::post ( simtime_t_cref  t)
static

returns the closest value of simtime after passed values

437 {
438  assert(t < SIMTIME_MAX);
439 
440  simtime_t stPost;
441  stPost.setRaw(t.raw() + 1);
442 
443  return stPost;
444 }
simtime_t inet::physicallayer::MappingUtils::pre ( simtime_t_cref  t)
static

returns the closest value of simtime before passed value

Referenced by inet::physicallayer::DimensionalSNIR::computeMin(), inet::physicallayer::DimensionalReception::computeMinPower(), and inet::physicallayer::DimensionalSignalAnalogModel::computeMinPower().

427 {
428  assert(t > SIMTIME_ZERO);
429 
430  simtime_t stPre;
431  stPre.setRaw(t.raw() - 1);
432 
433  return stPre;
434 }
Mapping * inet::physicallayer::MappingUtils::subtract ( const ConstMapping f1,
const ConstMapping f2 
)
static

Referenced by inet::physicallayer::operator-().

193 {
194  return applyElementWiseOperator(f1, f2, std::minus<Mapping::argument_value_t>());
195 }
static Mapping * applyElementWiseOperator(const ConstMapping &f1, const ConstMapping &f2, const Argument &intvlStart, const Argument &intvlEnd, Operator op)
Definition: MappingUtils.h:2272
Mapping * inet::physicallayer::MappingUtils::subtract ( const ConstMapping f1,
const ConstMapping f2,
Mapping::argument_value_cref_t  outOfRangeVal 
)
static
213 {
214  return applyElementWiseOperator(f1, f2, std::minus<Mapping::argument_value_t>(), outOfRangeVal, false);
215 }
static Mapping * applyElementWiseOperator(const ConstMapping &f1, const ConstMapping &f2, const Argument &intvlStart, const Argument &intvlEnd, Operator op)
Definition: MappingUtils.h:2272

Member Data Documentation

const Argument::mapped_type inet::physicallayer::MappingUtils::cMaxNotFound = -std::numeric_limits<Argument::mapped_type>::infinity()
static

The default value for findMax() functions if it does not find a maximum element.

It will be initialized with the negative infinity value.

Referenced by inet::physicallayer::FilledUpMappingIterator::FilledUpMappingIterator().

const Argument::mapped_type inet::physicallayer::MappingUtils::cMinNotFound = std::numeric_limits<Argument::mapped_type>::infinity()
static

The default value for findMin() functions if it does not find a minimum element.

It will be initialized with the infinity value.

Referenced by inet::physicallayer::FilledUpMappingIterator::FilledUpMappingIterator().


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