PGROUTING  2.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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, double factor, size_t max_cycles, int initial)
 
 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_base_node (std::unique_ptr< Base_node > node_ptr)
 
void add_node (const Vehicle_node &node)
 
std::vector
< General_vehicle_orders_t
get_postgres_result () const
 
size_t max_cycles () const
 
size_t & node_id ()
 
bool nodesOK () const
 
Solution optimize (const Solution init_solution)
 
void solve ()
 
Fleet trucks () const
 

Public Attributes

std::vector< std::unique_ptr
< Base_node > > 
m_base_nodes
 
pgrouting::tsp::Dmatrix m_cost_matrix
 

Static Public Attributes

static Pgr_messages msg
 

Static Protected Attributes

static Pgr_pickDeliverproblem
 

Private Attributes

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...
 
size_t m_node_id
 used to keep track of the next id the node gets in the eucledian version More...
 
std::vector< Vehicle_nodem_nodes
 
PD_Orders m_orders
 
Fleet m_trucks
 
std::vector< Solutionsolutions
 

Detailed Description

Definition at line 54 of file pgr_pickDeliver.h.

Constructor & Destructor Documentation

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

Definition at line 262 of file pgr_pickDeliver.cpp.

References pgrouting::tsp::Dmatrix::empty(), ENTERING, pgrouting::Pgr_messages::error, EXITING, pgrouting::Pgr_messages::get_error(), pgrouting::vrp::Fleet::is_fleet_ok(), pgrouting::Pgr_messages::log, m_cost_matrix, m_initial_id, m_orders, m_trucks, pgrouting::vrp::PD_problem::msg, and pgassert.

267  :
268  PD_problem(this),
269  m_initial_id(initial),
270  m_max_cycles(p_max_cycles),
271  m_node_id(0),
272  m_nodes(),
273  m_base_nodes(),
274  m_cost_matrix(),
275  m_orders(pd_orders),
276  m_trucks(vehicles, factor) {
277  ENTERING();
278  pgassert(!pd_orders.empty());
279  pgassert(!vehicles.empty());
281  pgassert(factor > 0);
282  pgassert(m_initial_id > 0 && m_initial_id < 7);
283 
284  if (!msg.get_error().empty()) {
285  return;
286  }
287 
288  pgassert(m_trucks.msg.get_error().empty());
289  pgassert(msg.get_error().empty());
290 
291  msg.log << "\n Checking fleet";
292  if (!m_trucks.is_fleet_ok()) {
294  pgassert(!m_trucks.msg.get_error().empty());
295  return;
296  }
297 
298  pgassert(m_trucks.msg.get_error().empty());
299 
300 
301 #ifndef NDEBUG
302  for (const auto t : m_trucks) {
303  msg.log << t << "\n";
304  }
305  for (const auto &o : m_orders) {
306  msg.log << o << "\n";
307  }
308 #endif
309 
310  /*
311  * check the (S, P, D, E) order on all vehicles
312  * stop when a feasible truck is found
313  */
314  msg.log << "\n Checking orders";
315  for (const auto &o : m_orders) {
316  if (!m_trucks.is_order_ok(o)) {
317  msg.error << "Order not feasible on any truck was found";
318  msg.log << "The order "
319  << o.pickup().order()
320  << " is not feasible on any truck";
321  msg.log << "\n" << o;
322  return;
323  }
324  }
325 
326  m_trucks.set_compatibles(m_orders);
327  EXITING();
328  } // constructor
std::vector< std::unique_ptr< Base_node > > m_base_nodes
std::ostringstream log
Stores the hint information.
Definition: pgr_messages.h:102
size_t m_node_id
used to keep track of the next id the node gets in the eucledian version
std::string get_error() const
get_error
#define EXITING()
Definition: pgr_messages.h:119
std::ostringstream error
Stores the error information.
Definition: pgr_messages.h:106
#define ENTERING()
Definition: pgr_messages.h:118
std::vector< Vehicle_node > m_nodes
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:81
pgrouting::tsp::Dmatrix m_cost_matrix
double empty() const
Definition: Dmatrix.h:116
bool is_fleet_ok() const
Definition: fleet.cpp:291
static Pgr_messages msg
Definition: pd_problem.h:48
size_t m_max_cycles
maximum cycles in the optimization
int m_initial_id
used define the initial solution algorithm to be used

