Download as pdf or txt
Download as pdf or txt
You are on page 1of 21

FINAL CASE STUDY

By Roberto Aguilar (A00571820), Sebastián Anaya (A01025398),


Alejandro Bautista (A01422539), Alan Galán (A01655268)

Design and Improvement of Logistic Systems


Professor Eduardo Bastida
Tecnológico de Monterrey
Campus Santa Fe
Aug. 1st, 2021
Index

Introduction 2

Genetic algorithm video 2

Solution example 3

Code comparison 10

Genetic algorithm code 12

Ant colony code 15

Final remarks 17

Recommendations 17

Conclusion 18

Evidence of teamwork 19

References 20

1
Introduction
There are plenty of problems for which optimal solutions can be found through
particular algorithms. However, there are some problems that because of their difficulty or
considerations can’t be solved using these methods. For such situations, there are
alternative methods that have been developed to adapt to these types of problems and allow
them to be solved, known as heuristics.
“An heuristic method is a procedure that attempts to find a feasible solution that is
very good, although not necessarily the optimal solution” (Hillier and Lieberman, 2010). This
means that the certainty of the obtained solution cannot be assured, although it is very likely
that the optimal solution is not too far away from said value. “A metaheuristic is a general
solution method that provides a general structure and strategic criteria to develop a specific
heuristic model that adjusts to a particular type of problem” (Hillier and Lieberman, 2010).
Previously, a heuristic method had to be developed to adjust to every problem under
consideration when there was no algorithm available to find an optimal solution.
This report centers around the genetic algorithm metaheuristic and the travelling
salesman problem (TSP). Firstly, through a video the metaheuristic is explained in general
terms regarding how it works and what are its most important characteristics. Then, a step
by step solution to a small TSP problem is presented in order to better understand how it
works and its application in a real life situation. Finally, a bigger problem is solved using a set
of data provided with coordinates of a certain number of clients that must be visited, parting
from an initial position (depot) before returning to it.
This solution to this problem is presented with the use of the genetic algorithm and
the ant colony metaheuristic. The objective of such is to compare the results obtained from
each in order to determine which gave the best solution. Finally, parting from this concept, a
set of recommendations for Heineken about how they could improve their distribution of
beers in Mexico City is presented at the end of this report.

Genetic algorithm video


The link shown below corresponds to the video in which the genetic algorithm is
presented. In such video, this metaheuristic is explained regarding how it works, what are its
main characteristics and particular elements, as well as the parameters that can be
controlled when working with it.

Link to video: https://youtu.be/Nq31zdZrY6o

2
Solution example
The following is a step by step solution of a small problem using the genetic algorithm
metaheuristic. The problem shown has 7 nodes and the distances from one to another are
as shown in Figure 1.

Figure [1]. Euclidean distance matrix of the problem

The model starts by feeding the data. This occurs in two places within the code.The first one
shown in Figure [1]. The Figure [2] shows the group coordinates set in the code. This
method creates the graphs of each method.

Figure [2]. The group of coordinates set in the code

Figure [3]. Part of the code in which the latitudes and longitudes are set

As shown in Figure 3, input the title of each coordinate next to the list of latitudes(j) and
another with the longitudes(k). The first part of the code creates the Euclidean distance
matrix. The lines of code that create the distance matrix are shown in the following image.

3
Random solutions

Figure [4]. First part of the code

Figure [5]. First part of the code

The code presented below creates the fitness function, this allows the user to categorize the
best options. The code displays the top 10 solutions before it actually shows them.
You can appreciate the ranking below, the left side it has the number and on the right side it
has the total distance.

4
Figure [6]. Ranking and total distance

Subsequently, the selection of the solutions that are the most suitable for the basis of the
next generation. The code shown below defines the previous process.

Figure [7]. Selection of the most suitable solutions

The image that is presented below shows the set of the solutions that is going to be
implemented for next generations.

5
Figure [8]. Solutions for next generations

Figure [9], shows the lines of the code where the function of the crossover of solutions for
the creation of the next generation is declared.

Figure [9]. Crossover declaration part of the code

6
Figure [10] displays the second generation solutions created during the crossover of first
generation final solutions.

Figure [10]. Second generation solutions after crossover

In figure [11] we can appreciate the lines of code in which we declare the mutation function
for the creation of the next generation.

Figure [11]. Mutation declaration part of the code

7
Figure [12] shows the mutations realized during the algorithm.

Figure [12]. Mutations shown in code

The following lines of code are responsible for generating the following generation out-puts,
this include mutated and crossover solution;

Figure [13]. Generation out-puts

8
The following are the mix of solutions due to the crossover:

Figure [14]. Solutions after crossover

The figure [15] contains the line of code that corresponds to the function of “GA=Genetic
Algorithm”.

Figure [15]. Genetic algorithm declaration

The figure [16] shows the parameters of the algorithm:

Figure [16]. Parameters for genetic algorithm

