Skip to content

Commit

Permalink
Merge pull request #229 from Manas23601/manas-week-5
Browse files Browse the repository at this point in the history
GSoC 22 : Manas Sivakumar Week 5
  • Loading branch information
Manas23601 authored Jul 18, 2022
2 parents 0cb3be0 + 910144b commit ff9b1aa
Show file tree
Hide file tree
Showing 19 changed files with 342 additions and 225 deletions.
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
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_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: 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 <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: project@pgrouting.org
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: project@pgrouting.org
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

0 comments on commit ff9b1aa

Please sign in to comment.