Here is the call graph for this function:

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 162 of file pgr_pickDeliver.cpp.

References pgrouting::tsp::Dmatrix::empty(), ENTERING, pgrouting::Pgr_messages::error, EXITING, pgrouting::Pgr_messages::get_error(), pgrouting::vrp::Fleet::is_fleet_ok(), pgrouting::Pgr_messages::log, m_cost_matrix, m_initial_id, m_orders, m_trucks, pgrouting::vrp::PD_problem::msg, nodesOK(), and pgassert.

168  :
169  PD_problem(this),
170  m_initial_id(initial),
171  m_max_cycles(p_max_cycles),
172  m_node_id(0),
173  m_nodes(),
174  m_base_nodes(),
175  m_cost_matrix(cost_matrix),
176  m_orders(pd_orders),
177  m_trucks(vehicles, factor) {
178  ENTERING();
179  pgassert(!pd_orders.empty());
180  pgassert(!vehicles.empty());
182  pgassert(m_initial_id > 0 && m_initial_id < 7);
183  pgassert(nodesOK());
184 
185  if (!msg.get_error().empty()) {
186  return;
187  }
188 
189  pgassert(m_trucks.msg.get_error().empty());
190  pgassert(msg.get_error().empty());
191 
192  msg.log << "\n Checking fleet ...";
193  if (!m_trucks.is_fleet_ok()) {
194  pgassert(msg.get_error().empty());
195  pgassert(!m_trucks.msg.get_error().empty());
197  return;
198  }
199  msg.log << "fleet OK \n";
200 
201 #if 0
202  for (const auto t : m_trucks) {
203  msg.log << t << "\n";
204  }
205  for (const auto &o : m_orders) {
206  msg.log << o << "\n";
207  }
208 #endif
209 
210  /*
211  * check the (S, P, D, E) order on all vehicles
212  * stop when a feasible truck is found
213  */
214  msg.log << "\n Checking orders";
215  for (const auto &o : m_orders) {
216  if (!m_trucks.is_order_ok(o)) {
217  msg.error << "Order not feasible on any truck was found";
218  msg.log << "The order "
219  << o.id()
220  << " is not feasible on any truck";
221  msg.log << "\n" << o;
222 #if 0
223  double old_speed(0);
224  for (auto t : m_trucks) {
225  if (old_speed == t.speed()) continue;
226  old_speed = t.speed();
227  msg.log << "****** With speed: " << t.speed() << "\n";
228  msg.log << t.start_site() << "\n";
229  msg.log << o.pickup() << "\n";
230  msg.log << "travel time to "
231  << t.start_site().travel_time_to(
232  o.pickup(), t.speed()) << "\n";
233 
234  msg.log << o.delivery() << "\n";
235  msg.log << t.end_site() << "\n";
236  msg.log << "travel time to "
237  << t.start_site().travel_time_to(
238  o.delivery(), t.speed())
239  << "\n";
240  t.push_back(o);
241  }
242 #endif
243  return;
244  }
245  }
246  msg.log << "orders OK \n";
247 
248  m_trucks.set_compatibles(m_orders);
249 #if 0
250  msg.error << "foo";
251  for (const auto t : m_trucks) {
252  msg.log << t << "\n";
253  }
254 #endif
255  EXITING();
256  } // constructor
std::vector< std::unique_ptr< Base_node > > m_base_nodes
std::ostringstream log
Stores the hint information.
Definition: pgr_messages.h:102
size_t m_node_id
used to keep track of the next id the node gets in the eucledian version
std::string get_error() const
get_error
#define EXITING()
Definition: pgr_messages.h:119
std::ostringstream error
Stores the error information.
Definition: pgr_messages.h:106
#define ENTERING()
Definition: pgr_messages.h:118
std::vector< Vehicle_node > m_nodes
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:81
pgrouting::tsp::Dmatrix m_cost_matrix
double empty() const
Definition: Dmatrix.h:116
bool is_fleet_ok() const
Definition: fleet.cpp:291
static Pgr_messages msg
Definition: pd_problem.h:48
size_t m_max_cycles
maximum cycles in the optimization
int m_initial_id
used define the initial solution algorithm to be used

Here is the call graph for this function:

Member Function Documentation

