Skip to content

Commit ff9b1aa

Browse files
authored
Merge pull request #229 from Manas23601/manas-week-5
GSoC 22 : Manas Sivakumar Week 5
2 parents 0cb3be0 + 910144b commit ff9b1aa

File tree

19 files changed

+342
-225
lines changed

19 files changed

+342
-225
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ src/version/_version.h
66
v[0-9]*
77
ortools
88
build1
9+
bin_packing.cc
10+
gpush.sh
11+
vroom-v1.12.0
912

1013
# files are ignored on gh-pages
1114
doxy

.vscode/settings.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"files.associations": {
3+
"knapsack_driver.h": "c"
4+
}
5+
}

CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -332,14 +332,14 @@ endforeach()
332332
#----------------------
333333

334334
# set(CMAKE_PREFIX_PATH "/home/manas/Codes/GSOC-2022/MyFork/ortools/build")
335-
add_subdirectory(ortools)
335+
# add_subdirectory(ortools)
336336
# set(ortools_DIR "/home/manas/Codes/GSOC-2022/MyFork/ortools/build")
337337
# set(absl_DIR "/home/manas/Codes/GSOC-2022/MyFork/ortools/build/_deps/absl-build")
338338
# set(re2_DIR "/home/manas/Codes/GSOC-2022/MyFork/ortools/build/_deps/re2-build/CMakeFiles/Export/lib/cmake/re2")
339339
# set(Protobuf_DIR "/home/manas/Codes/GSOC-2022/MyFork/ortools/build/_deps/protobuf-build/lib/cmake/protobuf")
340340
# find_package(ortools CONFIG REQUIRED)
341-
add_executable(myapp bin_packing.cc)
342-
target_link_libraries(myapp ortools::ortools)
341+
# add_executable(myapp bin_packing.cc)
342+
# target_link_libraries(myapp ortools::ortools)
343343

344344

345345
#-----------------------------------------------------------------------------

configuration.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ simulation | N | Y | N
2828
optimizers | Y | N | N
2929
initialsol | Y | N | N
3030
vroom | Y | Y | Y
31-
or_tools | N | N | N
31+
or_tools | Y | Y | N

docqueries/or_tools/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
SET(LOCAL_FILES
2+
knapsack
23
)
34

45
foreach (f ${LOCAL_FILES})

docqueries/or_tools/knapsack.result

Whitespace-only changes.

docqueries/or_tools/knapsack.test.sql

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,17 @@
1-
-- TODO make the single tests.
1+
CREATE TABLE knapsack_data(
2+
weight INTEGER,
3+
cost INTEGER);
4+
5+
INSERT INTO knapsack_data (weight, cost)
6+
VALUES
7+
(12, 4),
8+
(2, 2),
9+
(1, 1),
10+
(4, 10),
11+
(1, 2);
12+
13+
SELECT *
14+
FROM knapsack_data;
15+
16+
SELECT *
17+
FROM vrp_knapsack($$SELECT weight, cost FROM knapsack_data$$, 3);

docqueries/or_tools/test.conf

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/perl -w
2+
3+
%main::tests = (
4+
'any' => {
5+
'comment' => 'test for or-tools',
6+
'data' => [],
7+
'newdb' => 1,
8+
'tests' => [qw(
9+
knapsack
10+
)],
11+
12+
'documentation' => [qw(
13+
knapsack
14+
)],
15+
16+
'nottesting' => [qw(
17+
)]
18+
},
19+
);
20+
21+
1;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*PGR-GNU*****************************************************************
2+
* TODO fix licence
3+
File: matrixRows_input.h
4+
Copyright (c) 2022 Manas Sivakumar
5+
6+
------
7+
This program is free software; you can redistribute it and/or modify
8+
it under the terms of the GNU General Public License as published by
9+
the Free Software Foundation; either version 2 of the License, or
10+
(at your option) any later version.
11+
This program is distributed in the hope that it will be useful,
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
GNU General Public License for more details.
15+
You should have received a copy of the GNU General Public License
16+
along with this program; if not, write to the Free Software
17+
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18+
********************************************************************PGR-GNU*/
19+
20+
#ifndef INCLUDE_C_COMMON_WEIGHTS_COSTS_INPUT_H_
21+
#define INCLUDE_C_COMMON_WEIGHTS_COSTS_INPUT_H_
22+
#pragma once
23+
#include <stddef.h>
24+
25+
typedef struct Knapsack_rt Knapsack_rt;
26+
27+
/** @brief Get the weights and cost for each item */
28+
void get_weights_costs(
29+
char *sql,
30+
Knapsack_rt **rows,
31+
size_t *total_rows);
32+
33+
#endif // INCLUDE_C_COMMON_WEIGHTS_COSTS_INPUT_H_

