vrpRouting  0.3
vrprouting::problem::anonymous_namespace{matrix.cpp} Namespace Reference

Functions

Multiplier get_tdm (const std::vector< std::tuple< TTimestamp, Multiplier >> &tdm, TTimestamp time)
 
Multiplier next_tdm (const std::vector< std::tuple< TTimestamp, Multiplier >> &tdm, TTimestamp time)
 
std::vector< std::tuple< TTimestamp, Multiplier > > set_tdm (Time_multipliers_t *p_multipliers, size_t size_multipliers)
 
TTimestamp time_change (const std::vector< std::tuple< TTimestamp, Multiplier >> &tdm, TTimestamp time)
 

Function Documentation

◆ get_tdm()

Multiplier vrprouting::problem::anonymous_namespace{matrix.cpp}::get_tdm ( const std::vector< std::tuple< TTimestamp, Multiplier >> &  tdm,
TTimestamp  time 
)
Parameters
[in]tdmtime dependant multiplier container
[in]timethe time from where the multiplier is calculated
Returns
the multiplier corresponding to the time

Definition at line 78 of file matrix.cpp.

78  {
79  pgassert(time >= 0);
80  Multiplier coeff(1);
81  for (const auto &e : tdm) {
82  if (time < std::get<0>(e)) break;
83  coeff = std::get<1>(e);
84  }
85  return coeff;
86 }

References pgassert.

Referenced by vrprouting::problem::Matrix::travel_time().

◆ next_tdm()

Multiplier vrprouting::problem::anonymous_namespace{matrix.cpp}::next_tdm ( const std::vector< std::tuple< TTimestamp, Multiplier >> &  tdm,
TTimestamp  time 
)
Parameters
[in]tdmtime dependant multiplier container
[in]timethe time from where the multiplier is calculated
Returns
the next multiplier corresponding to the time

Definition at line 94 of file matrix.cpp.

94  {
95  Multiplier coeff(1);
96  for (const auto &e : tdm) {
97  coeff = std::get<1>(e);
98  if (std::get<0>(e) >= time) break;
99  }
100  return coeff;
101 }

Referenced by vrprouting::problem::Matrix::travel_time().

◆ set_tdm()

std::vector<std::tuple<TTimestamp, Multiplier> > vrprouting::problem::anonymous_namespace{matrix.cpp}::set_tdm ( Time_multipliers_t p_multipliers,
size_t  size_multipliers 
)
Parameters
[in]p_multiplierstime dependant multiplier data
[in]size_multipliersnumber of rows in the data
Returns
time dependant multiplier container

Definition at line 56 of file matrix.cpp.

56  {
57  pgassert(size_multipliers > 1);
58  std::vector<std::tuple<TTimestamp, Multiplier>> tdm;
59  /*
60  * Sort the multipliers info
61  */
62  std::sort(p_multipliers, p_multipliers + size_multipliers,
63  [] (const Time_multipliers_t &lhs, const Time_multipliers_t &rhs) {
64  return lhs.start_time < rhs.start_time;
65  });
66  for (size_t i = 0; i < size_multipliers; ++i) {
67  tdm.emplace_back(p_multipliers[i].start_time, p_multipliers[i].multiplier);
68  }
69  return tdm;
70 }

References pgassert, and Time_multipliers_t::start_time.

◆ time_change()

TTimestamp vrprouting::problem::anonymous_namespace{matrix.cpp}::time_change ( const std::vector< std::tuple< TTimestamp, Multiplier >> &  tdm,
TTimestamp  time 
)
Parameters
[in]tdmtime dependant multiplier container
[in]timethe time from where the multiplier is calculated
Returns
the time when multiplier change

Example with 3 time multiplier, no more multiplier after 11

0 9 11 |------------—|------------—|

time is 9:30 then the time change is the next one after that so 11 t_change = 0 0 < 9:30 true continue

t_change = 9 9 < 9:30 true

t_change = 11 11 < 9:30 false cycle breaks

return t_change = 11

time is 11:30

t_change = 0 0 < 11:30 true continue

t_change = 9 9 < 11:30 true

t_change = 11 11 < 11:30 true cycle ends naturally

return t_change = 11

post condition:

From first example t_change > time

from second example t_change is the last one on the list

Definition at line 154 of file matrix.cpp.

154  {
155  TTimestamp t_change(0);
156  for (const auto &e : tdm) {
157  t_change = std::get<0>(e);
158  if (time <= t_change) break;
159  }
160  pgassert((time <= t_change)
161  || (t_change == std::get<0>(tdm[tdm.size() - 1 ])));
162  return t_change;
163 }

References pgassert.

Referenced by vrprouting::problem::Matrix::travel_time().

Time_multipliers_t
Time Dependant Multipliers.
Definition: time_multipliers_t.h:46
pgassert
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:95
Time_multipliers_t::start_time
TTimestamp start_time
Time of day where the multiplier starts to be valid.
Definition: time_multipliers_t.h:48
TTimestamp
int64_t TTimestamp
Definition: typedefs.h:71
Multiplier
double Multiplier
Definition: typedefs.h:77