pgRouting
pgRouting extends the PostGIS / PostgreSQL geospatial database to provide geospatial routing functionality.
 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 #if defined(__MINGW32__) || defined(_MSC_VER)
32 #include <winsock2.h>
33 #include <windows.h>
34 #endif
35 
36 #include "./pickDeliver_driver.h"
37 #include <string.h>
38 #include <sstream>
39 #include <string>
40 #include <deque>
41 #include <vector>
42 #include "./../../common/src/pgr_assert.h"
43 #include "./../../common/src/pgr_types.h"
44 #include "./../../common/src/pgr_alloc.hpp"
45 #include "./pgr_pickDeliver.h"
46 
47 /************************************************************
48  customers_sql TEXT,
49  max_vehicles INTEGER,
50  capacity FLOAT,
51  max_cycles INTEGER,
52  ***********************************************************/
53 void
55  Customer_t *customers_arr,
56  size_t total_customers,
57  int max_vehicles,
58  double capacity,
59  double speed,
60  int max_cycles,
61  General_vehicle_orders_t **result_tuples,
62  size_t *total_count,
63  char ** log_msg,
64  char ** err_msg) {
65  std::ostringstream log;
66  try {
67  std::ostringstream tmp_log;
68  *result_tuples = NULL;
69  *total_count = 0;
70 
71  log << "Read data\n";
72  std::string error("");
74  customers_arr,
75  total_customers,
76  max_vehicles,
77  capacity,
78  speed,
79  max_cycles,
80  error);
81  if (error.compare("")) {
82  pd_problem.get_log(log);
83  *log_msg = strdup(log.str().c_str());
84  *err_msg = strdup(error.c_str());
85  return;
86  }
87  pd_problem.get_log(tmp_log);
88  log << "Finish Reading data\n";
89 
90  try {
91  pd_problem.solve();
92  } catch (AssertFailedException &except) {
93  pd_problem.get_log(log);
94  throw except;
95  }
96 
97  pd_problem.get_log(log);
98  log << "Finish solve\n";
99 
100  std::vector<General_vehicle_orders_t> solution;
101  pd_problem.get_postgres_result(solution);
102  pd_problem.get_log(tmp_log);
103  log << "solution size: " << solution.size() << "\n";
104 
105 
106  (*result_tuples) = pgr_alloc(solution.size(), (*result_tuples));
107  int seq = 0;
108  for (const auto &row : solution) {
109  (*result_tuples)[seq] = row;
110  ++seq;
111  }
112  (*total_count) = solution.size();
113 
114  pd_problem.get_log(log);
115  *log_msg = strdup(log.str().c_str());
116  } catch (AssertFailedException &except) {
117  log << except.what() << "\n";
118  *err_msg = strdup(log.str().c_str());
119  } catch (std::exception& except) {
120  log << except.what() << "\n";
121  *err_msg = strdup(log.str().c_str());
122  } catch(...) {
123  log << "Caught unknown exception!\n";
124  *err_msg = strdup(log.str().c_str());
125  }
126 }
127 
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:52
virtual const char * what() const
Definition: pgr_assert.cpp:62
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)