Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GSoC 2022: Manas Sivakumar Week 5 #229

Merged
merged 29 commits into from
Jul 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
ef39588
[include/c_types] Adding a struct for knapsack
Manas23601 Jul 10, 2022
5c7e34b
[include/c_types] add Knapsack_rt to typedefs.h file
Manas23601 Jul 10, 2022
f9d7bfc
gpush.sh
Manas23601 Jul 10, 2022
df3f904
Revert "gpush.sh"
Manas23601 Jul 10, 2022
2f76e65
Slight
Manas23601 Jul 10, 2022
d0423be
slight modification to function signature. Using one sql inner query …
Manas23601 Jul 10, 2022
e67c490
name changes
Manas23601 Jul 11, 2022
b5a560a
Changed knapsack signature
Manas23601 Jul 14, 2022
b8a799e
[ctypes] Fixed typo
Manas23601 Jul 14, 2022
b3d3483
[include/drivers] Updated Signature
Manas23601 Jul 14, 2022
b668c2a
Small code changes
Manas23601 Jul 14, 2022
72e7546
Small code changes
Manas23601 Jul 14, 2022
ac9ff68
Small code changes
Manas23601 Jul 14, 2022
b79330f
Small code changes
Manas23601 Jul 14, 2022
86bbd72
Small code changes
Manas23601 Jul 14, 2022
0504ab6
Small code changes
Manas23601 Jul 14, 2022
1b587a7
[src] Included Header Files
Manas23601 Jul 14, 2022
b2e8d6d
[CMakeLists.txt] Not processing OR-tools
Manas23601 Jul 14, 2022
fdf277f
fixed lint errors
Manas23601 Jul 14, 2022
d702ec3
Test knapsack function
Manas23601 Jul 14, 2022
a4a9d2f
Debugging
Manas23601 Jul 14, 2022
1cdf21e
get_weights_sql function
Manas23601 Jul 14, 2022
c7252dd
knapsack is connecting properly to postgres
Manas23601 Jul 14, 2022
943601f
Getting Command aborted error when running tests
Manas23601 Jul 14, 2022
2851a37
[docqueries] Can't understand the error message. changes in knapsack.…
Manas23601 Jul 14, 2022
711cfbb
Trying to fix get_weights_costs(SQL processor) function
Manas23601 Jul 14, 2022
31111a2
fixed new line issues
Manas23601 Jul 14, 2022
4363a4f
Can't figure out the cause of the error
Manas23601 Jul 14, 2022
910144b
deleted some files
Manas23601 Jul 14, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ src/version/_version.h
v[0-9]*
ortools
build1
bin_packing.cc
gpush.sh
vroom-v1.12.0

# files are ignored on gh-pages
doxy
Expand Down
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"files.associations": {
"knapsack_driver.h": "c"
}
}
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)


#-----------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion configuration.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions docqueries/or_tools/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
SET(LOCAL_FILES
knapsack
)

foreach (f ${LOCAL_FILES})
Expand Down
Empty file.
18 changes: 17 additions & 1 deletion docqueries/or_tools/knapsack.test.sql
Original file line number Diff line number Diff line change
@@ -1 +1,17 @@
-- TODO make the single tests.
CREATE TABLE knapsack_data(
weight INTEGER,
cost INTEGER);

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 weight, cost FROM knapsack_data$$, 3);
21 changes: 21 additions & 0 deletions docqueries/or_tools/test.conf
Original file line number Diff line number Diff line change
@@ -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;
33 changes: 33 additions & 0 deletions include/c_common/weights_costs_input.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*PGR-GNU*****************************************************************
* TODO fix licence
File: matrixRows_input.h
Copyright (c) 2022 Manas Sivakumar
[email protected]
------
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_COSTS_INPUT_H_
#define INCLUDE_C_COMMON_WEIGHTS_COSTS_INPUT_H_
#pragma once
#include <stddef.h>

typedef struct Knapsack_rt Knapsack_rt;

/** @brief Get the weights and cost for each item */
void get_weights_costs(
char *sql,
Knapsack_rt **rows,
size_t *total_rows);

#endif // INCLUDE_C_COMMON_WEIGHTS_COSTS_INPUT_H_
54 changes: 54 additions & 0 deletions include/c_types/knapsack_rt.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*PGR-GNU*****************************************************************
File: knapsack_rt.h

Copyright (c) 2022 Manas Sivakumar
Mail: [email protected]

------

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 <cstdint>
#else
# include <stdint.h>
#endif

/** @brief

@note C/C++/postgreSQL connecting structure for output
name | description
:----- | :-------
Index | Position of the item in the order in which the input was given
item_weight | Weight of the item
item_cost | Value of the item
*/

struct Knapsack_rt {
int64_t item_weight;
int64_t item_cost;
};

/*************************************************************************/

#endif // INCLUDE_C_TYPES_KNAPSACK_RT_H_
2 changes: 2 additions & 0 deletions include/c_types/typedefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -97,6 +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;
#endif

/*************************************************************************/
Expand Down
23 changes: 7 additions & 16 deletions include/drivers/or_tools/knapsack_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,32 +39,23 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
# include <stddef.h>
#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" {
#endif

/*********************************************************
weights_sql TEXT,
values_sql TEXT,
bin_capacity INTEGER,
max_cycles INTEGER,
weights_cost_sql TEXT,
capacity INTEGER,
********************************************************/
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,
void do_knapsack(
Knapsack_rt *knapsack_items, size_t total_knapsack_items,

double factor,
int max_cycles,
int initial_solution_id,
int capacity,

Solution_rt **return_tuples,
Knapsack_rt **return_tuples,
size_t *return_count,

char **log_msg,
Expand Down
2 changes: 1 addition & 1 deletion sql/or_tools/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
SET(LOCAL_FILES
_knapsack.sql
knapsack.sql
_knapsack.sql
)

foreach (f ${LOCAL_FILES})
Expand Down
13 changes: 6 additions & 7 deletions sql/or_tools/_knapsack.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*PGR-GNU*****************************************************************
File: _knapsack_0_1.sql
File: _knapsack.sql

Copyright (c) 2021 pgRouting developers
Mail: [email protected]
Expand Down Expand Up @@ -27,14 +27,13 @@ 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_cost SQL

INTEGER, -- bin capacity
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
Expand All @@ -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';
15 changes: 7 additions & 8 deletions sql/or_tools/knapsack.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*PGR-GNU*****************************************************************
File: knapsack_0-1.sql
File: knapsack_.sql

Copyright (c) 2021 pgRouting developers
Mail: [email protected]
Expand Down Expand Up @@ -28,24 +28,23 @@ 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_cost SQL

INTEGER, -- bin capacity
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
$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';
1 change: 1 addition & 0 deletions src/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading