PGROUTING  3.2
pgrouting::vrp::Pgr_pickDeliver Class Reference

#include "pgr_pickDeliver.h"

Inheritance diagram for pgrouting::vrp::Pgr_pickDeliver:
Collaboration diagram for pgrouting::vrp::Pgr_pickDeliver:

Public Member Functions

 Pgr_pickDeliver (const std::vector< PickDeliveryOrders_t > &pd_orders, const std::vector< Vehicle_t > &vehicles, const pgrouting::tsp::Dmatrix &cost_matrix, double factor, size_t max_cycles, int initial)
 Constructor for the matrix version. More...
 
void add_node (const Vehicle_node &node)
 
pgrouting::tsp::Dmatrix get_cost_matrix () const
 
Initials_code get_kind () const
 
std::vector< Vehicle_nodeget_nodes () const
 
std::vector< General_vehicle_orders_tget_postgres_result () const
 
size_t max_cycles () const
 
void solve ()
 
Fleet trucks () const
 

Public Attributes

Pgr_messages msg
 message controller for all classes More...
 

Private Attributes

friend Dnode
 
friend Fleet
 
friend Initial_solution
 
pgrouting::tsp::Dmatrix m_cost_matrix
 
int m_initial_id
 used define the initial solution algorithm to be used More...
 
size_t m_max_cycles
 maximum cycles in the optimization More...
 
std::vector< Vehicle_nodem_nodes
 
PD_Orders m_orders
 
Fleet m_trucks
 
friend PD_Orders
 
friend Solution
 
std::vector< Solutionsolutions
 

Detailed Description

Definition at line 57 of file pgr_pickDeliver.h.

Constructor & Destructor Documentation

◆ Pgr_pickDeliver()

pgrouting::vrp::Pgr_pickDeliver::Pgr_pickDeliver ( const std::vector< PickDeliveryOrders_t > &  pd_orders,
const std::vector< Vehicle_t > &  vehicles,
const pgrouting::tsp::Dmatrix cost_matrix,
double  factor,
size_t  p_max_cycles,
int  initial 
)

Constructor for the matrix version.

Definition at line 135 of file pgr_pickDeliver.cpp.

141  :
142  PD_problem(this),
143  m_initial_id(initial),
144  m_max_cycles(p_max_cycles),
145  m_nodes(),
146  m_cost_matrix(cost_matrix),
147  m_orders(pd_orders),
148  m_trucks(vehicles, factor) {
149  ENTERING(msg);
150  pgassert(!pd_orders.empty());
151  pgassert(!vehicles.empty());
153  if (!(m_initial_id > 0 && m_initial_id < OneDepot)) {
154  msg.log << "\n m_initial_id " << m_initial_id;
155  }
156  pgassertwm(m_initial_id > 0 && m_initial_id <= OneDepot, msg.get_log().c_str());
157  pgassert(!m_nodes.empty());
158 
159  if (!msg.get_error().empty()) {
160  return;
161  }
162 
163 #if 0
164  pgassert(m_trucks.msg().get_error().empty());
165  pgassert(msg().get_error().empty());
166 #endif
167 
168  msg.log << "\n Checking fleet ...";
169  if (!m_trucks.is_fleet_ok()) {
170  pgassert(msg.get_error().empty());
171 #if 0
172  pgassert(!m_trucks.msg.get_error().empty());
174 #endif
175  return;
176  }
177  msg.log << "fleet OK \n";
178 
179 #if 0
180  for (const auto t : m_trucks) {
181  msg.log << t << "\n";
182  }
183  for (const auto &o : m_orders) {
184  msg.log << o << "\n";
185  }
186 #endif
187 
188  /*
189  * check the (S, P, D, E) order on all vehicles
190  * stop when a feasible truck is found
191  */
192  msg.log << "\n Checking orders";
193  for (const auto &o : m_orders) {
194  if (!m_trucks.is_order_ok(o)) {
195  msg.error << "Order not feasible on any truck was found";
196  msg.log << "The order "
197  << o.id()
198  << " is not feasible on any truck";
199  msg.log << "\n" << o;
200 #if 0
201  double old_speed(0);
202  for (auto t : m_trucks) {
203  if (old_speed == t.speed()) continue;
204  old_speed = t.speed();
205  msg.log << "****** With speed: " << t.speed() << "\n";
206  msg.log << t.start_site() << "\n";
207  msg.log << o.pickup() << "\n";
208  msg.log << "travel time to "
209  << t.start_site().travel_time_to(
210  o.pickup(), t.speed()) << "\n";
211 
212  msg.log << o.delivery() << "\n";
213  msg.log << t.end_site() << "\n";
214  msg.log << "travel time to "
215  << t.start_site().travel_time_to(
216  o.delivery(), t.speed())
217  << "\n";
218  t.push_back(o);
219  }
220 #endif
221  return;
222  }
223  }
224  msg.log << "orders OK \n";
225 
227 #if 0
228  msg.error << "foo";
229  for (const auto t : m_trucks) {
230  msg.log << t << "\n";
231  }
232 #endif
233  EXITING(msg);
234  } // constructor

References pgrouting::tsp::Dmatrix::empty(), ENTERING, pgrouting::Pgr_messages::error, EXITING, pgrouting::Pgr_messages::get_error(), pgrouting::Pgr_messages::get_log(), pgrouting::vrp::Fleet::is_fleet_ok(), pgrouting::vrp::Fleet::is_order_ok(), pgrouting::Pgr_messages::log, m_cost_matrix, m_initial_id, m_nodes, m_orders, m_trucks, msg, pgrouting::vrp::Fleet::msg(), pgrouting::vrp::OneDepot, pgassert, pgassertwm, and pgrouting::vrp::Fleet::set_compatibles().

Member Function Documentation

◆ add_node()

void pgrouting::vrp::Pgr_pickDeliver::add_node ( const Vehicle_node node)

Definition at line 128 of file pgr_pickDeliver.cpp.

128  {
129  m_nodes.push_back(node);
130 }

References m_nodes.

Referenced by pgrouting::vrp::Fleet::build_fleet(), and pgrouting::vrp::PD_Orders::build_orders().

◆ get_cost_matrix()

pgrouting::tsp::Dmatrix pgrouting::vrp::Pgr_pickDeliver::get_cost_matrix ( ) const
inline

◆ get_kind()

Initials_code pgrouting::vrp::Pgr_pickDeliver::get_kind ( ) const
inline

Definition at line 84 of file pgr_pickDeliver.h.

84  {
85  return (Initials_code) m_initial_id;
86  }

References m_initial_id.

Referenced by pgrouting::vrp::Solution::get_kind().

◆ get_nodes()

std::vector<Vehicle_node> pgrouting::vrp::Pgr_pickDeliver::get_nodes ( ) const
inline

Definition at line 88 of file pgr_pickDeliver.h.

88  {
89  return m_nodes;
90  }

References m_nodes.

Referenced by pgrouting::vrp::Fleet::build_fleet(), and pgrouting::vrp::PD_Orders::build_orders().

◆ get_postgres_result()

std::vector< General_vehicle_orders_t > pgrouting::vrp::Pgr_pickDeliver::get_postgres_result ( ) const

Definition at line 94 of file pgr_pickDeliver.cpp.

94  {
95  auto result = solutions.back().get_postgres_result();
96 
97  General_vehicle_orders_t aggregates = {
98  /*
99  * Vehicle id = -2 indicates its an aggregate row
100  *
101  * (twv, cv, fleet, wait, duration)
102  */
103  -2, // summary row on vehicle_number
104  solutions.back().twvTot(), // on vehicle_id
105  solutions.back().cvTot(), // on vehicle_seq
106  -1, // on order_id
107  -1, // on stop_id
108  -2, // on stop_type (gets increased later by one so it gets -1)
109  -1, // not accounting total loads
110  solutions.back().total_travel_time(),
111  -1, // not accounting arrival_travel_time
112  solutions.back().wait_time(),
113  solutions.back().total_service_time(),
114  solutions.back().duration(),
115  };
116  result.push_back(aggregates);
117 
118 
119 #ifndef NDEBUG
120  for (const auto &sol : solutions) {
121  msg.log << sol.tau();
122  }
123 #endif
124  return result;
125 }

References pgrouting::Pgr_messages::log, msg, and solutions.

Referenced by do_pgr_pickDeliver(), and do_pgr_pickDeliverEuclidean().

◆ max_cycles()

size_t pgrouting::vrp::Pgr_pickDeliver::max_cycles ( ) const
inline

