vrpRouting  0.3
vrprouting::problem::Orders Class Reference

#include "orders.h"

Inheritance diagram for vrprouting::problem::Orders:
Collaboration diagram for vrprouting::problem::Orders:

Public Member Functions

 Orders ()=default
 
 Orders (const Orders &)=default
 
template<typename PTR >
 Orders (PickDeliveryOrders_t *p_orders, size_t p_size_orders, const PTR problem_ptr)
 
size_t find_best_I (const Identifiers< size_t > &within_this_set) const
 find the best order -> this More...
 
size_t find_best_I_J (const Identifiers< size_t > &within_this_set) const
 find the best order -> this -> order More...
 
size_t find_best_J (const Identifiers< size_t > &within_this_set) const
 find the best order -> this -> order More...
 
bool is_valid (Speed=1.0) const
 is the order valid? More...
 
void set_compatibles (Speed=1.0)
 set the compatability between all orders More...
 

Public Attributes

elements
 STL member. More...
 

Private Member Functions

void add_order (const PickDeliveryOrders_t &order, const Vehicle_node &pick, const Vehicle_node &drop)
 add in an order More...
 
template<typename PTR >
void build_orders (PickDeliveryOrders_t *, size_t, const PTR problem_ptr)
 

Friends

std::ostream & operator<< (std::ostream &log, const Orders &p_orders)
 

Detailed Description

Definition at line 48 of file orders.h.

Constructor & Destructor Documentation

◆ Orders() [1/3]

vrprouting::problem::Orders::Orders ( )
default

◆ Orders() [2/3]

vrprouting::problem::Orders::Orders ( const Orders )
default

◆ Orders() [3/3]

template<typename PTR >
vrprouting::problem::Orders::Orders ( PickDeliveryOrders_t p_orders,
size_t  p_size_orders,
const PTR  problem_ptr 
)
inline

Definition at line 56 of file orders.h.

56  {
57  Tw_node::m_time_matrix_ptr = &problem_ptr->time_matrix();
58  build_orders(p_orders, p_size_orders, problem_ptr);
59  }

References build_orders(), and vrprouting::problem::Tw_node::m_time_matrix_ptr.

Member Function Documentation

◆ add_order()

void vrprouting::problem::Orders::add_order ( const PickDeliveryOrders_t order,
const Vehicle_node pick,
const Vehicle_node drop 
)
inlineprivate

add in an order

Definition at line 88 of file orders.h.

90  {
91  push_back(Order(size(), order.id, pick, drop));
92  }

References PickDeliveryOrders_t::id.

◆ build_orders()

template<typename PTR >
void vrprouting::problem::Orders::build_orders ( PickDeliveryOrders_t orders,
size_t  size_orders,
const PTR  problem_ptr 
)
private
Parameters
[in]orders
[in]size_orders
[in]problem_ptrpointer to problem to get some needed information
  • Sort orders: ASC pick_open_t, deliver_close_t, id

Definition at line 102 of file orders.h.

102  {
106  std::sort(orders, orders + size_orders,
107  [] (const PickDeliveryOrders_t &lhs, const PickDeliveryOrders_t &rhs) {
108  if (lhs.pick_open_t == rhs.pick_open_t) {
109  if (lhs.deliver_close_t == rhs.deliver_close_t) {
110  return lhs.id < rhs.id;
111  } else {
112  return lhs.deliver_close_t < rhs.deliver_close_t;
113  }
114  } else {
115  return lhs.pick_open_t < rhs.pick_open_t;
116  }
117  });
118 
119  for (size_t i = 0; i < size_orders; ++i) {
120  auto order = orders[i];
121  Vehicle_node pick({problem_ptr->node_id()++, order, NodeType::kPickup});
122  Vehicle_node drop({problem_ptr->node_id()++, order, NodeType::kDelivery});
123 
124  problem_ptr->add_node(pick);
125  problem_ptr->add_node(drop);
126 
127  this->emplace_back(Order{size(), order.id, pick, drop});
128  }
129 }

References PickDeliveryOrders_t::pick_open_t.

Referenced by Orders().

◆ find_best_I()

size_t vrprouting::problem::Orders::find_best_I ( const Identifiers< size_t > &  within_this_set) const

find the best order -> this

Returns
the index of the order within_this_set that has more possibilities of placing orders before it
Parameters
[in]within_this_set
Precondition
not within_this_set.empty()

Definition at line 68 of file orders.cpp.

69  {
70  pgassert(!within_this_set.empty());
71  auto best_order = within_this_set.front();
72  size_t max_size = 0;
73  for (const auto o : within_this_set) {
74  auto size_I = this->at(o).subsetI(within_this_set).size();
75  if (max_size < size_I) {
76  max_size = size_I;
77  best_order = o;
78  }
79  }
80  return best_order;
81 }

