You are on page 1of 11

Skip to content

BUDHI'S NOTES
 Twitter
 
 Linkedin
 
 WordPress
Sidebar









PART II – SOLVING VEHICLE ROUTING


PROBLEM WITH EXCEL
March 13, 2016BudhiExcel, Logistics, Optimization, solver, Spreadsheet, supply chain, Tutorial, Vehicle Routing
 
 
 
 
 
 
11 Votes

“The vehicle routing problem lies at the heart of distribution


management.” – JF Cordeau
This post is part of logistics planning series. In the first part, we have discussed about facility
location problem where we learned about strategic planning in designing logistics network. After
selecting the best facility location, the next challenge in network optimization is to determine the
best routes to serve all customers from that location.This kind of problem is called vehicle
routing problem (VRP).

VRP is a classical problem which consist of determining the best routes for vehicles to visit and
serve a set of customers from specific location. Company like UPS and FedEx use VRP analysis
in daily basis for delivering parcel to their customers. Solving VRP to optimal solution is
difficult, since it is a NP-hard problem. Thus many commercial software tend to use heuristics
method to solve the problem for efficiency reason. In this post we are going to solve VRP by
maximizing the power of Excel. Let consider the following case:
Rahman  is a distribution planner in company XYZ. Every morning, he collects processed
customer orders from the past day and make a delivery plan to the customers. His task is to
determine efficient routes for truck drives to deliver packages from company depot to a set of
customers. He noticed that every trucks can only carry up to 400 packages and the average
customer demand is about 70 packages per day. It means that every truck can only serve 5 to 6
customers in a single route. With about 20 locations scattered across the region, Rahman gets
overwhelmed to perform the routing process manually. He asked you to help him with a better
planning process. He has mapped out his customer locations in a cartesian diagram and collect
the customer demand information as shown in figure and table below. Now he needs your
assistance to determine the best routes for the trucks. By assuming euclidean distance with road
factor 1, can you assist Rahman with the problem?
Like what we did with the facility location problem,  the first step to solve this problem in is to
design an Excel model which allow us to automatically evaluate solution quality by arbitrary
changing its decision variables. In VRP, the decision variables are a set of non-repetitive
numbers representing the sequence of customer locations to be visited by the trucks. So if I set
the decision variable as 6-7-5-15, the model should be able to return the total distance to visit
customer 6, 7, 5, and 15 in order sequence.
Besides, the model should also be able to consider that the trucks always start the route from
depot and also ends at the depot. So whenever a dispatched truck has reached its capacity limit, it
should return back to the depot. This means when I set the route as 6-5-7-15-1, the model should
be able to calculate the cumulative load and automatically insert a depot in between the schedule.

Considering the specified requirements, I set up a model in Excel as figure below. The


“Sequence” column showing the order of sequence for all customers. The “Cust-ID” column is
the decision variables representing the customer location for each sequence. The “Route-ID”
column shows the assigned route for every customer. The “Cml-Load” indicates the cumulative
customer demand for each route. Note that whenever the cumulative load about to reach the
truck capacity limit, the model automatically creates a new routes ID for the next customer. The
“Distance” column shows the distance between two adjacent locations. When a new route starts
or ends, it also takes into account the additional distance from and to the depot.
After setting up the Excel model, the second step is to to transfer the model into Solver to solve
the problem. To do this, you need to load Solver interface and type in the objective function and
decision variables cells based on the model into the form. Do not forget to set the decision
variables constraint as “integer” and “all different.” Thick the non-negative variables option and
select “evolutionary” as the solving method. Hits the “Solve” button and within minutes you
should be able to see solution proposed by Solver.
If you plot the solver solution into a scatter diagram, you will notice that the Solver’s solution for
VRP problem tend to be poor. The final routes often looks messy and counter-intuitive. But it
can be understood, since VRP is a difficult and complex problem; applying Solver directly to
the problem will less likely give a good solution. Therefore, we need to simplify the problem by
dividing it into smaller sub-problems. In this case, we are going to follow “cluster-first, route-
second” algorithm. The idea is to divide the customers into a set of clusters and then refine
its route sequence as sub-problems by using Solver.
STAGE 1: CLUSTERING CUSTOMERS
The easiest way to cluster the customers is to sweep the customer locaton in radial way with the
depot serving as a central point (see figure below). To do this, you can take an straight line from
arbitrary angle and sweep the customers locations in clockwise or counter-clockwise direction.
Assign every swept customers into the same route cluster until the truck cannot serves the next
customer demand due to its capacity limit.
I implemented the sweeping method in Excel as shown in figure below. The first step to do is to
convert the x-y coordinate into a polar radian location. The polar radian shows the
customer position in a degree relative to the depot location. You can do the conversion  by
using ATAN2 and DEGREE function in Excel. Let define Theta as customer location in degree,
thus:
Theta = MOD(DEGREE(ATAN2(Xcustomer-Xdepot, Ycustomer-Ydepot)), 360)

After converting the x-y coordinate into degree, the second step is to start the sweeping process
by sorting the theta in sequence. You may use RANK formula to perform this task or you can
also simply sort the column in ascending manner. If you implement this step correctly, you will
get a set of clustered customers as depicted in figure below. (Tips: you can improve the solution
by finding the best angle to start sweeping the customer location)
Now our problem has been divided into a set of clusters which we can treat as sub-problems.
This sub-problems are smaller and less complex than the complete problem. Thus, Solver should
be able to refine the route sequence for each cluster to improve the total solution quality.

STAGE 2: REFINING ROUTE SEQUENCE


In this stage, we will divide the big model into a number of sub-model representing each vehicle
routes. What you need to do is to segregate the model based on the Route-ID. See below figure:
The next step is to apply Solver to refine the solution for each routes. You can perform the
optimization at once, by selecting multiple decision variables in each route (tips: hold
the shift key when selecting the cells). The optimization procedure is the same as the previous
one. You transfer the objective function and all decision variables to Solver, set the constraint as
“integer” and “all different“, thick the Non-Negative Variable option, select the “evolutionary”
method, and hits the button. Voila, within seconds, Excel should be able to provide you with the
improved solution. Figure below depicts the comparison before and after the route optimization
with Solver.
As you can see from the figure above there are some improvement in the routes. Solver was able
to refine the solution quality for about 5% or about 139 km less than the initial solution. You
may see that the improvement in this case was not that significant. However the impact of route
refinement will vary from case to case. One thing that obvious is that the clustering stage plays
important role to solution quality. A better cluster will lead to a better solution. Nevertheless, the
best way to evaluate the solution is still by visualizing it. Human typically can spot potential
improvement quickly just by looking at the graph.

By setting up a model, now we can back to Rahman and assist him with a better planning
process. Since Rahman will perform this kind of task frequently with different customer size in
daily basis, you may also advice him to use only the sweep algorithm (stage 1) to speed up the
process. The model setup for the sweep algorithm is flexible enough to be expanded if necessary.
However you also need remind him that, like other NP-hard problem, the solution quality
resulted from such heuristics method will fall rapidly with the increase of problem size. If the
saving resulted from routing optimization is quite significant, you may also want to encourage
Rahman to speak with his manager to buy a dedicated software to support him performing
his task in daily basis.

***

I hope you enjoy the case. Any questions and remark, please leave it in the comment. I am more
than happy to answer. If you like this kind of post, you may also want to visit my other post
on logistics planning series. Thank you for reading.
Next Post: Minimizing empty container flows in logistics network.
Advertisements
SHARE THIS:

 Print
 LinkedIn
 Facebook
 Twitter

Part II – Solving Vehicle Routing Problem with Excel

POST NAVIGATION
← Part I – Optimizing Logistics Network with Excel
Part III – Minimizing Empty Container Flows with Excel →
10 THOUGHTS ON “PART II – SOLVING VEHICLE
ROUTING PROBLEM WITH EXCEL”
1. PETER SAYS:
 

Could you provide the formulas for the first excel model?

September 11, 2016 at 04:22 Reply


1. BUDHI SAYS:
 

Can you be more specific? Which formula do you need?

September 15, 2016 at 19:37 Reply


2. PETER SAYS:
 

Can you show the formula for distance calculations?

September 11, 2016 at 20:18 Reply


1. BUDHI SAYS:
 

Hi Peter, I use the sum of euclidean distance between customer location. The customer
location is determined by x and y as in cartesian diagram. For instance, the distance between
customer 1 and 2 can be formulated as follow: distance((x1, y1), (x2, y2)) = √(x1 – x2)² + (y1
– y2)². Hope this helps.

September 15, 2016 at 19:36 Reply


3. DOULFIKAR SHORAHBIL SAYS:
 

Salam, Thank you for sharing, thus it helped me a lot in my final project , however I copied same settings and
even data from your first and second part, i’m getting different wrong results , in the first part I got the long
number not int, something like: 3.56240364423134E+29
the second I cannot set the solver constraints right
could you please help or if you could share the spreadsheet
appreciate your valuable support .
Salam,

September 23, 2016 at 15:25 Reply


1. BUDHI SAYS:
 

Hi doulfikar, recently I got more and more case-specific questions like yours… So I am
considering to open the spreadsheet to public. I will announce it soon.

October 26, 2016 at 12:59 Reply


4. SEOULTECHKIM SAYS:
 

Would you show me how to make clustering graph by excel? I tried to make graph to show the location of but
i don’t know how to show the route on the graph…

October 25, 2016 at 17:40 Reply


1. BUDHI SAYS:
 
Hi Kim, it is easy. First you need to specify each city location with x-y coordinate. For
example xy coordinate for city A is (25, 43). Then you need to create a scatter chart based on
that list of location. Please make sure that the city location is in order as in the route. By using
scatter chart tools, Excel will automatically create the points and lines for you. There is a nice
tutorial with scatter chart that you can read here: https://support.office.com/en-
us/article/Present-your-data-in-a-scatter-chart-or-a-line-chart-4570a80f-599a-4d6b-a155-
104a9018b86e
October 26, 2016 at 13:10 Reply
5. SEOULTECHKIM SAYS:
 

Would you please let me know how to draw clustering graph? I don’t know how to make it.

October 25, 2016 at 18:26 Reply


6. AHMAD SAYS:
 

Hi Pak Budi.
Pak apa boleh di share untuk setting detail solvernya seperti apa ya Pak ?
Objectivenya
Changing variablenya
Constraints
Terima kasih banyak pak

November 3, 2016 at 13:32 Reply


LEAVE A REPLY
BLOG AT WORDPRESS.COM.

You might also like