9
The figure [17] shows the lines of code corresponding to the output variable once we run the
algorithm.

Figure [17]. Output variable part of the code

You can appreciate the values once we run the algorithm in the following lines,
Incipient distance/Good solution but not the best founded: 54.079519367237104
Eventual distance/Best solution founded: 52.15592519829276
Best Solution Route: [(0, 'Bangalore'), (1, 'Pune'), (2, 'Mumbai'), (3, 'Kashmir'), (4, 'Delhi'), (5,
'Lucknow'), (6, 'Patna’), (0, 'Bangalore')]

Code comparison
In this section of the report, two codes are presented through which the travelling salesman
problem (TSP) was solved using a set of data that was provided. The first is a genetic
algorithm code and the second is an ant colony code. Both were used to solve the instances
and provide a total travelled distance and the complete route from an initial position (depot)
to all the clients and back to the initial position (depot).
Considering that both are metaheuristic methods, a definitive optimal solution could
not be found, given that at most near approximations could be obtained. Thus, the solutions
obtained with each of them were compared in order to determine which metaheuristic
provided the best solution. This included the modification of the parameters of each in order
to observe the differences and attempt to obtain the best possible solution.
The data provided corresponded to clients in three different routes, each with a
different set of coordinates that had to be visited. Figs 18 through 20 show the coordinates
corresponding to each of the clients in the corresponding routes. The tables in Figs. 21
through 26 show the different results obtained while modifying the levels of the parameters
and registering the obtained distance travelled. The full spreadsheet can be visited by
clicking this link. In order to give more formality to the report, a sample graph for each set of

10
parameters was included in the last column of each table, but in a small size, which can be
made bigger by visiting the spreadsheet.

Fig [18]. Coordinates for clients in route labeled as “l410”

11
Fig [19]. Coordinates for clients in route labeled as “m310”

Fig [20]. Coordinates for clients in route labeled as “s410”

Genetic algorithm code


In order to carry out the application of the genetic algorithm metaheuristic on the following
link: https://colab.research.google.com/drive/1_7aYT9b1tQrT3i9nhlhZtOegFwUpvST8.
Having introduced the data provided, iterations were run for the coordinates shown in Figs.
18 through 20.
For each of the routes, the parameters that were modified to observe the impact on
the resulting average distance were the population size, the number of generations and the
mutation rate. For each one of them 5 different levels were set to observe the impact of
every particular parameter, whilst for the others a constant value was kept throughout all the
runs when it was not the one being measured. Moreover, for each iteration, 3 runs were
made in order to obtain different results from which an average and a standard deviation
could be calculated to better determine a reference according to the parameters’ levels.

12
Regarding the population size, it seems that as it increases, the average distance got
lower. The “l410” and the “m310” routes show this better than the s410 route. This might
have to do with the number of nodes because the first two have a relatively low number of
them, whilst the latter has a significantly bigger one. However, it’s also worth noting that as
the population size increases, so does the standard deviation, which may be an indicator
that more repetitions could be done in order to better determine the precision of the impact
of the population size on different amounts of nodes.
Finally, the number of generations and the mutation rate do affect the average
distance obtained, although not necessarily exponentially. In the “l410” and the “m310” route,
when this parameter increased, the average distance tended to increase and decrease
interruptidely. Thus, there was not a significant indicator as to how these parameters affect
the final result. Likewise happened with the standard deviation, with no clear indicator as if a
modification in these parameters contributed to it becoming better or worse. Perhaps the
only situation in which something could actually be observed, would be in the “s410”, given
that for this case, the average distance did decrease as the number of generations
increased. Interestingly, so did the standard deviation up to the third change in the
parameter (generations = 2000).

Fig [21]. Distance traveled in the l410 with modifications of the parameters

13
Fig [22]. Distance traveled in the m310 with modifications of the parameters

Fig [23]. Distance traveled in the s410 with modifications of the parameters

14
Ant colony code
To carry out the application of the Ant Colony code on the following link:
https://colab.research.google.com/drive/1buZmY0I6D-5twBHTBPYANZwWDsWxtmGD?auth
user=1#scrollTo=zMHcJ9Crimb4 . Having introduced the data provided, iterations were run
for the coordinates shown in Figs. 24 through 26.
The code was run a total of 15 times, changing the parameters as can be seen in the
figures below. The range of the parameters were obtained from a web page to use the most
common values ​of alpha and beta. The results obtained, helped to conclude that in ant
colony, the number of iterations doesn't vary much when there are a few nodes. The
parameters do not generate any changes in this case. In the first route, the parameter.
To see the impact of each parameter, what was done was to modify them with 3
different values ​and run it 3 times while the others remained constant so a proper analysis
was made. The route m310 was the one with less variation in the total distance results and
this can be due to less nodes than the others routes. While the others routes were the ones
with a more significant standard deviation, this means almost all the parameters had an
impact in the total distance.

Figure [24]. Distance traveled in the l410 with modifications of the parameters

15
Figure [25]. Distance traveled in the m310 with modifications of the parameters

Figure [26]. Distance traveled in the s410 with modifications of the parameters

16
Final remarks
As it was initially mentioned, the objective was to compare both metaheuristics to determine
through which a better result could be obtained when modifying its particular parameters.
According to the obtained results shown in Figs. 21 through 26, the ant colony metaheuristic
provides a better result (close to optimal) when the number of nodes is not so big. For the
“l410” and the “m310” routes, the average distances traveled and the best alternative were
better when running the ant colony, which was verified by having low variability, according to
the standard deviation.
However, the “s410” route resulted in a better overall average distance when running
the genetic algorithm. The difference was not only better but significant, considering that the
average distance with the genetic algorithm was almost 10 distance units lower. The only
uncertainty about this observation could be that as much as they may be the case, the
variability does prove to be higher. This may be worth considering in order to determine if the
modified parameters actually had an impact on that result or what happened between the
methods that caused such a great difference between one another.
As a proposal to better study and compare these metaheuristics, a design of
experiments could be very suitable for this case. The downside of it, however, is that it would
most likely be highly time consuming given the number of combinations that should be run in
order to obtain a precise and trustworthy result, considering the number of parameters and
the levels of each one of them. However, in case it can be done, a 2k-1 design could very well
be suitable to better compare and evaluate each of these metaheuristics.

Recommendations
The following is a set of recommendations addressed to Heineken regarding ways in which
they could improve the distribution of beer to clients in Mexico City.
It is fundamental to have clear what to have and what not to have in the warehouse
to not exceed the capacity. It is important to make sure that when an order is placed, the
company has the product available in their warehouse. It is quite easy to increase sales but
it is useless if you do not maintain a good relationship with the consumers. So it is important
to maintain a good quality at all times. If the production is quite high and you fill your
warehouse with products for which you do not have a sure picture of the demand and future
sale of that inventory, you could have great economic losses.
Having that clear, one key element for Heineken, it would be to implement intense
courses or bootcamps for their logistic employees so they could be developers using

17
programming languages, some of which are the most accurate for business analytics and
business logistics.
Another alternative would be to make usage of logistics and supply chain softwares
that are very user friendly and facilitate the work that is made through different methods and
programming languages. An example would be the software “Supply Chain Guru”, which
allows to input data from clients including coordinates, demand, available vehicles, operating
times, amongst many other factors into already existing formats and templates so that all
that users have to do is run the program and wait for the optimal solutions to be obtained.
Any of these solutions could be considered viable considering that depending on the
expertise level of the users on technology and coding, either a programming language that
suits the user’s particular needs can be used, or a more generalized one which also
facilitates the tasks with high levels of quality.

Conclusion
There is a huge impact in logistics in any company. Nowadays logistics lies in the fact
of being able to supply raw materials, products in process, and finished goods in a short and
efficient period of time. As engineers, it is essential to know and be able to optimize logistics
to reduce costs. In addition to being an extremely interesting area, it is an area of ​incredible
demand. Through this case study it is possible for us as students to obtain tools and context
for our future as engineers and entrepreneurs. This project is closely related to multiple
areas of the career, since industrial engineers must seek to promote the best logistic
operation possible, by reducing costs. Finally, this project taught us that the tools learned
throughout my career can be applied for professional innovation.

18
Evidence of teamwork

Figure [27]. WhatsApp Group used for communication between team members

Figure [28]. Zoom meeting to work on the different stages and requirements of the case
study and the report

19
References
Ant colony Algorithm notes - Programmer Sought. (2021). from
https://www.programmersought.com/article/71507191031/.

Bastida, E. & Núñez Rodrigo. (nd). Ruteo de última milla. Retrieved July 27th from:
https://colab.research.google.com/drive/176UyAu1TGoUKhWsSTtLChnnKWWSVdk
Y-

Hillier, F. S., & Lieberman, G. J. (2010). Introducción a la investigación de operaciones. (9th


ed.). McGraw-Hill.

IIT Kharagpur. (2018). Lecture 32: Genetic Algorithms. Retrieved July 27, 2021 from:
https://www.youtube.com/watch?v=ep3hLUDM7uA&t=0s

MindMachineTV. (2017). ¿Qué és un algoritmo genético? Retrieved July 27, 2021 from:
https://www.youtube.com/watch?v=Bhme3i8jHpU&t=0s

Paritosh3006. (2019). Travelling - SalesMan - Problem - Using - Genetic - Algorithm.


Retrieved July 29, 2021 from:
https://github.com/paritosh3006/Travelling-SalesMan-Problem-Using-Genetic-Algorith
m

Prasad Malakar, G. (2021). Introduction to Genetic Algorithm n application on Traveling


Sales Man Problem (TSP). Retrieved July 27, 2021 from:
https://www.youtube.com/watch?v=3GAfjE_ChRI

20

You might also like