include/c_types/knapsack_rt.h

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*PGR-GNU*****************************************************************
2+
File: knapsack_rt.h
3+
4+
Copyright (c) 2022 Manas Sivakumar
5+
6+
7+
------
8+
9+
This program is free software; you can redistribute it and/or modify
10+
it under the terms of the GNU General Public License as published by
11+
the Free Software Foundation; either version 2 of the License, or
12+
(at your option) any later version.
13+
14+
This program is distributed in the hope that it will be useful,
15+
but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
GNU General Public License for more details.
18+
19+
You should have received a copy of the GNU General Public License
20+
along with this program; if not, write to the Free Software
21+
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22+
23+
********************************************************************PGR-GNU*/
24+
/*! @file */
25+
26+
#ifndef INCLUDE_C_TYPES_KNAPSACK_RT_H_
27+
#define INCLUDE_C_TYPES_KNAPSACK_RT_H_
28+
#pragma once
29+
30+
/* for int64_t */
31+
#ifdef __cplusplus
32+
# include <cstdint>
33+
#else
34+
# include <stdint.h>
35+
#endif
36+
37+
/** @brief
38+
39+
@note C/C++/postgreSQL connecting structure for output
40+
name | description
41+
:----- | :-------
42+
Index | Position of the item in the order in which the input was given
43+
item_weight | Weight of the item
44+
item_cost | Value of the item
45+
*/
46+
47+
struct Knapsack_rt {
48+
int64_t item_weight;
49+
int64_t item_cost;
50+
};
51+
52+
/*************************************************************************/
53+
54+
#endif // INCLUDE_C_TYPES_KNAPSACK_RT_H_

include/c_types/typedefs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ using Vroom_matrix_t = struct Vroom_matrix_t;
6060
using Vroom_break_t = struct Vroom_break_t;
6161
using Vroom_time_window_t = struct Vroom_time_window_t;
6262
using Vroom_rt = struct Vroom_rt;
63+
using Knapsack_rt = struct Knapsack_rt;
6364
/*
6465
* Index on a container
6566
*/
@@ -97,6 +98,7 @@ typedef struct Vroom_matrix_t Vroom_matrix_t;
9798
typedef struct Vroom_break_t Vroom_break_t;
9899
typedef struct Vroom_time_window_t Vroom_time_window_t;
99100
typedef struct Vroom_rt Vroom_rt;
101+
typedef struct Knapsack_rt Knapsack_rt;
100102
#endif
101103

102104
/*************************************************************************/

include/drivers/or_tools/knapsack_driver.h

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,32 +39,23 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
3939
# include <stddef.h>
4040
#endif
4141

42-
#include "c_types/vehicle_t.h"
43-
#include "c_types/matrix_cell_t.h"
4442

45-
typedef struct PickDeliveryOrders_t PickDeliveryOrders_t;
46-
typedef struct Solution_rt Solution_rt;
43+
typedef struct Knapsack_rt Knapsack_rt;
4744