void pgrouting::vrp::Pgr_pickDeliver::add_base_node ( std::unique_ptr< Base_node node_ptr)
inline

Definition at line 86 of file pgr_pickDeliver.h.

References m_base_nodes.

Referenced by pgrouting::vrp::PD_Orders::add_order(), and pgrouting::vrp::Fleet::add_vehicle().

86  {
87  m_base_nodes.push_back(std::move(node_ptr));
88  }
std::vector< std::unique_ptr< Base_node > > m_base_nodes

Here is the caller graph for this function:

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

Definition at line 82 of file pgr_pickDeliver.h.

References m_nodes.

Referenced by pgrouting::vrp::PD_Orders::add_order(), and pgrouting::vrp::Fleet::add_vehicle().

82  {
83  m_nodes.push_back(node);
84  }
std::vector< Vehicle_node > m_nodes

Here is the caller graph for this function:

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

Definition at line 126 of file pgr_pickDeliver.cpp.

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

Referenced by do_pgr_pickDeliver(), and do_pgr_pickDeliverEuclidean().

126  {
127  auto result = solutions.back().get_postgres_result();
128 
129  General_vehicle_orders_t aggregates = {
130  /*
131  * Vehicle id = -2 indicates its an aggregate row
132  *
133  * (twv, cv, fleet, wait, duration)
134  */
135  -2, // summary row on vehicle_number
136  solutions.back().twvTot(), // on vehicle_id
137  solutions.back().cvTot(), // on vehicle_seq
138  -1, // on order_id
139  -1, // on stop_id
140  -2, // on stop_type (gets increased later by one so it gets -1)
141  -1, // not accounting total loads
142  solutions.back().total_travel_time(),
143  -1, // not accounting arrival_travel_time
144  solutions.back().wait_time(),
145  solutions.back().total_service_time(),
146  solutions.back().duration(),
147  };
148  result.push_back(aggregates);
149 
150 
151 #ifndef NDEBUG
152  for (const auto sol : solutions) {
153  msg.log << sol.tau();
154  }
155 #endif
156  return result;
157 }
std::ostringstream log
Stores the hint information.
Definition: pgr_messages.h:102
std::vector< Solution > solutions
static Pgr_messages msg
Definition: pd_problem.h:48

Here is the caller graph for this function:

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

Definition at line 78 of file pgr_pickDeliver.h.

References m_max_cycles.

78 {return m_max_cycles;}
size_t m_max_cycles
maximum cycles in the optimization
size_t& pgrouting::vrp::Pgr_pickDeliver::node_id ( )
inline

Definition at line 80 of file pgr_pickDeliver.h.

References m_node_id.

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

80 {return m_node_id;}
size_t m_node_id
used to keep track of the next id the node gets in the eucledian version

Here is the caller graph for this function:

bool pgrouting::vrp::Pgr_pickDeliver::nodesOK ( ) const

Definition at line 51 of file pgr_pickDeliver.cpp.

References ENTERING, EXITING, pgrouting::Pgr_messages::get_log(), m_base_nodes, m_nodes, pgrouting::vrp::PD_problem::msg, and pgassertwm.

Referenced by Pgr_pickDeliver().

51  {
52  ENTERING();
53  if (m_nodes.empty() && m_base_nodes.empty()) return true;
54 
55  pgassertwm(m_nodes.size() == m_base_nodes.size(), msg.get_log().c_str());
56  for (size_t i = 0; i < m_nodes.size() ; ++i) {
57  pgassertwm(m_nodes[i].id() == m_base_nodes[i]->id(),
58  msg.get_log().c_str());
59  pgassertwm(m_nodes[i].idx() == m_base_nodes[i]->idx(),
60  msg.get_log().c_str());
61  }
62  EXITING();
63  return true;
64 }
#define pgassertwm(expr, msg)
Adds a message to the assertion.
Definition: pgr_assert.h:104
std::vector< std::unique_ptr< Base_node > > m_base_nodes
std::string get_log() const
get_log
#define EXITING()
Definition: pgr_messages.h:119
#define ENTERING()
Definition: pgr_messages.h:118
std::vector< Vehicle_node > m_nodes
static Pgr_messages msg
Definition: pd_problem.h:48

Here is the call graph for this function:

Here is the caller graph for this function:

