PGROUTING  2.6
pickDeliverEuclidean_driver.cpp
Go to the documentation of this file.
1 /*PGR-GNU*****************************************************************
2 File: pickDeliver_driver.cpp
3 
4 Generated with Template by:
5 Copyright (c) 2015 pgRouting developers
6 Mail: project@pgrouting.org
7 
8 Function's developer:
9 Copyright (c) 2015 Celia Virginia Vergara Castillo
10 Mail:
11 
12 ------
13 
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 2 of the License, or
17 (at your option) any later version.
18 
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
23 
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 
28  ********************************************************************PGR-GNU*/
29 
30 
32 
33 #include <string.h>
34 #include <sstream>
35 #include <string>
36 #include <deque>
37 #include <vector>
38 
39 #include "vrp/pgr_pickDeliver.h"
40 
41 #include "cpp_common/pgr_assert.h"
42 #include "cpp_common/pgr_alloc.hpp"
43 
44 /************************************************************
45  customers_sql TEXT,
46  max_vehicles INTEGER,
47  factor FLOAT,
48  capacity FLOAT,
49  max_cycles INTEGER,
50  ***********************************************************/
51 void
53  PickDeliveryOrders_t *customers_arr,
54  size_t total_customers,
55 
56  Vehicle_t *vehicles_arr,
57  size_t total_vehicles,
58 
59  double factor,
60  int max_cycles,
61  int initial_solution_id,
62 
63  General_vehicle_orders_t **return_tuples,
64  size_t *return_count,
65 
66  char **log_msg,
67  char **notice_msg,
68  char **err_msg) {
69  std::ostringstream log;
70  std::ostringstream notice;
71  std::ostringstream err;
72  try {
73  std::ostringstream tmp_log;
74  *return_tuples = NULL;
75  *return_count = 0;
76 
77  /*
78  * transform to C++ containers
79  */
80  std::vector<PickDeliveryOrders_t> orders(
81  customers_arr, customers_arr + total_customers);
82  std::vector<Vehicle_t> vehicles(
83  vehicles_arr, vehicles_arr + total_vehicles);
84 
85  log << "Initialize problem\n";
87  orders,
88  vehicles,
89  factor,
90  max_cycles,
91  initial_solution_id);
92 
93  err << pd_problem.msg.get_error();
94  if (!err.str().empty()) {
95  log.str("");
96  log.clear();
97  log << pd_problem.msg.get_error();
98  log << pd_problem.msg.get_log();
99  *log_msg = pgr_msg(log.str().c_str());
100  *err_msg = pgr_msg(err.str().c_str());
101  return;
102  }
103  log << pd_problem.msg.get_log();
104  log << "Finish Reading data\n";
105 
106  try {
107  pd_problem.solve();
108  } catch (AssertFailedException &except) {
109  log << pd_problem.msg.get_log();
110  throw except;
111  } catch(...) {
112  log << "Caught unknown exception!";
113  throw;
114  }
115 
116  log << pd_problem.msg.get_log();
117  log << "Finish solve\n";
118 
119  auto solution = pd_problem.get_postgres_result();
120  log << pd_problem.msg.get_log();
121  log << "solution size: " << solution.size() << "\n";
122 
123 
124  if (!solution.empty()) {
125  (*return_tuples) = pgr_alloc(solution.size(), (*return_tuples));
126  int seq = 0;
127  for (const auto &row : solution) {
128  (*return_tuples)[seq] = row;
129  ++seq;
130  }
131  }
132  (*return_count) = solution.size();
133 
134  log << pd_problem.msg.get_log();
135 
136  pgassert(*err_msg == NULL);
137  *log_msg = log.str().empty()?
138  nullptr :
139  pgr_msg(log.str().c_str());
140  *notice_msg = notice.str().empty()?
141  nullptr :
142  pgr_msg(notice.str().c_str());
143  } catch (AssertFailedException &except) {
144  if (*return_tuples) free(*return_tuples);
145  (*return_count) = 0;
146  err << except.what();
147  *err_msg = pgr_msg(err.str().c_str());
148  *log_msg = pgr_msg(log.str().c_str());
149  } catch (std::exception& except) {
150  if (*return_tuples) free(*return_tuples);
151  (*return_count) = 0;
152  err << except.what();
153  *err_msg = pgr_msg(err.str().c_str());
154  *log_msg = pgr_msg(log.str().c_str());
155  } catch(...) {
156  if (*return_tuples) free(*return_tuples);
157  (*return_count) = 0;
158  err << "Caught unknown exception!";
159  *err_msg = pgr_msg(err.str().c_str());
160  *log_msg = pgr_msg(log.str().c_str());
161  }
162 }
Extends std::exception and is the exception that we throw if an assert fails.
Definition: pgr_assert.h:126
std::string get_log() const
get_log
std::string get_error() const
get_error
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:81
char * pgr_msg(const std::string &msg)
Definition: pgr_alloc.cpp:30
T * pgr_alloc(std::size_t size, T *ptr)
allocates memory
Definition: pgr_alloc.hpp:66
Assertions Handling.
static Pgr_messages msg
Definition: pd_problem.h:48
virtual const char * what() const
Definition: pgr_assert.cpp:53
void do_pgr_pickDeliverEuclidean(PickDeliveryOrders_t *customers_arr, size_t total_customers, Vehicle_t *vehicles_arr, size_t total_vehicles, double factor, int max_cycles, int initial_solution_id, General_vehicle_orders_t **return_tuples, size_t *return_count, char **log_msg, char **notice_msg, char **err_msg)
std::vector< General_vehicle_orders_t > get_postgres_result() const