From c0634a34daf841c89fbd326450c8b8bc6c0b0f19 Mon Sep 17 00:00:00 2001 From: cvvergara Date: Sun, 25 Aug 2024 15:30:45 -0600 Subject: [PATCH] Removing unused files --- include/c_common/arrays_input.h | 43 - include/c_common/matrixRows_input.h | 45 - include/c_common/orders_input.h | 53 -- include/c_common/time_multipliers_input.h | 49 - include/c_common/vehicles_input.h | 58 -- include/c_common/vroom/breaks_input.h | 46 - include/c_common/vroom/jobs_input.h | 46 - include/c_common/vroom/matrix_input.h | 46 - include/c_common/vroom/shipments_input.h | 46 - include/c_common/vroom/time_windows_input.h | 54 -- include/c_common/vroom/vehicles_input.h | 46 - include/cpp_common/get_check_data.hpp | 166 ---- include/vrp/initial_solution.h | 72 -- include/vrp/initials_code.h | 50 -- src/common/arrays_input.c | 230 ----- src/common/matrixRows_input.c | 201 ----- src/common/orders_input.c | 363 -------- src/common/time_multipliers_input.c | 194 ---- src/common/vehicles_input.c | 464 ---------- src/common/vroom/breaks_input.c | 167 ---- src/common/vroom/jobs_input.c | 204 ----- src/common/vroom/matrix_input.c | 166 ---- src/common/vroom/shipments_input.c | 219 ----- src/common/vroom/time_windows_input.c | 225 ----- src/common/vroom/vehicles_input.c | 225 ----- src/cpp_common/get_check_data.c | 946 -------------------- 26 files changed, 4424 deletions(-) delete mode 100644 include/c_common/arrays_input.h delete mode 100644 include/c_common/matrixRows_input.h delete mode 100644 include/c_common/orders_input.h delete mode 100644 include/c_common/time_multipliers_input.h delete mode 100644 include/c_common/vehicles_input.h delete mode 100644 include/c_common/vroom/breaks_input.h delete mode 100644 include/c_common/vroom/jobs_input.h delete mode 100644 include/c_common/vroom/matrix_input.h delete mode 100644 include/c_common/vroom/shipments_input.h delete mode 100644 include/c_common/vroom/time_windows_input.h delete mode 100644 include/c_common/vroom/vehicles_input.h delete mode 100644 include/cpp_common/get_check_data.hpp delete mode 100644 include/vrp/initial_solution.h delete mode 100644 include/vrp/initials_code.h delete mode 100644 src/common/arrays_input.c delete mode 100644 src/common/matrixRows_input.c delete mode 100644 src/common/orders_input.c delete mode 100644 src/common/time_multipliers_input.c delete mode 100644 src/common/vehicles_input.c delete mode 100644 src/common/vroom/breaks_input.c delete mode 100644 src/common/vroom/jobs_input.c delete mode 100644 src/common/vroom/matrix_input.c delete mode 100644 src/common/vroom/shipments_input.c delete mode 100644 src/common/vroom/time_windows_input.c delete mode 100644 src/common/vroom/vehicles_input.c delete mode 100644 src/cpp_common/get_check_data.c diff --git a/include/c_common/arrays_input.h b/include/c_common/arrays_input.h deleted file mode 100644 index 33db7eadc..000000000 --- a/include/c_common/arrays_input.h +++ /dev/null @@ -1,43 +0,0 @@ -/*PGR-GNU***************************************************************** -File: arrays_input.h - -Copyright (c) 2015 Celia Virginia Vergara Castillo -vicky_vergara@hotmail.com - ------- - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - - ********************************************************************PGR-GNU*/ - -#ifndef INCLUDE_C_COMMON_ARRAYS_INPUT_H_ -#define INCLUDE_C_COMMON_ARRAYS_INPUT_H_ -#pragma once - - -#include -#include -#include - -/** @brief enforces the input array to be @b NOT empty */ -int64_t* pgr_get_bigIntArray(size_t *arrlen, ArrayType *input); - -/** @brief Allows the input array to be empty */ -int64_t* pgr_get_bigIntArray_allowEmpty(size_t *arrlen, ArrayType *input); - -/** @brief Allows the input array, with non-negative elements to be empty */ -uint32_t* pgr_get_positiveIntArray_allowEmpty(size_t *arrlen, ArrayType *input); - -#endif // INCLUDE_C_COMMON_ARRAYS_INPUT_H_ diff --git a/include/c_common/matrixRows_input.h b/include/c_common/matrixRows_input.h deleted file mode 100644 index 5e3169981..000000000 --- a/include/c_common/matrixRows_input.h +++ /dev/null @@ -1,45 +0,0 @@ -/*PGR-GNU***************************************************************** -File: matrixRows_input.h - -Copyright (c) 2015 Celia Virginia Vergara Castillo -vicky_vergara@hotmail.com - ------- - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - - ********************************************************************PGR-GNU*/ - -#ifndef INCLUDE_C_COMMON_MATRIXROWS_INPUT_H_ -#define INCLUDE_C_COMMON_MATRIXROWS_INPUT_H_ -#pragma once - -#include - -typedef struct Matrix_cell_t Matrix_cell_t; - -/** @brief Get the travel time matrix */ -void get_matrixRows( - char *sql, - Matrix_cell_t **rows, - size_t *total_rows); - -/** @brief Get the travel time matrix with numerical types*/ -void get_matrixRows_plain( - char *sql, - Matrix_cell_t **rows, - size_t *total_rows); - -#endif // INCLUDE_C_COMMON_MATRIXROWS_INPUT_H_ diff --git a/include/c_common/orders_input.h b/include/c_common/orders_input.h deleted file mode 100644 index 6b2aa8261..000000000 --- a/include/c_common/orders_input.h +++ /dev/null @@ -1,53 +0,0 @@ -/*PGR-GNU***************************************************************** -File: orders_input.h - -Copyright (c) 2016 Celia Virginia Vergara Castillo -vicky_vergara@hotmail.com - ------- - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - - ********************************************************************PGR-GNU*/ - -#ifndef INCLUDE_C_COMMON_ORDERS_INPUT_H_ -#define INCLUDE_C_COMMON_ORDERS_INPUT_H_ -#pragma once - -#include -typedef struct Orders_t Orders_t; - -/** @brief Reads the pick-Deliver shipments for timestams and intervals*/ -void -get_shipments( - char *, - Orders_t **, - size_t *); - -/** @brief Reads the pick-Deliver shipments for raw data*/ -void -get_shipments_raw( - char *, - Orders_t **, - size_t *); - -/** @brief Reads the pick-Deliver shipments for euclidean information*/ -void -get_shipments_euclidean( - char *, - Orders_t **, - size_t *); - -#endif // INCLUDE_C_COMMON_ORDERS_INPUT_H_ diff --git a/include/c_common/time_multipliers_input.h b/include/c_common/time_multipliers_input.h deleted file mode 100644 index 229ea092f..000000000 --- a/include/c_common/time_multipliers_input.h +++ /dev/null @@ -1,49 +0,0 @@ -/*PGR-GNU***************************************************************** -File: time_multipliers_input.h - -Copyright (c) 2021 pgRouting developers -Mail: project@pgrouting.org - -Developer: -Copyright (c) 2021 Celia Virginia Vergara Castillo -Copyright (c) 2021 Joseph Emile Honour Percival - ------- - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - - ********************************************************************PGR-GNU*/ - -#ifndef INCLUDE_C_COMMON_TIME_MULTIPLIERS_INPUT_H_ -#define INCLUDE_C_COMMON_TIME_MULTIPLIERS_INPUT_H_ -#pragma once - -#include - -typedef struct Time_multipliers_t Time_multipliers_t; - -/** @brief Get the time multipliers using interval*/ -void get_timeMultipliers( - char *sql, - Time_multipliers_t **row, - size_t *total_rows); - -/** @brief Get the time multipliers using bigint*/ -void get_timeMultipliers_raw( - char *sql, - Time_multipliers_t **row, - size_t *total_rows); - -#endif // INCLUDE_C_COMMON_TIME_MULTIPLIERS_INPUT_H_ diff --git a/include/c_common/vehicles_input.h b/include/c_common/vehicles_input.h deleted file mode 100644 index ef36e0c90..000000000 --- a/include/c_common/vehicles_input.h +++ /dev/null @@ -1,58 +0,0 @@ -/*PGR-GNU***************************************************************** -File: vehicles_input.h - -Copyright (c) 2016 Celia Virginia Vergara Castillo -vicky_vergara@hotmail.com - ------- - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - - ********************************************************************PGR-GNU*/ - -#ifndef INCLUDE_C_COMMON_VEHICLES_INPUT_H_ -#define INCLUDE_C_COMMON_VEHICLES_INPUT_H_ -#pragma once - -#include -#include - -typedef struct Vehicle_t Vehicle_t; - -/** @brief Reads the vehicles information */ -void -get_vehicles( - char *, - Vehicle_t **, - size_t *, - bool); - -/** @brief Reads the vehicles information */ -void -get_vehicles_raw( - char *, - Vehicle_t **, - size_t *, - bool); - -/** @brief Reads the vehicles information */ -void -get_vehicles_euclidean( - char *, - Vehicle_t **, - size_t *, - bool); - -#endif // INCLUDE_C_COMMON_VEHICLES_INPUT_H_ diff --git a/include/c_common/vroom/breaks_input.h b/include/c_common/vroom/breaks_input.h deleted file mode 100644 index a5d2f85b4..000000000 --- a/include/c_common/vroom/breaks_input.h +++ /dev/null @@ -1,46 +0,0 @@ -/*PGR-GNU***************************************************************** -File: breaks_input.h - -Copyright (c) 2021 pgRouting developers -Mail: project@pgrouting.org - -Function's developer: -Copyright (c) 2021 Ashish Kumar -Mail: ashishkr23438@gmail.com - ------- - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - - ********************************************************************PGR-GNU*/ - -#ifndef INCLUDE_C_COMMON_VROOM_BREAKS_INPUT_H_ -#define INCLUDE_C_COMMON_VROOM_BREAKS_INPUT_H_ -#pragma once - -#include -#include - -typedef struct Vroom_break_t Vroom_break_t; - -/** @brief Reads the VROOM breaks */ -void -get_vroom_breaks( - char *breaks_sql, - Vroom_break_t **breaks, - size_t *total_breaks, - bool is_plain); - -#endif // INCLUDE_C_COMMON_VROOM_BREAKS_INPUT_H_ diff --git a/include/c_common/vroom/jobs_input.h b/include/c_common/vroom/jobs_input.h deleted file mode 100644 index 7ec4c0cb5..000000000 --- a/include/c_common/vroom/jobs_input.h +++ /dev/null @@ -1,46 +0,0 @@ -/*PGR-GNU***************************************************************** -File: jobs_input.h - -Copyright (c) 2021 pgRouting developers -Mail: project@pgrouting.org - -Function's developer: -Copyright (c) 2021 Ashish Kumar -Mail: ashishkr23438@gmail.com - ------- - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - - ********************************************************************PGR-GNU*/ - -#ifndef INCLUDE_C_COMMON_VROOM_JOBS_INPUT_H_ -#define INCLUDE_C_COMMON_VROOM_JOBS_INPUT_H_ -#pragma once - -#include -#include - -typedef struct Vroom_job_t Vroom_job_t; - -/** @brief Reads the VROOM jobs */ -void -get_vroom_jobs( - char *jobs_sql, - Vroom_job_t **jobs, - size_t *total_jobs, - bool is_plain); - -#endif // INCLUDE_C_COMMON_VROOM_JOBS_INPUT_H_ diff --git a/include/c_common/vroom/matrix_input.h b/include/c_common/vroom/matrix_input.h deleted file mode 100644 index 67c10756e..000000000 --- a/include/c_common/vroom/matrix_input.h +++ /dev/null @@ -1,46 +0,0 @@ -/*PGR-GNU***************************************************************** -File: matrix_input.h - -Copyright (c) 2021 pgRouting developers -Mail: project@pgrouting.org - -Function's developer: -Copyright (c) 2021 Ashish Kumar -Mail: ashishkr23438@gmail.com - ------- - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - - ********************************************************************PGR-GNU*/ - -#ifndef INCLUDE_C_COMMON_VROOM_MATRIX_INPUT_H_ -#define INCLUDE_C_COMMON_VROOM_MATRIX_INPUT_H_ -#pragma once - -#include -#include - -typedef struct Vroom_matrix_t Vroom_matrix_t; - -/** @brief Reads the VROOM matrix */ -void -get_vroom_matrix( - char *matrix_sql, - Vroom_matrix_t **matrix, - size_t *total_matrix_rows, - bool is_plain); - -#endif // INCLUDE_C_COMMON_VROOM_MATRIX_INPUT_H_ diff --git a/include/c_common/vroom/shipments_input.h b/include/c_common/vroom/shipments_input.h deleted file mode 100644 index 22008b461..000000000 --- a/include/c_common/vroom/shipments_input.h +++ /dev/null @@ -1,46 +0,0 @@ -/*PGR-GNU***************************************************************** -File: shipments_input.h - -Copyright (c) 2021 pgRouting developers -Mail: project@pgrouting.org - -Function's developer: -Copyright (c) 2021 Ashish Kumar -Mail: ashishkr23438@gmail.com - ------- - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - - ********************************************************************PGR-GNU*/ - -#ifndef INCLUDE_C_COMMON_VROOM_SHIPMENTS_INPUT_H_ -#define INCLUDE_C_COMMON_VROOM_SHIPMENTS_INPUT_H_ -#pragma once - -#include -#include - -typedef struct Vroom_shipment_t Vroom_shipment_t; - -/** @brief Reads the VROOM shipments */ -void -get_vroom_shipments( - char *shipments_sql, - Vroom_shipment_t **shipments, - size_t *total_shipments, - bool is_plain); - -#endif // INCLUDE_C_COMMON_VROOM_SHIPMENTS_INPUT_H_ diff --git a/include/c_common/vroom/time_windows_input.h b/include/c_common/vroom/time_windows_input.h deleted file mode 100644 index f139bd592..000000000 --- a/include/c_common/vroom/time_windows_input.h +++ /dev/null @@ -1,54 +0,0 @@ -/*PGR-GNU***************************************************************** -File: time_windows_input.h - -Copyright (c) 2021 pgRouting developers -Mail: project@pgrouting.org - -Function's developer: -Copyright (c) 2021 Ashish Kumar -Mail: ashishkr23438@gmail.com - ------- - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - - ********************************************************************PGR-GNU*/ - -#ifndef INCLUDE_C_COMMON_VROOM_TIME_WINDOWS_INPUT_H_ -#define INCLUDE_C_COMMON_VROOM_TIME_WINDOWS_INPUT_H_ -#pragma once - -#include -#include - -typedef struct Vroom_time_window_t Vroom_time_window_t; - -/** @brief Reads the VROOM time windows */ -void -get_vroom_time_windows( - char *time_windows_sql, - Vroom_time_window_t **time_windows, - size_t *total_time_windows, - bool is_plain); - -/** @brief Reads the VROOM shipments time windows */ -void -get_vroom_shipments_time_windows( - char *time_windows_sql, - Vroom_time_window_t **time_windows, - size_t *total_time_windows, - bool is_plain); - -#endif // INCLUDE_C_COMMON_VROOM_TIME_WINDOWS_INPUT_H_ diff --git a/include/c_common/vroom/vehicles_input.h b/include/c_common/vroom/vehicles_input.h deleted file mode 100644 index 3e27e22e3..000000000 --- a/include/c_common/vroom/vehicles_input.h +++ /dev/null @@ -1,46 +0,0 @@ -/*PGR-GNU***************************************************************** -File: vehicles_input.h - -Copyright (c) 2021 pgRouting developers -Mail: project@pgrouting.org - -Function's developer: -Copyright (c) 2021 Ashish Kumar -Mail: ashishkr23438@gmail.com - ------- - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - - ********************************************************************PGR-GNU*/ - -#ifndef INCLUDE_C_COMMON_VROOM_VEHICLES_INPUT_H_ -#define INCLUDE_C_COMMON_VROOM_VEHICLES_INPUT_H_ -#pragma once - -#include -#include - -typedef struct Vroom_vehicle_t Vroom_vehicle_t; - -/** @brief Reads the VROOM vehicles */ -void -get_vroom_vehicles( - char *vehicles_sql, - Vroom_vehicle_t **vehicles, - size_t *total_vehicles, - bool is_plain); - -#endif // INCLUDE_C_COMMON_VROOM_VEHICLES_INPUT_H_ diff --git a/include/cpp_common/get_check_data.hpp b/include/cpp_common/get_check_data.hpp deleted file mode 100644 index fe28ee169..000000000 --- a/include/cpp_common/get_check_data.hpp +++ /dev/null @@ -1,166 +0,0 @@ -/*PGR-GNU***************************************************************** -FILE: get_check_data.hpp - -Copyright (c) 2015 Celia Virginia Vergara Castillo -vicky_vergara@hotmail.com - ------- - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - - ********************************************************************PGR-GNU*/ - -#ifndef INCLUDE_CPP_COMMON_GET_CHECK_DATA_HPP_ -#define INCLUDE_CPP_COMMON_GET_CHECK_DATA_HPP_ -#pragma once - -#include "c_common/postgres_connection.h" -#include "cpp_common/info.hpp" -#include "c_types/typedefs.h" - -/** @brief Check whether the colNumber represent any specific column or NULL (SPI_ERROR_NOATTRIBUTE). */ -bool column_found(int colNumber); - -/** @brief Function tells expected type of each column and then check the correspondence type of each column. */ -void pgr_fetch_column_info( - Column_info_t info[], - int info_size); - -/*! @brief get value of specified column in char type. */ -char -spi_getChar( - HeapTuple *tuple, - TupleDesc *tupdesc, - Column_info_t info, - char default_value); - -/** @brief Function returns the values of specified columns in array. */ -int64_t* -spi_getBigIntArr( - HeapTuple *tuple, - TupleDesc *tupdesc, - Column_info_t info, - size_t *the_size); - -/** @brief Function returns the values of specified columns in array. */ -int64_t* -spi_getBigIntArr_allowEmpty( - HeapTuple *tuple, - TupleDesc *tupdesc, - Column_info_t info, - size_t *the_size); - -/** @brief Function returns the values of specified columns in array. */ -int64_t* -spi_getPositiveBigIntArr_allowEmpty( - HeapTuple *tuple, - TupleDesc *tupdesc, - Column_info_t info, - size_t *the_size); - -/** @brief Function returns the values of specified columns in array. */ -uint32_t* -spi_getPositiveIntArr_allowEmpty( - HeapTuple *tuple, - TupleDesc *tupdesc, - Column_info_t info, - size_t *the_size); - -/** @brief gets value of specified column in double type. */ -double -spi_getFloat8( - HeapTuple *tuple, - TupleDesc *tupdesc, - Column_info_t info); - -/** @brief gets string representation of the value of specified column. */ -char* -spi_getText( - HeapTuple *tuple, - TupleDesc *tupdesc, - Column_info_t info); - -/** @brief gets the vehicle max tasks value */ -int32_t -spi_getMaxTasks( - HeapTuple *tuple, - TupleDesc *tupdesc, - Column_info_t info); - -/** @brief Converts timestamp to timestamp without timezone */ -TTimestamp timestamp_without_timezone(TTimestamp timestamp); - -/** @brief gets a timestamp value from postgres type TIMESTAMP */ -TTimestamp get_TTimestamp(HeapTuple*, TupleDesc*, Column_info_t, TTimestamp); - -/** @brief gets a timestamp value from postgres type TIMESTAMP >= 1970-01-01 00:00:00*/ -TTimestamp get_PositiveTTimestamp(HeapTuple*, TupleDesc*, Column_info_t, TTimestamp); - -/** @brief gets a timestamp value from ANY-INTEGER */ -TTimestamp get_TTimestamp_plain(HeapTuple*, TupleDesc*, Column_info_t, TTimestamp); - -/** @brief gets a timestamp value from ANY-INTEGER > 0 */ -TTimestamp get_PositiveTTimestamp_plain(HeapTuple*, TupleDesc*, Column_info_t, TTimestamp); - -/** @brief gets an interval value from postgres type INTERVAL */ -TInterval get_TInterval(HeapTuple*, TupleDesc*, Column_info_t, TInterval); - -/** @brief gets an interval value from postgres type INTERVAL > 0 */ -TInterval get_PositiveTInterval(HeapTuple*, TupleDesc*, Column_info_t, TInterval); - -/** @brief gets an interval value from ANY-INTEGER */ -TInterval get_TInterval_plain(HeapTuple*, TupleDesc*, Column_info_t, TInterval); - -/** @brief gets an interval value from ANY-INTEGER > 0 */ -TInterval get_PositiveTInterval_plain(HeapTuple*, TupleDesc*, Column_info_t, TInterval); - -/** get Id from data */ -Id get_Id(HeapTuple*, TupleDesc*, Column_info_t, Id); - -/** get Idx from data */ -Idx get_Idx(HeapTuple*, TupleDesc*, Column_info_t, Idx); - -/** get StepType from data */ -StepType get_StepType(HeapTuple *, TupleDesc *, Column_info_t, StepType); - -/** get MatrixIndex from data */ -MatrixIndex get_MatrixIndex(HeapTuple*, TupleDesc*, Column_info_t, MatrixIndex); - -/** get Duration from data */ -Duration get_Duration(HeapTuple*, TupleDesc*, Column_info_t, Duration); - -/** get TravelCost from data */ -TravelCost get_Cost(HeapTuple*, TupleDesc*, Column_info_t, TravelCost); - -/** get Kind from data */ -char get_Kind(HeapTuple*, TupleDesc*, Column_info_t, char); - -/** get Priority from data */ -Priority get_Priority(HeapTuple*, TupleDesc*, Column_info_t, Priority); - -/** get Distance from data */ -Distance get_Distance(HeapTuple*, TupleDesc*, Column_info_t, Distance); - -/** get Amount from data */ -Amount get_Amount(HeapTuple*, TupleDesc*, Column_info_t, Amount); - -/** get positive Amount from data */ -PAmount get_PositiveAmount(HeapTuple*, TupleDesc*, Column_info_t, PAmount); - -/** get a coordinate value */ -Coordinate spi_getCoordinate(HeapTuple*, TupleDesc*, Column_info_t, Coordinate); - - -#endif // INCLUDE_CPP_COMMON_GET_CHECK_DATA_HPP_ diff --git a/include/vrp/initial_solution.h b/include/vrp/initial_solution.h deleted file mode 100644 index 2feea0d08..000000000 --- a/include/vrp/initial_solution.h +++ /dev/null @@ -1,72 +0,0 @@ -/*PGR-GNU***************************************************************** - -FILE: initial_solution.h - -Copyright (c) 2015 pgRouting developers -Mail: project@pgrouting.org - ------- - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - - ********************************************************************PGR-GNU*/ - -/*! @file */ - -#ifndef INCLUDE_VRP_INITIAL_SOLUTION_H_ -#define INCLUDE_VRP_INITIAL_SOLUTION_H_ -#pragma once - -#include -#include -#include "vrp/pd_orders.h" -#include "vrp/solution.h" -#include "vrp/initials_code.hpp" -#include "cpp_common/identifiers.hpp" - -namespace vrprouting { -namespace vrp { - - -class Pgr_pickDeliver; - - -class Initial_solution : public Solution { - public: - Initial_solution( - Initials_code kind, - size_t); - - void invariant() const; - - private: - /* - * one truck per order - */ - void one_truck_all_orders(); - - void do_while_foo(int kind); - - - private: - Identifiers all_orders; - Identifiers unassigned; - Identifiers assigned; -}; - -} // namespace vrp -} // namespace vrprouting - -#endif // INCLUDE_VRP_INITIAL_SOLUTION_H_ diff --git a/include/vrp/initials_code.h b/include/vrp/initials_code.h deleted file mode 100644 index 49989f54d..000000000 --- a/include/vrp/initials_code.h +++ /dev/null @@ -1,50 +0,0 @@ -/*PGR-GNU***************************************************************** - -FILE: initials_code.hpp - -Copyright (c) 2015 pgRouting developers -Mail: project@pgrouting.org - ------- - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - - ********************************************************************PGR-GNU*/ - -/*! @file */ - -#ifndef INCLUDE_VRP_INITIALS_CODE_H_ -#define INCLUDE_VRP_INITIALS_CODE_H_ -#pragma once - -namespace vrprouting { -namespace vrp { - -/*! Different kinds to insert an order into the vehicle */ -enum Initials_code { - OneTruck, /*! All orders in one truck */ - OnePerTruck, /*! One Order per truck */ - FrontTruck, /*! Insetion at the front of the truck */ - BackTruck, /*! Insetion at the back of the truck */ - BestInsert, /*! Best place to insert Order */ - BestBack, /*! Push back order that allows more orders to be inserted at the back */ - BestFront, /*! Push front order that allows more orders to be inserted at the front */ - OneDepot /*! Pick at front, drop at back, OneDepot for all vehicles */ -}; - -} // namespace vrp -} // namespace vrprouting - -#endif // INCLUDE_VRP_INITIALS_CODE_H_ diff --git a/src/common/arrays_input.c b/src/common/arrays_input.c deleted file mode 100644 index 24cbd7aea..000000000 --- a/src/common/arrays_input.c +++ /dev/null @@ -1,230 +0,0 @@ -/*PGR-GNU***************************************************************** -File: arrays_input.c - -Copyright (c) 2015 pgRouting developers -Mail: project@pgrouting.org - -Developer: -Copyright (c) 2015 Celia Virginia Vergara Castillo - ------- - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - - ********************************************************************PGR-GNU*/ -/* @file */ - -#include "c_common/arrays_input.h" - -#include -#include -#include - - -#ifdef PROFILE -#include "c_common/debug_macro.h" -#endif - -static -int64_t* -pgr_get_bigIntArr(ArrayType *v, size_t *arrlen, bool allow_empty) { -#ifdef PROFILE - clock_t start_t = clock(); -#endif - - int64_t *c_array = NULL; - - Oid element_type = ARR_ELEMTYPE(v); - int *dim = ARR_DIMS(v); - int ndim = ARR_NDIM(v); - int nitems = ArrayGetNItems(ndim, dim); - Datum *elements; - bool *nulls; - int16 typlen; - bool typbyval; - char typalign; - - assert((*arrlen) == 0); - - - if (allow_empty && (ndim == 0 || nitems <= 0)) { - return (int64_t*) NULL; - } - /* the array is not empty*/ - - if (ndim != 1) { - elog(ERROR, "One dimension expected"); - } - - if (nitems <= 0) { - elog(ERROR, "No elements found"); - } - - get_typlenbyvalalign(element_type, - &typlen, &typbyval, &typalign); - - /* validate input data type */ - switch (element_type) { - case INT2OID: - case INT4OID: - case INT8OID: - break; - default: - elog(ERROR, "Expected array of ANY-INTEGER"); - } - - deconstruct_array(v, element_type, typlen, typbyval, - typalign, &elements, &nulls, - &nitems); - - c_array = (int64_t *) palloc(sizeof(int64_t) * (size_t)nitems); - if (!c_array) { - elog(ERROR, "Out of memory!"); - } - - - int i; - for (i = 0; i < nitems; i++) { - if (nulls[i]) { - pfree(c_array); - elog(ERROR, "NULL value found in Array!"); - } else { - switch (element_type) { - case INT2OID: - c_array[i] = (int64_t) DatumGetInt16(elements[i]); - break; - case INT4OID: - c_array[i] = (int64_t) DatumGetInt32(elements[i]); - break; - case INT8OID: - c_array[i] = DatumGetInt64(elements[i]); - break; - } - } - } - (*arrlen) = (size_t)nitems; - - pfree(elements); - pfree(nulls); -#ifdef PROFILE - time_msg("reading Array", start_t, clock()); -#endif - return c_array; -} - - -static -uint32_t* -pgr_get_positiveIntArr(ArrayType *v, size_t *arrlen, bool allow_empty) { -#ifdef PROFILE - clock_t start_t = clock(); -#endif - - uint32_t *c_array = NULL; - - Oid element_type = ARR_ELEMTYPE(v); - int *dim = ARR_DIMS(v); - int ndim = ARR_NDIM(v); - int nitems = ArrayGetNItems(ndim, dim); - Datum *elements; - bool *nulls; - int16 typlen; - bool typbyval; - char typalign; - - assert((*arrlen) == 0); - - - if (allow_empty && (ndim == 0 || nitems <= 0)) { - return (uint32_t*) NULL; - } - /* the array is not empty*/ - - if (ndim != 1) { - elog(ERROR, "One dimension expected"); - } - - if (nitems <= 0) { - elog(ERROR, "No elements found"); - } - - get_typlenbyvalalign(element_type, - &typlen, &typbyval, &typalign); - - /* validate input data type */ - switch (element_type) { - case INT2OID: - case INT4OID: - break; - default: - elog(ERROR, "Expected array of INTEGER"); - } - - deconstruct_array(v, element_type, typlen, typbyval, - typalign, &elements, &nulls, - &nitems); - - c_array = (uint32_t *) palloc(sizeof(uint32_t) * (size_t)nitems); - if (!c_array) { - elog(ERROR, "Out of memory!"); - } - - - int i; - for (i = 0; i < nitems; i++) { - if (nulls[i]) { - pfree(c_array); - elog(ERROR, "NULL value found in Array!"); - } else { - int32_t element; - switch (element_type) { - case INT2OID: - element = (int32_t) DatumGetInt16(elements[i]); - break; - case INT4OID: - element = (int32_t) DatumGetInt32(elements[i]); - break; - } - if (element < 0) { - elog(ERROR, "Unexpected Negative value %d in array", element); - } - c_array[i] = (uint32_t) element; - } - } - (*arrlen) = (size_t)nitems; - - pfree(elements); - pfree(nulls); -#ifdef PROFILE - time_msg("reading Array", start_t, clock()); -#endif - return c_array; -} - - -int64_t* pgr_get_bigIntArray(size_t *arrlen, ArrayType *input) { - return pgr_get_bigIntArr(input, arrlen, false); -} - - - -int64_t* pgr_get_bigIntArray_allowEmpty(size_t *arrlen, ArrayType *input) { - return pgr_get_bigIntArr(input, arrlen, true); -} - - -uint32_t* pgr_get_positiveIntArray_allowEmpty(size_t *arrlen, ArrayType *input) { - return pgr_get_positiveIntArr(input, arrlen, true); -} diff --git a/src/common/matrixRows_input.c b/src/common/matrixRows_input.c deleted file mode 100644 index 006cdd891..000000000 --- a/src/common/matrixRows_input.c +++ /dev/null @@ -1,201 +0,0 @@ -/*PGR-GNU***************************************************************** -File: matrixRows_input.c - -Copyright (c) 2015 pgRouting developers -Mail: project@pgrouting.org - -Developer: -Copyright (c) 2015 Celia Virginia Vergara Castillo - ------- - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - - ********************************************************************PGR-GNU*/ - -#include "c_common/matrixRows_input.h" - -#include "cpp_common/info.hpp" -#include "cpp_common/matrix_cell_t.hpp" - -#include "cpp_common/get_check_data.hpp" - -#ifdef PROFILE -#include "c_common/time_msg.h" -#include "c_common/debug_macro.h" -#endif - -static -void fetch_plain( - HeapTuple *tuple, - TupleDesc *tupdesc, - Column_info_t info[3], - Matrix_cell_t *row) { - row->from_vid = get_Id(tuple, tupdesc, info[0], -1); - row->to_vid = get_Id(tuple, tupdesc, info[1], -1); - row->cost = get_PositiveTInterval_plain(tuple, tupdesc, info[2], 0); -} - -static -void fetch_timestamps( - HeapTuple *tuple, - TupleDesc *tupdesc, - Column_info_t info[3], - Matrix_cell_t *row) { - row->from_vid = get_Id(tuple, tupdesc, info[0], -1); - row->to_vid = get_Id(tuple, tupdesc, info[1], -1); - row->cost = get_PositiveTInterval(tuple, tupdesc, info[2], 0); -} - -/*! - * bigint start_vid, - * bigint end_vid, - * float agg_cost, - */ -static -void -get_matrixRows_general( - char *sql, - Column_info_t *info, - const int kind, - Matrix_cell_t **rows, - size_t *total_rows) { -#ifdef PROFILE - clock_t start_t = clock(); - PGR_DBG("%s", sql); -#endif - - const int tuple_limit = 1000000; - size_t total_tuples = 0; - const int column_count = 3; - - void *SPIplan; - SPIplan = vrp_SPI_prepare(sql); - - Portal SPIportal; - SPIportal = vrp_SPI_cursor_open(SPIplan); - - - bool moredata = true; - (*total_rows) = total_tuples; - - while (moredata == true) { - SPI_cursor_fetch(SPIportal, true, tuple_limit); - if (total_tuples == 0) - pgr_fetch_column_info(info, column_count); - - size_t ntuples = SPI_processed; - total_tuples += ntuples; - - if (ntuples > 0) { - if ((*rows) == NULL) - (*rows) = (Matrix_cell_t *)palloc0( - total_tuples * sizeof(Matrix_cell_t)); - else - (*rows) = (Matrix_cell_t *)repalloc( - (*rows), total_tuples * sizeof(Matrix_cell_t)); - - if ((*rows) == NULL) { - elog(ERROR, "Out of memory"); - } - - SPITupleTable *tuptable = SPI_tuptable; - TupleDesc tupdesc = SPI_tuptable->tupdesc; - - size_t t; - for (t = 0; t < ntuples; t++) { - HeapTuple tuple = tuptable->vals[t]; - switch (kind) { - case 0 : fetch_timestamps(&tuple, &tupdesc, info, - &(*rows)[total_tuples - ntuples + t]); - break; - case 1 : fetch_plain(&tuple, &tupdesc, info, - &(*rows)[total_tuples - ntuples + t]); - break; - } - } - SPI_freetuptable(tuptable); - } else { - moredata = false; - } - } - - SPI_cursor_close(SPIportal); - - - if (total_tuples == 0) { - (*total_rows) = 0; - return; - } - - (*total_rows) = total_tuples; -#ifdef PROFILE - time_msg(" reading time matrix", start_t, clock()); -#endif -} - -/** - * @param [in] sql SQL query that has the following columns: start_vid, end_vid, agg_cost - * @param [out] rows C Container that holds all the matrix rows - * @param [out] total_rows Total rows recieved - */ -void -get_matrixRows( - char *sql, - Matrix_cell_t **rows, - size_t *total_rows) { - Column_info_t info[3]; - - int i; - for (i = 0; i < 3; ++i) { - info[i].colNumber = -1; - info[i].type = 0; - info[i].strict = true; - info[i].eType = ANY_INTEGER; - } - info[0].name = "start_vid"; - info[1].name = "end_vid"; - info[2].name = "travel_time"; - - info[2].eType = INTERVAL; - get_matrixRows_general(sql, info, 0, rows, total_rows); -} - -/** - * @param [in] sql SQL query that has the following columns: start_vid, end_vid, agg_cost - * @param [out] rows C Container that holds all the matrix rows - * @param [out] total_rows Total rows recieved - */ -void -get_matrixRows_plain( - char *sql, - Matrix_cell_t **rows, - size_t *total_rows) { - Column_info_t info[3]; - - int i; - for (i = 0; i < 3; ++i) { - info[i].colNumber = -1; - info[i].type = 0; - info[i].strict = true; - info[i].eType = ANY_INTEGER; - } - info[0].name = "start_vid"; - info[1].name = "end_vid"; - info[2].name = "agg_cost"; - - info[2].eType = ANY_NUMERICAL; - get_matrixRows_general(sql, info, 1, rows, total_rows); -} diff --git a/src/common/orders_input.c b/src/common/orders_input.c deleted file mode 100644 index afdedbdad..000000000 --- a/src/common/orders_input.c +++ /dev/null @@ -1,363 +0,0 @@ -/*PGR-GNU***************************************************************** -File: pd_orders_input.c - -Copyright (c) 2016 pgRouting developers -Mail: project@pgrouting.org - -Developer: -Copyright (c) 2016 Celia Virginia Vergara Castillo - ------- - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - - ********************************************************************PGR-GNU*/ - -#include "c_common/orders_input.h" - -#include "cpp_common/orders_t.hpp" -#include "cpp_common/info.hpp" - -#include "c_common/debug_macro.h" -#include "cpp_common/get_check_data.hpp" -#ifdef PROFILE -#include "c_common/time_msg.h" -#endif - - -static -void fetch_euclidean( - HeapTuple *tuple, - TupleDesc *tupdesc, - Column_info_t *info, - Orders_t *pd_order) { - pd_order->id = get_Id(tuple, tupdesc, info[0], -1); - pd_order->demand = get_PositiveAmount(tuple, tupdesc, info[1], 0); - - /* - * the pickups - */ - pd_order->pick_open_t = get_TTimestamp_plain(tuple, tupdesc, info[2], -1); - pd_order->pick_close_t = get_TTimestamp_plain(tuple, tupdesc, info[3], -1); - pd_order->pick_service_t = get_TInterval_plain(tuple, tupdesc, info[4], 0); - - /* - * the deliveries - */ - pd_order->deliver_open_t = get_TTimestamp_plain(tuple, tupdesc, info[5], -1); - pd_order->deliver_close_t = get_TTimestamp_plain(tuple, tupdesc, info[6], -1); - pd_order->deliver_service_t = get_TInterval_plain(tuple, tupdesc, info[7], 0); - - pd_order->pick_x = spi_getCoordinate(tuple, tupdesc, info[8], 0); - pd_order->pick_y = spi_getCoordinate(tuple, tupdesc, info[9], 0); - pd_order->deliver_x = spi_getCoordinate(tuple, tupdesc, info[10], 0); - pd_order->deliver_y = spi_getCoordinate(tuple, tupdesc, info[11], 0); - - /* - * ignored information - */ - pd_order->pick_node_id = 0; - pd_order->deliver_node_id = 0; -} - - -static -void fetch_raw( - HeapTuple *tuple, - TupleDesc *tupdesc, - Column_info_t *info, - Orders_t *pd_order) { - pd_order->id = get_Id(tuple, tupdesc, info[0], -1); - pd_order->demand = get_PositiveAmount(tuple, tupdesc, info[1], 0); - - /* - * the pickups - */ - pd_order->pick_node_id = get_Id(tuple, tupdesc, info[8], -1); - pd_order->pick_open_t = get_TTimestamp_plain(tuple, tupdesc, info[2], -1); - pd_order->pick_close_t = get_TTimestamp_plain(tuple, tupdesc, info[3], -1); - pd_order->pick_service_t = get_TInterval_plain(tuple, tupdesc, info[4], 0); - - /* - * the deliveries - */ - pd_order->deliver_node_id = get_Id(tuple, tupdesc, info[9], -1); - pd_order->deliver_open_t = get_TTimestamp_plain(tuple, tupdesc, info[5], -1); - pd_order->deliver_close_t = get_TTimestamp_plain(tuple, tupdesc, info[6], -1); - pd_order->deliver_service_t = get_TInterval_plain(tuple, tupdesc, info[7], 0); - - - /* - * Ignored information - */ - pd_order->pick_x = 0; - pd_order->pick_y = 0; - pd_order->deliver_x = 0; - pd_order->deliver_y = 0; -} - -static -void fetch_timestamps( - HeapTuple *tuple, - TupleDesc *tupdesc, - Column_info_t *info, - Orders_t *pd_order) { - pd_order->id = get_Id(tuple, tupdesc, info[0], -1); - pd_order->demand = get_PositiveAmount(tuple, tupdesc, info[1], 0); - - /* - * the pickups - */ - pd_order->pick_node_id = get_Id(tuple, tupdesc, info[2], -1); - pd_order->pick_open_t = get_TTimestamp(tuple, tupdesc, info[3], -1); - pd_order->pick_close_t = get_TTimestamp(tuple, tupdesc, info[4], -1); - pd_order->pick_service_t = get_TInterval(tuple, tupdesc, info[5], 0); - - /* - * the deliveries - */ - pd_order->deliver_node_id = get_Id(tuple, tupdesc, info[6], -1); - pd_order->deliver_open_t = get_TTimestamp(tuple, tupdesc, info[7], -1); - pd_order->deliver_close_t = get_TTimestamp(tuple, tupdesc, info[8], -1); - pd_order->deliver_service_t = get_TInterval(tuple, tupdesc, info[9], 0); - - PGR_DBG("pick_service_t %ld deliver_service_t %ld", pd_order->pick_service_t, pd_order->deliver_service_t); - - /* - * Ignored information - */ - pd_order->pick_x = 0; - pd_order->pick_y = 0; - pd_order->deliver_x = 0; - pd_order->deliver_y = 0; -} - - - -static -void -pgr_get_pd_orders_general( - char *pd_orders_sql, - Orders_t **pd_orders, - size_t *total_pd_orders, - - Column_info_t *info, - const int column_count, - - int kind) { -#ifdef PROFILE - clock_t start_t = clock(); - PGR_DBG("%s", pd_orders_sql); -#endif - - const int tuple_limit = 1000000; - - - size_t total_tuples; - - void *SPIplan; - SPIplan = vrp_SPI_prepare(pd_orders_sql); - Portal SPIportal; - SPIportal = vrp_SPI_cursor_open(SPIplan); - - bool moredata = true; - (*total_pd_orders) = total_tuples = 0; - - /* on the first tuple get the column numbers */ - - while (moredata == true) { - SPI_cursor_fetch(SPIportal, true, tuple_limit); - if (total_tuples == 0) { - pgr_fetch_column_info(info, column_count); - } - size_t ntuples = SPI_processed; - total_tuples += ntuples; - if (ntuples > 0) { - if ((*pd_orders) == NULL) - (*pd_orders) = (Orders_t *)palloc0( - total_tuples * sizeof(Orders_t)); - else - (*pd_orders) = (Orders_t *)repalloc( - (*pd_orders), - total_tuples * sizeof(Orders_t)); - - if ((*pd_orders) == NULL) { - elog(ERROR, "Out of memory"); - } - - size_t t; - SPITupleTable *tuptable = SPI_tuptable; - TupleDesc tupdesc = SPI_tuptable->tupdesc; - for (t = 0; t < ntuples; t++) { - HeapTuple tuple = tuptable->vals[t]; - switch (kind) { - case 0 : fetch_timestamps(&tuple, &tupdesc, info, - &(*pd_orders)[total_tuples - ntuples + t]); - break; - case 1 : fetch_raw(&tuple, &tupdesc, info, - &(*pd_orders)[total_tuples - ntuples + t]); - break; - case 2 : fetch_euclidean(&tuple, &tupdesc, info, - &(*pd_orders)[total_tuples - ntuples + t]); - break; - } - } - SPI_freetuptable(tuptable); - } else { - moredata = false; - } - } - - SPI_cursor_close(SPIportal); - - if (total_tuples == 0) { - (*total_pd_orders) = 0; - return; - } - - (*total_pd_orders) = total_tuples; -#ifdef PROFILE - time_msg("reading shipments", start_t, clock()); -#endif -} - -/** - * @param[in] sql SQL query to execute - * @param[out] rows C Container that holds the data - * @param[out] total_rows Total rows recieved - */ -void -get_shipments( - char *sql, - Orders_t **rows, - size_t *total_rows) { - const int column_count = 10; - Column_info_t info[10]; - - for (int i = 0; i < column_count; ++i) { - info[i].colNumber = -1; - info[i].type = 0; - info[i].strict = true; - info[i].eType = ANY_INTEGER; - } - - info[0].name = "id"; - info[1].name = "amount"; - info[2].name = "p_id"; - info[3].name = "p_tw_open"; - info[4].name = "p_tw_close"; - info[5].name = "p_t_service"; - info[6].name = "d_id"; - info[7].name = "d_tw_open"; - info[8].name = "d_tw_close"; - info[9].name = "d_t_service"; - - info[3].eType = TIMESTAMP; - info[4].eType = TIMESTAMP; - info[7].eType = TIMESTAMP; - info[8].eType = TIMESTAMP; - info[5].eType = INTERVAL; - info[9].eType = INTERVAL; - - /* service is optional*/ - info[5].strict = false; - info[9].strict = false; - - pgr_get_pd_orders_general(sql, rows, total_rows, info, column_count, 0); -} - -/** - * @param[in] sql SQL query to execute - * @param[out] rows C Container that holds the data - * @param[out] total_rows Total rows recieved - */ -void -get_shipments_raw( - char *sql, - Orders_t **rows, - size_t *total_rows) { - const int column_count = 10; - Column_info_t info[10]; - - for (int i = 0; i < column_count; ++i) { - info[i].colNumber = -1; - info[i].type = 0; - info[i].strict = true; - info[i].eType = ANY_INTEGER; - } - - info[0].name = "id"; - info[1].name = "amount"; - info[2].name = "p_open"; - info[3].name = "p_close"; - info[4].name = "p_service"; - info[5].name = "d_open"; - info[6].name = "d_close"; - info[7].name = "d_service"; - info[8].name = "p_id"; - info[9].name = "d_id"; - - /* service is optional*/ - info[4].strict = false; - info[7].strict = false; - - pgr_get_pd_orders_general(sql, rows, total_rows, info, column_count, 1); -} - -/** - * @param[in] sql SQL query to execute - * @param[out] rows C Container that holds the data - * @param[out] total_rows Total rows recieved - */ -void -get_shipments_euclidean( - char *sql, - Orders_t **rows, - size_t *total_rows) { - const int column_count = 12; - Column_info_t info[12]; - - for (int i = 0; i < column_count; ++i) { - info[i].colNumber = -1; - info[i].type = 0; - info[i].strict = true; - info[i].eType = ANY_INTEGER; - } - - info[0].name = "id"; - info[1].name = "amount"; - info[2].name = "p_open"; - info[3].name = "p_close"; - info[4].name = "p_service"; - info[5].name = "d_open"; - info[6].name = "d_close"; - info[7].name = "d_service"; - info[8].name = "p_x"; - info[9].name = "p_y"; - info[10].name = "d_x"; - info[11].name = "d_y"; - - /* service is optional*/ - info[4].strict = false; - info[7].strict = false; - - /* (x,y) are ignored*/ - info[8].eType = ANY_NUMERICAL; - info[9].eType = ANY_NUMERICAL; - info[10].eType = ANY_NUMERICAL; - info[11].eType = ANY_NUMERICAL; - - pgr_get_pd_orders_general(sql, rows, total_rows, info, column_count, 2); -} diff --git a/src/common/time_multipliers_input.c b/src/common/time_multipliers_input.c deleted file mode 100644 index 4c31ef907..000000000 --- a/src/common/time_multipliers_input.c +++ /dev/null @@ -1,194 +0,0 @@ -/*PGR-GNU***************************************************************** -File: time_multipliers_input.c - -Copyright (c) 2021 pgRouting developers -Mail: project@pgrouting.org - -Developer: -Copyright (c) 2021 Copyright (c) 2021 Joseph Emile Honour Percival - ------- - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - - ********************************************************************PGR-GNU*/ - -#include "c_common/time_multipliers_input.h" - -#include "cpp_common/info.hpp" -#include "cpp_common/time_multipliers_t.hpp" -#include "cpp_common/get_check_data.hpp" - -#ifdef PROFILE -#include "c_common/time_msg.h" -#include "c_common/debug_macro.h" -#endif - - -static -void fetch_raw( - HeapTuple *tuple, - TupleDesc *tupdesc, - Column_info_t info[2], - Time_multipliers_t *row) { - row->start_time = get_TTimestamp_plain(tuple, tupdesc, info[0], 0); - row->multiplier = spi_getFloat8(tuple, tupdesc, info[1]); -} - -static -void fetch_timestamps( - HeapTuple *tuple, - TupleDesc *tupdesc, - Column_info_t info[2], - Time_multipliers_t *row) { - row->start_time = get_TTimestamp(tuple, tupdesc, info[0], 0); - row->multiplier = spi_getFloat8(tuple, tupdesc, info[1]); -} - -/** - * param [in] sql multipliers SQL - * param [in,out] rows catptured information - * param [in,out] total_rows total information captured - */ -static -void get_timeMultipliersGeneral( - char *sql, - Column_info_t *info, - const int kind, - Time_multipliers_t **rows, - size_t *total_rows) { -#ifdef PROFILE - clock_t start_t = clock(); - PGR_DBG("%s", sql); -#endif - const int tuple_limit = 1000000; - size_t total_tuples = 0; - const int column_count = 2; - - void *SPIplan; - SPIplan = vrp_SPI_prepare(sql); - - Portal SPIportal; - SPIportal = vrp_SPI_cursor_open(SPIplan); - - - bool moredata = true; - (*total_rows) = total_tuples; - - while (moredata == true) { - SPI_cursor_fetch(SPIportal, true, tuple_limit); - if (total_tuples == 0) - pgr_fetch_column_info(info, column_count); - - size_t ntuples = SPI_processed; - total_tuples += ntuples; - - if (ntuples > 0) { - if ((*rows) == NULL) - (*rows) = (Time_multipliers_t *)palloc0( - total_tuples * sizeof(Time_multipliers_t)); - else - (*rows) = (Time_multipliers_t *)repalloc( - (*rows), total_tuples * sizeof(Time_multipliers_t)); - - if ((*rows) == NULL) { - elog(ERROR, "Out of memory"); - } - - SPITupleTable *tuptable = SPI_tuptable; - TupleDesc tupdesc = SPI_tuptable->tupdesc; - - for (size_t t = 0; t < ntuples; t++) { - HeapTuple tuple = tuptable->vals[t]; - switch (kind) { - case 0 : fetch_timestamps(&tuple, &tupdesc, info, - &(*rows)[total_tuples - ntuples + t]); - break; - case 1 : fetch_raw(&tuple, &tupdesc, info, - &(*rows)[total_tuples - ntuples + t]); - break; - } - } - SPI_freetuptable(tuptable); - } else { - moredata = false; - } - } - - SPI_cursor_close(SPIportal); - - - if (total_tuples == 0) { - (*total_rows) = 0; - return; - } - - (*total_rows) = total_tuples; -#ifdef PROFILE - time_msg("reading time dependant multipliers", start_t, clock()); -#endif -} - -/** - @param [in] sql query that has the following columns: start_time, multiplier - @param [out] rows C Container that holds all the multipliers rows - @param [out] total_rows Total rows recieved - */ -void get_timeMultipliers( - char *sql, - Time_multipliers_t **rows, - size_t *total_rows) { - Column_info_t info[2]; - - int i; - for (i = 0; i < 2; ++i) { - info[i].colNumber = -1; - info[i].type = 0; - info[i].strict = true; - info[i].eType = ANY_NUMERICAL; - } - info[0].name = "start_time"; - info[1].name = "multiplier"; - - info[0].eType = TIMESTAMP; - - get_timeMultipliersGeneral(sql, info, 0, rows, total_rows); -} - -/** - @param [in] sql query that has the following columns: start_time, multiplier - @param [out] rows C Container that holds all the multipliers - @param [out] total_rows Total rows recieved - */ -void get_timeMultipliers_raw( - char *sql, - Time_multipliers_t **rows, - size_t *total_rows) { - Column_info_t info[2]; - - int i; - for (i = 0; i < 2; ++i) { - info[i].colNumber = -1; - info[i].type = 0; - info[i].strict = true; - info[i].eType = ANY_NUMERICAL; - } - info[0].name = "start_value"; - info[1].name = "multiplier"; - - info[0].eType = ANY_INTEGER; - - get_timeMultipliersGeneral(sql, info, 1, rows, total_rows); -} diff --git a/src/common/vehicles_input.c b/src/common/vehicles_input.c deleted file mode 100644 index 8ae5dd2be..000000000 --- a/src/common/vehicles_input.c +++ /dev/null @@ -1,464 +0,0 @@ -/*PGR-GNU***************************************************************** -File: vehicles_input.c - -Copyright (c) 2016 pgRouting developers -Mail: project@pgrouting.org - -Developer: -Copyright (c) 2016 Celia Virginia Vergara Castillo - ------- - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - - ********************************************************************PGR-GNU*/ - -#include "c_common/vehicles_input.h" - -#include -#include - - -#include "cpp_common/info.hpp" -#include "cpp_common/vehicle_t.hpp" - -#include "cpp_common/get_check_data.hpp" - -#ifdef PROFILE -#include "c_common/time_msg.h" -#include "c_common/debug_macro.h" -#endif - -static -void check_pairs(Column_info_t lhs, Column_info_t rhs) { - if (!(column_found(lhs.colNumber)) && column_found(rhs.colNumber)) { - ereport(ERROR, - (errmsg("Column \'%s\' not Found", lhs.name), - errhint("%s was found, also column is expected %s ", - rhs.name, lhs.name))); - } -} - -static -void fetch_euclidean( - HeapTuple *tuple, - TupleDesc *tupdesc, - Column_info_t *info, - Vehicle_t *vehicle, - bool with_stops) { - bool with_id = false; - /* - * s_tw_open, s_tw_close must exist or non at all - */ - check_pairs(info[4], info[5]); - check_pairs(info[5], info[4]); - /* - * e_tw_open, e_tw_close must exist or non at all - */ - check_pairs(info[6], info[7]); - check_pairs(info[7], info[6]); - - /* - * e_x, e_y must exist or non at all - */ - check_pairs(info[13], info[14]); - check_pairs(info[14], info[13]); - - vehicle->id = get_Id(tuple, tupdesc, info[0], -1); - vehicle->capacity = get_PositiveAmount(tuple, tupdesc, info[1], 0); - vehicle->cant_v = get_PositiveAmount(tuple, tupdesc, info[2], 1); - vehicle->speed = column_found(info[3].colNumber) ? spi_getFloat8(tuple, tupdesc, info[3]) : 1; - - /* - * start values - */ - vehicle->start_open_t = get_TTimestamp_plain(tuple, tupdesc, info[4], 0); - vehicle->start_close_t = get_TTimestamp_plain(tuple, tupdesc, info[5], INT64_MAX); - - /* - * end values - */ - vehicle->end_open_t = get_TTimestamp_plain(tuple, tupdesc, info[6], vehicle->start_open_t); - vehicle->end_close_t = get_TTimestamp_plain(tuple, tupdesc, info[7], vehicle->start_close_t); - - /* - * service time values - */ - vehicle->start_service_t = get_PositiveTInterval_plain(tuple, tupdesc, info[9], 0); - vehicle->end_service_t = get_PositiveTInterval_plain(tuple, tupdesc, info[10], 0); - - /* - * stops - */ - vehicle->stops = NULL; - vehicle->stops_size = 0; - if (with_stops && column_found(info[8].colNumber)) { - vehicle->stops = spi_getBigIntArr_allowEmpty(tuple, tupdesc, info[8], &vehicle->stops_size); - } - - /* - * Values for eucledian - */ - vehicle->start_x = with_id ? 0 : spi_getCoordinate(tuple, tupdesc, info[11], 0); - vehicle->start_y = with_id ? 0 : spi_getCoordinate(tuple, tupdesc, info[12], 0); - vehicle->end_x = with_id ? 0 : spi_getCoordinate(tuple, tupdesc, info[13], vehicle->start_x); - vehicle->end_y = with_id ? 0 : spi_getCoordinate(tuple, tupdesc, info[14], vehicle->start_y); -} - -static -void fetch_raw( - HeapTuple *tuple, - TupleDesc *tupdesc, - Column_info_t *info, - Vehicle_t *vehicle, - bool with_stops) { - /* - * s_tw_open, s_tw_close must exist or non at all - */ - check_pairs(info[6], info[7]); - check_pairs(info[7], info[6]); - /* - * e_tw_open, e_tw_close must exist or non at all - */ - check_pairs(info[10], info[11]); - check_pairs(info[10], info[11]); - - vehicle->id = get_Id(tuple, tupdesc, info[0], -1); - vehicle->capacity = get_PositiveAmount(tuple, tupdesc, info[1], 0); - vehicle->cant_v = get_PositiveAmount(tuple, tupdesc, info[2], 1); - vehicle->speed = column_found(info[3].colNumber) ? spi_getFloat8(tuple, tupdesc, info[3]) : 1; - vehicle->stops = NULL; - vehicle->stops_size = 0; - if (with_stops && column_found(info[4].colNumber)) { - vehicle->stops = spi_getBigIntArr_allowEmpty(tuple, tupdesc, info[4], &vehicle->stops_size); - } - - /* - * start values - */ - vehicle->start_node_id = get_Id(tuple, tupdesc, info[5], -1); - vehicle->start_open_t = get_TTimestamp_plain(tuple, tupdesc, info[6], 0); - vehicle->start_close_t = get_TTimestamp_plain(tuple, tupdesc, info[7], INT64_MAX); - vehicle->start_service_t = get_PositiveTInterval_plain(tuple, tupdesc, info[8], 0); - - /* - * end values - */ - vehicle->end_node_id = get_Id(tuple, tupdesc, info[9], vehicle->start_node_id); - vehicle->end_open_t = get_TTimestamp_plain(tuple, tupdesc, info[10], vehicle->start_open_t); - vehicle->end_close_t = get_TTimestamp_plain(tuple, tupdesc, info[11], vehicle->start_close_t); - vehicle->end_service_t = get_PositiveTInterval_plain(tuple, tupdesc, info[12], 0); - - /* - * Ignored values - */ - vehicle->start_x = 0; - vehicle->start_y = 0; - vehicle->end_x = 0; - vehicle->end_y = 0; -} - -static -void fetch_timestamps( - HeapTuple *tuple, - TupleDesc *tupdesc, - Column_info_t *info, - Vehicle_t *vehicle, - bool with_stops) { - /* - * s_tw_open, s_tw_close must exist or non at all - */ - check_pairs(info[6], info[7]); - check_pairs(info[7], info[6]); - /* - * e_tw_open, e_tw_close must exist or non at all - */ - check_pairs(info[10], info[11]); - check_pairs(info[10], info[11]); - - vehicle->id = get_Id(tuple, tupdesc, info[0], -1); - vehicle->capacity = get_PositiveAmount(tuple, tupdesc, info[1], 0); - vehicle->cant_v = get_PositiveAmount(tuple, tupdesc, info[2], 1); - vehicle->speed = column_found(info[3].colNumber) ? spi_getFloat8(tuple, tupdesc, info[3]) : 1; - vehicle->stops = NULL; - vehicle->stops_size = 0; - if (with_stops && column_found(info[4].colNumber)) { - vehicle->stops = spi_getBigIntArr_allowEmpty(tuple, tupdesc, info[4], &vehicle->stops_size); - } - - /* - * start values - */ - vehicle->start_node_id = get_Id(tuple, tupdesc, info[5], -1); - vehicle->start_open_t = get_TTimestamp(tuple, tupdesc, info[6], 0); - vehicle->start_close_t = get_TTimestamp(tuple, tupdesc, info[7], INT64_MAX); - vehicle->start_service_t = get_PositiveTInterval(tuple, tupdesc, info[8], 0); - - /* - * end values - */ - vehicle->end_node_id = get_Id(tuple, tupdesc, info[9], vehicle->start_node_id); - vehicle->end_open_t = get_TTimestamp(tuple, tupdesc, info[10], vehicle->start_open_t); - vehicle->end_close_t = get_TTimestamp(tuple, tupdesc, info[11], vehicle->start_close_t); - vehicle->end_service_t = get_PositiveTInterval(tuple, tupdesc, info[12], 0); - - /* - * Ignored values - */ - vehicle->start_x = 0; - vehicle->start_y = 0; - vehicle->end_x = 0; - vehicle->end_y = 0; -} - - -static -void db_get_vehicles( - char *vehicles_sql, - Vehicle_t **vehicles, - size_t *total_vehicles, - - Column_info_t *info, - const int column_count, - - int kind, - bool with_stops) { -#ifdef PROFILE - clock_t start_t = clock(); - PGR_DBG("%s", vehicles_sql); -#endif - - const int tuple_limit = 1000000; - - size_t total_tuples; - - void *SPIplan; - SPIplan = vrp_SPI_prepare(vehicles_sql); - Portal SPIportal; - SPIportal = vrp_SPI_cursor_open(SPIplan); - - bool moredata = true; - (*total_vehicles) = total_tuples = 0; - - /* on the first tuple get the column numbers */ - - while (moredata == true) { - SPI_cursor_fetch(SPIportal, true, tuple_limit); - if (total_tuples == 0) { - pgr_fetch_column_info(info, column_count); - } - size_t ntuples = SPI_processed; - total_tuples += ntuples; - if (ntuples > 0) { - if ((*vehicles) == NULL) - (*vehicles) = (Vehicle_t *)palloc0( - total_tuples * sizeof(Vehicle_t)); - else - (*vehicles) = (Vehicle_t *)repalloc( - (*vehicles), - total_tuples * sizeof(Vehicle_t)); - - if ((*vehicles) == NULL) { - elog(ERROR, "Out of memory"); - } - - size_t t; - SPITupleTable *tuptable = SPI_tuptable; - TupleDesc tupdesc = SPI_tuptable->tupdesc; - for (t = 0; t < ntuples; t++) { - HeapTuple tuple = tuptable->vals[t]; - switch (kind) { - case 0 : fetch_timestamps(&tuple, &tupdesc, info, - &(*vehicles)[total_tuples - ntuples + t], with_stops); - break; - case 1 : fetch_raw(&tuple, &tupdesc, info, - &(*vehicles)[total_tuples - ntuples + t], with_stops); - break; - case 2 : fetch_euclidean(&tuple, &tupdesc, info, - &(*vehicles)[total_tuples - ntuples + t], with_stops); - break; - } - } - SPI_freetuptable(tuptable); - } else { - moredata = false; - } - } - - SPI_cursor_close(SPIportal); - - if (total_tuples == 0) { - (*total_vehicles) = 0; - return; - } - - (*total_vehicles) = total_tuples; -#ifdef PROFILE - time_msg("reading vehicles", start_t, clock()); -#endif -} - -/** - * @param[in] sql SQL query to execute - * @param[in] with_stops do not ignore stops column - * @param[out] rows C Container that holds the data - * @param[out] total_rows Total rows recieved - */ -void -get_vehicles( - char *sql, - Vehicle_t **rows, - size_t *total_rows, - bool with_stops) { - const int column_count = 13; - Column_info_t info[13]; - - for (int i = 0; i < column_count; ++i) { - info[i].colNumber = -1; - info[i].type = 0; - info[i].strict = false; - info[i].eType = ANY_INTEGER; - } - - info[0].name = "id"; - info[1].name = "capacity"; - info[2].name = "number"; - info[3].name = "speed"; - info[4].name = "stops"; - info[5].name = "s_id"; - info[6].name = "s_tw_open"; - info[7].name = "s_tw_close"; - info[8].name = "s_t_service"; - info[9].name = "e_id"; - info[10].name = "e_tw_open"; - info[11].name = "e_tw_close"; - info[12].name = "e_t_service"; - - info[6].eType = TIMESTAMP; - info[7].eType = TIMESTAMP; - info[10].eType = TIMESTAMP; - info[11].eType = TIMESTAMP; - info[8].eType = INTERVAL; - info[12].eType = INTERVAL; - - info[4].eType = ANY_INTEGER_ARRAY; // stops - info[3].eType = ANY_NUMERICAL; // speed - - info[0].strict = true; - info[1].strict = true; - info[5].strict = true; - - db_get_vehicles(sql, rows, total_rows, info, column_count, 0, with_stops); -} - -/** - * @param[in] sql SQL query to execute - * @param[in] with_stops do not ignore stops column - * @param[out] rows C Container that holds the data - * @param[out] total_rows Total rows recieved - */ -void -get_vehicles_raw( - char *sql, - Vehicle_t **rows, - size_t *total_rows, - bool with_stops) { - const int column_count = 13; - Column_info_t info[13]; - - for (int i = 0; i < column_count; ++i) { - info[i].colNumber = -1; - info[i].type = 0; - info[i].strict = false; - info[i].eType = ANY_INTEGER; - } - - info[0].name = "id"; - info[1].name = "capacity"; - info[2].name = "number"; - info[3].name = "speed"; - info[4].name = "stops"; - info[5].name = "s_id"; - info[6].name = "s_open"; - info[7].name = "s_close"; - info[8].name = "s_service"; - info[9].name = "e_id"; - info[10].name = "e_open"; - info[11].name = "e_close"; - info[12].name = "e_service"; - - - info[4].eType = ANY_INTEGER_ARRAY; // stops - info[3].eType = ANY_NUMERICAL; // speed - - info[0].strict = true; - info[1].strict = true; - info[5].strict = true; - - db_get_vehicles(sql, rows, total_rows, info, column_count, 1, with_stops); -} - -/** - * @param[in] sql SQL query to execute - * @param[in] with_stops do not ignore stops column - * @param[out] rows C Container that holds the data - * @param[out] total_rows Total rows recieved - */ -void -get_vehicles_euclidean( - char *sql, - Vehicle_t **rows, - size_t *total_rows, - bool with_stops) { - const int column_count = 15; - Column_info_t info[15]; - - for (int i = 0; i < column_count; ++i) { - info[i].colNumber = -1; - info[i].type = 0; - info[i].strict = false; - info[i].eType = ANY_INTEGER; - } - - info[0].name = "id"; - info[1].name = "capacity"; - info[2].name = "number"; - info[3].name = "speed"; - info[4].name = "s_open"; - info[5].name = "s_close"; - info[6].name = "e_open"; - info[7].name = "e_close"; - info[8].name = "stops"; - info[9].name = "s_service"; - info[10].name = "e_service"; - info[11].name = "s_x"; - info[12].name = "s_y"; - info[13].name = "e_x"; - info[14].name = "e_y"; - - - info[8].eType = ANY_INTEGER_ARRAY; // stops - info[11].eType = ANY_NUMERICAL; // s_x - info[12].eType = ANY_NUMERICAL; // s_y - info[13].eType = ANY_NUMERICAL; // e_x - info[14].eType = ANY_NUMERICAL; // e_y - - info[0].strict = true; - info[1].strict = true; - info[11].strict = true; - info[12].strict = true; - - db_get_vehicles(sql, rows, total_rows, info, column_count, 2, with_stops); -} diff --git a/src/common/vroom/breaks_input.c b/src/common/vroom/breaks_input.c deleted file mode 100644 index 5e0a62619..000000000 --- a/src/common/vroom/breaks_input.c +++ /dev/null @@ -1,167 +0,0 @@ -/*PGR-GNU***************************************************************** -File: breaks_input.c - -Copyright (c) 2021 pgRouting developers -Mail: project@pgrouting.org - -Function's developer: -Copyright (c) 2021 Ashish Kumar -Mail: ashishkr23438@gmail.com - ------- - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - - ********************************************************************PGR-GNU*/ - -#include "c_common/vroom/breaks_input.h" - -#include "cpp_common/vroom_break_t.hpp" -#include "cpp_common/info.hpp" - -#include "c_common/debug_macro.h" -#include "cpp_common/get_check_data.hpp" - -static -void fetch_breaks( - HeapTuple *tuple, - TupleDesc *tupdesc, - Column_info_t *info, - Vroom_break_t *vroom_break, - bool is_plain) { - vroom_break->id = get_Idx(tuple, tupdesc, info[0], 0); - vroom_break->vehicle_id = get_Idx(tuple, tupdesc, info[1], 0); - if (is_plain) { - vroom_break->service = get_Duration(tuple, tupdesc, info[2], 0); - } else { - vroom_break->service = - (Duration)get_PositiveTInterval(tuple, tupdesc, info[2], 0); - } - vroom_break->data = column_found(info[3].colNumber) - ? spi_getText(tuple, tupdesc, info[3]) - : strdup("{}"); -} - - -static -void db_get_breaks( - char *breaks_sql, - Vroom_break_t **breaks, - size_t *total_breaks, - - Column_info_t *info, - const int column_count, - bool is_plain) { -#ifdef PROFILE - clock_t start_t = clock(); - PGR_DBG("%s", breaks_sql); -#endif - - const int tuple_limit = 1000000; - - size_t total_tuples; - - void *SPIplan; - SPIplan = vrp_SPI_prepare(breaks_sql); - Portal SPIportal; - SPIportal = vrp_SPI_cursor_open(SPIplan); - - bool moredata = true; - (*total_breaks) = total_tuples = 0; - - /* on the first tuple get the column numbers */ - - while (moredata == true) { - SPI_cursor_fetch(SPIportal, true, tuple_limit); - if (total_tuples == 0) { - pgr_fetch_column_info(info, column_count); - } - size_t ntuples = SPI_processed; - total_tuples += ntuples; - if (ntuples > 0) { - if ((*breaks) == NULL) - (*breaks) = (Vroom_break_t *)palloc0( - total_tuples * sizeof(Vroom_break_t)); - else - (*breaks) = (Vroom_break_t *)repalloc( - (*breaks), - total_tuples * sizeof(Vroom_break_t)); - - if ((*breaks) == NULL) { - elog(ERROR, "Out of memory"); - } - - size_t t; - SPITupleTable *tuptable = SPI_tuptable; - TupleDesc tupdesc = SPI_tuptable->tupdesc; - for (t = 0; t < ntuples; t++) { - HeapTuple tuple = tuptable->vals[t]; - fetch_breaks(&tuple, &tupdesc, info, - &(*breaks)[total_tuples - ntuples + t], is_plain); - } - SPI_freetuptable(tuptable); - } else { - moredata = false; - } - } - - SPI_cursor_close(SPIportal); - - if (total_tuples == 0) { - (*total_breaks) = 0; - return; - } - - (*total_breaks) = total_tuples; -#ifdef PROFILE - time_msg("reading breaks", start_t, clock()); -#endif -} - - -void -get_vroom_breaks( - char *sql, - Vroom_break_t **rows, - size_t *total_rows, - bool is_plain) { - int kColumnCount = 4; - Column_info_t info[kColumnCount]; - - for (int i = 0; i < kColumnCount; ++i) { - info[i].colNumber = -1; - info[i].type = 0; - info[i].strict = true; - info[i].eType = ANY_INTEGER; - } - - info[0].name = "id"; - info[1].name = "vehicle_id"; - info[2].name = "service"; - info[3].name = "data"; - - info[2].eType = INTEGER; // service - info[3].eType = JSONB; // data - - if (!is_plain) { - info[2].eType = INTERVAL; // service - } - - /* service and data are not mandatory */ - info[2].strict = false; - info[3].strict = false; - - db_get_breaks(sql, rows, total_rows, info, kColumnCount, is_plain); -} diff --git a/src/common/vroom/jobs_input.c b/src/common/vroom/jobs_input.c deleted file mode 100644 index f23b64f92..000000000 --- a/src/common/vroom/jobs_input.c +++ /dev/null @@ -1,204 +0,0 @@ -/*PGR-GNU***************************************************************** -File: jobs_input.c - -Copyright (c) 2021 pgRouting developers -Mail: project@pgrouting.org - -Function's developer: -Copyright (c) 2021 Ashish Kumar -Mail: ashishkr23438@gmail.com - ------- - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - - ********************************************************************PGR-GNU*/ - -#include "c_common/vroom/jobs_input.h" - -#include "cpp_common/vroom_job_t.hpp" -#include "cpp_common/info.hpp" - -#include "c_common/debug_macro.h" -#include "cpp_common/get_check_data.hpp" - -static -void fetch_jobs( - HeapTuple *tuple, - TupleDesc *tupdesc, - Column_info_t *info, - Vroom_job_t *job, - bool is_plain) { - job->id = get_Idx(tuple, tupdesc, info[0], 0); - job->location_id = get_MatrixIndex(tuple, tupdesc, info[1], 0); - - if (is_plain) { - job->setup = get_Duration(tuple, tupdesc, info[2], 0); - job->service = get_Duration(tuple, tupdesc, info[3], 0); - } else { - job->setup = (Duration)get_PositiveTInterval(tuple, tupdesc, info[2], 0); - job->service = (Duration)get_PositiveTInterval(tuple, tupdesc, info[3], 0); - } - - /* - * The deliveries - */ - job->delivery_size = 0; - job->delivery = column_found(info[4].colNumber) ? - spi_getPositiveBigIntArr_allowEmpty(tuple, tupdesc, info[4], &job->delivery_size) - : NULL; - - /* - * The pickups - */ - job->pickup_size = 0; - job->pickup = column_found(info[5].colNumber) ? - spi_getPositiveBigIntArr_allowEmpty(tuple, tupdesc, info[5], &job->pickup_size) - : NULL; - - job->skills_size = 0; - job->skills = column_found(info[6].colNumber) ? - spi_getPositiveIntArr_allowEmpty(tuple, tupdesc, info[6], &job->skills_size) - : NULL; - - job->priority = get_Priority(tuple, tupdesc, info[7], 0); - - job->data = column_found(info[8].colNumber) - ? spi_getText(tuple, tupdesc, info[8]) - : strdup("{}"); -} - - -static -void db_get_jobs( - char *jobs_sql, - Vroom_job_t **jobs, - size_t *total_jobs, - - Column_info_t *info, - const int column_count, - bool is_plain) { -#ifdef PROFILE - clock_t start_t = clock(); - PGR_DBG("%s", jobs_sql); -#endif - - const int tuple_limit = 1000000; - - size_t total_tuples; - - void *SPIplan; - SPIplan = vrp_SPI_prepare(jobs_sql); - Portal SPIportal; - SPIportal = vrp_SPI_cursor_open(SPIplan); - - bool moredata = true; - (*total_jobs) = total_tuples = 0; - - /* on the first tuple get the column numbers */ - - while (moredata == true) { - SPI_cursor_fetch(SPIportal, true, tuple_limit); - if (total_tuples == 0) { - pgr_fetch_column_info(info, column_count); - } - size_t ntuples = SPI_processed; - total_tuples += ntuples; - if (ntuples > 0) { - if ((*jobs) == NULL) - (*jobs) = (Vroom_job_t *)palloc0( - total_tuples * sizeof(Vroom_job_t)); - else - (*jobs) = (Vroom_job_t *)repalloc( - (*jobs), - total_tuples * sizeof(Vroom_job_t)); - - if ((*jobs) == NULL) { - elog(ERROR, "Out of memory"); - } - - size_t t; - SPITupleTable *tuptable = SPI_tuptable; - TupleDesc tupdesc = SPI_tuptable->tupdesc; - for (t = 0; t < ntuples; t++) { - HeapTuple tuple = tuptable->vals[t]; - fetch_jobs(&tuple, &tupdesc, info, - &(*jobs)[total_tuples - ntuples + t], is_plain); - } - SPI_freetuptable(tuptable); - } else { - moredata = false; - } - } - - SPI_cursor_close(SPIportal); - - if (total_tuples == 0) { - (*total_jobs) = 0; - return; - } - - (*total_jobs) = total_tuples; -#ifdef PROFILE - time_msg("reading jobs", start_t, clock()); -#endif -} - - -void -get_vroom_jobs( - char *sql, - Vroom_job_t **rows, - size_t *total_rows, - bool is_plain) { - int kColumnCount = 9; - Column_info_t info[kColumnCount]; - - for (int i = 0; i < kColumnCount; ++i) { - info[i].colNumber = -1; - info[i].type = 0; - info[i].strict = false; - info[i].eType = ANY_INTEGER; - } - - info[0].name = "id"; - info[1].name = "location_id"; - info[2].name = "setup"; - info[3].name = "service"; - info[4].name = "delivery"; - info[5].name = "pickup"; - info[6].name = "skills"; - info[7].name = "priority"; - info[8].name = "data"; - - info[2].eType = INTEGER; // setup - info[3].eType = INTEGER; // service - info[4].eType = ANY_INTEGER_ARRAY; // delivery - info[5].eType = ANY_INTEGER_ARRAY; // pickup - info[6].eType = INTEGER_ARRAY; // skills - info[7].eType = INTEGER; // priority - info[8].eType = JSONB; // data - - if (!is_plain) { - info[2].eType = INTERVAL; // setup - info[3].eType = INTERVAL; // service - } - - /* Only id and location_id are mandatory */ - info[0].strict = true; - info[1].strict = true; - - db_get_jobs(sql, rows, total_rows, info, kColumnCount, is_plain); -} diff --git a/src/common/vroom/matrix_input.c b/src/common/vroom/matrix_input.c deleted file mode 100644 index 4452ee5f3..000000000 --- a/src/common/vroom/matrix_input.c +++ /dev/null @@ -1,166 +0,0 @@ -/*PGR-GNU***************************************************************** -File: matrix_input.c - -Copyright (c) 2021 pgRouting developers -Mail: project@pgrouting.org - -Function's developer: -Copyright (c) 2021 Ashish Kumar -Mail: ashishkr23438@gmail.com - ------- - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - - ********************************************************************PGR-GNU*/ - -#include "c_common/vroom/matrix_input.h" - -#include "cpp_common/vroom_matrix_t.hpp" -#include "cpp_common/info.hpp" - -#include "c_common/debug_macro.h" -#include "cpp_common/get_check_data.hpp" - -void fetch_matrix( - HeapTuple *tuple, - TupleDesc *tupdesc, - Column_info_t *info, - Vroom_matrix_t *matrix, - bool is_plain) { - matrix->start_id = get_MatrixIndex(tuple, tupdesc, info[0], -1); - matrix->end_id = get_MatrixIndex(tuple, tupdesc, info[1], -1); - - if (is_plain) { - matrix->duration = get_Duration(tuple, tupdesc, info[2], 0); - } else { - matrix->duration = (Duration)get_PositiveTInterval(tuple, tupdesc, info[2], 0); - } - - // If unspecified, cost is same as the duration - matrix->cost = get_Cost(tuple, tupdesc, info[3], matrix->duration); -} - - -static -void db_get_matrix( - char *matrix_sql, - Vroom_matrix_t **matrix, - size_t *total_matrix_rows, - - Column_info_t *info, - const int column_count, - bool is_plain) { -#ifdef PROFILE - clock_t start_t = clock(); - PGR_DBG("%s", matrix_sql); -#endif - - const int tuple_limit = 1000000; - - size_t total_tuples; - - void *SPIplan; - SPIplan = vrp_SPI_prepare(matrix_sql); - Portal SPIportal; - SPIportal = vrp_SPI_cursor_open(SPIplan); - - bool moredata = true; - (*total_matrix_rows) = total_tuples = 0; - - /* on the first tuple get the column numbers */ - - while (moredata == true) { - SPI_cursor_fetch(SPIportal, true, tuple_limit); - if (total_tuples == 0) { - pgr_fetch_column_info(info, column_count); - } - size_t ntuples = SPI_processed; - total_tuples += ntuples; - if (ntuples > 0) { - if ((*matrix) == NULL) - (*matrix) = (Vroom_matrix_t *)palloc0( - total_tuples * sizeof(Vroom_matrix_t)); - else - (*matrix) = (Vroom_matrix_t *)repalloc( - (*matrix), - total_tuples * sizeof(Vroom_matrix_t)); - - if ((*matrix) == NULL) { - elog(ERROR, "Out of memory"); - } - - size_t t; - SPITupleTable *tuptable = SPI_tuptable; - TupleDesc tupdesc = SPI_tuptable->tupdesc; - for (t = 0; t < ntuples; t++) { - HeapTuple tuple = tuptable->vals[t]; - fetch_matrix(&tuple, &tupdesc, info, - &(*matrix)[total_tuples - ntuples + t], is_plain); - } - SPI_freetuptable(tuptable); - } else { - moredata = false; - } - } - - SPI_cursor_close(SPIportal); - - if (total_tuples == 0) { - (*total_matrix_rows) = 0; - return; - } - - (*total_matrix_rows) = total_tuples; -#ifdef PROFILE - time_msg("reading matrix", start_t, clock()); -#endif -} - - -void -get_vroom_matrix( - char *sql, - Vroom_matrix_t **rows, - size_t *total_rows, - bool is_plain) { - int kColumnCount = 4; - Column_info_t info[kColumnCount]; - - for (int i = 0; i < kColumnCount; ++i) { - info[i].colNumber = -1; - info[i].type = 0; - info[i].strict = true; - info[i].eType = ANY_INTEGER; - } - info[0].name = "start_id"; - info[1].name = "end_id"; - info[2].name = "duration"; - info[3].name = "cost"; - - info[2].eType = INTEGER; // duration - info[3].eType = INTEGER; // cost - - if (!is_plain) { - info[2].eType = INTERVAL; // duration - } - - /** - * cost is not mandatory - */ - info[3].strict = false; - - db_get_matrix(sql, rows, total_rows, info, kColumnCount, is_plain); -} diff --git a/src/common/vroom/shipments_input.c b/src/common/vroom/shipments_input.c deleted file mode 100644 index 88e9d90db..000000000 --- a/src/common/vroom/shipments_input.c +++ /dev/null @@ -1,219 +0,0 @@ -/*PGR-GNU***************************************************************** -File: shipments_input.c - -Copyright (c) 2021 pgRouting developers -Mail: project@pgrouting.org - -Function's developer: -Copyright (c) 2021 Ashish Kumar -Mail: ashishkr23438@gmail.com - ------- - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - - ********************************************************************PGR-GNU*/ - -#include "c_common/vroom/shipments_input.h" - -#include "cpp_common/vroom_shipment_t.hpp" -#include "cpp_common/info.hpp" - -#include "c_common/debug_macro.h" -#include "cpp_common/get_check_data.hpp" - -static -void fetch_shipments( - HeapTuple *tuple, - TupleDesc *tupdesc, - Column_info_t *info, - Vroom_shipment_t *shipment, - bool is_plain) { - shipment->id = get_Idx(tuple, tupdesc, info[0], 0); - - shipment->p_location_id = get_MatrixIndex(tuple, tupdesc, info[1], 0); - shipment->d_location_id = get_MatrixIndex(tuple, tupdesc, info[4], 0); - - if (is_plain) { - shipment->p_setup = get_Duration(tuple, tupdesc, info[2], 0); - shipment->p_service = get_Duration(tuple, tupdesc, info[3], 0); - shipment->d_setup = get_Duration(tuple, tupdesc, info[5], 0); - shipment->d_service = get_Duration(tuple, tupdesc, info[6], 0); - } else { - shipment->p_setup = - (Duration)get_PositiveTInterval(tuple, tupdesc, info[2], 0); - shipment->p_service = - (Duration)get_PositiveTInterval(tuple, tupdesc, info[3], 0); - shipment->d_setup = - (Duration)get_PositiveTInterval(tuple, tupdesc, info[5], 0); - shipment->d_service = - (Duration)get_PositiveTInterval(tuple, tupdesc, info[6], 0); - } - - shipment->amount_size = 0; - shipment->amount = column_found(info[7].colNumber) ? - spi_getPositiveBigIntArr_allowEmpty(tuple, tupdesc, info[7], &shipment->amount_size) - : NULL; - - shipment->skills_size = 0; - shipment->skills = column_found(info[8].colNumber) ? - spi_getPositiveIntArr_allowEmpty(tuple, tupdesc, info[8], &shipment->skills_size) - : NULL; - - shipment->priority = get_Priority(tuple, tupdesc, info[9], 0); - - shipment->p_data = column_found(info[10].colNumber) - ? spi_getText(tuple, tupdesc, info[10]) - : strdup("{}"); - shipment->d_data = column_found(info[11].colNumber) - ? spi_getText(tuple, tupdesc, info[11]) - : strdup("{}"); -} - - -static -void db_get_shipments( - char *shipments_sql, - Vroom_shipment_t **shipments, - size_t *total_shipments, - - Column_info_t *info, - const int column_count, - bool is_plain) { -#ifdef PROFILE - clock_t start_t = clock(); - PGR_DBG("%s", shipments_sql); -#endif - - const int tuple_limit = 1000000; - - size_t total_tuples; - - void *SPIplan; - SPIplan = vrp_SPI_prepare(shipments_sql); - Portal SPIportal; - SPIportal = vrp_SPI_cursor_open(SPIplan); - - bool moredata = true; - (*total_shipments) = total_tuples = 0; - - /* on the first tuple get the column numbers */ - - while (moredata == true) { - SPI_cursor_fetch(SPIportal, true, tuple_limit); - if (total_tuples == 0) { - pgr_fetch_column_info(info, column_count); - } - size_t ntuples = SPI_processed; - total_tuples += ntuples; - if (ntuples > 0) { - if ((*shipments) == NULL) - (*shipments) = (Vroom_shipment_t *)palloc0( - total_tuples * sizeof(Vroom_shipment_t)); - else - (*shipments) = (Vroom_shipment_t *)repalloc( - (*shipments), - total_tuples * sizeof(Vroom_shipment_t)); - - if ((*shipments) == NULL) { - elog(ERROR, "Out of memory"); - } - - size_t t; - SPITupleTable *tuptable = SPI_tuptable; - TupleDesc tupdesc = SPI_tuptable->tupdesc; - for (t = 0; t < ntuples; t++) { - HeapTuple tuple = tuptable->vals[t]; - fetch_shipments(&tuple, &tupdesc, info, - &(*shipments)[total_tuples - ntuples + t], is_plain); - } - SPI_freetuptable(tuptable); - } else { - moredata = false; - } - } - - SPI_cursor_close(SPIportal); - - if (total_tuples == 0) { - (*total_shipments) = 0; - return; - } - - (*total_shipments) = total_tuples; -#ifdef PROFILE - time_msg("reading shipments", start_t, clock()); -#endif -} - - -void -get_vroom_shipments( - char *sql, - Vroom_shipment_t **rows, - size_t *total_rows, - bool is_plain) { - int kColumnCount = 12; - Column_info_t info[kColumnCount]; - - for (int i = 0; i < kColumnCount; ++i) { - info[i].colNumber = -1; - info[i].type = 0; - info[i].strict = false; - info[i].eType = ANY_INTEGER; - } - - info[0].name = "id"; - - /* pickup shipments */ - info[1].name = "p_location_id"; - info[2].name = "p_setup"; - info[3].name = "p_service"; - - /* delivery shipments */ - info[4].name = "d_location_id"; - info[5].name = "d_setup"; - info[6].name = "d_service"; - - info[7].name = "amount"; - info[8].name = "skills"; - info[9].name = "priority"; - info[10].name = "p_data"; - info[11].name = "d_data"; - - info[2].eType = INTEGER; // p_setup - info[3].eType = INTEGER; // p_service - info[5].eType = INTEGER; // d_setup - info[6].eType = INTEGER; // d_service - info[7].eType = ANY_INTEGER_ARRAY; // amount - info[8].eType = INTEGER_ARRAY; // skills - info[9].eType = INTEGER; // priority - info[10].eType = JSONB; // p_data - info[11].eType = JSONB; // d_data - - if (!is_plain) { - info[2].eType = INTERVAL; // p_setup - info[3].eType = INTERVAL; // p_service - info[5].eType = INTERVAL; // d_setup - info[6].eType = INTERVAL; // d_service - } - - /* id and location_id of pickup and delivery are mandatory */ - info[0].strict = true; - info[1].strict = true; - info[4].strict = true; - - db_get_shipments(sql, rows, total_rows, info, kColumnCount, is_plain); -} diff --git a/src/common/vroom/time_windows_input.c b/src/common/vroom/time_windows_input.c deleted file mode 100644 index 3d6ece02a..000000000 --- a/src/common/vroom/time_windows_input.c +++ /dev/null @@ -1,225 +0,0 @@ -/*PGR-GNU***************************************************************** -File: time_windows_input.c - -Copyright (c) 2021 pgRouting developers -Mail: project@pgrouting.org - -Function's developer: -Copyright (c) 2021 Ashish Kumar -Mail: ashishkr23438@gmail.com - ------- - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - - ********************************************************************PGR-GNU*/ - -#include "c_common/vroom/time_windows_input.h" - -#include "cpp_common/vroom_time_window_t.hpp" -#include "cpp_common/info.hpp" - -#include "c_common/debug_macro.h" -#include "cpp_common/get_check_data.hpp" - -static -void fetch_time_windows( - HeapTuple *tuple, - TupleDesc *tupdesc, - Column_info_t *info, - Vroom_time_window_t *time_window, - bool is_shipment, - bool is_plain) { - - time_window->id = get_Idx(tuple, tupdesc, info[0], 0); - - if (is_shipment) { - char kind = get_Kind(tuple, tupdesc, info[1], ' '); - if (kind != 'p' && kind != 'd') { - ereport(ERROR, (errmsg("Invalid kind %c", kind), - errhint("Kind must be either 'p' or 'd'"))); - } - time_window->kind = kind; - if (is_plain) { - time_window->tw_open = get_Duration(tuple, tupdesc, info[2], 0); - time_window->tw_close = get_Duration(tuple, tupdesc, info[3], 0); - } else { - time_window->tw_open = - (Duration)get_PositiveTTimestamp(tuple, tupdesc, info[2], 0); - time_window->tw_close = - (Duration)get_PositiveTTimestamp(tuple, tupdesc, info[3], 0); - } - } else { - if (is_plain) { - time_window->tw_open = get_Duration(tuple, tupdesc, info[1], 0); - time_window->tw_close = get_Duration(tuple, tupdesc, info[2], 0); - } else { - time_window->tw_open = - (Duration)get_PositiveTTimestamp(tuple, tupdesc, info[1], 0); - time_window->tw_close = - (Duration)get_PositiveTTimestamp(tuple, tupdesc, info[2], 0); - } - } - - if (time_window->tw_open > time_window->tw_close) { - ereport(ERROR, - (errmsg("Invalid time window (%d, %d)", - time_window->tw_open, time_window->tw_close), - errhint("Time window start time %d must be " - "less than or equal to time window end time %d", - time_window->tw_open, time_window->tw_close))); - } -} - - -static -void db_get_time_windows( - char *time_windows_sql, - Vroom_time_window_t **time_windows, - size_t *total_time_windows, - - Column_info_t *info, - const int column_count, - bool is_shipment, - bool is_plain) { -#ifdef PROFILE - clock_t start_t = clock(); - PGR_DBG("%s", time_windows_sql); -#endif - - const int tuple_limit = 1000000; - - size_t total_tuples; - - void *SPIplan; - SPIplan = vrp_SPI_prepare(time_windows_sql); - Portal SPIportal; - SPIportal = vrp_SPI_cursor_open(SPIplan); - - bool moredata = true; - (*total_time_windows) = total_tuples = 0; - - /* on the first tuple get the column numbers */ - - while (moredata == true) { - SPI_cursor_fetch(SPIportal, true, tuple_limit); - if (total_tuples == 0) { - pgr_fetch_column_info(info, column_count); - } - size_t ntuples = SPI_processed; - total_tuples += ntuples; - if (ntuples > 0) { - if ((*time_windows) == NULL) - (*time_windows) = (Vroom_time_window_t *)palloc0( - total_tuples * sizeof(Vroom_time_window_t)); - else - (*time_windows) = (Vroom_time_window_t *)repalloc( - (*time_windows), - total_tuples * sizeof(Vroom_time_window_t)); - - if ((*time_windows) == NULL) { - elog(ERROR, "Out of memory"); - } - - size_t t; - SPITupleTable *tuptable = SPI_tuptable; - TupleDesc tupdesc = SPI_tuptable->tupdesc; - for (t = 0; t < ntuples; t++) { - HeapTuple tuple = tuptable->vals[t]; - fetch_time_windows(&tuple, &tupdesc, info, - &(*time_windows)[total_tuples - ntuples + t], - is_shipment, is_plain); - } - SPI_freetuptable(tuptable); - } else { - moredata = false; - } - } - - SPI_cursor_close(SPIportal); - - if (total_tuples == 0) { - (*total_time_windows) = 0; - return; - } - - (*total_time_windows) = total_tuples; -#ifdef PROFILE - time_msg("reading time windows", start_t, clock()); -#endif -} - - -void -get_vroom_time_windows( - char *sql, - Vroom_time_window_t **rows, - size_t *total_rows, - bool is_plain) { - int kColumnCount = 3; - Column_info_t info[kColumnCount]; - - for (int i = 0; i < kColumnCount; ++i) { - info[i].colNumber = -1; - info[i].type = 0; - info[i].strict = true; - info[i].eType = INTEGER; - } - - info[0].name = "id"; - info[1].name = "tw_open"; - info[2].name = "tw_close"; - - info[0].eType = ANY_INTEGER; // id - - if (!is_plain) { - info[1].eType = TIMESTAMP; // tw_open - info[2].eType = TIMESTAMP; // tw_close - } - - db_get_time_windows(sql, rows, total_rows, info, kColumnCount, 0, is_plain); -} - -void -get_vroom_shipments_time_windows( - char *sql, - Vroom_time_window_t **rows, - size_t *total_rows, - bool is_plain) { - int kColumnCount = 4; - Column_info_t info[kColumnCount]; - - for (int i = 0; i < kColumnCount; ++i) { - info[i].colNumber = -1; - info[i].type = 0; - info[i].strict = true; - info[i].eType = INTEGER; - } - - info[0].name = "id"; - info[1].name = "kind"; - info[2].name = "tw_open"; - info[3].name = "tw_close"; - - info[0].eType = ANY_INTEGER; // id - info[1].eType = CHAR1; // kind - - if (!is_plain) { - info[2].eType = TIMESTAMP; // tw_open - info[3].eType = TIMESTAMP; // tw_close - } - - db_get_time_windows(sql, rows, total_rows, info, kColumnCount, 1, is_plain); -} diff --git a/src/common/vroom/vehicles_input.c b/src/common/vroom/vehicles_input.c deleted file mode 100644 index d406fda49..000000000 --- a/src/common/vroom/vehicles_input.c +++ /dev/null @@ -1,225 +0,0 @@ -/*PGR-GNU***************************************************************** -File: vehicles_input.c - -Copyright (c) 2021 pgRouting developers -Mail: project@pgrouting.org - -Function's developer: -Copyright (c) 2021 Ashish Kumar -Mail: ashishkr23438@gmail.com - ------- - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - - ********************************************************************PGR-GNU*/ - -#include "c_common/vroom/vehicles_input.h" - -#include "cpp_common/vroom_vehicle_t.hpp" -#include "cpp_common/info.hpp" - -#include "c_common/debug_macro.h" -#include "cpp_common/get_check_data.hpp" - -static -void fetch_vehicles( - HeapTuple *tuple, - TupleDesc *tupdesc, - Column_info_t *info, - Vroom_vehicle_t *vehicle, - bool is_plain) { - vehicle->id = get_Idx(tuple, tupdesc, info[0], 0); - vehicle->start_id = get_MatrixIndex(tuple, tupdesc, info[1], -1); - vehicle->end_id = get_MatrixIndex(tuple, tupdesc, info[2], -1); - - vehicle->capacity_size = 0; - vehicle->capacity = column_found(info[3].colNumber) ? - spi_getPositiveBigIntArr_allowEmpty(tuple, tupdesc, info[3], &vehicle->capacity_size) - : NULL; - - vehicle->skills_size = 0; - vehicle->skills = column_found(info[4].colNumber) ? - spi_getPositiveIntArr_allowEmpty(tuple, tupdesc, info[4], &vehicle->skills_size) - : NULL; - - if (is_plain) { - vehicle->tw_open = get_Duration(tuple, tupdesc, info[5], 0); - vehicle->tw_close = get_Duration(tuple, tupdesc, info[6], UINT_MAX); - } else { - vehicle->tw_open = - (Duration)get_PositiveTTimestamp(tuple, tupdesc, info[5], 0); - vehicle->tw_close = - (Duration)get_PositiveTTimestamp(tuple, tupdesc, info[6], UINT_MAX); - } - - if (vehicle->tw_open > vehicle->tw_close) { - ereport(ERROR, - (errmsg("Invalid time window (%d, %d)", - vehicle->tw_open, vehicle->tw_close), - errhint("Time window start time %d must be " - "less than or equal to time window end time %d", - vehicle->tw_open, vehicle->tw_close))); - } - - vehicle->speed_factor = column_found(info[7].colNumber) ? - spi_getFloat8(tuple, tupdesc, info[7]) - : 1.0; - - if (vehicle->speed_factor <= 0.0) { - ereport(ERROR, (errmsg("Invalid speed_factor %lf", vehicle->speed_factor), - errhint("Speed factor must be greater than 0"))); - } - - vehicle->max_tasks = column_found(info[8].colNumber) - ? spi_getMaxTasks(tuple, tupdesc, info[8]) - : INT_MAX; // 2147483647 - - vehicle->data = column_found(info[9].colNumber) - ? spi_getText(tuple, tupdesc, info[9]) - : strdup("{}"); -} - - -static -void db_get_vehicles( - char *vehicles_sql, - Vroom_vehicle_t **vehicles, - size_t *total_vehicles, - - Column_info_t *info, - const int column_count, - bool is_plain) { -#ifdef PROFILE - clock_t start_t = clock(); - PGR_DBG("%s", vehicles_sql); -#endif - - const int tuple_limit = 1000000; - - size_t total_tuples; - - void *SPIplan; - SPIplan = vrp_SPI_prepare(vehicles_sql); - Portal SPIportal; - SPIportal = vrp_SPI_cursor_open(SPIplan); - - bool moredata = true; - (*total_vehicles) = total_tuples = 0; - - /* on the first tuple get the column numbers */ - - while (moredata == true) { - SPI_cursor_fetch(SPIportal, true, tuple_limit); - if (total_tuples == 0) { - /* Atleast one out of start_id or end_id must be present */ - info[1].colNumber = SPI_fnumber(SPI_tuptable->tupdesc, "start_id"); - info[2].colNumber = SPI_fnumber(SPI_tuptable->tupdesc, "end_id"); - if (!column_found(info[1].colNumber) && !column_found(info[2].colNumber)) { - elog(ERROR, "At least one out of start_id or end_id must be present"); - } - pgr_fetch_column_info(info, column_count); - } - size_t ntuples = SPI_processed; - total_tuples += ntuples; - if (ntuples > 0) { - if ((*vehicles) == NULL) - (*vehicles) = (Vroom_vehicle_t *)palloc0( - total_tuples * sizeof(Vroom_vehicle_t)); - else - (*vehicles) = (Vroom_vehicle_t *)repalloc( - (*vehicles), - total_tuples * sizeof(Vroom_vehicle_t)); - - if ((*vehicles) == NULL) { - elog(ERROR, "Out of memory"); - } - - size_t t; - SPITupleTable *tuptable = SPI_tuptable; - TupleDesc tupdesc = SPI_tuptable->tupdesc; - for (t = 0; t < ntuples; t++) { - HeapTuple tuple = tuptable->vals[t]; - fetch_vehicles(&tuple, &tupdesc, info, - &(*vehicles)[total_tuples - ntuples + t], is_plain); - } - SPI_freetuptable(tuptable); - } else { - moredata = false; - } - } - - SPI_cursor_close(SPIportal); - - if (total_tuples == 0) { - (*total_vehicles) = 0; - return; - } - - (*total_vehicles) = total_tuples; -#ifdef PROFILE - time_msg("reading vehicles", start_t, clock()); -#endif -} - - -void -get_vroom_vehicles( - char *sql, - Vroom_vehicle_t **rows, - size_t *total_rows, - bool is_plain) { - int kColumnCount = 10; - Column_info_t info[kColumnCount]; - - for (int i = 0; i < kColumnCount; ++i) { - info[i].colNumber = -1; - info[i].type = 0; - info[i].strict = false; - info[i].eType = ANY_INTEGER; - } - - info[0].name = "id"; - info[1].name = "start_id"; - info[2].name = "end_id"; - info[3].name = "capacity"; - info[4].name = "skills"; - info[5].name = "tw_open"; - info[6].name = "tw_close"; - info[7].name = "speed_factor"; - info[8].name = "max_tasks"; - info[9].name = "data"; - - info[3].eType = ANY_INTEGER_ARRAY; // capacity - info[4].eType = INTEGER_ARRAY; // skills - info[5].eType = INTEGER; // tw_open - info[6].eType = INTEGER; // tw_close - info[7].eType = ANY_NUMERICAL; // speed_factor - info[8].eType = INTEGER; // max_tasks - info[9].eType = JSONB; // data - - if (!is_plain) { - info[5].eType = TIMESTAMP; // tw_open - info[6].eType = TIMESTAMP; // tw_close - } - - /** - * id is mandatory. - * At least one out of start_id or end_id must be present, but that is checked later. - */ - info[0].strict = true; - - db_get_vehicles(sql, rows, total_rows, info, kColumnCount, is_plain); -} diff --git a/src/cpp_common/get_check_data.c b/src/cpp_common/get_check_data.c deleted file mode 100644 index 2596048f5..000000000 --- a/src/cpp_common/get_check_data.c +++ /dev/null @@ -1,946 +0,0 @@ -/*PGR-GNU***************************************************************** -File: get_check_data.c - -Copyright (c) 2015 pgRouting developers -Mail: project@pgrouting.org - -Developer: -Copyright (c) 2015 Celia Virginia Vergara Castillo - ------- - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - - ********************************************************************PGR-GNU*/ - -#include -#include -#include "c_common/postgres_connection.h" -#include // NOLINT [build/include_order] -#include // NOLINT [build/include_order] - -#include "cpp_common/get_check_data.hpp" -#include "c_common/arrays_input.h" - -#include "catalog/pg_type.h" - -#include "c_common/debug_macro.h" -#include "c_types/typedefs.h" - -static -void -check_interval_type(Column_info_t info) { - if (!(info.type == 1186)) { - elog(ERROR, - "Unexpected Column '%s' type. Expected INTERVAL", - info.name); - } -} - -/* - * [BPCHAROID](https://doxygen.postgresql.org/include_2catalog_2pg__type_8h.html#afa7749dbe36d31874205189d9d6b21d7) - * [INT2ARRAYOID](https://doxygen.postgresql.org/include_2catalog_2pg__type_8h.html#ac265fe7b0bb75fead13b16bf072722e9) - */ -static -void -check_char_type(Column_info_t info) { - if (!(info.type == BPCHAROID)) { - elog(ERROR, "Unexpected Column '%s' type. Expected CHAR", info.name); - } -} - -static -void -check_text_type(Column_info_t info) { - if (!(info.type == TEXTOID)) { - elog(ERROR, "Unexpected Column '%s' type. Expected TEXT", info.name); - } -} - -static -void -check_jsonb_type(Column_info_t info) { - if (!(info.type == JSONBOID)) { - elog(ERROR, "Unexpected Column '%s' type. Expected JSONB %ld", info.name, info.type); - } -} - -static -void -check_integer_type(Column_info_t info) { - if (!(info.type == INT2OID || info.type == INT4OID)) { - ereport(ERROR, - (errmsg_internal("Unexpected type in column '%s'.", info.name), - errhint("Expected SMALLINT or INTEGER"))); - } -} - -static -void -check_any_integer_type(Column_info_t info) { - if (!(info.type == INT2OID - || info.type == INT4OID - || info.type == INT8OID)) { - ereport(ERROR, - (errmsg_internal("Unexpected type in column '%s'.", info.name), - errhint("Expected ANY-INTEGER"))); - } -} - -static -void -check_integerarray_type(Column_info_t info) { - if (!(info.type == INT2ARRAYOID - || info.type == INT4ARRAYOID)) { - elog(ERROR, - "Unexpected Column '%s' type. Expected SMALLINT-ARRAY or INTEGER-ARRAY", - info.name); - } -} - -static -void -check_any_integerarray_type(Column_info_t info) { - if (!(info.type == INT2ARRAYOID - || info.type == INT4ARRAYOID - || info.type == 1016)) { - elog(ERROR, - "Unexpected Column '%s' type. Expected ANY-INTEGER-ARRAY", - info.name); - } -} - -static -void -check_any_numerical_type(Column_info_t info) { - if (!(info.type == INT2OID - || info.type == INT4OID - || info.type == INT8OID - || info.type == FLOAT4OID - || info.type == FLOAT8OID - || info.type == NUMERICOID)) { - ereport(ERROR, - (errmsg_internal("Unexpected type in column '%s'.", info.name), - errhint("Found: %lu\nExpected ANY-NUMERICAL", info.type))); - } -} - -static -void -check_timestamp_type(Column_info_t info) { - if (!(info.type == 1114)) { - elog(ERROR, - "Unexpected Column '%s' type. Expected TIMESTAMP", - info.name); - } -} - -static -bool -fetch_column_info( - Column_info_t *info) { - /* - * [SPI_fnumber](https://www.postgresql.org/docs/12/spi-spi-fnumber.html) - */ - info->colNumber = SPI_fnumber(SPI_tuptable->tupdesc, info->name); - if (info->strict && !column_found(info->colNumber)) { - elog(ERROR, "Column '%s' not Found", info->name); - } - - if (column_found(info->colNumber)) { - /* - * [SPI_gettypeid](https://www.postgresql.org/docs/12/spi-spi-gettypeid.html) - */ - (info->type) = SPI_gettypeid(SPI_tuptable->tupdesc, (info->colNumber)); - PGR_DBG("%s %ld", info->name, info->type); - if (SPI_result == SPI_ERROR_NOATTRIBUTE) { - elog(ERROR, "Type of column '%s' not Found", info->name); - } - return true; - } - return false; -} - -static -int32_t -spi_getInt(HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info) { - Datum binval; - bool isnull; - int32_t value = 0; - binval = SPI_getbinval(*tuple, *tupdesc, info.colNumber, &isnull); - - if (isnull) elog(ERROR, "Unexpected Null value in column %s", info.name); - - switch (info.type) { - case INT2OID: - value = (int32_t) DatumGetInt16(binval); - break; - case INT4OID: - value = (int32_t) DatumGetInt32(binval); - break; - default: - ereport(ERROR, - (errmsg_internal("Unexpected type in column '%s'.", info.name), - errhint("Found: %lu\nExpected INTEGER", info.type))); - } - return value; -} - -static -int64_t -spi_getBigInt(HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info) { - Datum binval; - bool isnull; - int64_t value = 0; - binval = SPI_getbinval(*tuple, *tupdesc, info.colNumber, &isnull); - - if (isnull) elog(ERROR, "Unexpected Null value in column %s", info.name); - - switch (info.type) { - case INT2OID: - value = (int64_t) DatumGetInt16(binval); - break; - case INT4OID: - value = (int64_t) DatumGetInt32(binval); - break; - case INT8OID: - value = DatumGetInt64(binval); - break; - default: - ereport(ERROR, - (errmsg_internal("Unexpected type in column '%s'.", info.name), - errhint("Found: %lu\nExpected ANY-INTEGER", info.type))); - } - return value; -} - -static -TTimestamp -spi_getTimeStamp(HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info) { - Datum binval; - bool isnull; - TTimestamp value = 0; - binval = SPI_getbinval(*tuple, *tupdesc, info.colNumber, &isnull); - - if (isnull) elog(ERROR, "Unexpected Null value in column %s", info.name); - - switch (info.type) { - case 1114: - value = timestamp_without_timezone((TTimestamp) Int64GetDatum(binval)); - break; - default: - elog(ERROR, - "[SPI_getTimeStamp] Unexpected type in column %s. found %ld expected 1114", - info.name, info.type); - } - return value; -} - -static -TInterval -spi_getInterval(HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info) { - Datum binval; - bool isnull; - Interval* interval; - - binval = SPI_getbinval(*tuple, *tupdesc, info.colNumber, &isnull); - - if (isnull) elog(ERROR, "Unexpected Null value in column %s", info.name); - - switch (info.type) { - case INTERVALOID: - interval = DatumGetIntervalP(binval); - break; - default: - elog(ERROR, - "[spi_getInterval] Unexpected type in column %s. found %ld expected %d", - info.name, info.type, INTERVALOID); - } - PGR_DBG("time %ld secs %ld", interval->time, - interval->time / 1000000 - + interval->day * SECS_PER_DAY - + (int64_t)(interval->month * ((DAYS_PER_YEAR / (double) MONTHS_PER_YEAR) * SECS_PER_DAY))); - - return interval->time / 1000000 - + interval->day * SECS_PER_DAY - + (int64_t)(interval->month * ((DAYS_PER_YEAR / (double) MONTHS_PER_YEAR) * SECS_PER_DAY)); -} - -/* - @param[in] tuple input row to be examined. - @param[in] tupdesc input row description. - @param[in] info contain column information. - @param[in] default_value returned when column contain NULL value. - - @throw ERROR Unexpected Column type. Expected column type is CHAR. - @throw ERROR When value of column is NULL. - - @return Char type of column value is returned. - - * http://doxygen.postgresql.org/include_2catalog_2pg__type_8h.html; - * [SPI_getbinval](https://www.postgresql.org/docs/8.1/static/spi-spi-getbinval.html) - * [Datum](https://doxygen.postgresql.org/datum_8h.html) - * [DatumGetInt16](https://doxygen.postgresql.org/postgres_8h.html#aec991e04209850f29a8a63df0c78ba2d) - */ -char -spi_getChar( - HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info, char default_value) { - Datum binval; - bool isNull; - char value = default_value; - - binval = SPI_getbinval(*tuple, *tupdesc, info.colNumber, &isNull); - if (!(info.type == BPCHAROID)) { - elog(ERROR, "Unexpected Column type of %s. Expected CHAR", info.name); - } - if (!isNull) { - value = ((char*)binval)[1]; - } else { - if (info.strict) { - elog(ERROR, "Unexpected Null value in column %s", info.name); - } - value = default_value; - } - return value; -} - -int32_t -spi_getMaxTasks( - HeapTuple *tuple, - TupleDesc *tupdesc, - Column_info_t info) { - int32_t value = spi_getInt(tuple, tupdesc, info); - if (value < 0) { - ereport( - ERROR, - (errmsg("Invalid max_tasks value %d", value), - errhint( - "Maximum number of tasks must be greater than or equal to 0"))); - } - return value; -} - -int64_t* -spi_getBigIntArr( - HeapTuple *tuple, - TupleDesc *tupdesc, - Column_info_t info, - size_t *the_size) { - bool is_null = false; - - Datum raw_array = SPI_getbinval(*tuple, *tupdesc, info.colNumber, &is_null); - /* - * [DatumGetArrayTypeP](https://doxygen.postgresql.org/array_8h.html#aa1b8e77c103863862e06a7b7c07ec532) - * [pgr_get_bigIntArray](http://docs.pgrouting.org/doxy/2.2/arrays__input_8c_source.html) - */ - ArrayType *pg_array = DatumGetArrayTypeP(raw_array); - - return pgr_get_bigIntArray((size_t*)the_size, pg_array); -} - -int64_t* -spi_getBigIntArr_allowEmpty( - HeapTuple *tuple, - TupleDesc *tupdesc, - Column_info_t info, - size_t *the_size) { - bool is_null = false; - - Datum raw_array = SPI_getbinval(*tuple, *tupdesc, info.colNumber, &is_null); - /* - * [DatumGetArrayTypeP](https://doxygen.postgresql.org/array_8h.html#aa1b8e77c103863862e06a7b7c07ec532) - * [pgr_get_bigIntArray](http://docs.pgrouting.org/doxy/2.2/arrays__input_8c_source.html) - */ - if (!raw_array) { - *the_size = 0; - return NULL; - } - - ArrayType *pg_array = DatumGetArrayTypeP(raw_array); - - return pgr_get_bigIntArray_allowEmpty(the_size, pg_array); -} - -int64_t* -spi_getPositiveBigIntArr_allowEmpty( - HeapTuple *tuple, - TupleDesc *tupdesc, - Column_info_t info, - size_t *the_size) { - int64_t *array = spi_getBigIntArr_allowEmpty(tuple, tupdesc, info, the_size); - for (size_t i = 0; i < *the_size; i++) { - if (array[i] < 0) { - elog(ERROR, "Unexpected Negative value %ld in array", array[i]); - } - } - return array; -} - - -uint32_t* -spi_getPositiveIntArr_allowEmpty( - HeapTuple *tuple, - TupleDesc *tupdesc, - Column_info_t info, - size_t *the_size) { - bool is_null = false; - - Datum raw_array = SPI_getbinval(*tuple, *tupdesc, info.colNumber, &is_null); - if (!raw_array) { - *the_size = 0; - return NULL; - } - - ArrayType *pg_array = DatumGetArrayTypeP(raw_array); - - return pgr_get_positiveIntArray_allowEmpty(the_size, pg_array); -} - - -/** - * @param[in] tuple - * @param[in] tupdesc - * @param[in] info about the column been fetched - * @param[in] opt_value default value when the column does not exist - * - * @returns The value found - * @returns opt_value when the column does not exist - */ -TTimestamp -get_TTimestamp_plain(HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info, TTimestamp opt_value) { - return column_found(info.colNumber)? - (TTimestamp)spi_getBigInt(tuple, tupdesc, info) - : opt_value; -} - -/** - * @param[in] tuple - * @param[in] tupdesc - * @param[in] info about the column been fetched - * @param[in] opt_value default value when the column does not exist - * - * @returns The value found - * @returns opt_value when the column does not exist - * - * exceptions when the value is negative - * @pre for positive values only - */ -TTimestamp -get_PositiveTTimestamp_plain(HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info, TTimestamp opt_value) { - TTimestamp value = get_TTimestamp_plain(tuple, tupdesc, info, opt_value); - if (value < 0) elog(ERROR, "Unexpected Negative value in column %s", info.name); - return value; -} - -/** - * @param[in] tuple - * @param[in] tupdesc - * @param[in] info about the column been fetched - * @param[in] opt_value default value when the column does not exist - * - * @returns The value found - * @returns opt_value when the column does not exist - */ -TTimestamp -get_TTimestamp(HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info, TTimestamp opt_value) { - return column_found(info.colNumber)? - spi_getTimeStamp(tuple, tupdesc, info) - : opt_value; -} - -/** - * @param[in] tuple - * @param[in] tupdesc - * @param[in] info about the column been fetched - * @param[in] opt_value default value when the column does not exist - * - * @returns The value found - * @returns opt_value when the column does not exist - * - * exceptions when the value is negative - * @pre for positive values only - */ -TTimestamp -get_PositiveTTimestamp(HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info, TTimestamp opt_value) { - TTimestamp value = get_TTimestamp(tuple, tupdesc, info, opt_value); - if (value < 0) elog(ERROR, "Unexpected Negative value in column %s", info.name); - return value; -} - -/** - * @param[in] tuple - * @param[in] tupdesc - * @param[in] info about the column been fetched - * @param[in] opt_value default value when the column does not exist - * - * @returns The value found - * @returns opt_value when the column does not exist - */ -TInterval -get_TInterval(HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info, TInterval opt_value) { - return column_found(info.colNumber)? - (TInterval)spi_getInterval(tuple, tupdesc, info) - : opt_value; -} - -/** - * @param[in] tuple - * @param[in] tupdesc - * @param[in] info about the column been fetched - * @param[in] opt_value default value when the column does not exist - * - * @returns The value found - * @returns opt_value when the column does not exist - * - * exceptions when the value is negative - * @pre for positive values only - */ -TInterval -get_PositiveTInterval(HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info, TInterval opt_value) { - TInterval value = get_TInterval(tuple, tupdesc, info, opt_value); - if (value < 0) elog(ERROR, "Unexpected Negative value in column %s", info.name); - return (TInterval) value; -} - -/** - * @param[in] tuple - * @param[in] tupdesc - * @param[in] info about the column been fetched - * @param[in] opt_value default value when the column does not exist - * - * @returns The value found - * @returns opt_value when the column does not exist - */ -TInterval -get_TInterval_plain(HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info, TInterval opt_value) { - return column_found(info.colNumber)? - (TInterval)spi_getBigInt(tuple, tupdesc, info) - : opt_value; -} - -/** - * @param[in] tuple - * @param[in] tupdesc - * @param[in] info about the column been fetched - * @param[in] opt_value default value when the column does not exist - * - * @returns The value found - * @returns opt_value when the column does not exist - * - * exceptions when the value is negative - * @pre for positive values only - */ -TInterval -get_PositiveTInterval_plain(HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info, TInterval opt_value) { - TInterval value = get_TInterval_plain(tuple, tupdesc, info, opt_value); - if (value < 0) elog(ERROR, "Unexpected Negative value in column %s", info.name); - return (TInterval) value; -} - -/** - * @param[in] tuple - * @param[in] tupdesc - * @param[in] info about the column been fetched - * @param[in] opt_value default value when the column does not exist - * - * @returns The value found - * @returns opt_value when the column does not exist - */ -Id -get_Id(HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info, Id opt_value) { - return column_found(info.colNumber)? - (Id)spi_getBigInt(tuple, tupdesc, info) - : opt_value; -} - -/** - * @param[in] tuple - * @param[in] tupdesc - * @param[in] info about the column been fetched - * @param[in] opt_value default value when the column does not exist - * - * @returns The value found - * @returns opt_value when the column does not exist - * - * exceptions when the value is not positive - * @pre for positive values only - */ -Idx -get_Idx(HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info, Idx opt_value) { - Id value = get_Id(tuple, tupdesc, info, 0); - if (value <= 0) elog(ERROR, "Unexpected Negative value or Zero in column %s", info.name); - return column_found(info.colNumber)? (Idx) value : opt_value; -} - -/** - * @param[in] tuple - * @param[in] tupdesc - * @param[in] info about the column been fetched - * @param[in] opt_value default value when the column does not exist - * - * @returns The value found - * @returns opt_value when the column does not exist - */ -StepType get_StepType(HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info, - StepType opt_value) { - StepType step_type = column_found(info.colNumber) - ? spi_getInt(tuple, tupdesc, info) - : opt_value; - StepType min_value = 1; - StepType max_value = 6; - if (step_type < min_value || step_type > max_value) { - elog(ERROR, "Step value should lie between %d and %d", min_value, max_value); - } - return step_type; -} - -/** - * @param[in] tuple - * @param[in] tupdesc - * @param[in] info about the column been fetched - * @param[in] opt_value default value when the column does not exist - * - * @returns The value found - * @returns opt_value when the column does not exist - */ -Amount -get_Amount(HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info, Amount opt_value) { - return (Amount) column_found(info.colNumber)? - spi_getBigInt(tuple, tupdesc, info) - : opt_value; -} - -/** - * @param[in] tuple - * @param[in] tupdesc - * @param[in] info about the column been fetched - * @param[in] opt_value default value when the column does not exist - * - * @returns The value found - * @returns opt_value when the column does not exist - * - * exceptions when the value is negative - * @pre for non-negative values only - */ -PAmount -get_PositiveAmount(HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info, PAmount opt_value) { - Amount value = get_Amount(tuple, tupdesc, info, 0); - if (value < 0) elog(ERROR, "Unexpected Negative value in column %s", info.name); - return column_found(info.colNumber)? (PAmount) value : opt_value; -} - - -/** - * @param[in] tuple - * @param[in] tupdesc - * @param[in] info about the column been fetched - * @param[in] opt_value default value when the column does not exist - * - * @returns The value found - * @returns opt_value when the column does not exist - * - * exceptions when the value is not positive - * @pre for positive values only - */ -MatrixIndex -get_MatrixIndex(HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info, MatrixIndex opt_value) { - if (column_found(info.colNumber)) { - int64_t value = spi_getBigInt(tuple, tupdesc, info); - if (value < 0) elog(ERROR, "Unexpected Negative value in column %s", info.name); - return (MatrixIndex) value; - } - return opt_value; -} - - -/** - * @param[in] tuple - * @param[in] tupdesc - * @param[in] info about the column been fetched - * @param[in] opt_value default value when the column does not exist - * - * @returns The value found - * @returns opt_value when the column does not exist - * - * exceptions when the value is negative - * @pre for non-negative values only - */ -Duration -get_Duration(HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info, Duration opt_value) { - if (column_found(info.colNumber)) { - int32_t value = spi_getInt(tuple, tupdesc, info); - if (value < 0) elog(ERROR, "Unexpected Negative value in column %s", info.name); - return (Duration) value; - } - return opt_value; -} - - -/** - * @param[in] tuple - * @param[in] tupdesc - * @param[in] info about the column been fetched - * @param[in] opt_value default value when the column does not exist - * - * @returns The value found - * @returns opt_value when the column does not exist - * - * exceptions when the value is negative - * @pre for non-negative values only - */ -TravelCost -get_Cost(HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info, TravelCost opt_value) { - if (column_found(info.colNumber)) { - int32_t value = spi_getInt(tuple, tupdesc, info); - if (value < 0) elog(ERROR, "Unexpected Negative value in column %s", info.name); - return (TravelCost)value; - } - return opt_value; -} - - -/** - * @param[in] tuple - * @param[in] tupdesc - * @param[in] info about the column been fetched - * @param[in] opt_value default value when the column does not exist - * - * @returns The value found - * @returns opt_value when the column does not exist - * - */ -char -get_Kind(HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info, char opt_value) { - if (column_found(info.colNumber)) { - char value = spi_getChar(tuple, tupdesc, info, opt_value); - return value; - } - return opt_value; -} - - -/** - * @param[in] tuple - * @param[in] tupdesc - * @param[in] info about the column been fetched - * @param[in] opt_value default value when the column does not exist - * - * @returns The value found - * @returns opt_value when the column does not exist - * - * exceptions when the value is negative - * @pre for non-negative values only - */ -Priority -get_Priority(HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info, Priority opt_value) { - if (column_found(info.colNumber)) { - int32_t value = spi_getInt(tuple, tupdesc, info); - if (value < 0) elog(ERROR, "Unexpected Negative value in column %s", info.name); - if (value > 100) elog(ERROR, "Priority exceeds the max priority 100"); - return (Priority) value; - } - return opt_value; -} - - -/** - * @param[in] tuple - * @param[in] tupdesc - * @param[in] info about the column been fetched - * @param[in] opt_value default value when the column does not exist - * - * @returns The value found - * @returns opt_value when the column does not exist - * - * exceptions when the value is negative - * @pre for non-negative values only - */ -Distance -get_Distance(HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info, Distance opt_value) { - if (column_found(info.colNumber)) { - int32_t value = spi_getInt(tuple, tupdesc, info); - if (value < 0) elog(ERROR, "Unexpected Negative value in column %s", info.name); - return (Distance) value; - } - return opt_value; -} - - -double -spi_getFloat8(HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info) { - Datum binval; - bool isnull = false; - double value = 0.0; - binval = SPI_getbinval(*tuple, *tupdesc, info.colNumber, &isnull); - if (isnull) - elog(ERROR, "Unexpected Null value in column %s", info.name); - - switch (info.type) { - case INT2OID: - value = (double) DatumGetInt16(binval); - break; - case INT4OID: - value = (double) DatumGetInt32(binval); - break; - case INT8OID: - value = (double) DatumGetInt64(binval); - break; - case FLOAT4OID: - value = (double) DatumGetFloat4(binval); - break; - case FLOAT8OID: - value = DatumGetFloat8(binval); - break; - case NUMERICOID: - /* Note: out-of-range values will be clamped to +-HUGE_VAL */ - value = (double) DatumGetFloat8(DirectFunctionCall1(numeric_float8_no_overflow, binval)); - break; - default: - ereport(ERROR, - (errmsg_internal("Unexpected type in column '%s'.", info.name), - errhint("Found: %lu\nExpected ANY-NUMERICAL", info.type))); - } - return value; -} - -Coordinate -spi_getCoordinate(HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info, Coordinate opt_value) { - return column_found(info.colNumber)? - (Coordinate) spi_getFloat8(tuple, tupdesc, info) - : opt_value; -} - -/** - * under development - */ -/* - * [DatumGetCString](https://doxygen.postgresql.org/postgres_8h.html#ae401c8476d1a12b420e3061823a206a7) - */ -char* -spi_getText(HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info) { - char *val = DatumGetCString(SPI_getvalue(*tuple, *tupdesc, info.colNumber)); - return val; -} - -/** - * Steps: - * 1) Similar to: https://doxygen.postgresql.org/backend_2utils_2adt_2timestamp_8c.html#a52973f03ed8296b632d4028121f7e077 - * 2) Using time.h to convert - * - * from time.h - * struct tm - * timezone - */ -TTimestamp -timestamp_without_timezone(TTimestamp timestamp) { - /* - * step 1 - */ - Timestamp date; - Timestamp time = timestamp; - TMODULO(time, date, USECS_PER_DAY); - if (time < INT64CONST(0)) { - time += USECS_PER_DAY; - date -= 1; - } - date += POSTGRES_EPOCH_JDATE; - /* Julian day routine does not work for negative Julian days */ - if (date < 0 || date > (Timestamp) INT_MAX) { - ereport(ERROR, - (errcode(ERRCODE_INTERNAL_ERROR), - errmsg("Julian day routine does not work for negative Julian days"))); - } - - /* - * using structure from time.h to store values - */ - struct tm info; - fsec_t fsec; - - /* - * calling postgres functions - */ - j2date((int) date, &info.tm_year, &info.tm_mon, &info.tm_mday); - dt2time(time, &info.tm_hour, &info.tm_min, &info.tm_sec, &fsec); - - /* - * adjust values before calling mktime - */ - info.tm_isdst = -1; - info.tm_year = info.tm_year - 1900; - info.tm_mon = info.tm_mon - 1; - - /* - * mktime & timezone are defined in time.h - */ - return mktime(&info) - timezone; -} - - -/* - * @param[in] colNumber Column number (count starts at 1). - - * [SPI_ERROR_NOATTRIBUTE](https://doxygen.postgresql.org/spi_8h.html#ac1512d8aaa23c2d57bb0d1eb8f453ee2) - * @return @b TRUE when colNumber exist. - * @b FALSE when colNumber was not found. -*/ -bool -column_found(int colNumber) { - return !(colNumber == SPI_ERROR_NOATTRIBUTE); -} - - -void pgr_fetch_column_info( - Column_info_t info[], - int info_size) { - for (int i = 0; i < info_size; ++i) { - if (fetch_column_info(&info[i])) { - switch (info[i].eType) { - case INTEGER: - check_integer_type(info[i]); - break; - case ANY_INTEGER: - check_any_integer_type(info[i]); - break; - case ANY_NUMERICAL: - check_any_numerical_type(info[i]); - break; - case TEXT: - check_text_type(info[i]); - break; - case JSONB: - check_jsonb_type(info[i]); - break; - case CHAR1: - check_char_type(info[i]); - break; - case INTEGER_ARRAY: - check_integerarray_type(info[i]); - break; - case ANY_INTEGER_ARRAY: - check_any_integerarray_type(info[i]); - break; - case TIMESTAMP: - check_timestamp_type(info[i]); - break; - case INTERVAL: - check_interval_type(info[i]); - break; - default: - elog(ERROR, "Unknown type of column %s", info[i].name); - } - } - } -}