References Identifiers< T >::empty(), Identifiers< T >::front(), and pgassert.

Referenced by vrprouting::initialsol::simple::Initial_solution::do_while_feasible().

◆ find_best_I_J()

size_t vrprouting::problem::Orders::find_best_I_J ( const Identifiers< size_t > &  within_this_set) const

find the best order -> this -> order

Returns
the index of the order within_this_set that has more possibilities of placing orders before or after it
Parameters
[in]within_this_set
Precondition
not within_this_set.empty()

Definition at line 89 of file orders.cpp.

90  {
91  pgassert(!within_this_set.empty());
92  auto best_order = within_this_set.front();
93  size_t max_size = 0;
94 
95  for (const auto o : within_this_set) {
96  auto size_I = this->at(o).subsetI(within_this_set).size();
97  auto size_J = this->at(o).subsetJ(within_this_set).size();
98  if (max_size < (std::max)(size_I, size_J)) {
99  max_size = (std::max)(size_I, size_J);
100  best_order = o;
101  }
102  }
103  return best_order;
104 }

References Identifiers< T >::empty(), Identifiers< T >::front(), and pgassert.

◆ find_best_J()

size_t vrprouting::problem::Orders::find_best_J ( const Identifiers< size_t > &  within_this_set) const

find the best order -> this -> order

Returns
the index of the order within_this_set that has more possibilities of placing orders after it
Parameters
[in]within_this_set
Precondition
not within_this_set.empty()

Definition at line 46 of file orders.cpp.

47  {
48  pgassert(!within_this_set.empty());
49  auto best_order = within_this_set.front();
50  size_t max_size = 0;
51 
52  for (const auto o : within_this_set) {
53  auto size_J = this->at(o).subsetJ(within_this_set).size();
54  if (max_size < size_J) {
55  max_size = size_J;
56  best_order = o;
57  }
58  }
59  return best_order;
60 }

References Identifiers< T >::empty(), Identifiers< T >::front(), and pgassert.

Referenced by vrprouting::initialsol::simple::Initial_solution::do_while_feasible().

◆ is_valid()

bool vrprouting::problem::Orders::is_valid ( Speed  speed = 1.0) const

is the order valid?

Returns
true when each order from the set of orders is valid

Definition at line 110 of file orders.cpp.

110  {
111  for (const auto &o : *this) {
112  if (!o.is_valid(speed)) {
113  return false;
114  }
115  pgassert(o.pickup().is_pickup());
116  pgassert(o.delivery().is_delivery());
117  /* P -> D */
118  pgassert(o.delivery().is_compatible_IJ(o.pickup(), speed));
119  }
120  return true;
121 }

References pgassert.

◆ set_compatibles()

void vrprouting::problem::Orders::set_compatibles ( Speed  speed = 1.0)

set the compatability between all orders

Postcondition
For each order: order -> {J} is set
For each order: {I} -> order is set

Definition at line 128 of file orders.cpp.

128  {
129  for (auto &I : *this) {
130  for (const auto& J : *this) {
131  I.set_compatibles(J, speed);
132  }
133  }
134 }

Referenced by vrprouting::problem::PickDeliver::PickDeliver().

Friends And Related Function Documentation

◆ operator<<

std::ostream& operator<< ( std::ostream &  log,
const Orders p_orders 
)
friend

Definition at line 76 of file orders.h.

76  {
77  log << "Orders\n";
78  for (const auto &o : p_orders) log << o << "\n";
79  log << "end Orders\n";
80  return log;
81  }

Member Data Documentation

◆ elements

T std::vector< T >::elements
inherited

STL member.


The documentation for this class was generated from the following files:
vrprouting::problem::Orders::build_orders
void build_orders(PickDeliveryOrders_t *, size_t, const PTR problem_ptr)
Definition: orders.h:102
PickDeliveryOrders_t
order's attributes
Definition: pickDeliveryOrders_t.h:56
vrprouting::problem::kDelivery
@ kDelivery
delivery site
Definition: node_types.h:38
pgassert
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:95
PickDeliveryOrders_t::id
Id id
Definition: pickDeliveryOrders_t.h:59
PickDeliveryOrders_t::pick_open_t
TTimestamp pick_open_t
Pickup node identifier.
Definition: pickDeliveryOrders_t.h:66
Identifiers::empty
bool empty() const
Definition: identifiers.hpp:78
vrprouting::problem::kPickup
@ kPickup
pickup site
Definition: node_types.h:37
Identifiers::front
T front() const
Definition: identifiers.hpp:79
vrprouting::problem::Tw_node::m_time_matrix_ptr
static const Matrix * m_time_matrix_ptr
Definition: tw_node.h:139