4845
#ifdef __cplusplus
4946
extern "C" {
5047
#endif
5148

5249
/*********************************************************
53-
weights_sql TEXT,
54-
values_sql TEXT,
55-
bin_capacity INTEGER,
56-
max_cycles INTEGER,
50+
weights_cost_sql TEXT,
51+
capacity INTEGER,
5752
********************************************************/
58-
void do_pgr_pickDeliver(
59-
PickDeliveryOrders_t *pd_orders_arr, size_t total_pd_orders,
60-
Vehicle_t *vehicles_arr, size_t total_vehicles,
61-
Matrix_cell_t *matrix_cells_arr, size_t total_cells,
53+
void do_knapsack(
54+
Knapsack_rt *knapsack_items, size_t total_knapsack_items,
6255

63-
double factor,
64-
int max_cycles,
65-
int initial_solution_id,
56+
int capacity,
6657

67-
Solution_rt **return_tuples,
58+
Knapsack_rt **return_tuples,
6859
size_t *return_count,
6960

7061
char **log_msg,

sql/or_tools/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
SET(LOCAL_FILES
2+
_knapsack.sql
23
knapsack.sql
3-
_knapsack.sql
44
)
55

66
foreach (f ${LOCAL_FILES})

sql/or_tools/_knapsack.sql

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*PGR-GNU*****************************************************************
2-
File: _knapsack_0_1.sql
2+
File: _knapsack.sql
33
44
Copyright (c) 2021 pgRouting developers
55
@@ -27,14 +27,13 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
2727

2828

2929
CREATE OR REPLACE FUNCTION _vrp_knapsack(
30-
TEXT, -- weights SQL
31-
TEXT, -- values SQL
30+
TEXT, -- weights_cost SQL
3231

33-
INTEGER, -- bin capacity
32+
INTEGER, -- capacity
3433

35-
OUT total_value INTEGER,
34+
OUT total_cost INTEGER,
3635
OUT total_weight INTEGER,
37-
OUT packed_items INTEGER[],
36+
OUT packed_costs INTEGER[],
3837
OUT packed_weights INTEGER[]
3938
)
4039
RETURNS SETOF RECORD AS
@@ -43,5 +42,5 @@ LANGUAGE c VOLATILE STRICT;
4342

4443
-- COMMENTS
4544

46-
COMMENT ON FUNCTION _vrp_knapsack(TEXT, TEXT, INTEGER)
45+
COMMENT ON FUNCTION _vrp_knapsack(TEXT, INTEGER)
4746
IS 'vrprouting internal function';

sql/or_tools/knapsack.sql

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*PGR-GNU*****************************************************************
2-
File: knapsack_0-1.sql
2+
File: knapsack_.sql
33
44
Copyright (c) 2021 pgRouting developers
55
@@ -28,24 +28,23 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
2828

2929

3030
CREATE OR REPLACE FUNCTION vrp_knapsack(
31-
TEXT, -- weights SQL
32-
TEXT, -- values SQL
31+
TEXT, -- weights_cost SQL
3332

34-
INTEGER, -- bin capacity
33+
INTEGER, -- capacity
3534

36-
OUT total_value INTEGER,
35+
OUT total_cost INTEGER,
3736
OUT total_weight INTEGER,
38-
OUT packed_items INTEGER[],
37+
OUT packed_cost INTEGER[],
3938
OUT packed_weights INTEGER[]
4039
)
4140
RETURNS SETOF RECORD AS
4241
$BODY$
4342
SELECT *
44-
FROM vrp_knapsack(_pgr_get_statement($1), _pgr_get_statement($2), $3);
43+
FROM _vrp_knapsack(_pgr_get_statement($1), $2);
4544
$BODY$
4645
LANGUAGE SQL VOLATILE STRICT;
4746

4847
-- COMMENTS
4948

50-
COMMENT ON FUNCTION vrp_knapsack(TEXT, TEXT, INTEGER)
49+
COMMENT ON FUNCTION vrp_knapsack(TEXT, INTEGER)
5150
IS 'vrp_knapsack';

src/common/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ ADD_LIBRARY(common OBJECT
77
orders_input.c
88
vehicles_input.c
99
time_multipliers_input.c
10+
weights_costs_input.c
1011

1112
time_msg.c
1213
e_report.c

0 commit comments

Comments
 (0)