From ef3958896bab5bbb1623a76ccea6d1dad4b44beb Mon Sep 17 00:00:00 2001
From: Manas
Date: Sun, 10 Jul 2022 21:26:49 +0530
Subject: [PATCH 01/28] [include/c_types] Adding a struct for knapsack
---
include/c_types/knapsack_rt.h | 59 +++++++++++++++++++++++++++++++++++
include/c_types/typedefs.h | 3 +-
2 files changed, 61 insertions(+), 1 deletion(-)
create mode 100644 include/c_types/knapsack_rt.h
diff --git a/include/c_types/knapsack_rt.h b/include/c_types/knapsack_rt.h
new file mode 100644
index 0000000000..cbb9db0899
--- /dev/null
+++ b/include/c_types/knapsack_rt.h
@@ -0,0 +1,59 @@
+/*PGR-GNU*****************************************************************
+File: knapsack_rt.h
+
+Copyright (c) 2022 Manas Sivakumar
+Mail: 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*/
+/*! @file */
+
+#ifndef INCLUDE_C_TYPES_KNAPSACK_RT_H_
+#define INCLUDE_C_TYPES_KNAPSACK_RT_H_
+#pragma once
+
+/* for int64_t */
+#ifdef __cplusplus
+# include
+#else
+# include
+#endif
+
+/** @brief
+
+@note C/C++/postgreSQL connecting structure for output
+name | description
+:----- | :-------
+TotalWeight | Cumulative Weight of items in the knapsack
+TotalValue | Cumulative Value of items in the knapsack
+Index | Position of the item in the order in which the input was given
+ItemWeight | Weight of the item
+ItemValue | Value of the item
+*/
+
+struct Knapsack_rt {
+ int64_t TotalWeight;
+ int64_t TotalValue;
+ int Index;
+ int ItemWeight;
+ int ItemValue;
+};
+
+/*************************************************************************/
+
+#endif // INCLUDE_C_TYPES_KNAPSACK_RT_H_
diff --git a/include/c_types/typedefs.h b/include/c_types/typedefs.h
index 84bb26cb20..823511d730 100644
--- a/include/c_types/typedefs.h
+++ b/include/c_types/typedefs.h
@@ -97,8 +97,9 @@ typedef struct Vroom_matrix_t Vroom_matrix_t;
typedef struct Vroom_break_t Vroom_break_t;
typedef struct Vroom_time_window_t Vroom_time_window_t;
typedef struct Vroom_rt Vroom_rt;
+typedef struct knapsack_rt knapsack_rt;
#endif
/*************************************************************************/
-#endif // INCLUDE_C_TYPES_TYPEDEFS_H_
+#endif // INCLUDE_C_TYPES_TYPEDEFS_H_
From 5c7e34b30ffffa46244fa8a58f2a91aa0bc61149 Mon Sep 17 00:00:00 2001
From: Manas
Date: Sun, 10 Jul 2022 21:29:04 +0530
Subject: [PATCH 02/28] [include/c_types] add Knapsack_rt to typedefs.h file
---
include/c_types/typedefs.h | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/include/c_types/typedefs.h b/include/c_types/typedefs.h
index 823511d730..1924ef402c 100644
--- a/include/c_types/typedefs.h
+++ b/include/c_types/typedefs.h
@@ -60,6 +60,7 @@ using Vroom_matrix_t = struct Vroom_matrix_t;
using Vroom_break_t = struct Vroom_break_t;
using Vroom_time_window_t = struct Vroom_time_window_t;
using Vroom_rt = struct Vroom_rt;
+using Knapsack_rt = struct Knapsack_rt;
/*
* Index on a container
*/
@@ -97,7 +98,7 @@ typedef struct Vroom_matrix_t Vroom_matrix_t;
typedef struct Vroom_break_t Vroom_break_t;
typedef struct Vroom_time_window_t Vroom_time_window_t;
typedef struct Vroom_rt Vroom_rt;
-typedef struct knapsack_rt knapsack_rt;
+typedef struct Knapsack_rt Knapsack_rt;
#endif
/*************************************************************************/
From f9d7bfc01b531f22d3d2d4a85d254e8355e9ed7e Mon Sep 17 00:00:00 2001
From: Manas
Date: Sun, 10 Jul 2022 23:22:25 +0530
Subject: [PATCH 03/28] gpush.sh
---
.gitignore | 2 +
include/drivers/or_tools/knapsack_driver.h | 18 +--
src/or_tools/knapsack.c | 172 +--------------------
src/or_tools/knapsack_driver.cpp | 4 +-
4 files changed, 16 insertions(+), 180 deletions(-)
diff --git a/.gitignore b/.gitignore
index 93ee6f1e23..29c3b13bb8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,6 +6,8 @@ src/version/_version.h
v[0-9]*
ortools
build1
+gpush.sh
+bin_packing.cc
# files are ignored on gh-pages
doxy
diff --git a/include/drivers/or_tools/knapsack_driver.h b/include/drivers/or_tools/knapsack_driver.h
index 9873fa2330..4455f68ee3 100644
--- a/include/drivers/or_tools/knapsack_driver.h
+++ b/include/drivers/or_tools/knapsack_driver.h
@@ -6,7 +6,7 @@ Mail: project@pgrouting.org
Function's developer:
Copyright (c) 2022 Manas Sivakumar
-Mail:
+Mail: Manas Sivakumar
------
@@ -39,11 +39,10 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
# include
#endif
-#include "c_types/vehicle_t.h"
-#include "c_types/matrix_cell_t.h"
+
typedef struct PickDeliveryOrders_t PickDeliveryOrders_t;
-typedef struct Solution_rt Solution_rt;
+typedef struct Knapsack_rt Knapsack_rt;
#ifdef __cplusplus
extern "C" {
@@ -55,16 +54,11 @@ extern "C" {
bin_capacity INTEGER,
max_cycles INTEGER,
********************************************************/
- void do_pgr_pickDeliver(
+ void do_knapsack(
PickDeliveryOrders_t *pd_orders_arr, size_t total_pd_orders,
- Vehicle_t *vehicles_arr, size_t total_vehicles,
- Matrix_cell_t *matrix_cells_arr, size_t total_cells,
-
- double factor,
- int max_cycles,
- int initial_solution_id,
+
- Solution_rt **return_tuples,
+ Knapsack_rt **return_tuples,
size_t *return_count,
char **log_msg,
diff --git a/src/or_tools/knapsack.c b/src/or_tools/knapsack.c
index feec208e79..448beed962 100644
--- a/src/or_tools/knapsack.c
+++ b/src/or_tools/knapsack.c
@@ -24,7 +24,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#include "c_common/e_report.h"
#include "c_common/time_msg.h"
-
+#include "c_types/knapsack_rt.h"
#include "drivers/or_tools/knapsack_driver.h"
PGDLLEXPORT Datum
@@ -37,44 +37,10 @@ void
process(
char* weights_sql,
char* values_sql,
- char* matrix_sql,
int bin_capacity,
- double factor,
- int max_cycles,
- int initial_solution_id,
-
- Solution_rt **result_tuples,
+
+ Knapsack_rt **result_tuples,
size_t *result_count) {
-#if 0
- if (factor <= 0) {
- ereport(ERROR,
- (errcode(ERRCODE_INTERNAL_ERROR),
- errmsg("Illegal value in parameter: factor"),
- errhint("Value found: %f <= 0", factor)));
- (*result_count) = 0;
- (*result_tuples) = NULL;
- return;
- }
-
- if (max_cycles < 0) {
- ereport(ERROR,
- (errcode(ERRCODE_INTERNAL_ERROR),
- errmsg("Illegal value in parameter: max_cycles"),
- errhint("Value found: %d <= 0", max_cycles)));
- (*result_count) = 0;
- (*result_tuples) = NULL;
- return;
- }
-
- if (initial_solution_id < 0 || initial_solution_id > 7) {
- ereport(ERROR,
- (errcode(ERRCODE_INTERNAL_ERROR),
- errmsg("Illegal value in parameter: initial"),
- errhint("Value found: %d <= 0", initial_solution_id)));
- (*result_count) = 0;
- (*result_tuples) = NULL;
- return;
- }
pgr_SPI_connect();
@@ -97,112 +63,13 @@ process(
return;
}
-
- Vehicle_t *vehicles_arr = NULL;
- size_t total_vehicles = 0;
- get_vehicles_raw(vehicles_sql,
- &vehicles_arr, &total_vehicles,
- false);
-
- if (total_vehicles == 0) {
- (*result_count) = 0;
- (*result_tuples) = NULL;
-
- /* freeing memory before return */
- if (pd_orders_arr) {pfree(pd_orders_arr); pd_orders_arr = NULL;}
- if (vehicles_arr) {pfree(vehicles_arr); vehicles_arr = NULL;}
-
- pgr_SPI_finish();
- ereport(ERROR,
- (errcode(ERRCODE_INTERNAL_ERROR),
- errmsg("No vehicles found")));
- return;
- }
-
- PGR_DBG("total orders %ld", total_pd_orders);
- for (size_t i = 0; i < total_pd_orders; i++) {
- PGR_DBG("%ld %f pick %ld - %ld %ld %ld"
- "deliver %ld - %ld %ld %ld ",
- pd_orders_arr[i].id,
- pd_orders_arr[i].demand,
-
- pd_orders_arr[i].pick_node_id,
-
- pd_orders_arr[i].pick_open_t,
- pd_orders_arr[i].pick_close_t,
- pd_orders_arr[i].pick_service_t,
-
- pd_orders_arr[i].deliver_node_id,
-
- pd_orders_arr[i].deliver_open_t,
- pd_orders_arr[i].deliver_close_t,
- pd_orders_arr[i].deliver_service_t);
- }
-
-
-
- PGR_DBG("total vehicles %ld", total_vehicles);
- for (size_t i = 0; i < total_vehicles; i++) {
- PGR_DBG("%ld %f %f , start %ld %ld %ld %ld "
- "end %ld %ld %ld %ld number %ld ",
- vehicles_arr[i].id,
- vehicles_arr[i].capacity,
- vehicles_arr[i].speed,
-
- vehicles_arr[i].start_node_id,
- vehicles_arr[i].start_open_t,
- vehicles_arr[i].start_close_t,
- vehicles_arr[i].start_service_t,
-
- vehicles_arr[i].end_node_id,
- vehicles_arr[i].end_open_t,
- vehicles_arr[i].end_close_t,
- vehicles_arr[i].end_service_t,
-
- vehicles_arr[i].cant_v);
- }
-
- Matrix_cell_t *matrix_cells_arr = NULL;
- size_t total_cells = 0;
- get_matrixRows_plain(matrix_sql, &matrix_cells_arr, &total_cells);
-
- PGR_DBG("total matrix rows %ld", total_cells);
- for (size_t i = 0; i < total_cells; i++) {
- PGR_DBG("%ld %ld %f",
- matrix_cells_arr[i].from_vid,
- matrix_cells_arr[i].to_vid,
- matrix_cells_arr[i].cost);
- }
-
- if (total_cells == 0) {
- (*result_count) = 0;
- (*result_tuples) = NULL;
-
- /* freeing memory before return */
- if (pd_orders_arr) {pfree(pd_orders_arr); pd_orders_arr = NULL;}
- if (vehicles_arr) {pfree(vehicles_arr); vehicles_arr = NULL;}
- if (matrix_cells_arr) {pfree(matrix_cells_arr); matrix_cells_arr = NULL;}
-
- ereport(WARNING,
- (errcode(ERRCODE_INTERNAL_ERROR),
- errmsg("No matrix found")));
- pgr_SPI_finish();
- return;
- }
-
-
- PGR_DBG("Total %ld orders in query:", total_pd_orders);
- PGR_DBG("Total %ld vehicles in query:", total_vehicles);
- PGR_DBG("Total %ld matrix cells in query:", total_cells);
-
-
PGR_DBG("Starting processing");
clock_t start_t = clock();
char *log_msg = NULL;
char *notice_msg = NULL;
char *err_msg = NULL;
- do_pgr_pickDeliver(
+ do_knapsack(
pd_orders_arr, total_pd_orders,
vehicles_arr, total_vehicles,
matrix_cells_arr, total_cells,
@@ -218,31 +85,7 @@ process(
¬ice_msg,
&err_msg);
- time_msg("pgr_pickDeliver", start_t, clock());
-
- if (err_msg && (*result_tuples)) {
- pfree(*result_tuples);
- (*result_count) = 0;
- (*result_tuples) = NULL;
- }
- pgr_global_report(log_msg, notice_msg, err_msg);
-/* TODO(dev) remove unused includes */
-#include "c_common/orders_input.h"
-#include "c_common/vehicles_input.h"
-#include "c_common/matrixRows_input.h"
-#include "c_types/pickDeliveryOrders_t.h"
-#include "drivers/pgr_pickDeliver/pickDeliver_driver.h"
-#include "c_types/solution_rt.h"
- /* freeing memory before return */
- if (log_msg) {pfree(log_msg); log_msg = NULL;}
- if (notice_msg) {pfree(notice_msg); notice_msg = NULL;}
- if (err_msg) {pfree(err_msg); err_msg = NULL;}
- if (pd_orders_arr) {pfree(pd_orders_arr); pd_orders_arr = NULL;}
- if (vehicles_arr) {pfree(vehicles_arr); vehicles_arr = NULL;}
- if (matrix_cells_arr) {pfree(matrix_cells_arr); matrix_cells_arr = NULL;}
-
pgr_SPI_finish();
-#endif
}
@@ -263,10 +106,7 @@ _vrp_knapsack(PG_FUNCTION_ARGS) {
process(
text_to_cstring(PG_GETARG_TEXT_P(0)),
text_to_cstring(PG_GETARG_TEXT_P(1)),
- text_to_cstring(PG_GETARG_TEXT_P(2)),
- PG_GETARG_FLOAT8(3),
- PG_GETARG_INT32(4),
- PG_GETARG_INT32(5),
+ PG_GETARG_INT32(2),
&result_tuples,
&result_count);
@@ -286,7 +126,7 @@ _vrp_knapsack(PG_FUNCTION_ARGS) {
funcctx = SRF_PERCALL_SETUP();
tuple_desc = funcctx->tuple_desc;
- result_tuples = (Solution_rt*) funcctx->user_fctx;
+ result_tuples = (Knapsack_rt*) funcctx->user_fctx;
if (funcctx->call_cntr < funcctx->max_calls) {
HeapTuple tuple;
diff --git a/src/or_tools/knapsack_driver.cpp b/src/or_tools/knapsack_driver.cpp
index c72200e4db..f31aabb696 100644
--- a/src/or_tools/knapsack_driver.cpp
+++ b/src/or_tools/knapsack_driver.cpp
@@ -1,9 +1,9 @@
/*PGR-GNU*****************************************************************
File: pickDeliver_driver.cpp
-Copyright (c) 2015 pgRouting developers
+Copyright (c) 2022 pgRouting developers
Mail: project@pgrouting.org
Function's developer:
-Copyright (c) 2015 Celia Virginia Vergara Castillo
+Copyright (c) 2022 Manas Sivakumar
------
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
From df3f904a2d147be9c6ac6b8f1cea032ff5960150 Mon Sep 17 00:00:00 2001
From: Manas
Date: Sun, 10 Jul 2022 23:23:49 +0530
Subject: [PATCH 04/28] Revert "gpush.sh"
This reverts commit f9d7bfc01b531f22d3d2d4a85d254e8355e9ed7e.
---
.gitignore | 2 -
include/drivers/or_tools/knapsack_driver.h | 18 ++-
src/or_tools/knapsack.c | 172 ++++++++++++++++++++-
src/or_tools/knapsack_driver.cpp | 4 +-
4 files changed, 180 insertions(+), 16 deletions(-)
diff --git a/.gitignore b/.gitignore
index 29c3b13bb8..93ee6f1e23 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,8 +6,6 @@ src/version/_version.h
v[0-9]*
ortools
build1
-gpush.sh
-bin_packing.cc
# files are ignored on gh-pages
doxy
diff --git a/include/drivers/or_tools/knapsack_driver.h b/include/drivers/or_tools/knapsack_driver.h
index 4455f68ee3..9873fa2330 100644
--- a/include/drivers/or_tools/knapsack_driver.h
+++ b/include/drivers/or_tools/knapsack_driver.h
@@ -6,7 +6,7 @@ Mail: project@pgrouting.org
Function's developer:
Copyright (c) 2022 Manas Sivakumar
-Mail: Manas Sivakumar
+Mail:
------
@@ -39,10 +39,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
# include
#endif
-
+#include "c_types/vehicle_t.h"
+#include "c_types/matrix_cell_t.h"
typedef struct PickDeliveryOrders_t PickDeliveryOrders_t;
-typedef struct Knapsack_rt Knapsack_rt;
+typedef struct Solution_rt Solution_rt;
#ifdef __cplusplus
extern "C" {
@@ -54,11 +55,16 @@ extern "C" {
bin_capacity INTEGER,
max_cycles INTEGER,
********************************************************/
- void do_knapsack(
+ void do_pgr_pickDeliver(
PickDeliveryOrders_t *pd_orders_arr, size_t total_pd_orders,
-
+ Vehicle_t *vehicles_arr, size_t total_vehicles,
+ Matrix_cell_t *matrix_cells_arr, size_t total_cells,
+
+ double factor,
+ int max_cycles,
+ int initial_solution_id,
- Knapsack_rt **return_tuples,
+ Solution_rt **return_tuples,
size_t *return_count,
char **log_msg,
diff --git a/src/or_tools/knapsack.c b/src/or_tools/knapsack.c
index 448beed962..feec208e79 100644
--- a/src/or_tools/knapsack.c
+++ b/src/or_tools/knapsack.c
@@ -24,7 +24,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#include "c_common/e_report.h"
#include "c_common/time_msg.h"
-#include "c_types/knapsack_rt.h"
+
#include "drivers/or_tools/knapsack_driver.h"
PGDLLEXPORT Datum
@@ -37,10 +37,44 @@ void
process(
char* weights_sql,
char* values_sql,
+ char* matrix_sql,
int bin_capacity,
-
- Knapsack_rt **result_tuples,
+ double factor,
+ int max_cycles,
+ int initial_solution_id,
+
+ Solution_rt **result_tuples,
size_t *result_count) {
+#if 0
+ if (factor <= 0) {
+ ereport(ERROR,
+ (errcode(ERRCODE_INTERNAL_ERROR),
+ errmsg("Illegal value in parameter: factor"),
+ errhint("Value found: %f <= 0", factor)));
+ (*result_count) = 0;
+ (*result_tuples) = NULL;
+ return;
+ }
+
+ if (max_cycles < 0) {
+ ereport(ERROR,
+ (errcode(ERRCODE_INTERNAL_ERROR),
+ errmsg("Illegal value in parameter: max_cycles"),
+ errhint("Value found: %d <= 0", max_cycles)));
+ (*result_count) = 0;
+ (*result_tuples) = NULL;
+ return;
+ }
+
+ if (initial_solution_id < 0 || initial_solution_id > 7) {
+ ereport(ERROR,
+ (errcode(ERRCODE_INTERNAL_ERROR),
+ errmsg("Illegal value in parameter: initial"),
+ errhint("Value found: %d <= 0", initial_solution_id)));
+ (*result_count) = 0;
+ (*result_tuples) = NULL;
+ return;
+ }
pgr_SPI_connect();
@@ -63,13 +97,112 @@ process(
return;
}
+
+ Vehicle_t *vehicles_arr = NULL;
+ size_t total_vehicles = 0;
+ get_vehicles_raw(vehicles_sql,
+ &vehicles_arr, &total_vehicles,
+ false);
+
+ if (total_vehicles == 0) {
+ (*result_count) = 0;
+ (*result_tuples) = NULL;
+
+ /* freeing memory before return */
+ if (pd_orders_arr) {pfree(pd_orders_arr); pd_orders_arr = NULL;}
+ if (vehicles_arr) {pfree(vehicles_arr); vehicles_arr = NULL;}
+
+ pgr_SPI_finish();
+ ereport(ERROR,
+ (errcode(ERRCODE_INTERNAL_ERROR),
+ errmsg("No vehicles found")));
+ return;
+ }
+
+ PGR_DBG("total orders %ld", total_pd_orders);
+ for (size_t i = 0; i < total_pd_orders; i++) {
+ PGR_DBG("%ld %f pick %ld - %ld %ld %ld"
+ "deliver %ld - %ld %ld %ld ",
+ pd_orders_arr[i].id,
+ pd_orders_arr[i].demand,
+
+ pd_orders_arr[i].pick_node_id,
+
+ pd_orders_arr[i].pick_open_t,
+ pd_orders_arr[i].pick_close_t,
+ pd_orders_arr[i].pick_service_t,
+
+ pd_orders_arr[i].deliver_node_id,
+
+ pd_orders_arr[i].deliver_open_t,
+ pd_orders_arr[i].deliver_close_t,
+ pd_orders_arr[i].deliver_service_t);
+ }
+
+
+
+ PGR_DBG("total vehicles %ld", total_vehicles);
+ for (size_t i = 0; i < total_vehicles; i++) {
+ PGR_DBG("%ld %f %f , start %ld %ld %ld %ld "
+ "end %ld %ld %ld %ld number %ld ",
+ vehicles_arr[i].id,
+ vehicles_arr[i].capacity,
+ vehicles_arr[i].speed,
+
+ vehicles_arr[i].start_node_id,
+ vehicles_arr[i].start_open_t,
+ vehicles_arr[i].start_close_t,
+ vehicles_arr[i].start_service_t,
+
+ vehicles_arr[i].end_node_id,
+ vehicles_arr[i].end_open_t,
+ vehicles_arr[i].end_close_t,
+ vehicles_arr[i].end_service_t,
+
+ vehicles_arr[i].cant_v);
+ }
+
+ Matrix_cell_t *matrix_cells_arr = NULL;
+ size_t total_cells = 0;
+ get_matrixRows_plain(matrix_sql, &matrix_cells_arr, &total_cells);
+
+ PGR_DBG("total matrix rows %ld", total_cells);
+ for (size_t i = 0; i < total_cells; i++) {
+ PGR_DBG("%ld %ld %f",
+ matrix_cells_arr[i].from_vid,
+ matrix_cells_arr[i].to_vid,
+ matrix_cells_arr[i].cost);
+ }
+
+ if (total_cells == 0) {
+ (*result_count) = 0;
+ (*result_tuples) = NULL;
+
+ /* freeing memory before return */
+ if (pd_orders_arr) {pfree(pd_orders_arr); pd_orders_arr = NULL;}
+ if (vehicles_arr) {pfree(vehicles_arr); vehicles_arr = NULL;}
+ if (matrix_cells_arr) {pfree(matrix_cells_arr); matrix_cells_arr = NULL;}
+
+ ereport(WARNING,
+ (errcode(ERRCODE_INTERNAL_ERROR),
+ errmsg("No matrix found")));
+ pgr_SPI_finish();
+ return;
+ }
+
+
+ PGR_DBG("Total %ld orders in query:", total_pd_orders);
+ PGR_DBG("Total %ld vehicles in query:", total_vehicles);
+ PGR_DBG("Total %ld matrix cells in query:", total_cells);
+
+
PGR_DBG("Starting processing");
clock_t start_t = clock();
char *log_msg = NULL;
char *notice_msg = NULL;
char *err_msg = NULL;
- do_knapsack(
+ do_pgr_pickDeliver(
pd_orders_arr, total_pd_orders,
vehicles_arr, total_vehicles,
matrix_cells_arr, total_cells,
@@ -85,7 +218,31 @@ process(
¬ice_msg,
&err_msg);
+ time_msg("pgr_pickDeliver", start_t, clock());
+
+ if (err_msg && (*result_tuples)) {
+ pfree(*result_tuples);
+ (*result_count) = 0;
+ (*result_tuples) = NULL;
+ }
+ pgr_global_report(log_msg, notice_msg, err_msg);
+/* TODO(dev) remove unused includes */
+#include "c_common/orders_input.h"
+#include "c_common/vehicles_input.h"
+#include "c_common/matrixRows_input.h"
+#include "c_types/pickDeliveryOrders_t.h"
+#include "drivers/pgr_pickDeliver/pickDeliver_driver.h"
+#include "c_types/solution_rt.h"
+ /* freeing memory before return */
+ if (log_msg) {pfree(log_msg); log_msg = NULL;}
+ if (notice_msg) {pfree(notice_msg); notice_msg = NULL;}
+ if (err_msg) {pfree(err_msg); err_msg = NULL;}
+ if (pd_orders_arr) {pfree(pd_orders_arr); pd_orders_arr = NULL;}
+ if (vehicles_arr) {pfree(vehicles_arr); vehicles_arr = NULL;}
+ if (matrix_cells_arr) {pfree(matrix_cells_arr); matrix_cells_arr = NULL;}
+
pgr_SPI_finish();
+#endif
}
@@ -106,7 +263,10 @@ _vrp_knapsack(PG_FUNCTION_ARGS) {
process(
text_to_cstring(PG_GETARG_TEXT_P(0)),
text_to_cstring(PG_GETARG_TEXT_P(1)),
- PG_GETARG_INT32(2),
+ text_to_cstring(PG_GETARG_TEXT_P(2)),
+ PG_GETARG_FLOAT8(3),
+ PG_GETARG_INT32(4),
+ PG_GETARG_INT32(5),
&result_tuples,
&result_count);
@@ -126,7 +286,7 @@ _vrp_knapsack(PG_FUNCTION_ARGS) {
funcctx = SRF_PERCALL_SETUP();
tuple_desc = funcctx->tuple_desc;
- result_tuples = (Knapsack_rt*) funcctx->user_fctx;
+ result_tuples = (Solution_rt*) funcctx->user_fctx;
if (funcctx->call_cntr < funcctx->max_calls) {
HeapTuple tuple;
diff --git a/src/or_tools/knapsack_driver.cpp b/src/or_tools/knapsack_driver.cpp
index f31aabb696..c72200e4db 100644
--- a/src/or_tools/knapsack_driver.cpp
+++ b/src/or_tools/knapsack_driver.cpp
@@ -1,9 +1,9 @@
/*PGR-GNU*****************************************************************
File: pickDeliver_driver.cpp
-Copyright (c) 2022 pgRouting developers
+Copyright (c) 2015 pgRouting developers
Mail: project@pgrouting.org
Function's developer:
-Copyright (c) 2022 Manas Sivakumar
+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
From 2f76e6588b7e49936fca62722ec42f023a07ce6c Mon Sep 17 00:00:00 2001
From: Manas
Date: Sun, 10 Jul 2022 23:47:59 +0530
Subject: [PATCH 05/28] Slight
---
include/c_types/knapsack_rt.h | 4 ----
sql/or_tools/_knapsack.sql | 5 ++---
sql/or_tools/knapsack.sql | 7 +++----
src/or_tools/knapsack.c | 7 +++----
src/or_tools/knapsack_driver.cpp | 2 +-
5 files changed, 9 insertions(+), 16 deletions(-)
diff --git a/include/c_types/knapsack_rt.h b/include/c_types/knapsack_rt.h
index cbb9db0899..7c00bb8e69 100644
--- a/include/c_types/knapsack_rt.h
+++ b/include/c_types/knapsack_rt.h
@@ -39,16 +39,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
@note C/C++/postgreSQL connecting structure for output
name | description
:----- | :-------
-TotalWeight | Cumulative Weight of items in the knapsack
-TotalValue | Cumulative Value of items in the knapsack
Index | Position of the item in the order in which the input was given
ItemWeight | Weight of the item
ItemValue | Value of the item
*/
struct Knapsack_rt {
- int64_t TotalWeight;
- int64_t TotalValue;
int Index;
int ItemWeight;
int ItemValue;
diff --git a/sql/or_tools/_knapsack.sql b/sql/or_tools/_knapsack.sql
index 7f64734712..9dcc3e528e 100644
--- a/sql/or_tools/_knapsack.sql
+++ b/sql/or_tools/_knapsack.sql
@@ -27,8 +27,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
CREATE OR REPLACE FUNCTION _vrp_knapsack(
- TEXT, -- weights SQL
- TEXT, -- values SQL
+ TEXT, -- weights_values SQL
INTEGER, -- bin capacity
@@ -43,5 +42,5 @@ LANGUAGE c VOLATILE STRICT;
-- COMMENTS
-COMMENT ON FUNCTION _vrp_knapsack(TEXT, TEXT, INTEGER)
+COMMENT ON FUNCTION _vrp_knapsack(TEXT, INTEGER)
IS 'vrprouting internal function';
\ No newline at end of file
diff --git a/sql/or_tools/knapsack.sql b/sql/or_tools/knapsack.sql
index fa0db2ea8c..80ae58e90c 100644
--- a/sql/or_tools/knapsack.sql
+++ b/sql/or_tools/knapsack.sql
@@ -28,8 +28,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
CREATE OR REPLACE FUNCTION vrp_knapsack(
- TEXT, -- weights SQL
- TEXT, -- values SQL
+ TEXT, -- weights_values SQL
INTEGER, -- bin capacity
@@ -41,11 +40,11 @@ CREATE OR REPLACE FUNCTION vrp_knapsack(
RETURNS SETOF RECORD AS
$BODY$
SELECT *
- FROM vrp_knapsack(_pgr_get_statement($1), _pgr_get_statement($2), $3);
+ FROM vrp_knapsack(_pgr_get_statement($1), $2);
$BODY$
LANGUAGE SQL VOLATILE STRICT;
-- COMMENTS
-COMMENT ON FUNCTION vrp_knapsack(TEXT, TEXT, INTEGER)
+COMMENT ON FUNCTION vrp_knapsack(TEXT, INTEGER)
IS 'vrp_knapsack';
\ No newline at end of file
diff --git a/src/or_tools/knapsack.c b/src/or_tools/knapsack.c
index 448beed962..dfe58b9b5b 100644
--- a/src/or_tools/knapsack.c
+++ b/src/or_tools/knapsack.c
@@ -35,8 +35,7 @@ PG_FUNCTION_INFO_V1(_vrp_knapsack);
static
void
process(
- char* weights_sql,
- char* values_sql,
+ char* weights_values_sql,
int bin_capacity,
Knapsack_rt **result_tuples,
@@ -44,9 +43,9 @@ process(
pgr_SPI_connect();
- PickDeliveryOrders_t *pd_orders_arr = NULL;
+ Knapsack_rt *pd_orders_arr = NULL;
size_t total_pd_orders = 0;
- get_shipments_raw(pd_orders_sql,
+ get_weights_values(weights_values_sql,
&pd_orders_arr, &total_pd_orders);
if (total_pd_orders == 0) {
diff --git a/src/or_tools/knapsack_driver.cpp b/src/or_tools/knapsack_driver.cpp
index f31aabb696..7e8b8d46f0 100644
--- a/src/or_tools/knapsack_driver.cpp
+++ b/src/or_tools/knapsack_driver.cpp
@@ -66,7 +66,7 @@ get_initial_solution(vrprouting::problem::PickDeliver* problem_ptr, int m_initia
} // namespace
void
-do_pgr_pickDeliver(
+do_knapsack(
struct PickDeliveryOrders_t customers_arr[],
size_t total_customers,
From e67c490145f9d0eff39557e50d1e57a8d4e00975 Mon Sep 17 00:00:00 2001
From: Manas
Date: Mon, 11 Jul 2022 23:10:36 +0530
Subject: [PATCH 06/28] name changes
---
include/drivers/or_tools/knapsack_driver.h | 17 ++++++-----------
sql/or_tools/knapsack.sql | 2 +-
src/or_tools/knapsack.c | 4 ++--
3 files changed, 9 insertions(+), 14 deletions(-)
diff --git a/include/drivers/or_tools/knapsack_driver.h b/include/drivers/or_tools/knapsack_driver.h
index 9873fa2330..2609827e57 100644
--- a/include/drivers/or_tools/knapsack_driver.h
+++ b/include/drivers/or_tools/knapsack_driver.h
@@ -39,11 +39,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
# include
#endif
-#include "c_types/vehicle_t.h"
-#include "c_types/matrix_cell_t.h"
typedef struct PickDeliveryOrders_t PickDeliveryOrders_t;
-typedef struct Solution_rt Solution_rt;
+typedef struct Knapsack_rt Knapsack_rt;
#ifdef __cplusplus
extern "C" {
@@ -55,16 +53,13 @@ extern "C" {
bin_capacity INTEGER,
max_cycles INTEGER,
********************************************************/
- void do_pgr_pickDeliver(
+ void do_knapsack(
PickDeliveryOrders_t *pd_orders_arr, size_t total_pd_orders,
- Vehicle_t *vehicles_arr, size_t total_vehicles,
- Matrix_cell_t *matrix_cells_arr, size_t total_cells,
+ Knapsack_t *knapsack_arr, size_t total_items,
- double factor,
- int max_cycles,
- int initial_solution_id,
-
- Solution_rt **return_tuples,
+ int bin_capacity,
+
+ Knapsack_rt **return_tuples,
size_t *return_count,
char **log_msg,
diff --git a/sql/or_tools/knapsack.sql b/sql/or_tools/knapsack.sql
index 80ae58e90c..ebb3c0614c 100644
--- a/sql/or_tools/knapsack.sql
+++ b/sql/or_tools/knapsack.sql
@@ -40,7 +40,7 @@ CREATE OR REPLACE FUNCTION vrp_knapsack(
RETURNS SETOF RECORD AS
$BODY$
SELECT *
- FROM vrp_knapsack(_pgr_get_statement($1), $2);
+ FROM _vrp_knapsack(_pgr_get_statement($1), $2);
$BODY$
LANGUAGE SQL VOLATILE STRICT;
diff --git a/src/or_tools/knapsack.c b/src/or_tools/knapsack.c
index 608e1bcd80..68967821fe 100644
--- a/src/or_tools/knapsack.c
+++ b/src/or_tools/knapsack.c
@@ -38,7 +38,7 @@ process(
char* weights_values_sql,
int bin_capacity,
- Solution_rt **result_tuples,
+ Knapsack_rt **result_tuples,
size_t *result_count) {
pgr_SPI_connect();
@@ -139,7 +139,7 @@ _vrp_knapsack(PG_FUNCTION_ARGS) {
funcctx = SRF_PERCALL_SETUP();
tuple_desc = funcctx->tuple_desc;
- result_tuples = (Solution_rt*) funcctx->user_fctx;
+ result_tuples = (Knapsack_rt*) funcctx->user_fctx;
if (funcctx->call_cntr < funcctx->max_calls) {
HeapTuple tuple;
From b5a560aec7a9c2f02504ed1e7cba107f2409cee6 Mon Sep 17 00:00:00 2001
From: Manas
Date: Thu, 14 Jul 2022 16:15:40 +0530
Subject: [PATCH 07/28] Changed knapsack signature
---
include/c_types/knapsack_rt.h | 9 ++++-----
sql/or_tools/_knapsack.sql | 4 ++--
sql/or_tools/knapsack.sql | 4 ++--
src/or_tools/knapsack.c | 34 ++++++++++++++++------------------
4 files changed, 24 insertions(+), 27 deletions(-)
diff --git a/include/c_types/knapsack_rt.h b/include/c_types/knapsack_rt.h
index 7c00bb8e69..7c0454f432 100644
--- a/include/c_types/knapsack_rt.h
+++ b/include/c_types/knapsack_rt.h
@@ -40,14 +40,13 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
name | description
:----- | :-------
Index | Position of the item in the order in which the input was given
-ItemWeight | Weight of the item
-ItemValue | Value of the item
+item_weight | Weight of the item
+item_cost | Value of the item
*/
struct Knapsack_rt {
- int Index;
- int ItemWeight;
- int ItemValue;
+ int64_t item_weight;
+ int64_t item_calue;
};
/*************************************************************************/
diff --git a/sql/or_tools/_knapsack.sql b/sql/or_tools/_knapsack.sql
index 9dcc3e528e..b9bbde151b 100644
--- a/sql/or_tools/_knapsack.sql
+++ b/sql/or_tools/_knapsack.sql
@@ -27,9 +27,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
CREATE OR REPLACE FUNCTION _vrp_knapsack(
- TEXT, -- weights_values SQL
+ TEXT, -- weights_cost SQL
- INTEGER, -- bin capacity
+ INTEGER, -- capacity
OUT total_value INTEGER,
OUT total_weight INTEGER,
diff --git a/sql/or_tools/knapsack.sql b/sql/or_tools/knapsack.sql
index ebb3c0614c..dd155c7901 100644
--- a/sql/or_tools/knapsack.sql
+++ b/sql/or_tools/knapsack.sql
@@ -28,9 +28,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
CREATE OR REPLACE FUNCTION vrp_knapsack(
- TEXT, -- weights_values SQL
+ TEXT, -- weights_cost SQL
- INTEGER, -- bin capacity
+ INTEGER, -- capacity
OUT total_value INTEGER,
OUT total_weight INTEGER,
diff --git a/src/or_tools/knapsack.c b/src/or_tools/knapsack.c
index 68967821fe..3ad8150600 100644
--- a/src/or_tools/knapsack.c
+++ b/src/or_tools/knapsack.c
@@ -35,25 +35,25 @@ PG_FUNCTION_INFO_V1(_vrp_knapsack);
static
void
process(
- char* weights_values_sql,
- int bin_capacity,
+ char* weights_cost_sql,
+ int capacity,
Knapsack_rt **result_tuples,
size_t *result_count) {
pgr_SPI_connect();
- Knapsack_rt *pd_orders_arr = NULL;
- size_t total_pd_orders = 0;
- get_weights_values(weights_values_sql,
- &pd_orders_arr, &total_pd_orders);
+ Knapsack_rt *knapsack_items = NULL;
+ size_t total_knapsack_items = 0;
+ get_weights_cost(weights_cost_sql,
+ &knapsack_items, &total_knapsack_items);
- if (total_pd_orders == 0) {
+ if (total_knapsack_items == 0) {
(*result_count) = 0;
(*result_tuples) = NULL;
/* freeing memory before return */
- if (pd_orders_arr) {pfree(pd_orders_arr); pd_orders_arr = NULL;}
+ if (knapsack_items) {pfree(knapsack_items); knapsack_items = NULL;}
pgr_SPI_finish();
ereport(ERROR,
@@ -61,18 +61,16 @@ process(
errmsg("No orders found")));
return;
}
-
-
-
+
+ clock_t start_t = clock();
+ char *log_msg = NULL;
+ char *notice_msg = NULL;
+ char *err_msg = NULL;
do_pgr_pickDeliver(
- pd_orders_arr, total_pd_orders,
- vehicles_arr, total_vehicles,
- matrix_cells_arr, total_cells,
-
- factor,
- max_cycles,
- initial_solution_id,
+ knapsack_items, total_knapsack_items,
+
+ capacity,
result_tuples,
result_count,
From b8a799ef2430cf308acdbe8272f85cd2c2ed3aef Mon Sep 17 00:00:00 2001
From: Manas
Date: Thu, 14 Jul 2022 16:17:19 +0530
Subject: [PATCH 08/28] [ctypes] Fixed typo
---
include/c_types/knapsack_rt.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/c_types/knapsack_rt.h b/include/c_types/knapsack_rt.h
index 7c0454f432..ee99c40c21 100644
--- a/include/c_types/knapsack_rt.h
+++ b/include/c_types/knapsack_rt.h
@@ -46,7 +46,7 @@ item_cost | Value of the item
struct Knapsack_rt {
int64_t item_weight;
- int64_t item_calue;
+ int64_t item_cost;
};
/*************************************************************************/
From b3d34830e0a848d12951312001bb272671b0465f Mon Sep 17 00:00:00 2001
From: Manas
Date: Thu, 14 Jul 2022 16:21:56 +0530
Subject: [PATCH 09/28] [include/drivers] Updated Signature
---
include/drivers/or_tools/knapsack_driver.h | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/include/drivers/or_tools/knapsack_driver.h b/include/drivers/or_tools/knapsack_driver.h
index 2609827e57..5a7518b51b 100644
--- a/include/drivers/or_tools/knapsack_driver.h
+++ b/include/drivers/or_tools/knapsack_driver.h
@@ -54,10 +54,9 @@ extern "C" {
max_cycles INTEGER,
********************************************************/
void do_knapsack(
- PickDeliveryOrders_t *pd_orders_arr, size_t total_pd_orders,
- Knapsack_t *knapsack_arr, size_t total_items,
-
- int bin_capacity,
+ Knapsack_rt *knapsack_items, size_t total_knapsack_items,
+
+ int capacity,
Knapsack_rt **return_tuples,
size_t *return_count,
From b668c2aa200f5838f0fd2109a60f20b9f485a3b0 Mon Sep 17 00:00:00 2001
From: Manas
Date: Thu, 14 Jul 2022 16:38:17 +0530
Subject: [PATCH 10/28] Small code changes
---
CMakeLists.txt | 6 +++---
configuration.conf | 2 +-
docqueries/or_tools/knapsack.test.sql | 4 +++-
include/c_types/typedefs.h | 2 +-
include/drivers/or_tools/knapsack_driver.h | 2 --
sql/or_tools/CMakeLists.txt | 2 +-
sql/or_tools/_knapsack.sql | 4 ++--
sql/or_tools/knapsack.sql | 4 ++--
src/or_tools/knapsack.c | 17 +++--------------
src/or_tools/knapsack_driver.cpp | 18 +++++-------------
10 files changed, 21 insertions(+), 40 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 08c6cf93ca..5711b99fa3 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -332,14 +332,14 @@ endforeach()
#----------------------
# set(CMAKE_PREFIX_PATH "/home/manas/Codes/GSOC-2022/MyFork/ortools/build")
-add_subdirectory(ortools)
+# add_subdirectory(ortools)
# set(ortools_DIR "/home/manas/Codes/GSOC-2022/MyFork/ortools/build")
# set(absl_DIR "/home/manas/Codes/GSOC-2022/MyFork/ortools/build/_deps/absl-build")
# set(re2_DIR "/home/manas/Codes/GSOC-2022/MyFork/ortools/build/_deps/re2-build/CMakeFiles/Export/lib/cmake/re2")
# set(Protobuf_DIR "/home/manas/Codes/GSOC-2022/MyFork/ortools/build/_deps/protobuf-build/lib/cmake/protobuf")
# find_package(ortools CONFIG REQUIRED)
-add_executable(myapp bin_packing.cc)
-target_link_libraries(myapp ortools::ortools)
+# add_executable(myapp bin_packing.cc)
+# target_link_libraries(myapp ortools::ortools)
#-----------------------------------------------------------------------------
diff --git a/configuration.conf b/configuration.conf
index 05b0af88a7..cb1f091169 100644
--- a/configuration.conf
+++ b/configuration.conf
@@ -28,4 +28,4 @@ simulation | N | Y | N
optimizers | Y | N | N
initialsol | Y | N | N
vroom | Y | Y | Y
-or_tools | N | N | N
+or_tools | Y | Y | N
diff --git a/docqueries/or_tools/knapsack.test.sql b/docqueries/or_tools/knapsack.test.sql
index af360e1854..039d4500a0 100644
--- a/docqueries/or_tools/knapsack.test.sql
+++ b/docqueries/or_tools/knapsack.test.sql
@@ -1 +1,3 @@
--- TODO make the single tests.
\ No newline at end of file
+-- TODO make the single tests.
+
+SELECT * FROM vrp_knapsack($$ SELECT * FROM knapsack_data$$, 3);
\ No newline at end of file
diff --git a/include/c_types/typedefs.h b/include/c_types/typedefs.h
index 1924ef402c..03c41a6211 100644
--- a/include/c_types/typedefs.h
+++ b/include/c_types/typedefs.h
@@ -103,4 +103,4 @@ typedef struct Knapsack_rt Knapsack_rt;
/*************************************************************************/
-#endif // INCLUDE_C_TYPES_TYPEDEFS_H_
+#endif // INCLUDE_C_TYPES_TYPEDEFS_H_
diff --git a/include/drivers/or_tools/knapsack_driver.h b/include/drivers/or_tools/knapsack_driver.h
index 5a7518b51b..9dbae0cf11 100644
--- a/include/drivers/or_tools/knapsack_driver.h
+++ b/include/drivers/or_tools/knapsack_driver.h
@@ -39,8 +39,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
# include
#endif
-
-typedef struct PickDeliveryOrders_t PickDeliveryOrders_t;
typedef struct Knapsack_rt Knapsack_rt;
#ifdef __cplusplus
diff --git a/sql/or_tools/CMakeLists.txt b/sql/or_tools/CMakeLists.txt
index 44586ef4d7..9d76c13cc9 100644
--- a/sql/or_tools/CMakeLists.txt
+++ b/sql/or_tools/CMakeLists.txt
@@ -1,6 +1,6 @@
SET(LOCAL_FILES
+ _knapsack.sql
knapsack.sql
- _knapsack.sql
)
foreach (f ${LOCAL_FILES})
diff --git a/sql/or_tools/_knapsack.sql b/sql/or_tools/_knapsack.sql
index b9bbde151b..522038b09c 100644
--- a/sql/or_tools/_knapsack.sql
+++ b/sql/or_tools/_knapsack.sql
@@ -31,9 +31,9 @@ CREATE OR REPLACE FUNCTION _vrp_knapsack(
INTEGER, -- capacity
- OUT total_value INTEGER,
+ OUT total_cost INTEGER,
OUT total_weight INTEGER,
- OUT packed_items INTEGER[],
+ OUT packed_costs INTEGER[],
OUT packed_weights INTEGER[]
)
RETURNS SETOF RECORD AS
diff --git a/sql/or_tools/knapsack.sql b/sql/or_tools/knapsack.sql
index dd155c7901..846a2fce92 100644
--- a/sql/or_tools/knapsack.sql
+++ b/sql/or_tools/knapsack.sql
@@ -32,9 +32,9 @@ CREATE OR REPLACE FUNCTION vrp_knapsack(
INTEGER, -- capacity
- OUT total_value INTEGER,
+ OUT total_cost INTEGER,
OUT total_weight INTEGER,
- OUT packed_items INTEGER[],
+ OUT packed_cost INTEGER[],
OUT packed_weights INTEGER[]
)
RETURNS SETOF RECORD AS
diff --git a/src/or_tools/knapsack.c b/src/or_tools/knapsack.c
index 3ad8150600..422e1c775f 100644
--- a/src/or_tools/knapsack.c
+++ b/src/or_tools/knapsack.c
@@ -107,7 +107,7 @@ _vrp_knapsack(PG_FUNCTION_ARGS) {
FuncCallContext *funcctx;
TupleDesc tuple_desc;
- Solution_rt *result_tuples = 0;
+ Knapsack_rt *Knapsack_tuples = 0;
size_t result_count = 0;
if (SRF_IS_FIRSTCALL()) {
@@ -156,19 +156,8 @@ _vrp_knapsack(PG_FUNCTION_ARGS) {
}
values[0] = Int32GetDatum(funcctx->call_cntr + 1);
- values[1] = Int32GetDatum(result_tuples[call_cntr].vehicle_seq);
- values[2] = Int64GetDatum(result_tuples[call_cntr].vehicle_id);
- values[3] = Int32GetDatum(result_tuples[call_cntr].stop_seq);
- values[4] = Int32GetDatum(result_tuples[call_cntr].stop_type + 1);
- values[5] = Int64GetDatum(result_tuples[call_cntr].stop_id);
- values[6] = Int64GetDatum(result_tuples[call_cntr].order_id);
- values[7] = Int64GetDatum(result_tuples[call_cntr].cargo);
- values[8] = Int64GetDatum(result_tuples[call_cntr].travelTime);
- values[9] = Int64GetDatum(result_tuples[call_cntr].arrivalTime);
- values[10] = Int64GetDatum(result_tuples[call_cntr].waitDuration);
- values[11] = Int64GetDatum(result_tuples[call_cntr].serviceDuration);
- values[12] = Int64GetDatum(result_tuples[call_cntr].departureTime);
-
+ values[1] = Int32GetDatum(result_tuples[call_cntr].item_weight);
+ values[2] = Int64GetDatum(result_tuples[call_cntr].item_cost);
tuple = heap_form_tuple(tuple_desc, values, nulls);
result = HeapTupleGetDatum(tuple);
diff --git a/src/or_tools/knapsack_driver.cpp b/src/or_tools/knapsack_driver.cpp
index 2384e20e8f..1cee37efdf 100644
--- a/src/or_tools/knapsack_driver.cpp
+++ b/src/or_tools/knapsack_driver.cpp
@@ -67,21 +67,13 @@ get_initial_solution(vrprouting::problem::PickDeliver* problem_ptr, int m_initia
void
do_knapsack(
- struct PickDeliveryOrders_t customers_arr[],
- size_t total_customers,
+ struct Knapsack_rt knapsack_items[],
+ size_t total_items,
- Vehicle_t *vehicles_arr,
- size_t total_vehicles,
+ int capacity,
- Matrix_cell_t *matrix_cells_arr,
- size_t total_cells,
-
- double factor,
- int max_cycles,
- int initial_solution_id,
-
- Solution_rt **return_tuples,
- size_t *return_count,
+ Knapsack_rt **return_tuples,
+ Knapsack_t *return_count,
char **log_msg,
char **notice_msg,
From 72e75463bf545bc7d544dfbcf4fe95c34b947092 Mon Sep 17 00:00:00 2001
From: Manas
Date: Thu, 14 Jul 2022 16:41:12 +0530
Subject: [PATCH 11/28] Small code changes
---
src/or_tools/knapsack.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/or_tools/knapsack.c b/src/or_tools/knapsack.c
index 422e1c775f..797597f7c8 100644
--- a/src/or_tools/knapsack.c
+++ b/src/or_tools/knapsack.c
@@ -67,7 +67,7 @@ process(
char *notice_msg = NULL;
char *err_msg = NULL;
- do_pgr_pickDeliver(
+ do_knapsack(
knapsack_items, total_knapsack_items,
capacity,
From ac9ff68a7911d680596df73ac7661e73441e2ffd Mon Sep 17 00:00:00 2001
From: Manas
Date: Thu, 14 Jul 2022 16:43:57 +0530
Subject: [PATCH 12/28] Small code changes
---
configuration.conf | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/configuration.conf b/configuration.conf
index cb1f091169..05b0af88a7 100644
--- a/configuration.conf
+++ b/configuration.conf
@@ -28,4 +28,4 @@ simulation | N | Y | N
optimizers | Y | N | N
initialsol | Y | N | N
vroom | Y | Y | Y
-or_tools | Y | Y | N
+or_tools | N | N | N
From b79330f7e6e190a783d5e48804b7f459a84b2ce7 Mon Sep 17 00:00:00 2001
From: Manas
Date: Thu, 14 Jul 2022 16:45:50 +0530
Subject: [PATCH 13/28] Small code changes
---
src/or_tools/knapsack.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/src/or_tools/knapsack.c b/src/or_tools/knapsack.c
index 797597f7c8..c7b8707f74 100644
--- a/src/or_tools/knapsack.c
+++ b/src/or_tools/knapsack.c
@@ -92,9 +92,7 @@ process(
if (log_msg) {pfree(log_msg); log_msg = NULL;}
if (notice_msg) {pfree(notice_msg); notice_msg = NULL;}
if (err_msg) {pfree(err_msg); err_msg = NULL;}
- if (pd_orders_arr) {pfree(pd_orders_arr); pd_orders_arr = NULL;}
- if (vehicles_arr) {pfree(vehicles_arr); vehicles_arr = NULL;}
- if (matrix_cells_arr) {pfree(matrix_cells_arr); matrix_cells_arr = NULL;}
+ if (knapsack_items) {pfree(knapsack_items); knapsack_items = NULL;}
pgr_SPI_finish();
@@ -107,7 +105,7 @@ _vrp_knapsack(PG_FUNCTION_ARGS) {
FuncCallContext *funcctx;
TupleDesc tuple_desc;
- Knapsack_rt *Knapsack_tuples = 0;
+ Knapsack_rt *result_tuples = 0;
size_t result_count = 0;
if (SRF_IS_FIRSTCALL()) {
From 86bbd72ad586548aaa2b3f51b6e9423e587b74a0 Mon Sep 17 00:00:00 2001
From: Manas
Date: Thu, 14 Jul 2022 16:46:17 +0530
Subject: [PATCH 14/28] Small code changes
---
configuration.conf | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/configuration.conf b/configuration.conf
index 05b0af88a7..cb1f091169 100644
--- a/configuration.conf
+++ b/configuration.conf
@@ -28,4 +28,4 @@ simulation | N | Y | N
optimizers | Y | N | N
initialsol | Y | N | N
vroom | Y | Y | Y
-or_tools | N | N | N
+or_tools | Y | Y | N
From 0504ab6a5ded37fd2543ab4fe49e5341bc994c64 Mon Sep 17 00:00:00 2001
From: Manas
Date: Thu, 14 Jul 2022 16:49:50 +0530
Subject: [PATCH 15/28] Small code changes
---
src/or_tools/knapsack.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/or_tools/knapsack.c b/src/or_tools/knapsack.c
index c7b8707f74..c166e5e129 100644
--- a/src/or_tools/knapsack.c
+++ b/src/or_tools/knapsack.c
@@ -105,7 +105,7 @@ _vrp_knapsack(PG_FUNCTION_ARGS) {
FuncCallContext *funcctx;
TupleDesc tuple_desc;
- Knapsack_rt *result_tuples = 0;
+ Knapsack_rt *result_tuples = NULL;
size_t result_count = 0;
if (SRF_IS_FIRSTCALL()) {
From 1b587a71044cb28ee3264c1a50638bce2de02ac8 Mon Sep 17 00:00:00 2001
From: Manas
Date: Thu, 14 Jul 2022 16:55:07 +0530
Subject: [PATCH 16/28] [src] Included Header Files
---
.vscode/settings.json | 5 +++++
include/drivers/or_tools/knapsack_driver.h | 6 ++----
src/or_tools/knapsack.c | 2 +-
3 files changed, 8 insertions(+), 5 deletions(-)
create mode 100644 .vscode/settings.json
diff --git a/.vscode/settings.json b/.vscode/settings.json
new file mode 100644
index 0000000000..9cb0100533
--- /dev/null
+++ b/.vscode/settings.json
@@ -0,0 +1,5 @@
+{
+ "files.associations": {
+ "knapsack_driver.h": "c"
+ }
+}
\ No newline at end of file
diff --git a/include/drivers/or_tools/knapsack_driver.h b/include/drivers/or_tools/knapsack_driver.h
index 9dbae0cf11..bb3e789503 100644
--- a/include/drivers/or_tools/knapsack_driver.h
+++ b/include/drivers/or_tools/knapsack_driver.h
@@ -46,10 +46,8 @@ extern "C" {
#endif
/*********************************************************
- weights_sql TEXT,
- values_sql TEXT,
- bin_capacity INTEGER,
- max_cycles INTEGER,
+ weights_cost_sql TEXT,
+ capacity INTEGER,
********************************************************/
void do_knapsack(
Knapsack_rt *knapsack_items, size_t total_knapsack_items,
diff --git a/src/or_tools/knapsack.c b/src/or_tools/knapsack.c
index c166e5e129..98beeb5ac5 100644
--- a/src/or_tools/knapsack.c
+++ b/src/or_tools/knapsack.c
@@ -24,7 +24,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#include "c_common/e_report.h"
#include "c_common/time_msg.h"
-
+#include "c_types/knapsack_rt.h"
#include "drivers/or_tools/knapsack_driver.h"
PGDLLEXPORT Datum
From b2e8d6df9ee43634978be208dad71e88e3570e8e Mon Sep 17 00:00:00 2001
From: Manas
Date: Thu, 14 Jul 2022 17:02:16 +0530
Subject: [PATCH 17/28] [CMakeLists.txt] Not processing OR-tools
---
configuration.conf | 2 +-
include/drivers/or_tools/knapsack_driver.h | 1 +
src/or_tools/knapsack_driver.cpp | 3 ++-
3 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/configuration.conf b/configuration.conf
index cb1f091169..05b0af88a7 100644
--- a/configuration.conf
+++ b/configuration.conf
@@ -28,4 +28,4 @@ simulation | N | Y | N
optimizers | Y | N | N
initialsol | Y | N | N
vroom | Y | Y | Y
-or_tools | Y | Y | N
+or_tools | N | N | N
diff --git a/include/drivers/or_tools/knapsack_driver.h b/include/drivers/or_tools/knapsack_driver.h
index bb3e789503..aad41a827f 100644
--- a/include/drivers/or_tools/knapsack_driver.h
+++ b/include/drivers/or_tools/knapsack_driver.h
@@ -39,6 +39,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
# include
#endif
+
typedef struct Knapsack_rt Knapsack_rt;
#ifdef __cplusplus
diff --git a/src/or_tools/knapsack_driver.cpp b/src/or_tools/knapsack_driver.cpp
index 1cee37efdf..3e0d038e5a 100644
--- a/src/or_tools/knapsack_driver.cpp
+++ b/src/or_tools/knapsack_driver.cpp
@@ -40,6 +40,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#include "problem/pickDeliver.h"
#include "initialsol/initials_code.h"
#include "problem/matrix.h"
+#include "c_types/knapsack_rt.h"
namespace {
vrprouting::problem::Solution
@@ -73,7 +74,7 @@ do_knapsack(
int capacity,
Knapsack_rt **return_tuples,
- Knapsack_t *return_count,
+ size_t *return_count,
char **log_msg,
char **notice_msg,
From fdf277fe949f2c19c673e565f97997b333bdcbae Mon Sep 17 00:00:00 2001
From: Manas
Date: Thu, 14 Jul 2022 17:20:44 +0530
Subject: [PATCH 18/28] fixed lint errors
---
include/drivers/or_tools/knapsack_driver.h | 4 ++--
src/or_tools/knapsack.c | 10 ++++------
src/or_tools/knapsack_driver.cpp | 3 +--
3 files changed, 7 insertions(+), 10 deletions(-)
diff --git a/include/drivers/or_tools/knapsack_driver.h b/include/drivers/or_tools/knapsack_driver.h
index aad41a827f..d18e96712a 100644
--- a/include/drivers/or_tools/knapsack_driver.h
+++ b/include/drivers/or_tools/knapsack_driver.h
@@ -52,9 +52,9 @@ extern "C" {
********************************************************/
void do_knapsack(
Knapsack_rt *knapsack_items, size_t total_knapsack_items,
-
+
int capacity,
-
+
Knapsack_rt **return_tuples,
size_t *return_count,
diff --git a/src/or_tools/knapsack.c b/src/or_tools/knapsack.c
index 98beeb5ac5..4ed990322d 100644
--- a/src/or_tools/knapsack.c
+++ b/src/or_tools/knapsack.c
@@ -37,10 +37,9 @@ void
process(
char* weights_cost_sql,
int capacity,
-
+
Knapsack_rt **result_tuples,
size_t *result_count) {
-
pgr_SPI_connect();
Knapsack_rt *knapsack_items = NULL;
@@ -61,7 +60,7 @@ process(
errmsg("No orders found")));
return;
}
-
+
clock_t start_t = clock();
char *log_msg = NULL;
char *notice_msg = NULL;
@@ -69,7 +68,7 @@ process(
do_knapsack(
knapsack_items, total_knapsack_items,
-
+
capacity,
result_tuples,
@@ -95,7 +94,6 @@ process(
if (knapsack_items) {pfree(knapsack_items); knapsack_items = NULL;}
pgr_SPI_finish();
-
}
@@ -114,7 +112,7 @@ _vrp_knapsack(PG_FUNCTION_ARGS) {
oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
process(
- text_to_cstring(PG_GETARG_TEXT_P(0)),
+ text_to_cstring(PG_GETARG_TEXT_P(0)),
PG_GETARG_INT32(1),
&result_tuples,
&result_count);
diff --git a/src/or_tools/knapsack_driver.cpp b/src/or_tools/knapsack_driver.cpp
index 3e0d038e5a..37b67674db 100644
--- a/src/or_tools/knapsack_driver.cpp
+++ b/src/or_tools/knapsack_driver.cpp
@@ -52,8 +52,7 @@ get_initial_solution(vrprouting::problem::PickDeliver* problem_ptr, int m_initia
if (m_initial_id == 0) {
for (int i = 1; i < 7; ++i) {
if (i == 1) {
- m_solutions = Initial_solution((Initials_code)i, problem_ptr);
- } else {
+ m_solutions = Initial_solution((Initials_code)i, problem_ptr); } else {
auto new_sol = Initial_solution((Initials_code)i, problem_ptr);
m_solutions = (new_sol < m_solutions)? new_sol : m_solutions;
}
From d702ec32a72660ae49ccb2e0312d3f31a69b5f7d Mon Sep 17 00:00:00 2001
From: Manas
Date: Thu, 14 Jul 2022 18:35:22 +0530
Subject: [PATCH 19/28] Test knapsack function
---
.gitignore | 1 +
docqueries/or_tools/knapsack.result | 0
docqueries/or_tools/test.conf | 21 ++++
src/or_tools/knapsack.c | 2 +-
vroom-v1.12.0 | 1 +
vrprun.sh | 155 ++++++++++++++++++++++++++++
6 files changed, 179 insertions(+), 1 deletion(-)
create mode 100644 docqueries/or_tools/knapsack.result
create mode 100644 docqueries/or_tools/test.conf
create mode 160000 vroom-v1.12.0
create mode 100755 vrprun.sh
diff --git a/.gitignore b/.gitignore
index 0e103a468b..9a35a416bf 100644
--- a/.gitignore
+++ b/.gitignore
@@ -8,6 +8,7 @@ ortools
build1
bin_packing.cc
gpush.sh
+vroom-1.12.0
# files are ignored on gh-pages
doxy
diff --git a/docqueries/or_tools/knapsack.result b/docqueries/or_tools/knapsack.result
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/docqueries/or_tools/test.conf b/docqueries/or_tools/test.conf
new file mode 100644
index 0000000000..94df081b96
--- /dev/null
+++ b/docqueries/or_tools/test.conf
@@ -0,0 +1,21 @@
+#!/usr/bin/perl -w
+
+%main::tests = (
+ 'any' => {
+ 'comment' => 'test for or-tools',
+ 'data' => [],
+ 'newdb' => 1,
+ 'tests' => [qw(
+ knapsack
+ )],
+
+ 'documentation' => [qw(
+ knapsack
+ )],
+
+ 'nottesting' => [qw(
+ )]
+ },
+);
+
+1;
\ No newline at end of file
diff --git a/src/or_tools/knapsack.c b/src/or_tools/knapsack.c
index 4ed990322d..70114ceef9 100644
--- a/src/or_tools/knapsack.c
+++ b/src/or_tools/knapsack.c
@@ -41,7 +41,7 @@ process(
Knapsack_rt **result_tuples,
size_t *result_count) {
pgr_SPI_connect();
-
+ elog(WARNING, "Stopping execution");
Knapsack_rt *knapsack_items = NULL;
size_t total_knapsack_items = 0;
get_weights_cost(weights_cost_sql,
diff --git a/vroom-v1.12.0 b/vroom-v1.12.0
new file mode 160000
index 0000000000..d3abd6b22f
--- /dev/null
+++ b/vroom-v1.12.0
@@ -0,0 +1 @@
+Subproject commit d3abd6b22fe4afc0daa64d6b905911999b12dcdd
diff --git a/vrprun.sh b/vrprun.sh
new file mode 100755
index 0000000000..4f14ff2406
--- /dev/null
+++ b/vrprun.sh
@@ -0,0 +1,155 @@
+#!/bin/bash
+
+set -e
+
+DIR=$(git rev-parse --show-toplevel)
+pushd "${DIR}" > /dev/null || exit 1
+
+# The next two lines need to be executed only once
+# pushd tools/testers/ ; tar -xf matrix_new_values.tar.gz; popd
+# sudo apt-get install libssl-dev libasio-dev libglpk-dev
+
+# copy this file into the root of your repository
+# adjust to your needs
+
+# This run.sh is intended for 3.x.x
+VERSION=$(grep -Po '(?<=project\(VRPROUTING VERSION )[^;]+' CMakeLists.txt)
+echo "pgRouting VERSION ${VERSION}"
+
+# set up your postgres version, port and compiler (if more than one)
+PGVERSION="13"
+PGPORT="5432"
+PGBIN="/usr/lib/postgresql/${PGVERSION}/bin"
+PGINC="/usr/include/postgresql/${PGVERSION}/server"
+# When more than one compiler is installed
+GCC=""
+
+QUERIES_DIRS=$(ls docqueries -1)
+TAP_DIRS=$(ls pgtap -1)
+
+QUERIES_DIRS=""
+TAP_DIRS=""
+
+function install_vroom {
+ cd "${DIR}"
+ rm -rf ./vroom-v1.12.0
+ git clone --depth 1 --branch v1.12.0 https://github.com/VROOM-Project/vroom ./vroom-v1.12.0
+ pushd vroom-v1.12.0/
+ git submodule update --init
+ cd src/
+ USE_ROUTING=false make shared
+ popd
+}
+
+function set_cmake {
+ # Using all defaults
+ #cmake ..
+
+ # Options Release RelWithDebInfo MinSizeRel Debug
+ #cmake -DCMAKE_BUILD_TYPE=Debug ..
+
+ # Additional debug information
+ #cmake -DPgRouting_DEBUG=ON -DCMAKE_BUILD_TYPE=Debug ..
+
+ # with documentation (like the one the website)
+ #cmake -DDOC_USE_BOOTSTRAP=ON -DWITH_DOC=ON ..
+
+ # with developers documentation
+ #cmake -DWITH_DOC=ON -DBUILD_DOXY=ON ..
+
+ #CXX=clang++ CC=clang cmake -DPOSTGRESQL_BIN=${PGBIN} -DCMAKE_BUILD_TYPE=Debug ..
+
+ cmake "-DPostgreSQL_INCLUDE_DIR=${PGINC}" -DCMAKE_BUILD_TYPE=Debug -DWITH_DOC=OFF "-DVROOM_INSTALL_PATH=$DIR/vroom-v1.12.0" ..
+}
+
+function tap_test {
+ echo --------------------------------------------
+ echo pgTap test all
+ echo --------------------------------------------
+
+ dropdb --if-exists -p $PGPORT ___pgr___test___
+ createdb -p $PGPORT ___pgr___test___
+ echo $PGPORT
+ tools/testers/pg_prove_tests.sh manas $PGPORT
+ dropdb -p $PGPORT ___pgr___test___
+}
+
+function action_tests {
+ echo --------------------------------------------
+ echo Update signatures
+ echo --------------------------------------------
+
+ tools/scripts/get_signatures.sh -p ${PGPORT}
+ tools/scripts/notes2news.pl
+ bash tools/scripts/test_signatures.sh
+ bash tools/scripts/test_shell.sh
+ bash tools/scripts/test_license.sh
+ bash tools/scripts/code_checker.sh
+ tools/testers/doc_queries_generator.pl -documentation -pgport $PGPORT
+}
+
+function set_compiler {
+ echo ------------------------------------
+ echo ------------------------------------
+ echo "Compiling with G++-$1"
+ echo ------------------------------------
+
+ if [ -n "$1" ]; then
+ update-alternatives --set gcc "/usr/bin/gcc-$1"
+ fi
+}
+
+function build_doc {
+ pushd build > /dev/null || exit 1
+ #rm -rf doc/*
+ make doc
+ #make linkcheck
+ #rm -rf doxygen/*
+ #make doxy
+ popd > /dev/null || exit 1
+}
+
+function build {
+ pushd build > /dev/null || exit 1
+ set_cmake
+ make -j 16
+ #make VERBOSE=1
+ sudo make install
+ popd > /dev/null || exit 1
+
+}
+
+function test_compile {
+
+ set_compiler "${GCC}"
+
+ #install_vroom
+ build
+
+ echo --------------------------------------------
+ echo Execute documentation queries
+ echo --------------------------------------------
+ for d in ${QUERIES_DIRS}
+ do
+ #tools/testers/doc_queries_generator.pl -alg "${d}" -documentation -pgport "${PGPORT}"
+ #tools/testers/doc_queries_generator.pl -alg "${d}" -debug1 -pgport "${PGPORT}"
+ tools/testers/doc_queries_generator.pl -alg "${d}" -pgport "${PGPORT}"
+ done
+
+
+ echo --------------------------------------------
+ echo Execute tap_directories
+ echo --------------------------------------------
+ for d in ${TAP_DIRS}
+ do
+ bash taptest.sh "${d}" "-p ${PGPORT}"
+ done
+
+ #build_doc
+ #tools/testers/doc_queries_generator.pl -pgport $PGPORT
+ #exit 0
+
+ tap_test
+ action_tests
+}
+test_compile
From a4a9d2ffd361cc615f39e5968faa0061e514ab3a Mon Sep 17 00:00:00 2001
From: Manas
Date: Thu, 14 Jul 2022 18:54:15 +0530
Subject: [PATCH 20/28] Debugging
---
docqueries/or_tools/knapsack.test.sql | 22 ++++++++++++++++++++--
src/or_tools/knapsack.c | 3 ++-
vrprun.sh | 3 ++-
3 files changed, 24 insertions(+), 4 deletions(-)
diff --git a/docqueries/or_tools/knapsack.test.sql b/docqueries/or_tools/knapsack.test.sql
index 039d4500a0..72a3b22221 100644
--- a/docqueries/or_tools/knapsack.test.sql
+++ b/docqueries/or_tools/knapsack.test.sql
@@ -1,3 +1,21 @@
--- TODO make the single tests.
+CREATE TABLE knapsack_data(
+ weight INTEGER,
+ cost INTEGER);
-SELECT * FROM vrp_knapsack($$ SELECT * FROM knapsack_data$$, 3);
\ No newline at end of file
+INSERT INTO knapsack_data (weight, cost)
+VALUES
+(12, 4),
+(2, 2),
+(1, 1),
+(4, 10),
+(1, 2);
+
+SELECT *
+FROM knapsack_data;
+
+SELECT *
+FROM vrp_knapsack($$SELECT * FROM knapsack_data$$, 3);
+
+
+SELECT *
+FROM vrp_knapsack($$SELECT * FROM knapsack_data$$, 3);
\ No newline at end of file
diff --git a/src/or_tools/knapsack.c b/src/or_tools/knapsack.c
index 70114ceef9..3a8aa3c1a4 100644
--- a/src/or_tools/knapsack.c
+++ b/src/or_tools/knapsack.c
@@ -41,6 +41,7 @@ process(
Knapsack_rt **result_tuples,
size_t *result_count) {
pgr_SPI_connect();
+#if 0
elog(WARNING, "Stopping execution");
Knapsack_rt *knapsack_items = NULL;
size_t total_knapsack_items = 0;
@@ -92,7 +93,7 @@ process(
if (notice_msg) {pfree(notice_msg); notice_msg = NULL;}
if (err_msg) {pfree(err_msg); err_msg = NULL;}
if (knapsack_items) {pfree(knapsack_items); knapsack_items = NULL;}
-
+#endif
pgr_SPI_finish();
}
diff --git a/vrprun.sh b/vrprun.sh
index 4f14ff2406..11658b992f 100755
--- a/vrprun.sh
+++ b/vrprun.sh
@@ -150,6 +150,7 @@ function test_compile {
#exit 0
tap_test
- action_tests
+ #action_tests
+
}
test_compile
From 1cdf21e394cbaafe0215a70ea12e4b3811182c8d Mon Sep 17 00:00:00 2001
From: Manas
Date: Thu, 14 Jul 2022 19:00:42 +0530
Subject: [PATCH 21/28] get_weights_sql function
---
include/c_common/weights_costs_input.h | 34 ++++++
src/common/weights_costs_input.c | 142 +++++++++++++++++++++++++
src/or_tools/knapsack.c | 2 +-
3 files changed, 177 insertions(+), 1 deletion(-)
create mode 100644 include/c_common/weights_costs_input.h
create mode 100644 src/common/weights_costs_input.c
diff --git a/include/c_common/weights_costs_input.h b/include/c_common/weights_costs_input.h
new file mode 100644
index 0000000000..bfd757ec13
--- /dev/null
+++ b/include/c_common/weights_costs_input.h
@@ -0,0 +1,34 @@
+/*PGR-GNU*****************************************************************
+ * TODO fix licence
+File: matrixRows_input.h
+Copyright (c) 2022 Manas Sivakumar
+manas23601@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_WEIGHTS_COST_INPUT_H_
+#define INCLUDE_C_COMMON_WEIGHTS_COST_INPUT_H_
+#pragma once
+
+#include
+
+typedef struct Knapsack_rt Knapsack_rt;
+
+/** @brief Get the weights and cost for each item */
+void get_weights_cost(
+ char *sql,
+ Knapsack_rt **rows,
+ size_t *total_rows);
+
+#endif // INCLUDE_C_COMMON_WEIGHTS__COSTS_INPUT_H_
\ No newline at end of file
diff --git a/src/common/weights_costs_input.c b/src/common/weights_costs_input.c
new file mode 100644
index 0000000000..bbd07229e9
--- /dev/null
+++ b/src/common/weights_costs_input.c
@@ -0,0 +1,142 @@
+/*PGR-GNU*****************************************************************
+File: weights_costs_input.c
+Copyright (c) 2022 pgRouting developers
+Mail: project@pgrouting.org
+Developer:
+Copyright (c) 2022 Manas Sivakumar
+------
+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/weights_costs_input.h"
+
+#include "c_types/column_info_t.h"
+#include "c_types/knapsack_rt.h"
+
+#include "c_common/get_check_data.h"
+
+#ifdef PROFILE
+#include "c_common/time_msg.h"
+#include "c_common/debug_macro.h"
+#endif
+
+static
+void fetch_weights(
+ HeapTuple *tuple,
+ TupleDesc *tupdesc,
+ Column_info_t info[2],
+ Weight_t *row) {
+ row->weight = get_Id(tuple, tupdesc, info[0], -1);
+ row->cost = get_Id(tuple, tupdesc, info[1], -1);
+}
+
+static
+void
+get_weights_general(
+ char *sql,
+ Column_info_t *info,
+ Weight_t **rows,
+ size_t *total_rows) {
+#ifdef 1
+ 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 = pgr_SPI_prepare(sql);
+
+ Portal SPIportal;
+ SPIportal = pgr_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) = (Weight_t *)palloc0(
+ total_tuples * sizeof(Weight_t));
+ else
+ (*rows) = (Weight_t *)repalloc(
+ (*rows), total_tuples * sizeof(Weight_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];
+ fetch_weights(&tuple, &tupdesc, info,
+ &(*rows)[total_tuples - ntuples + t]);
+ }
+ 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 weights", 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_weights_costs(
+ char *sql,
+ Weight_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_INTEGER;
+ }
+ info[0].name = "weight";
+ info[1].name = "cost";
+
+ info[2].eType = INTERVAL;
+ get_weights_general(sql, info, rows, total_rows);
+}
\ No newline at end of file
diff --git a/src/or_tools/knapsack.c b/src/or_tools/knapsack.c
index 3a8aa3c1a4..0fd6798679 100644
--- a/src/or_tools/knapsack.c
+++ b/src/or_tools/knapsack.c
@@ -45,7 +45,7 @@ process(
elog(WARNING, "Stopping execution");
Knapsack_rt *knapsack_items = NULL;
size_t total_knapsack_items = 0;
- get_weights_cost(weights_cost_sql,
+ get_weights_costs(weights_cost_sql,
&knapsack_items, &total_knapsack_items);
if (total_knapsack_items == 0) {
From c7252dd53ca5717b3fe581f95ec9c661b7c9f374 Mon Sep 17 00:00:00 2001
From: Manas
Date: Thu, 14 Jul 2022 19:26:53 +0530
Subject: [PATCH 22/28] knapsack is connecting properly to postgres
---
configuration.conf | 2 +-
docqueries/or_tools/knapsack.result | 43 +++++++++++++++++++++++++++++
src/or_tools/knapsack.c | 10 +++++--
src/or_tools/knapsack_driver.cpp | 22 ++++++++++-----
vrprun.sh | 2 +-
5 files changed, 68 insertions(+), 11 deletions(-)
diff --git a/configuration.conf b/configuration.conf
index 05b0af88a7..cb1f091169 100644
--- a/configuration.conf
+++ b/configuration.conf
@@ -28,4 +28,4 @@ simulation | N | Y | N
optimizers | Y | N | N
initialsol | Y | N | N
vroom | Y | Y | Y
-or_tools | N | N | N
+or_tools | Y | Y | N
diff --git a/docqueries/or_tools/knapsack.result b/docqueries/or_tools/knapsack.result
index e69de29bb2..907d0c94ac 100644
--- a/docqueries/or_tools/knapsack.result
+++ b/docqueries/or_tools/knapsack.result
@@ -0,0 +1,43 @@
+BEGIN;
+BEGIN
+SET client_min_messages TO NOTICE;
+SET
+CREATE TABLE knapsack_data(
+ weight INTEGER,
+ cost INTEGER);
+CREATE TABLE
+INSERT INTO knapsack_data (weight, cost)
+VALUES
+(12, 4),
+(2, 2),
+(1, 1),
+(4, 10),
+(1, 2);
+INSERT 0 5
+SELECT *
+FROM knapsack_data;
+ weight | cost
+--------+------
+ 12 | 4
+ 2 | 2
+ 1 | 1
+ 4 | 10
+ 1 | 2
+(5 rows)
+
+SELECT *
+FROM vrp_knapsack($$SELECT * FROM knapsack_data$$, 3);
+WARNING: Stopping execution
+ total_cost | total_weight | packed_cost | packed_weights
+------------+--------------+-------------+----------------
+(0 rows)
+
+SELECT *
+FROM vrp_knapsack($$SELECT * FROM knapsack_data$$, 3);
+WARNING: Stopping execution
+ total_cost | total_weight | packed_cost | packed_weights
+------------+--------------+-------------+----------------
+(0 rows)
+
+ROLLBACK;
+ROLLBACK
diff --git a/src/or_tools/knapsack.c b/src/or_tools/knapsack.c
index 0fd6798679..1f553196bb 100644
--- a/src/or_tools/knapsack.c
+++ b/src/or_tools/knapsack.c
@@ -35,14 +35,20 @@ PG_FUNCTION_INFO_V1(_vrp_knapsack);
static
void
process(
- char* weights_cost_sql,
+ char* weights_costs_sql,
int capacity,
Knapsack_rt **result_tuples,
size_t *result_count) {
pgr_SPI_connect();
-#if 0
+ weights_costs_sql = weights_costs_sql;
+ PGR_DBG("%d", capacity);
+ result_tuples = NULL;
+ result_count = 0;
+ if (result_tuples) {pfree(result_tuples); result_tuples = NULL;}
+ result_count = result_count + 1 -1;
elog(WARNING, "Stopping execution");
+#if 0
Knapsack_rt *knapsack_items = NULL;
size_t total_knapsack_items = 0;
get_weights_costs(weights_cost_sql,
diff --git a/src/or_tools/knapsack_driver.cpp b/src/or_tools/knapsack_driver.cpp
index 37b67674db..fa7998f957 100644
--- a/src/or_tools/knapsack_driver.cpp
+++ b/src/or_tools/knapsack_driver.cpp
@@ -40,7 +40,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#include "problem/pickDeliver.h"
#include "initialsol/initials_code.h"
#include "problem/matrix.h"
-#include "c_types/knapsack_rt.h"
namespace {
vrprouting::problem::Solution
@@ -52,7 +51,8 @@ get_initial_solution(vrprouting::problem::PickDeliver* problem_ptr, int m_initia
if (m_initial_id == 0) {
for (int i = 1; i < 7; ++i) {
if (i == 1) {
- m_solutions = Initial_solution((Initials_code)i, problem_ptr); } else {
+ m_solutions = Initial_solution((Initials_code)i, problem_ptr);
+ } else {
auto new_sol = Initial_solution((Initials_code)i, problem_ptr);
m_solutions = (new_sol < m_solutions)? new_sol : m_solutions;
}
@@ -67,12 +67,20 @@ get_initial_solution(vrprouting::problem::PickDeliver* problem_ptr, int m_initia
void
do_knapsack(
- struct Knapsack_rt knapsack_items[],
- size_t total_items,
+ struct PickDeliveryOrders_t customers_arr[],
+ size_t total_customers,
- int capacity,
+ Vehicle_t *vehicles_arr,
+ size_t total_vehicles,
- Knapsack_rt **return_tuples,
+ Matrix_cell_t *matrix_cells_arr,
+ size_t total_cells,
+
+ double factor,
+ int max_cycles,
+ int initial_solution_id,
+
+ Solution_rt **return_tuples,
size_t *return_count,
char **log_msg,
@@ -257,4 +265,4 @@ do_knapsack(
*err_msg = pgr_msg(err.str().c_str());
*log_msg = pgr_msg(log.str().c_str());
}
-}
+}
\ No newline at end of file
diff --git a/vrprun.sh b/vrprun.sh
index 11658b992f..d8f154a80f 100755
--- a/vrprun.sh
+++ b/vrprun.sh
@@ -27,7 +27,7 @@ GCC=""
QUERIES_DIRS=$(ls docqueries -1)
TAP_DIRS=$(ls pgtap -1)
-QUERIES_DIRS=""
+QUERIES_DIRS="or_tools"
TAP_DIRS=""
function install_vroom {
From 943601f4f4d274de9fbc9d1c335e03a8042fbd5c Mon Sep 17 00:00:00 2001
From: Manas
Date: Thu, 14 Jul 2022 19:44:52 +0530
Subject: [PATCH 23/28] Getting Command aborted error when running tests
---
include/c_common/weights_costs_input.h | 2 +-
sql/or_tools/_knapsack.sql | 2 +-
sql/or_tools/knapsack.sql | 2 +-
src/common/CMakeLists.txt | 1 +
src/common/weights_costs_input.c | 20 ++++++++++----------
src/or_tools/knapsack.c | 11 ++++++++++-
6 files changed, 24 insertions(+), 14 deletions(-)
diff --git a/include/c_common/weights_costs_input.h b/include/c_common/weights_costs_input.h
index bfd757ec13..092e29c403 100644
--- a/include/c_common/weights_costs_input.h
+++ b/include/c_common/weights_costs_input.h
@@ -26,7 +26,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
typedef struct Knapsack_rt Knapsack_rt;
/** @brief Get the weights and cost for each item */
-void get_weights_cost(
+void get_weights_costs(
char *sql,
Knapsack_rt **rows,
size_t *total_rows);
diff --git a/sql/or_tools/_knapsack.sql b/sql/or_tools/_knapsack.sql
index 522038b09c..7b49f8c730 100644
--- a/sql/or_tools/_knapsack.sql
+++ b/sql/or_tools/_knapsack.sql
@@ -1,5 +1,5 @@
/*PGR-GNU*****************************************************************
-File: _knapsack_0_1.sql
+File: _knapsack.sql
Copyright (c) 2021 pgRouting developers
Mail: project@pgrouting.org
diff --git a/sql/or_tools/knapsack.sql b/sql/or_tools/knapsack.sql
index 846a2fce92..fe12d261e3 100644
--- a/sql/or_tools/knapsack.sql
+++ b/sql/or_tools/knapsack.sql
@@ -1,5 +1,5 @@
/*PGR-GNU*****************************************************************
-File: knapsack_0-1.sql
+File: knapsack_.sql
Copyright (c) 2021 pgRouting developers
Mail: project@pgrouting.org
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt
index 268e4c29c2..513575f711 100644
--- a/src/common/CMakeLists.txt
+++ b/src/common/CMakeLists.txt
@@ -7,6 +7,7 @@ ADD_LIBRARY(common OBJECT
orders_input.c
vehicles_input.c
time_multipliers_input.c
+ weights_costs_input.c
time_msg.c
e_report.c
diff --git a/src/common/weights_costs_input.c b/src/common/weights_costs_input.c
index bbd07229e9..de5926234a 100644
--- a/src/common/weights_costs_input.c
+++ b/src/common/weights_costs_input.c
@@ -35,9 +35,9 @@ void fetch_weights(
HeapTuple *tuple,
TupleDesc *tupdesc,
Column_info_t info[2],
- Weight_t *row) {
- row->weight = get_Id(tuple, tupdesc, info[0], -1);
- row->cost = get_Id(tuple, tupdesc, info[1], -1);
+ Knapsack_rt *row) {
+ row->item_weight = get_Id(tuple, tupdesc, info[0], -1);
+ row->item_cost = get_Id(tuple, tupdesc, info[1], -1);
}
static
@@ -45,9 +45,9 @@ void
get_weights_general(
char *sql,
Column_info_t *info,
- Weight_t **rows,
+ Knapsack_rt **rows,
size_t *total_rows) {
-#ifdef 1
+#if 0
clock_t start_t = clock();
PGR_DBG("%s", sql);
#endif
@@ -76,11 +76,11 @@ get_weights_general(
if (ntuples > 0) {
if ((*rows) == NULL)
- (*rows) = (Weight_t *)palloc0(
- total_tuples * sizeof(Weight_t));
+ (*rows) = (Knapsack_rt *)palloc0(
+ total_tuples * sizeof(Knapsack_rt));
else
- (*rows) = (Weight_t *)repalloc(
- (*rows), total_tuples * sizeof(Weight_t));
+ (*rows) = (Knapsack_rt *)repalloc(
+ (*rows), total_tuples * sizeof(Knapsack_rt));
if ((*rows) == NULL) {
elog(ERROR, "Out of memory");
@@ -123,7 +123,7 @@ get_weights_general(
void
get_weights_costs(
char *sql,
- Weight_t **rows,
+ Knapsack_rt **rows,
size_t *total_rows) {
Column_info_t info[2];
diff --git a/src/or_tools/knapsack.c b/src/or_tools/knapsack.c
index 1f553196bb..b4a04aaa19 100644
--- a/src/or_tools/knapsack.c
+++ b/src/or_tools/knapsack.c
@@ -23,7 +23,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#include "c_common/debug_macro.h"
#include "c_common/e_report.h"
#include "c_common/time_msg.h"
-
+#include "c_common/weights_costs_input.h"
#include "c_types/knapsack_rt.h"
#include "drivers/or_tools/knapsack_driver.h"
@@ -48,6 +48,15 @@ process(
if (result_tuples) {pfree(result_tuples); result_tuples = NULL;}
result_count = result_count + 1 -1;
elog(WARNING, "Stopping execution");
+
+ Knapsack_rt *weights_arr = NULL;
+ size_t total_weights = 0;
+#if 0
+ if (weights_arr) {pfree(weights_arr); weights_arr = NULL;}
+ total_weights = total_weights + 1 -1;
+#endif
+ get_weights_costs(weights_costs_sql,
+ &weights_arr, &total_weights);
#if 0
Knapsack_rt *knapsack_items = NULL;
size_t total_knapsack_items = 0;
From 2851a3714d46e945b3631295c469edf19637ad94 Mon Sep 17 00:00:00 2001
From: Manas
Date: Thu, 14 Jul 2022 20:11:20 +0530
Subject: [PATCH 24/28] [docqueries] Can't understand the error message.
changes in knapsack.test.sql is not reflected
---
docqueries/or_tools/knapsack.result | 15 +++------------
docqueries/or_tools/knapsack.test.sql | 6 +-----
2 files changed, 4 insertions(+), 17 deletions(-)
diff --git a/docqueries/or_tools/knapsack.result b/docqueries/or_tools/knapsack.result
index 907d0c94ac..a7e2a97596 100644
--- a/docqueries/or_tools/knapsack.result
+++ b/docqueries/or_tools/knapsack.result
@@ -26,18 +26,9 @@ FROM knapsack_data;
(5 rows)
SELECT *
-FROM vrp_knapsack($$SELECT * FROM knapsack_data$$, 3);
+FROM vrp_knapsack($$SELECT weight, cost FROM knapsack_data$$, 3);
WARNING: Stopping execution
- total_cost | total_weight | packed_cost | packed_weights
-------------+--------------+-------------+----------------
-(0 rows)
-
-SELECT *
-FROM vrp_knapsack($$SELECT * FROM knapsack_data$$, 3);
-WARNING: Stopping execution
- total_cost | total_weight | packed_cost | packed_weights
-------------+--------------+-------------+----------------
-(0 rows)
-
+ERROR: Column 'èÀÔóÿH‹EødH3%(' not Found
+CONTEXT: SQL function "vrp_knapsack" statement 1
ROLLBACK;
ROLLBACK
diff --git a/docqueries/or_tools/knapsack.test.sql b/docqueries/or_tools/knapsack.test.sql
index 72a3b22221..e3517462b4 100644
--- a/docqueries/or_tools/knapsack.test.sql
+++ b/docqueries/or_tools/knapsack.test.sql
@@ -14,8 +14,4 @@ SELECT *
FROM knapsack_data;
SELECT *
-FROM vrp_knapsack($$SELECT * FROM knapsack_data$$, 3);
-
-
-SELECT *
-FROM vrp_knapsack($$SELECT * FROM knapsack_data$$, 3);
\ No newline at end of file
+FROM vrp_knapsack($$SELECT weight, cost FROM knapsack_data$$, 3);
From 711cfbbaa60c9e0396a70585022e6f8c2fc47612 Mon Sep 17 00:00:00 2001
From: Manas
Date: Thu, 14 Jul 2022 20:33:08 +0530
Subject: [PATCH 25/28] Trying to fix get_weights_costs(SQL processor) function
---
docqueries/or_tools/knapsack.result | 34 -----------------------------
src/common/weights_costs_input.c | 4 +---
2 files changed, 1 insertion(+), 37 deletions(-)
diff --git a/docqueries/or_tools/knapsack.result b/docqueries/or_tools/knapsack.result
index a7e2a97596..e69de29bb2 100644
--- a/docqueries/or_tools/knapsack.result
+++ b/docqueries/or_tools/knapsack.result
@@ -1,34 +0,0 @@
-BEGIN;
-BEGIN
-SET client_min_messages TO NOTICE;
-SET
-CREATE TABLE knapsack_data(
- weight INTEGER,
- cost INTEGER);
-CREATE TABLE
-INSERT INTO knapsack_data (weight, cost)
-VALUES
-(12, 4),
-(2, 2),
-(1, 1),
-(4, 10),
-(1, 2);
-INSERT 0 5
-SELECT *
-FROM knapsack_data;
- weight | cost
---------+------
- 12 | 4
- 2 | 2
- 1 | 1
- 4 | 10
- 1 | 2
-(5 rows)
-
-SELECT *
-FROM vrp_knapsack($$SELECT weight, cost FROM knapsack_data$$, 3);
-WARNING: Stopping execution
-ERROR: Column 'èÀÔóÿH‹EødH3%(' not Found
-CONTEXT: SQL function "vrp_knapsack" statement 1
-ROLLBACK;
-ROLLBACK
diff --git a/src/common/weights_costs_input.c b/src/common/weights_costs_input.c
index de5926234a..3dab1a791d 100644
--- a/src/common/weights_costs_input.c
+++ b/src/common/weights_costs_input.c
@@ -54,7 +54,7 @@ get_weights_general(
const int tuple_limit = 1000000;
size_t total_tuples = 0;
- const int column_count = 3;
+ const int column_count = 2;
void *SPIplan;
SPIplan = pgr_SPI_prepare(sql);
@@ -136,7 +136,5 @@ get_weights_costs(
}
info[0].name = "weight";
info[1].name = "cost";
-
- info[2].eType = INTERVAL;
get_weights_general(sql, info, rows, total_rows);
}
\ No newline at end of file
From 31111a209bd3c4a634f7cc3f9d960f04883f61e7 Mon Sep 17 00:00:00 2001
From: Manas
Date: Thu, 14 Jul 2022 20:41:33 +0530
Subject: [PATCH 26/28] fixed new line issues
---
include/c_common/weights_costs_input.h | 7 +++----
src/common/weights_costs_input.c | 2 +-
src/or_tools/knapsack.c | 2 +-
src/or_tools/knapsack_driver.cpp | 2 +-
4 files changed, 6 insertions(+), 7 deletions(-)
diff --git a/include/c_common/weights_costs_input.h b/include/c_common/weights_costs_input.h
index 092e29c403..668aeeb0d7 100644
--- a/include/c_common/weights_costs_input.h
+++ b/include/c_common/weights_costs_input.h
@@ -17,10 +17,9 @@ 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_WEIGHTS_COST_INPUT_H_
-#define INCLUDE_C_COMMON_WEIGHTS_COST_INPUT_H_
+#ifndef INCLUDE_C_COMMON_WEIGHTS_COSTS_INPUT_H_
+#define INCLUDE_C_COMMON_WEIGHTS_COSTS_INPUT_H_
#pragma once
-
#include
typedef struct Knapsack_rt Knapsack_rt;
@@ -31,4 +30,4 @@ void get_weights_costs(
Knapsack_rt **rows,
size_t *total_rows);
-#endif // INCLUDE_C_COMMON_WEIGHTS__COSTS_INPUT_H_
\ No newline at end of file
+#endif // INCLUDE_C_COMMON_WEIGHTS_COSTS_INPUT_H_
diff --git a/src/common/weights_costs_input.c b/src/common/weights_costs_input.c
index 3dab1a791d..a45cd8fdac 100644
--- a/src/common/weights_costs_input.c
+++ b/src/common/weights_costs_input.c
@@ -137,4 +137,4 @@ get_weights_costs(
info[0].name = "weight";
info[1].name = "cost";
get_weights_general(sql, info, rows, total_rows);
-}
\ No newline at end of file
+}
diff --git a/src/or_tools/knapsack.c b/src/or_tools/knapsack.c
index b4a04aaa19..4030e7a883 100644
--- a/src/or_tools/knapsack.c
+++ b/src/or_tools/knapsack.c
@@ -51,7 +51,7 @@ process(
Knapsack_rt *weights_arr = NULL;
size_t total_weights = 0;
-#if 0
+#if 0
if (weights_arr) {pfree(weights_arr); weights_arr = NULL;}
total_weights = total_weights + 1 -1;
#endif
diff --git a/src/or_tools/knapsack_driver.cpp b/src/or_tools/knapsack_driver.cpp
index fa7998f957..2384e20e8f 100644
--- a/src/or_tools/knapsack_driver.cpp
+++ b/src/or_tools/knapsack_driver.cpp
@@ -265,4 +265,4 @@ do_knapsack(
*err_msg = pgr_msg(err.str().c_str());
*log_msg = pgr_msg(log.str().c_str());
}
-}
\ No newline at end of file
+}
From 4363a4f292b4cd777a567aad9d4d8f92c4e359bf Mon Sep 17 00:00:00 2001
From: Manas
Date: Thu, 14 Jul 2022 21:10:22 +0530
Subject: [PATCH 27/28] Can't figure out the cause of the error
---
docqueries/or_tools/CMakeLists.txt | 1 +
src/or_tools/knapsack.c | 2 +-
2 files changed, 2 insertions(+), 1 deletion(-)
diff --git a/docqueries/or_tools/CMakeLists.txt b/docqueries/or_tools/CMakeLists.txt
index 85ace15888..990e45f2a2 100644
--- a/docqueries/or_tools/CMakeLists.txt
+++ b/docqueries/or_tools/CMakeLists.txt
@@ -1,4 +1,5 @@
SET(LOCAL_FILES
+ knapsack
)
foreach (f ${LOCAL_FILES})
diff --git a/src/or_tools/knapsack.c b/src/or_tools/knapsack.c
index 4030e7a883..035d203fbe 100644
--- a/src/or_tools/knapsack.c
+++ b/src/or_tools/knapsack.c
@@ -60,7 +60,7 @@ process(
#if 0
Knapsack_rt *knapsack_items = NULL;
size_t total_knapsack_items = 0;
- get_weights_costs(weights_cost_sql,
+ get_weights_costs(weights_costs_sql,
&knapsack_items, &total_knapsack_items);
if (total_knapsack_items == 0) {
From 910144ba7fc5aaf2da5350e2ee8a3998e33edb6a Mon Sep 17 00:00:00 2001
From: Manas
Date: Thu, 14 Jul 2022 21:28:52 +0530
Subject: [PATCH 28/28] deleted some files
---
.gitignore | 2 +-
vroom-v1.12.0 | 1 -
vrprun.sh | 156 --------------------------------------------------
3 files changed, 1 insertion(+), 158 deletions(-)
delete mode 160000 vroom-v1.12.0
delete mode 100755 vrprun.sh
diff --git a/.gitignore b/.gitignore
index 9a35a416bf..2735dea235 100644
--- a/.gitignore
+++ b/.gitignore
@@ -8,7 +8,7 @@ ortools
build1
bin_packing.cc
gpush.sh
-vroom-1.12.0
+vroom-v1.12.0
# files are ignored on gh-pages
doxy
diff --git a/vroom-v1.12.0 b/vroom-v1.12.0
deleted file mode 160000
index d3abd6b22f..0000000000
--- a/vroom-v1.12.0
+++ /dev/null
@@ -1 +0,0 @@
-Subproject commit d3abd6b22fe4afc0daa64d6b905911999b12dcdd
diff --git a/vrprun.sh b/vrprun.sh
deleted file mode 100755
index d8f154a80f..0000000000
--- a/vrprun.sh
+++ /dev/null
@@ -1,156 +0,0 @@
-#!/bin/bash
-
-set -e
-
-DIR=$(git rev-parse --show-toplevel)
-pushd "${DIR}" > /dev/null || exit 1
-
-# The next two lines need to be executed only once
-# pushd tools/testers/ ; tar -xf matrix_new_values.tar.gz; popd
-# sudo apt-get install libssl-dev libasio-dev libglpk-dev
-
-# copy this file into the root of your repository
-# adjust to your needs
-
-# This run.sh is intended for 3.x.x
-VERSION=$(grep -Po '(?<=project\(VRPROUTING VERSION )[^;]+' CMakeLists.txt)
-echo "pgRouting VERSION ${VERSION}"
-
-# set up your postgres version, port and compiler (if more than one)
-PGVERSION="13"
-PGPORT="5432"
-PGBIN="/usr/lib/postgresql/${PGVERSION}/bin"
-PGINC="/usr/include/postgresql/${PGVERSION}/server"
-# When more than one compiler is installed
-GCC=""
-
-QUERIES_DIRS=$(ls docqueries -1)
-TAP_DIRS=$(ls pgtap -1)
-
-QUERIES_DIRS="or_tools"
-TAP_DIRS=""
-
-function install_vroom {
- cd "${DIR}"
- rm -rf ./vroom-v1.12.0
- git clone --depth 1 --branch v1.12.0 https://github.com/VROOM-Project/vroom ./vroom-v1.12.0
- pushd vroom-v1.12.0/
- git submodule update --init
- cd src/
- USE_ROUTING=false make shared
- popd
-}
-
-function set_cmake {
- # Using all defaults
- #cmake ..
-
- # Options Release RelWithDebInfo MinSizeRel Debug
- #cmake -DCMAKE_BUILD_TYPE=Debug ..
-
- # Additional debug information
- #cmake -DPgRouting_DEBUG=ON -DCMAKE_BUILD_TYPE=Debug ..
-
- # with documentation (like the one the website)
- #cmake -DDOC_USE_BOOTSTRAP=ON -DWITH_DOC=ON ..
-
- # with developers documentation
- #cmake -DWITH_DOC=ON -DBUILD_DOXY=ON ..
-
- #CXX=clang++ CC=clang cmake -DPOSTGRESQL_BIN=${PGBIN} -DCMAKE_BUILD_TYPE=Debug ..
-
- cmake "-DPostgreSQL_INCLUDE_DIR=${PGINC}" -DCMAKE_BUILD_TYPE=Debug -DWITH_DOC=OFF "-DVROOM_INSTALL_PATH=$DIR/vroom-v1.12.0" ..
-}
-
-function tap_test {
- echo --------------------------------------------
- echo pgTap test all
- echo --------------------------------------------
-
- dropdb --if-exists -p $PGPORT ___pgr___test___
- createdb -p $PGPORT ___pgr___test___
- echo $PGPORT
- tools/testers/pg_prove_tests.sh manas $PGPORT
- dropdb -p $PGPORT ___pgr___test___
-}
-
-function action_tests {
- echo --------------------------------------------
- echo Update signatures
- echo --------------------------------------------
-
- tools/scripts/get_signatures.sh -p ${PGPORT}
- tools/scripts/notes2news.pl
- bash tools/scripts/test_signatures.sh
- bash tools/scripts/test_shell.sh
- bash tools/scripts/test_license.sh
- bash tools/scripts/code_checker.sh
- tools/testers/doc_queries_generator.pl -documentation -pgport $PGPORT
-}
-
-function set_compiler {
- echo ------------------------------------
- echo ------------------------------------
- echo "Compiling with G++-$1"
- echo ------------------------------------
-
- if [ -n "$1" ]; then
- update-alternatives --set gcc "/usr/bin/gcc-$1"
- fi
-}
-
-function build_doc {
- pushd build > /dev/null || exit 1
- #rm -rf doc/*
- make doc
- #make linkcheck
- #rm -rf doxygen/*
- #make doxy
- popd > /dev/null || exit 1
-}
-
-function build {
- pushd build > /dev/null || exit 1
- set_cmake
- make -j 16
- #make VERBOSE=1
- sudo make install
- popd > /dev/null || exit 1
-
-}
-
-function test_compile {
-
- set_compiler "${GCC}"
-
- #install_vroom
- build
-
- echo --------------------------------------------
- echo Execute documentation queries
- echo --------------------------------------------
- for d in ${QUERIES_DIRS}
- do
- #tools/testers/doc_queries_generator.pl -alg "${d}" -documentation -pgport "${PGPORT}"
- #tools/testers/doc_queries_generator.pl -alg "${d}" -debug1 -pgport "${PGPORT}"
- tools/testers/doc_queries_generator.pl -alg "${d}" -pgport "${PGPORT}"
- done
-
-
- echo --------------------------------------------
- echo Execute tap_directories
- echo --------------------------------------------
- for d in ${TAP_DIRS}
- do
- bash taptest.sh "${d}" "-p ${PGPORT}"
- done
-
- #build_doc
- #tools/testers/doc_queries_generator.pl -pgport $PGPORT
- #exit 0
-
- tap_test
- #action_tests
-
-}
-test_compile