Definition at line 80 of file pgr_pickDeliver.h.

80 {return m_max_cycles;}

References m_max_cycles.

◆ solve()

void pgrouting::vrp::Pgr_pickDeliver::solve ( )

Definition at line 51 of file pgr_pickDeliver.cpp.

51  {
52  auto initial_sols = solutions;
53 
54  if (m_initial_id == 0) {
55  msg.log << "trying all \n";
56  for (int i = 1; i < 7; ++i) {
57  initial_sols.push_back(Initial_solution((Initials_code)i, m_orders.size()));
58  msg.log << "solution " << i << "\n" << initial_sols.back().tau();
59  // TODO(vicky) calculate the time it takes
60  msg.log << "Initial solution " << i
61  << " duration: " << initial_sols.back().duration();
62  }
63  } else {
64  msg.log << "only trying " << m_initial_id << "\n";
65  initial_sols.push_back(Initial_solution((Initials_code)m_initial_id, m_orders.size()));
66  // TODO(vicky) calculate the time it takes
67  msg.log << "Initial solution " << m_initial_id
68  << " duration: " << initial_sols[0].duration();
69  }
70 
71 
72  /*
73  * Sorting solutions: the best is at the back
74  */
75  pgassert(!initial_sols.empty());
76  std::sort(initial_sols.begin(), initial_sols.end(), []
77  (const Solution &lhs, const Solution &rhs) -> bool {
78  return rhs < lhs;
79  });
80 
81 #if 1
82  solutions.push_back(Optimize(initial_sols.back(), m_max_cycles));
83 #else
84  solutions.push_back(initial_sols.back());
85 #endif
86  pgassert(!solutions.empty());
87 
88  msg.log << "best solution duration = " << solutions.back().duration();
89 }

References Initial_solution, pgrouting::Pgr_messages::log, m_initial_id, m_max_cycles, m_orders, msg, pgassert, pgrouting::vrp::PD_Orders::size(), and solutions.

Referenced by do_pgr_pickDeliver(), and do_pgr_pickDeliverEuclidean().

◆ trucks()

Fleet pgrouting::vrp::Pgr_pickDeliver::trucks ( ) const
inline

Definition at line 96 of file pgr_pickDeliver.h.

96 {return m_trucks;}

References m_trucks.

Member Data Documentation

◆ Dnode

friend pgrouting::vrp::Pgr_pickDeliver::Dnode
private

Definition at line 59 of file pgr_pickDeliver.h.

◆ Fleet

friend pgrouting::vrp::Pgr_pickDeliver::Fleet
private

Definition at line 58 of file pgr_pickDeliver.h.

◆ Initial_solution

friend pgrouting::vrp::Pgr_pickDeliver::Initial_solution
private

Definition at line 62 of file pgr_pickDeliver.h.

Referenced by solve().

◆ m_cost_matrix

pgrouting::tsp::Dmatrix pgrouting::vrp::Pgr_pickDeliver::m_cost_matrix
private

Definition at line 111 of file pgr_pickDeliver.h.

Referenced by get_cost_matrix(), and Pgr_pickDeliver().

◆ m_initial_id

int pgrouting::vrp::Pgr_pickDeliver::m_initial_id
private

used define the initial solution algorithm to be used

Definition at line 105 of file pgr_pickDeliver.h.

Referenced by get_kind(), Pgr_pickDeliver(), and solve().

◆ m_max_cycles

size_t pgrouting::vrp::Pgr_pickDeliver::m_max_cycles
private

maximum cycles in the optimization

Definition at line 108 of file pgr_pickDeliver.h.

Referenced by max_cycles(), and solve().

◆ m_nodes

std::vector<Vehicle_node> pgrouting::vrp::Pgr_pickDeliver::m_nodes
private

Definition at line 110 of file pgr_pickDeliver.h.

Referenced by add_node(), get_nodes(), and Pgr_pickDeliver().

◆ m_orders

PD_Orders pgrouting::vrp::Pgr_pickDeliver::m_orders
private

Definition at line 113 of file pgr_pickDeliver.h.

Referenced by Pgr_pickDeliver(), and solve().

◆ m_trucks

Fleet pgrouting::vrp::Pgr_pickDeliver::m_trucks
private

Definition at line 114 of file pgr_pickDeliver.h.

