<div dir="ltr"><div>Hi All,<br><br><br></div><div> I was a gsoc student this year for pgRouting. My job was initially to refactor the current implementation of VRP but over the course of time the goals were changed and finally the end result was a partially optimized VRP with time windows .The optimization part is still in progress and i will continue improving it .Thanks to my mentors Steve and Daniel for their support and motivation. <br>
<br></div><div>Here is a how to use guide with some explaination as well : The documentaion is same one as developed by Razequl last year with some minor changes.<br><br><a href="https://github.com/pgRouting/pgrouting/wiki/How-to-use-guide">https://github.com/pgRouting/pgrouting/wiki/How-to-use-guide</a><br>
<br><br><br></div><div><i><b># Single Depot Vehicle Routing Problem with Time Windows</b></i><br><br><br>Everything remains same as in VRP developed by Razequl last year , except the procedure name which is cvrpOneDepot() for this version of VRP ,this user guide was developed by Razequl ,since all the process is same i did not find the need to develop a new one.<br>
<br><i><b>## Overview</b></i><br><br>The single depot vehicle routing problem with time windows solves the scheduling problem related to delivering packages from a central depot to a variety of customers while letting you prioritize delivery deliveries by time windows. For example, you might have a delivery that must be made between 8:00 and 10:00. You can have multiple delivery vehicles that have varying capacity. And a list of orders that needs to be fulfilled. The orders are assigned to vehicles and each vehicle gets an ordered list of deliveries to make and returns to the depot.<br>
<br><i><b>## How Does It Work?</b></i><br><br>This is part of the pgRouting OpenSource project that extends PostgreSQL database and add functionality related to solving graph problems, specifically related to vehicle route planning. The user creates database tables defining the vehicles and their capacity, the orders, their size, delivery location and their delivery window. It also includes the depot location and operating time window for the depot. Then using other pgRouting tools a distance matrix needs to be generated between all the orders and the depot then the problem can be solved using a TABU search methodology.<br>
<br><i><b>## Where can I get the code?</b></i><br><br>In general you should be familiar with pgRouting v2.0.0 that can be found at the following link. The VRP code is found in the source repository under branch "gsoc-vrp". For a more accurate description of building and installing pgRouting use the link below. We surfisically cover many of these points here but only to the extent that they are specific to the VRP code.<br>
<br><a href="http://pgrouting.org/">http://pgrouting.org/</a><br><br>Or you can get it out of git source repository and build and install it with:<br><br>```<br>git clone <a href="https://github.com/pgRouting/pgrouting.git">https://github.com/pgRouting/pgrouting.git</a><br>
cd pgrouting<br>git checkout gsoc-cvrptw<br>mkdir build<br>cd build<br>cmake -DWITH_DOC=NO ..<br>make && make install<br>cd ..<br>```<br><br><i><b>### How do I install and create a database?</b></i><br><br>The following commands will work from the command line or you can use pgadmin3 and perform the equivalent operations.<br>
<br><br>createdb -U postgres -h localhost mytest_vrp<br>psql -U postgres -h localhost mytest_vrp<br>create extension postgis;<br>create extension pgrouting;<br></div><div>\q<br></div><div><br>You can test it with the following commands:<br>
<br><br>psql -U postgres -h localhost mytest_vrp<br>\i src/vrp_basic/test/VRP-any-00.data<br>\i src/vrp_basic/test/VRP-any-01.test<br></div><div>\q<br></div><div><br><i><b><br>## How do I setup the tables?</b></i><br>Three tables need to be passed as input parameter. They are vehicles table, orders table and distance table. More specification follows:<br>
<i><b><br>### Vehicle table:</b></i><br>This is a relatively simple table consisting vehicle information. There should be two columns. One is Vehicle_Id which is a unique id of a vehicle, the other column is the capacity of that particular vehicle in number of units. The total load of the vehicle cannot be over its specified capacity.<br>
<br><i><b>### Orders table:</b></i><br>This table contains the order information and also the information of the single depot from where the vehicle will start and return to. This table should contain 7 columns. They are:<br>
<br> - Id: A unique identifier of the order.<br><br> - x: The x or longitude of the order location.<br><br> - y: The y or latitude value of the order location.<br><br> - Order_unit: Number of unit the customer has ordered.<br>
<br> - Open_Time: Earliest time the customer is willing to receive the order. The delivery to the cosutmer will start on or after this time even if it is reached earlier. The time should be in minutes from a reference time which is the open time of the depot. So, the open time of the depot should be 0 and all the time should be given with respect to it. It is user's responsibility to convert the time.<br>
<br> - Close_Time: Latest time teh customer is willing to receive the order. The delivery must start on or before this time.<br><br> - Service_Time: Estimated time to serve the order. It may be proportional to order_unit but the user should put this in. The vehicle must stay this time in that particular order location.<br>
<br><i><b>### Distance table:</b></i><br>This table contains the point to point cost/ distance and traveltime information. This table can be generated using the other functions available in pgrouting. This table should have five columns.<br>
<br> - Src_Id: The id of the source.<br><br> - Dest_id: The id of the destination.<br><br> - Cost: The cost of traveling from the given source to the given destination.<br><br> - Distance: The distance from the source to the destination.<br>
<br> - TravelTime: The time to travel from the source to destination.<br><br>Note that sometimes cost and distance or travel time may be the same value, but still the user need to put all these three values.<br><br><i><b>### How are the time windows defined?</b></i><br>
As mentioned earlier, the time windows are given with respect to the open time of the depot. For example you can think of these times as minutes from the depot open time. The open time of the depot should be considered 0. There should also be a close time for the depot. All the vehicles are expected to return depot by this time. The orders time window should be in between. The user should convert the time to this format before passing it to the solver for a real scenario. For example, if a depot opens at 8:00 am and closes at 7:00 pm and a customer is willing to get delivery within 10:00 am and 10:40 am then the depot open time and close time will be 0 and 660 minutes respectively while the customer open and close time will be 120 and 160 minutes, respectively, from the depot open time of 0 minutes.<br>
<br><i><b>### How can I compute the distance matrix?</b></i><br>There are several options to compute the distance matrix. apsp_johnson or apsp_warshall can be used. Please refer to pgrouting documentation for further details on using these.<br>
<b><br>## How do I solve the problem?</b><br>Once the tables are set one can solve the problem by calling the pg function <b>pgr_vrpOneDepot</b> with the following input parameters:<br>```<br> order_sql text,<br> vehicle_sql text,<br>
cost_sql text,<br> depot_id integer,<br>```<br>Here order_sql is a text containing the sql for generating the order table. vehicle_sql contains the sql for generating the vehicle table and cost_sql contains the sql for generating the cost table. The fourth parameter depot_id is an integer denoting which from the order table actually represents the depot. If the tables are already in the database then simple select over them will work. Here is a simple example of calling the function:<br>
```<br>select * from pgr_cvrpOneDepot(<br> 'select * from vrp_orders'::text,<br> 'select * from vrp_vehicles'::text,<br> 'select * from vrp_distance'::text,<br> 1 );<br>```<br>To use this one must first create tables vrp_orders, vrp_vehicles and vrp_distance in the respective database. VRP-any-00.data under the test directory contains sql to create such tables and sample data.<br>
<br><i><b>## How do I interpret the problem results?</b></i><br>The result table should have 5 columns. They are:<br><br> - Vehicle_Id: The id of the vehicle for the current route. <br><br> - Order_id: The id of order that is served.<br>
<br> - Order_pos: The serial of the order in the current route. For example if order_pos is 3 that means this order is the 3rd order to be served by this vehicle. The order_pos the depot will be either 0 or n + 1 depending on whether the vehicle is leaving or arriving to the depot.<br>
<br> - Depart_time: When the vehicle is leaveing the customer. The time is given in minute with reference to the open time of the depot.<br><br> - Arrival_Time: When the vehicle starts serving the customer. Note that even if the vehicle reaches the customer before the open_time it can only start serving at the open time for that customer.<br>
<br><br>Here is an example of a sample result:<br>```<br>Order_id| Order_pos| Vehicle_Id | Arrival_Time| Depart_Time<br> 1 | 0 | 15 | -1 | 0<br> 63 | 1 | 15 | 52 | 62<br>
68 | 2 | 15 | 70 | 80<br> 72 | 3 | 15 | 93 | 103<br> 36 | 4 | 15 | 139 | 149<br> 38 | 5 | 15 | 152 | 162<br>
1 | 6 | 15 | 202 | -1<br> 1 | 0 | 8 | -1 | 0<br> 24 | 1 | 8 | 65 | 75<br> 27 | 2 | 8 | 137 | 147<br>
1 | 3 | 8 | 205 | -1<br>```<br><br>This means there are two routes. Vehicle with id 15 starts from depot at time 0 starts service at order with id 63 at time 52, leaves from there at time 62, starts service at order 68 at time 70, leaves from there at time 80 and so on and finally returns depot at time 202. The other vehicle also leaves depot at time 0 serves order 24 and 27 and returns depot at time 205. For this example the depot close time was set to 240. For actual driving direction information from this table may be used with pgrouting functions for generating path and driving directions.<br>
<br><br><br></div><div>Thanks <br><br></div><div>Mukul Priya<br></div><div><br><br><br></div></div>