Solution pgrouting::vrp::Pgr_pickDeliver::optimize ( const Solution  init_solution)

Definition at line 67 of file pgr_pickDeliver.cpp.

References pgrouting::vrp::Optimize::best_solution, pgrouting::Pgr_messages::log, m_max_cycles, pgrouting::vrp::PD_problem::msg, pgassert, and pgrouting::vrp::Solution::tau().

67  {
68  pgassert(false);
69  /*
70  * Optimize a solution
71  */
72 #if 1
73  msg.log << "max_cycles: " << m_max_cycles << "\n";
74  Optimize opt_solution(solution, m_max_cycles);
75 #else
76  Optimize opt_solution(solution, 1);
77 #endif
78  msg.log << opt_solution.best_solution.tau("optimized");
79  return opt_solution.best_solution;
80 }
std::ostringstream log
Stores the hint information.
Definition: pgr_messages.h:102
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:81
static Pgr_messages msg
Definition: pd_problem.h:48
size_t m_max_cycles
maximum cycles in the optimization

Here is the call graph for this function:

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

Definition at line 83 of file pgr_pickDeliver.cpp.

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

Referenced by do_pgr_pickDeliver(), and do_pgr_pickDeliverEuclidean().

83  {
84  auto initial_sols = solutions;
85 
86  if (m_initial_id == 0) {
87  msg.log << "trying all \n";
88  for (int i = 1; i < 7; ++i) {
89  initial_sols.push_back(Initial_solution(i, m_orders.size()));
90  msg.log << "solution " << i << "\n" << initial_sols.back().tau();
91  // TODO(vicky) calculate the time it takes
92  msg.log << "Initial solution " << i
93  << " duration: " << initial_sols.back().duration();
94  }
95  } else {
96  msg.log << "only trying " << m_initial_id << "\n";
97  initial_sols.push_back(Initial_solution(m_initial_id, m_orders.size()));
98  // TODO(vicky) calculate the time it takes
99  msg.log << "Initial solution " << m_initial_id
100  << " duration: " << initial_sols[0].duration();
101  }
102 
103 
104  /*
105  * Sorting solutions: the best is at the back
106  */
107  pgassert(!initial_sols.empty());
108  std::sort(initial_sols.begin(), initial_sols.end(), []
109  (const Solution &lhs, const Solution &rhs) -> bool {
110  return rhs < lhs;
111  });
112 
113 #if 1
114  solutions.push_back(Optimize(initial_sols.back(), m_max_cycles));
115 #else
116  solutions.push_back(initial_sols.back());
117 #endif
118  pgassert(!solutions.empty());
119 
120  msg.log << "best solution duration = " << solutions.back().duration();
121 }
std::ostringstream log
Stores the hint information.
Definition: pgr_messages.h:102
std::vector< Solution > solutions
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:81
size_t size() const
Definition: pd_orders.h:78
static Pgr_messages msg
Definition: pd_problem.h:48
size_t m_max_cycles
maximum cycles in the optimization
int m_initial_id
used define the initial solution algorithm to be used

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 94 of file pgr_pickDeliver.h.

References m_trucks.

Member Data Documentation

std::vector<std::unique_ptr<Base_node> > pgrouting::vrp::Pgr_pickDeliver::m_base_nodes
int pgrouting::vrp::Pgr_pickDeliver::m_initial_id
private

used define the initial solution algorithm to be used

Definition at line 98 of file pgr_pickDeliver.h.

Referenced by Pgr_pickDeliver(), and solve().

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

maximum cycles in the optimization

Definition at line 101 of file pgr_pickDeliver.h.

Referenced by max_cycles(), optimize(), and solve().

size_t pgrouting::vrp::Pgr_pickDeliver::m_node_id
private

used to keep track of the next id the node gets in the eucledian version

Definition at line 104 of file pgr_pickDeliver.h.

Referenced by node_id().

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

Definition at line 106 of file pgr_pickDeliver.h.

Referenced by add_node(), and nodesOK().

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

Definition at line 114 of file pgr_pickDeliver.h.

Referenced by Pgr_pickDeliver(), and solve().

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

Definition at line 115 of file pgr_pickDeliver.h.

Referenced by Pgr_pickDeliver(), and trucks().

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

Definition at line 116 of file pgr_pickDeliver.h.

Referenced by get_postgres_result(), and solve().


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