Referenced by Pgr_pickDeliver(), and trucks().

◆ msg

◆ PD_Orders

friend pgrouting::vrp::Pgr_pickDeliver::PD_Orders
private

Definition at line 60 of file pgr_pickDeliver.h.

◆ Solution

friend pgrouting::vrp::Pgr_pickDeliver::Solution
private

Definition at line 61 of file pgr_pickDeliver.h.

◆ solutions

std::vector<Solution> pgrouting::vrp::Pgr_pickDeliver::solutions
private

Definition at line 115 of file pgr_pickDeliver.h.

Referenced by get_postgres_result(), and solve().


The documentation for this class was generated from the following files:
pgrouting::vrp::Pgr_pickDeliver::m_max_cycles
size_t m_max_cycles
maximum cycles in the optimization
Definition: pgr_pickDeliver.h:108
pgrouting::vrp::PD_Orders::size
size_t size() const
Definition: pd_orders.h:79
pgrouting::vrp::Pgr_pickDeliver::solutions
std::vector< Solution > solutions
Definition: pgr_pickDeliver.h:115
EXITING
#define EXITING(x)
Definition: pgr_messages.h:94
pgrouting::vrp::Fleet::is_order_ok
bool is_order_ok(const Order &order) const
Given an order, Cycle trhugh all the trucks to verify if the order can be served by at least one truc...
Definition: fleet.cpp:288
pgrouting::vrp::Pgr_pickDeliver::m_trucks
Fleet m_trucks
Definition: pgr_pickDeliver.h:114
pgrouting::vrp::Pgr_pickDeliver::Solution
friend Solution
Definition: pgr_pickDeliver.h:61
ENTERING
#define ENTERING(x)
Definition: pgr_messages.h:93
pgassertwm
#define pgassertwm(expr, msg)
Adds a message to the assertion.
Definition: pgr_assert.h:117
pgrouting::Pgr_messages::error
std::ostringstream error
Stores the error information.
Definition: pgr_messages.h:85
pgrouting::Pgr_messages::log
std::ostringstream log
Stores the hint information.
Definition: pgr_messages.h:81
pgrouting::vrp::Pgr_pickDeliver::msg
Pgr_messages msg
message controller for all classes
Definition: pgr_pickDeliver.h:99
pgrouting::vrp::Fleet::is_fleet_ok
bool is_fleet_ok() const
Definition: fleet.cpp:253
pgrouting::Pgr_messages::get_error
std::string get_error() const
get_error
Definition: pgr_messages.cpp:53
pgrouting::vrp::Fleet::msg
static Pgr_messages & msg()
the problem message
Definition: fleet.cpp:46
pgassert
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:94
pgrouting::vrp::Pgr_pickDeliver::m_cost_matrix
pgrouting::tsp::Dmatrix m_cost_matrix
Definition: pgr_pickDeliver.h:111
pgrouting::vrp::OneDepot
@ OneDepot
Push front order that allows more orders to be inserted at the front.
Definition: initials_code.h:44
pgrouting::vrp::Pgr_pickDeliver::m_nodes
std::vector< Vehicle_node > m_nodes
Definition: pgr_pickDeliver.h:110
pgrouting::Pgr_messages::get_log
std::string get_log() const
get_log
Definition: pgr_messages.cpp:36
pgrouting::vrp::Pgr_pickDeliver::Initial_solution
friend Initial_solution
Definition: pgr_pickDeliver.h:62
General_vehicle_orders_t
Definition: general_vehicle_orders_t.h:49
pgrouting::tsp::Dmatrix::empty
bool empty() const
Definition: Dmatrix.h:118
pgrouting::vrp::Pgr_pickDeliver::m_orders
PD_Orders m_orders
Definition: pgr_pickDeliver.h:113
pgrouting::vrp::Fleet::set_compatibles
void set_compatibles(const PD_Orders &orders)
Definition: fleet.cpp:313
pgrouting::vrp::Initials_code
Initials_code
Different kinds to insert an order into the vehicle.
Definition: initials_code.h:36
pgrouting::vrp::Pgr_pickDeliver::m_initial_id
int m_initial_id
used define the initial solution algorithm to be used
Definition: pgr_pickDeliver.h:105
pgrouting::vrp::PD_problem::PD_problem
PD_problem()=delete
Not allwing initialization without information.