vrp_vroomJobsPlain - Experimental¶
vrp_vroomJobsPlain
- Vehicle Routing Problem with VROOM, involving only jobs, with plain integer values instead of TIMESTAMP or INTERVAL.
Warning
Possible server crash
These functions might create a server crash
Warning
Experimental functions
They are not officially of the current release.
They likely will not be officially be part of the next release:
The functions might not make use of ANY-INTEGER and ANY-NUMERICAL
Name might change.
Signature might change.
Functionality might change.
pgTap tests might be missing.
Might need c/c++ coding.
May lack documentation.
Documentation if any might need to be rewritten.
Documentation examples might need to be automatically generated.
Might need a lot of feedback from the comunity.
Might depend on a proposed function of vrpRouting
Might depend on a deprecated function of vrpRouting
Availability
Version 0.3.0
Function modified for VROOM 1.11.0
Version 0.2.0
New experimental function
Description¶
VROOM is an open-source optimization engine that aims at providing good solutions to various real-life vehicle routing problems (VRP) within a small computing time. This function can be used to get the solution to a problem involving only jobs.
Signature¶
Summary
vrp_vroomJobsPlain(
Jobs SQL, Jobs Time Windows SQL,
Vehicles SQL, Breaks SQL, Breaks Time Windows SQL,
Matrix SQL [, exploration_level] [, timeout]) -- Experimental on v0.2
RETURNS SET OF
(seq, vehicle_seq, vehicle_id, vehicle_data, step_seq, step_type, task_id,
task_data, arrival, travel_time, service_time, waiting_time, departure, load)
Optional parameters are named parameters and have a default value.
Using defaults
vrp_vroomJobsPlain(
Jobs SQL, Jobs Time Windows SQL,
Vehicles SQL, Breaks SQL, Breaks Time Windows SQL,
Matrix SQL)
RETURNS SET OF
(seq, vehicle_seq, vehicle_id, vehicle_data, step_seq, step_type, task_id,
task_data, arrival, travel_time, service_time, waiting_time, departure, load)
Example: This example is based on the VROOM Data of the Sample Data network:
SELECT *
FROM vrp_vroomJobsPlain(
'SELECT * FROM vroom.jobs',
'SELECT * FROM vroom.jobs_time_windows',
'SELECT * FROM vroom.vehicles',
'SELECT * FROM vroom.breaks',
'SELECT * FROM vroom.breaks_time_windows',
'SELECT * FROM vroom.matrix'
);
seq | vehicle_seq | vehicle_id | vehicle_data | step_seq | step_type | task_id | location_id | task_data | arrival | travel_time | setup_time | service_time | waiting_time | departure | load
-----+-------------+------------+--------------+----------+-----------+---------+-------------+-----------+---------+-------------+------------+--------------+--------------+-----------+-------
1 | 1 | 1 | {} | 1 | 1 | -1 | 1 | {} | 300 | 0 | 0 | 0 | 0 | 300 | {20}
2 | 1 | 1 | {} | 2 | 5 | 1 | 1 | {} | 300 | 0 | 0 | 0 | 0 | 300 | {20}
3 | 1 | 1 | {} | 3 | 2 | 1 | 1 | {} | 300 | 0 | 0 | 250 | 3325 | 3875 | {20}
4 | 1 | 1 | {} | 4 | 6 | -1 | 1 | {} | 3875 | 0 | 0 | 0 | 0 | 3875 | {20}
5 | 1 | 1 | {} | 0 | 0 | 0 | 0 | {} | 0 | 0 | 0 | 250 | 3325 | 0 | {}
6 | 2 | 2 | {} | 1 | 1 | -1 | 1 | {} | 275 | 0 | 0 | 0 | 0 | 275 | {100}
7 | 2 | 2 | {} | 2 | 5 | 2 | 1 | {} | 275 | 0 | 0 | 10 | 0 | 285 | {100}
8 | 2 | 2 | {} | 3 | 2 | 2 | 2 | {} | 335 | 50 | 0 | 250 | 915 | 1500 | {100}
9 | 2 | 2 | {} | 4 | 2 | 5 | 4 | {} | 1590 | 90 | 0 | 250 | 0 | 1840 | {100}
10 | 2 | 2 | {} | 5 | 2 | 3 | 3 | {} | 1890 | 50 | 0 | 250 | 835 | 2975 | {100}
11 | 2 | 2 | {} | 6 | 2 | 4 | 3 | {} | 2975 | 0 | 0 | 250 | 550 | 3775 | {100}
12 | 2 | 2 | {} | 7 | 6 | -1 | 3 | {} | 3775 | 0 | 0 | 0 | 0 | 3775 | {100}
13 | 2 | 2 | {} | 0 | 0 | 0 | 0 | {} | 0 | 190 | 0 | 1010 | 2300 | 0 | {}
14 | 0 | 0 | {} | 0 | 0 | 0 | 0 | {} | 0 | 190 | 0 | 1260 | 5625 | 0 | {}
(14 rows)
Parameters¶
Parameter |
Type |
Description |
---|---|---|
Jobs SQL |
|
Jobs SQL query describing the single-location pickup and/or delivery tasks. |
Jobs Time Windows SQL |
|
Time Windows SQL query describing valid slots for job service start. |
Vehicles SQL |
|
Vehicles SQL query describing the available vehicles. |
Breaks SQL |
|
Breaks SQL query describing the driver breaks. |
Breaks Time Windows SQL |
|
Time Windows SQL query describing valid slots for break start. |
Matrix SQL |
|
Time Matrix SQL query containing the distance or travel times between the locations. |
Optional Parameters¶
Parameter |
Type |
Default |
Description |
---|---|---|---|
exploration_level |
|
\(5\) |
Exploration level to use while solving.
|
timeout |
|
\(-1\) |
Timeout value to stop the solving process.
|
Inner Queries¶
Jobs SQL¶
A SELECT
statement that returns the following columns:
id, location_id
[, setup, service, delivery, pickup, skills, priority, data]
Column |
Type |
Default |
Description |
---|---|---|---|
id |
|
Positive unique identifier of the job. |
|
location_id |
|
Positive identifier of the job location. |
|
setup |
|
\(0\) |
Job setup duration. |
service |
|
\(0\) |
Job service duration. |
delivery |
|
Empty Array |
Array of non-negative integers describing multidimensional quantities for delivery such as number of items, weight, volume etc.
|
pickup |
|
Empty Array |
Array of non-negative integers describing multidimensional quantities for pickup such as number of items, weight, volume etc.
|
skills |
|
Empty Array |
Array of non-negative integers defining mandatory skills. |
priority |
|
0 |
Priority level of the job
|
data |
|
‘{}’::JSONB |
Any metadata information of the job. |
Where:
- ANY-INTEGER
SMALLINT, INTEGER, BIGINT
Vehicles SQL¶
A SELECT
statement that returns the following columns:
id, start_id, end_id
[, capacity, skills, tw_open, tw_close, speed_factor, max_tasks, data]
Column |
Type |
Default |
Description |
---|---|---|---|
id |
|
Positive unique identifier of the vehicle. |
|
start_id |
|
Positive identifier of the vehicle start location. |
|
end_id |
|
Positive identifier of the vehicle end location. |
|
capacity |
|
Empty Array |
Array of non-negative integers describing multidimensional quantities such as number of items, weight, volume etc.
|
skills |
|
Empty Array |
Array of non-negative integers defining mandatory skills. |
tw_open |
|
\(0\) |
Time window opening time. |
tw_close |
|
\(4294967295\) |
Time window closing time. |
speed_factor |
|
\(1.0\) |
Vehicle travel time multiplier.
|
max_tasks |
|
\(2147483647\) |
Maximum number of tasks in a route for the vehicle.
|
data |
|
‘{}’::JSONB |
Any metadata information of the vehicle. |
Note:
At least one of the
start_id
orend_id
shall be present.If
end_id
is omitted, the resulting route will stop at the last visited task, whose choice is determined by the optimization process.If
start_id
is omitted, the resulting route will start at the first visited task, whose choice is determined by the optimization process.To request a round trip, specify both
start_id
andend_id
as the same index.A vehicle is only allowed to serve a set of tasks if the resulting load at each route step is lower than the matching value in capacity for each metric. When using multiple components for amounts, it is recommended to put the most important/limiting metrics first.
It is assumed that all delivery-related amounts for jobs are loaded at vehicle start, while all pickup-related amounts for jobs are brought back at vehicle end.
tw_open ≤ tw_close
Breaks SQL¶
A SELECT
statement that returns the following columns:
id, vehicle_id [, service, data]
Column |
Type |
Default |
Description |
---|---|---|---|
id |
|
Positive unique identifier of the break. (unique for the same vehicle). |
|
vehicle_id |
|
Positive unique identifier of the vehicle. |
|
service |
|
\(0\) |
The break duration. |
data |
|
‘{}’::JSONB |
Any metadata information of the break. |
Time Windows SQL¶
A SELECT
statement that returns the following columns:
id [, kind], tw_open, tw_close
Column |
Type |
Description |
---|---|---|
id |
|
Positive unique identifier of the job, pickup/delivery shipment, or break. |
kind |
|
Only required for shipments time windows. Value in [‘p’, ‘d’] indicating whether the time window is for:
|
tw_open |
|
Time window opening time. |
tw_close |
|
Time window closing time. |
Note:
All timings are in seconds when represented as an
INTEGER
.Every row must satisfy the condition:
tw_open ≤ tw_close
.It is up to users to decide how to describe time windows:
Relative values, e.g. [0, 14400] for a 4 hours time window starting at the beginning of the planning horizon. In that case all times reported in output with the arrival column are relative to the start of the planning horizon.
Absolute values, “real” timestamps. In that case all times reported in output with the arrival column can be interpreted as timestamps.
Time Matrix SQL¶
A SELECT
statement that returns the following columns:
start_id, end_id, duration [, cost]
Column |
Type |
Default |
Description |
---|---|---|---|
start_id |
|
Identifier of the start node. |
|
end_id |
|
Identifier of the end node. |
|
duration |
|
Time to travel from |
|
cost |
|
duration |
Cost to travel from |
Result Columns¶
Returns set of
(seq, vehicle_seq, vehicle_id, vehicle_data, step_seq, step_type, task_id,
task_data, arrival, travel_time, service_time, waiting_time, load)
Column |
Type |
Description |
---|---|---|
seq |
|
Sequential value starting from 1. |
vehicle_seq |
|
Sequential value starting from 1 for current vehicles. The \(n^{th}\) vehicle in the solution.
|
vehicle_id |
|
Current vehicle identifier.
|
vehicle_data |
|
Metadata information of the vehicle |
step_seq |
|
Sequential value starting from 1 for the stops made by the current vehicle. The \(m^{th}\) stop of the current vehicle.
|
step_type |
|
Kind of the step location the vehicle is at:
|
task_id |
|
Identifier of the task performed at this step.
|
location_id |
|
Identifier of the task location.
|
task_data |
|
Metadata information of the task |
arrival |
|
Estimated time of arrival at this step. |
travel_time |
|
Travel time from previous
|
setup_time |
|
Setup time at this step. |
service_time |
|
Service time at this step. |
waiting_time |
|
Waiting time upon arrival at this step. |
departure |
|
Estimated time of arrival at this step.
|
load |
|
Vehicle load after step completion (with capacity constraints) |
Note:
Unallocated tasks are mentioned at the end with
vehicle_id = -1
.The last step of every vehicle denotes the summary row, where the columns
travel_time
,service_time
andwaiting_time
denote the total time for the corresponding vehicle,The last row denotes the summary for the complete problem, where the columns
travel_time
,service_time
andwaiting_time
denote the total time for the complete problem,
Additional Example¶
Problem involving 2 jobs, using a single vehicle, corresponding to the VROOM Documentation Example 2.
SELECT *
FROM vrp_vroomJobsPlain(
$jobs$
SELECT * FROM (
VALUES (1414, 2), (1515, 3)
) AS C(id, location_id)
$jobs$,
NULL,
$vehicles$
SELECT * FROM (
VALUES (1, 1, 4)
) AS C(id, start_id, end_id)
$vehicles$,
NULL,
NULL,
$matrix$
SELECT * FROM (
VALUES (1, 2, 2104), (1, 3, 197), (1, 4, 1299),
(2, 1, 2103), (2, 3, 2255), (2, 4, 3152),
(3, 1, 197), (3, 2, 2256), (3, 4, 1102),
(4, 1, 1299), (4, 2, 3153), (4, 3, 1102)
) AS C(start_id, end_id, duration)
$matrix$
);
seq | vehicle_seq | vehicle_id | vehicle_data | step_seq | step_type | task_id | location_id | task_data | arrival | travel_time | setup_time | service_time | waiting_time | departure | load
-----+-------------+------------+--------------+----------+-----------+---------+-------------+-----------+---------+-------------+------------+--------------+--------------+-----------+------
1 | 1 | 1 | {} | 1 | 1 | -1 | 1 | {} | 0 | 0 | 0 | 0 | 0 | 0 | {}
2 | 1 | 1 | {} | 2 | 2 | 1414 | 2 | {} | 2104 | 2104 | 0 | 0 | 0 | 2104 | {}
3 | 1 | 1 | {} | 3 | 2 | 1515 | 3 | {} | 4359 | 2255 | 0 | 0 | 0 | 4359 | {}
4 | 1 | 1 | {} | 4 | 6 | -1 | 4 | {} | 5461 | 1102 | 0 | 0 | 0 | 5461 | {}
5 | 1 | 1 | {} | 0 | 0 | 0 | 0 | {} | 0 | 5461 | 0 | 0 | 0 | 0 | {}
6 | 0 | 0 | {} | 0 | 0 | 0 | 0 | {} | 0 | 5461 | 0 | 0 | 0 | 0 | {}
(6 rows)