# (10) - HERE Tour Planning - Logistics Route Planning And Cost Estimation

In the previous nine articles, we have introduced many HERE related map services, including:
1. HERE Data Hub / Studio: Map data storage, publishing and map production.
2. HERE Map Tile API: bitmap (PNG/JPEG) map tiles.
3. HERE Geocode and Search API: location and address query, reverse search.
4. HERE Waypoints Sequence: Optimal sorting of waypoints.
5. HERE Routing API: path calculation and detailed guidance.
6. HERE Matrix Routing: Calculation of the spatial relationship between multiple points.
7. HERE Isoline Routing: Calculation of reachable range in specific time or space.
Generally speaking, we usually use several services to integrate together to publish our own services. For example, the residential security map we have made combines HERE Data Hub / Studio, HERE Map Tile API and HERE Geocode and Search API. However, the HERE Tour Planning service we are going to introduce today is a new service launched by HERE, which combines the characteristics of several services and aims at the usage scenarios of the logistics industry.
The purpose of HERE Tour Planning is to be used as a delivery system in the logistics industry, so it can meet the following needs:
1. Support the calculation of logistics or people flow for the "fleet", so it is possible to plan the route of multiple vehicles at the same time.
2. Support two behaviors: "delivery / drop off" and "receive / pick up".
3. It can be set according to the vehicle and cargo parameters in the fleet, such as vehicle load and cargo weight, vehicle capacity and cargo volume, the number of vehicles and the number of passengers and so on.
4. Special functions can be set for the vehicles in the fleet, such as setting the vehicle as a refrigerated car, or with a boom, etc.
5. Support the cost parameters of the fleet, such as mileage unit cost, time unit cost, and fixed cost. The operating cost of the fleet can be calculated accurately before dispatch.
6. Support legal restrictions, such as maximum mileage limit, driving time limit, and rest time limit.
7. Support scheduling, such as commuting time and location.
8. Support avoiding specific roads, such as toll roads, high-speed roads, tunnels, ferries, earth-rock roads, etc.
9. Support the sorting function of waypoints based on traffic conditions (real-time or historical).
10. For customer locations that cannot be reached (satisfied), it is also possible to calculate the reasons why they cannot be reached (satisfied).
HERE Tour Planning official website: https://developer.here.com/products/tour-planning
Now, let’s play with a free service provided by HERE: HERE WeGo Deliver
### HERE WeGo Deliver
[HERE WeGo Deliver](https://wegodeliver.here.com/) is a service that combines the map function and the function of HERE Tour Planning. Simply put, this tool provides small businesses with the power of HERE Tour Planning. Function, any business can use this service to manage their own fleet.
This service is free until the end of 2020, so we will try it now.
First, please open this URL: https://wegodeliver.here.com/

When it is turned on for the first time, there will be some simple explanations on the left side of the screen. HERE also provides a two-minute explanation video to introduce [HERE WeGo Deliver](https://wegodeliver.here.com/) Features:
<iframe width="560" height="315" src="https://www.youtube.com/embed/I-1cSeZ7A8w?controls=0" frameborder="0" allow="accelerometer; autoplay; clipboard-write ; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>

Let’s go back to the interface of [HERE WeGo Deliver](https://wegodeliver.here.com/). On the left side of the screen, you can press the right arrow to watch a brief description.

Then click "Start planning" to experience.

If the browser asks if you want to know your location information, you can choose whether to allow it according to your needs. Here we will allow it first, so that the map will move to your location, which is more convenient to operate.

Then the map will move to your location, you can click "Accept cookies" or "Decline" to choose whether to accept cookies.
The interface used is quite simple, first enter the company name and location, and then set up your fleet. The fleet can be the simplest single vehicle setting (no other detailed parameters are set), or multiple vehicles can be set, up to 100 vehicles. After determining the number of vehicles, please also set the capacity of each vehicle, whether to return to the company after the task, and set working hours. The default "Full Day" is from 8 am to 6 pm. It can also be modified manually.

Let us first set the company name and location to "Taipei 101" and set "5" cars, the unit capacity of each car is "10", and use the default "Full Day" time. Then press "Next".

The second step is to set up an order. Here are three ways to enter order information:
One: Import using CSV file. A template is also provided here, let’s download it first and take a look:

After clicking "DOWNLOAD", a form named "here-wego-deliver-template.csv" will be downloaded, and we can use Excel or OpenOffice Calc or any text editor to open it. The following is a demonstration of opening with OpenOffice Calc.
The text encoding of this csv file is UTF-8 and separated by commas.

After opening, you can see several fields:
* Order ID: Order number (freely defined)
* Name: Customer name (freely defined)
* Phone: customer phone number (freely defined)
* Email: customer email address (freely defined)
* Address: Customer address (this part will be converted into latitude and longitude during the calculation process, please confirm its correctness)
* Order Notes: order notes (any text prompt)
* Start Time: Customer opening time-starting point
* End Time: Customer opening time-end
* Service time (min): client operating time (refers to the time it takes for the driver to receive or send a package at the client, in minutes)
* Demand: Capacity demand (this part will be related to the vehicle capacity you set. If the customer's capacity demand exceeds the vehicle capacity, it may not be able to receive the shipment.)
※ Please note: During the process, the vehicle may have other goods to be delivered or just received, so this part will also be included in the calculation.
You can directly fill in the order information in this format and upload it to [HERE WeGo Deliver](https://wegodeliver.here.com/).

However, we will upload it directly without modifying it. Drag this file in directly, the system will read this file after dragging in, and convert the address into latitude and longitude, and then display it on the map.
Because it is a preset template by the system, the location is also randomly selected, basically just around the place you set for the departure point.

You can also try to modify the content of the template. I will randomly fill in the addresses of several [KFC](https://www1.kfcclub.com.tw/tw/ShopSearch) in Taipei, and then upload them.

After uploading, the results will be displayed on the map:

The order information we just entered will also appear on the left of the screen. After confirming that it is correct, please click "Plan Tour" below

After a few seconds, the planning results will be displayed on the map! On the left side of the screen, "VEHICLES USED" will display the number of vehicles needed. Here we have previously entered five vehicles, but according to the planning result, only two vehicles can complete all orders. "ASSIGNED ORDERS" shows that there are a total of 11 orders, and all of them can be completed.

Below you can also click on the planning results of these two vehicles to view the entire delivery or pickup route. For example, this is the route of the first vehicle:

This is the route of the second car:

Click on each destination on the map, and the estimated time of arrival and departure will also appear:

Click on the eye symbol of each car to view the details of the route:

Click the arrow symbol on the right in the route details to open a HERE WeGo web version of the path plan:

In addition, click the PDF button above, and a text version of the itinerary plan will be downloaded with a QR Code next to it. If you have installed the mobile version of the HERE Wego App, the App will be opened for route planning.
(However, the Chinese address display of this PDF may be problematic.)

Use iPhone to scan QR Code to open HERE Wego App to plan the path:

In addition to using the CSV upload method, you can also enter manually one by one:

You can also click "Demo" to let the system randomly select a destination, which is similar to generating a CSV template:

The above is the introduction of [HERE WeGo Deliver](https://wegodeliver.here.com/). Of course, you can also directly use the API to put the functions of Tour Planning into your system or service.
For example: https://aquawill.github.io/tour_planning_demo/tour_planning_demo.html is an example of implementing HERE Tour Planning. This example presents the results of vehicle list input, customer list input, cost calculation and route optimization. The total calculated quantity is 10 vehicles corresponding to 160 customer locations.
* Vehicle list: https://github.com/aquawill/tour_planning_demo/blob/master/fleet.csv

* Customer list: https://github.com/aquawill/tour_planning_demo/blob/master/destinations.csv

HERE Tour Planning can calculate your fleet operating costs, as well as total driving mileage, total driving time, and even rest time according to the cost parameters you enter. You can refer to the parameters in the vehicle list as follows:
* cost_distance: cost per meter (usually fuel cost and vehicle wear cost)
* cost_time: cost per second (usually the cost of vehicle wear)
* cost_fixed: fixed cost (usually staff salary, management expenses)
* shift_start: work time (00:00:00Z represents eight o'clock in the morning Taiwan time)
* shift_end: off-duty time (09:00:00Z represents 5:00 pm Taiwan time)
* break_start: start break time
* break_end: end break time
* break_duration: total break time
* capacity_mass: vehicle load
* capacity_size: cargo volume limit
* shift_time: shift time (seconds)
* amount: the number of vehicles
So we can know that there are two vehicles (ISUZU_NLR and MITSUBISHI_CANTER) in the fleet, five each. The vehicle operating cost planned this time is calculated as follows:
Total cost: 37530.86299999998 NTD
Total mileage: 2,160,221 meters
Total time spent: 277840 seconds
Driving time: 190840 seconds
Operation time: 51000 seconds
Waiting time: 0 seconds
Rest time: 36000 seconds

Each location will have its own estimated time of arrival and departure, vehicle number, etc.

As for places that are out of reach, reasons why they are out of reach will also be returned.

You can refer to the route, sequence and estimated arrival/departure time of each vehicle on the map. For example, the route sequence of the first car is:
```
0 --> departure/None/[24.970504, 121.2516]
1 --> c000133/KFC-Taipei Nangang Restaurant/[25.05579, 121.61395]
2 --> c000090/KFC-Keelung Zhong Er Restaurant/[25.12979, 121.74067]
3 --> c000046/KFC-Keelung Renyi Restaurant/[25.12789, 121.75095]
4 --> c000127/KFC-Shilin Wenchang Restaurant/[25.09447, 121.5223]
5 --> c000039/KFC-Taipei Shilin Restaurant/[25.0873, 121.5259]
6 --> c000148/KFC-Tianmu Zhongshan Restaurant/[25.11824, 121.53014]
7 --> c000098/KFC-Taipei Tianmu Restaurant/[25.11811, 121.53084]
8 --> c000130/Kfc KFC/[25.11456, 121.51752]
9 --> c000008/KFC-Taipei Shipai Restaurant/[25.11494, 121.51556]
10 --> c000057/KFC-Beitou Guangming Restaurant/[25.13673, 121.50431]
11 --> c000066/KFC-Nankan Zhongzheng Restaurant/[25.04407, 121.29408]
11 --> break/None/[25.04407, 121.29408]
12 --> c000059/KFC-Taoyuan Taimao Restaurant/[25.05292, 121.28768]
13 --> c000060/KFC-Linkou Fuxing Restaurant/[25.05909, 121.36743]
14 --> c000135/KFC-Taoyuan Dayuan Restaurant/[25.06246, 121.20148]
15 --> arrival/None/[24.970504, 121.2516]
```
As you can see, even the rest place (KFC-Nankan Zhongzheng Restaurant) has been planned, so in addition to planning the best sequence and saving costs, it can also meet the requirements of laws and regulations.
The above is the introduction of HERE Tour Planning.