PGROUTING  2.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
pickDeliver_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 
31 #include "./pickDeliver_driver.h"
32 
33 #include <string.h>
34 #include <sstream>
35 #include <string>
36 #include <deque>
37 #include <vector>
38 
39 #include "./pgr_pickDeliver.h"
40 
41 #include "./../../common/src/pgr_assert.h"
42 #include "./../../common/src/pgr_alloc.hpp"
43 
44 /************************************************************
45  customers_sql TEXT,
46  max_vehicles INTEGER,
47  capacity FLOAT,
48  max_cycles INTEGER,
49  ***********************************************************/
50 void
52  Customer_t *customers_arr,
53  size_t total_customers,
54  int max_vehicles,
55  double capacity,
56  double speed,
57  int max_cycles,
58  General_vehicle_orders_t **result_tuples,
59  size_t *total_count,
60  char ** log_msg,
61  char ** err_msg) {
62  std::ostringstream log;
63  try {
64  std::ostringstream tmp_log;
65  *result_tuples = NULL;
66  *total_count = 0;
67 
68  log << "Read data\n";
69  std::string error("");
71  customers_arr,
72  total_customers,
73  max_vehicles,
74  capacity,
75  speed,
76  max_cycles,
77  error);
78  if (error.compare("")) {
79  pd_problem.get_log(log);
80  *log_msg = strdup(log.str().c_str());
81  *err_msg = strdup(error.c_str());
82  return;
83  }
84  pd_problem.get_log(tmp_log);
85  log << "Finish Reading data\n";
86 
87  try {
88  pd_problem.solve();
89  } catch (AssertFailedException &except) {
90  pd_problem.get_log(log);
91  throw except;
92  }
93 
94  pd_problem.get_log(log);
95  log << "Finish solve\n";
96 
97  std::vector<General_vehicle_orders_t> solution;
98  pd_problem.get_postgres_result(solution);
99  pd_problem.get_log(tmp_log);
100  log << "solution size: " << solution.size() << "\n";
101 
102 
103  (*result_tuples) = pgr_alloc(solution.size(), (*result_tuples));
104  int seq = 0;
105  for (const auto &row : solution) {
106  (*result_tuples)[seq] = row;
107  ++seq;
108  }
109  (*total_count) = solution.size();
110 
111  pd_problem.get_log(log);
112  *log_msg = strdup(log.str().c_str());
113  } catch (AssertFailedException &except) {
114  log << except.what() << "\n";
115  *err_msg = strdup(log.str().c_str());
116  } catch (std::exception& except) {
117  log << except.what() << "\n";
118  *err_msg = strdup(log.str().c_str());
119  } catch(...) {
120  log << "Caught unknown exception!\n";
121  *err_msg = strdup(log.str().c_str());
122  }
123 }
124 
Extends std::exception and is the exception that we throw if an assert fails.
Definition: pgr_assert.h:126
void get_postgres_result(std::vector< General_vehicle_orders_t > &result) const
std::ostream & get_log(std::ostream &p_log) const
get_log
T * pgr_alloc(std::size_t size, T *ptr)
allocates memory
Definition: pgr_alloc.hpp:62
virtual const char * what() const
Definition: pgr_assert.cpp:53
char * err_msg
Definition: BDATester.cpp:50
void do_pgr_pickDeliver(Customer_t *customers_arr, size_t total_customers, int max_vehicles, double capacity, double speed, int max_cycles, General_vehicle_orders_t **result_tuples, size_t *total_count, char **log_msg, char **err_msg)