SlideShare a Scribd company logo
ME8107
Artificial Intelligence for Mechanical Engineers
Prof. Vincent Chan
Project Report
Xuming Gao
500420541
Nov 26, 2014
2
Table of Contents
1. Introduction 3
2. State of the Problem 5
3. Literature Review 6
4. Solve by GA 8
5. Conclusion 14
6. Reference 15
7. Appendix 16
3
Introduction
In many fields, looking for a shortest path is a need in order to achieve time and
economic efficient. To an international company, a well-organized shipping plan
means more cargoes could be shipped to their destination with the same amount of
time, or the same amount of goods reaches their purchasers in a shorter time. To a
family, a carefully designed travelling plan could be considered cheaper in cost on
transportation or having time to visit more places, resulting a more enjoyable journey.
Path planning is not new, and there are many experts from different fields solved
this problem with very smart methods. Strangely, humans are never satisfied with
their current status. Therefore, more elites have been joining in the study of the path
planning problem, and more and more systems have been developed to solve the path
planning problem more efficiently with better solutions.
Genetic algorithm is one of the artificial algorithms that have been developed to
solve not only the mathematical problem, but also other engineering and/or scientific
problems such as path planning problem. The genetic algorithm is based on Charles
Darwin’s biological theory of evolution in the mid-19th century (Hillier, Frederick S.
and Lieberman, Gerald J., 2005). Features are depended based on genes, and
chromosomes are carrying all genes that an object has. Two chromosome pairs a
group of parents when it happens to create the next generation, and some part
chromosomes, which is genius, will be passed from parents to children. Children
having better genes will have a higher chance to survive and become parents and pass
on genes. There is also a chance that a mutation happens. Most mutation causes
4
disadvantage or no effect; however, sometimes a mutation give a better feature to fit
the environment, which means a higher chance to survive. The entire process happens
randomly; as a result, the next generation is not guaranteed to be better than the
current generation, but always children with more suitable features survive. Similar to
the biological evolution theory, genetic algorithm contains randomly happening
crossover, mutation, and selection (select children with better features). Because of its
randomness, the local maxima and minima will be avoided; and this allows the
answer is closer to the real optical solution.
5
State of the Problem
There is a new couple are planning where to spend their honeymoons. They came
across an idea that spend their days to visit Europe. They found a travel agency to
plan a trip for them so that they do not spend too much money on the travelling.
During the travel planner was trying to design a trip for the new couple, there is an
unexpectable system shutdown at him. After he reboot his computer, he found that the
must-visit countries that the couple mentioned were lost.; and he also could not recall
the must-visit countries as well as the starting country and ending country. Because
the flight-ticket are already booked, the first country and last country to visit cannot
be changed due to they would not like to pay for the cancellation fee; but the order of
the rest visiting countries are not important to them. No one country is planned to visit
twice. Because the deadline to deliver the travelling plan is almost due and the planer
cannot reach the couple with any method, he has no time to wait for contact them
again. Therefore, he decided to write a program with a graphical user interface which
allows the couple to select all the countries that they want to visit including the
starting and ending country. As return, the best travel plan will be shown to them.
6
Literature Review
The travelling salesman problem (TSP) is a classic example of path planning. The
travelling salesman provides an optimal (shortest) path of the traveler to cover all
stated places. There is no specific starting or ending point. The traveler could start in
any place, but must return to the same place at the end of the journey. Except the
starting place (also the ending place), there is no other place can be visited more than
once. There is no limit on the sequence of the place to be visited. The next places can
be chosen from any remaining (has-not-been-visited) places. The distance between
any of the two places are known.
One of the popular method is solving TSP by simulated annealing. This
arithmetic is simulating annealing process in metallurgy. The entire process of
annealing includes heating and slow cooling stages. Temperature is an important
variable in simulated annealing algorithm, and temperature is usually manually set
high to enlarge the searching area in order to find the most optimal solution. The
internal energy is calculated at this temperature and recorded. Then, the cooling
process starts. With slowly decreasing temperature, internal energy is calculated at
each temperature and then comparing with the current minimum energy. The
minimum energy updates itself during each iteration. If energy at new temperature is
lower, the minimum energy gets updates; if the new temperature is higher, by
predefined possibility, it will choose either update or eject the new value. Either
iteration reaches its predefined number or the minimum energy decreases below the
desired energy threshold, the program will stopped. [2]
7
There are two major problems in simulated annealing method. One is being the
initial temperature setup. If the temperature is set high, there is higher chance to
acquire the most optimal solution but taking longer computing time; or with
reasonable low temperature, it might not find the most optimal solution but saving
computational cost. Another major problem is rate of decreasing temperature. It
always needs several times experiments to determine a suitable cooling rate. [3, 4]
Overall, TSP problem could be solved by using simulated annealing algorithm,
and it gives better optimal solution than by greedy method [4].
Another method is done by ant colony optimization algorithm. This algorithm
simulates the ant finding shortest path to its colony during foraging. Ant returns
colony the earliest it chose the shortest path, and pheromone is left on the path earliest.
Following ants will select this path due to higher pheromone intensity, and this path
will be reinforced to attract more ants. Eventually, the longer paths will be abandoned.
Ant colony algorithm is a good candidate when dealing with problems such as
travelling salesman problem and 0-1 knapsack problem although computation cost is
relatively high. [5-9]
8
Solve by GA
The real European map is used with manually marked European countries as
shown in Figure 1. Each black spot represents a country.
Figure 1 Marked European Country
In order to acquire the relative position of all the spotted countries on the map,
MatLab image toolbox is utilized to convince. First, the image is converted to a gray
scale image from a regular RGB image, the gray image can be seen in figure 2. Then,
the grayscale image is being further processed to be a binary image with threshold
0.99 as shown in figure 3. A matrix of x- y- coordinates of black spots are acquired,
and the distance between any two countries could be calculated based on x- y-
coordinates.
9
Figure 2 Gray Scale Image
Figure 3 Binary Image with threshold 0.99
10
Figure 4 Centroid to acquire x-y coordinates
Once all the countries’ coordinates are acquired, all data is transferred to an excel
file along with the corresponding country name to store the original data. In this excel
file, the numerical index (1, 2, 3…) can be used to index country name and
coordinate.
With the selection of user, all parameters are written to variables and these
variables are corresponding parameters in the genetic algorithm.
Starting country and ending country are passed on separately from must-visit
countries since starting and ending country are fixed variables once the user select and
the program is started. The coordinate and name of starting country and ending
country are pulled from the original data and written to four variables (start country
coordinate, start country name, end country coordinate, and end country name). User
selected must-visit countries are stored in a one-dimensional array, and there will be
no country index that the user did not select. Two new matrices are created by pulling
selected countries coordinates and name, one matrix (n by 2) stores coordinates and
11
the other one (n by 1) stores name (n is the number of country selected). Selected
countries’ coordinates and names have new indexes. With all the coordinates, distance
between any two selected countries are calculated and stored for later use.
And here, genetic algorithm starts.
Initiation
Firstly, population size, mutation rate are defined to be 20 and 1%, respectively.
The gene used is the index of the country, and the chromosome (parent) is a string of
country index. 20 parents are randomly generated.
Evaluation
The fitness function is applied to each parent to calculate the total distance of
travelling based on the order of country index in the parent. All the fitness values are
gathered. In this case, lower fitness value is better because lower fitness value means
shorter distance.
Grouping
The fitness value is sorted from low to high in a row, and only the top ten lowest
total distance will be kept and used in the next step. The parent in the i-th row is
paired with the parent in the (11-i)th row to form five groups in total. Each group of
parents creates four children to keep the population remains the same for the next
generation. Children are created after mate and mutation.
12
Mating
Two numbers are randomly generated: rand1 and rand2. Rand1 is responsable for
the selection of parent, and rand2 is for gene.
Parent 1: 0~0.4999
Parent 2: 0.5~0.9999
First Half Gene: 0~0.4999
Second Half Gene: 0.5~0.9999
If rand1 falls in the range of parent 1, then parent 1 is selected; otherwise parent 2
is selected. If rand2 falls in the first half gene’s range, then the first half gene is passed
on to the child; otherwise, the second half gene is passed on. For example,
rand1=0.2365 and rand2=0.9666, then the second half gene in parent 1 is passed on to
the child. The remaining gene of this child is selected from the other parent in the
group in the same order of this parent from available genes (numbers that have not
been appeared in the child).
Mutating
The rate of mutation is predefined as 1%. A link is chosen to be the place when
mutation happens. Whenever a mutation happens, the two numbers connected by the
link will be exchanged. If there are in total 12 selected must-visit countries, there will
be 12 numbers to represent each country and 11 links to connect all the numbers.
Therefore, for one child, there are 11 links that possibly a mutation happens. Similar
to select parent and gene, random numbers are generated to decide where the mutation
happens. 11 random numbers are created and any number is less than 0.01 (1%)
means mutation happens: switch two numbers connected by the corresponding link.
13
Once the mutation process is over, one iteration is done. Children become parents
and next iteration starts. The entire process is repeated from evaluation to mutation
until the maximum iteration is reached.
In every iteration, after sorting the fitness value, the shortest fitness value in this
iteration is compared with the global minimum: if global minimum is greater than this
fitness value, then, the global minimum is updated to this fitness value and the
corresponding path (index sequence is stored); if global minimum is smaller, then the
process continues. The global minimum is initially set to be positive infinity to ensure
it is bigger than any total travel distance of any possible travel sequence.
After maximum iteration is reached, distances from starting country to the first
index country in optimal solution and from the last index country to ending country
are calculated and then added onto global minimum. In addition, starting and ending
country names are inserted in the optimal solution sequence in the first and last place.
Updated string of names and global minimum are returned to the user. String of names
displays the best travel sequence, while the global minimum is showing the optimal
travel distance.
Output
The output of this program is the sequence of visiting country. The path can be
either seen in the MatLab workspace or in an Excel file that created by the program.
In addition, a path map will also be shown for convenience.
14
Conclusion
The genetic algorithm is quite suitable for traveling salesman problem. It is unlike
heuristic search which needs much computational cost. Although the genetic
algorithm method does not guarantee the best solution will be found, the result is
close enough to the best solution. It also has potential to get even closer to the best
answer. One method is adding more iterations. Because only the best results from
iteration will be kept, the solution gets closer and closer to its ultimate optimal
solution. So, by running more iterations, the answers become more optimal. Another
method is applying different mating method. This may cause improve the answer, but
also may decrease the performance. The mutation rate is another option to apply
change which may either advance or dis-advance the performance.
In conclusion, genetic algorithm suits problems that do not need the best solution,
but a good-enough solution. Path planning or travelling salesman problem is one of
the perfect example of genetic algorithm programming.
15
Reference
[1] Hillier, Frederick S. and Lieberman, Gerald J. (2005). Introduction of Operations
Research. Toronto; Boston: McGraw Hill.
[2] Corana, A., Marchesi, M., Martini, C., & Ridella, S. (1987). Minimizing multimodal
functions of continuous variables with the "simulated annealing" algorithm corrigenda
ACM Transactions on Mathematical Software (TOMS), 13(3), 262-280.
doi:10.1145/29380.29864
[3] Randelman, R. E., & Grest, G. S. (1986). N-city traveling salesman problem: Optimization
by simulated annealings. Journal of Statistical Physics, 45(5-6), 885-890.
doi:10.1007/BF01020579
[4] Ismail, Z., & Ibrahim, W. R. W. (2008). Traveling salesman approach for solving petrol
distribution using simulated annealing. American Journal of Applied Sciences, 5(11),
1543-1546. doi:10.3844/ajassp.2008.1543.1546
[5] Ellis, J. F. (2002). Ant colony optimization for approximate solutions to the traveling
salesman problem
[6] Dorigo, M., & Blum, C. (2005). Ant colony optimization theory: A survey. Theoretical
Computer Science, 344(2), 243-278. doi:10.1016/j.tcs.2005.05.020
[7] Dorigo, M., Dorigo, M., Birattari, M., Birattari, M., Stutzle, T., & Stutzle, T. (2006). Ant
colony optimization. IEEE Computational Intelligence Magazine, 1(4), 28-39.
doi:10.1109/MCI.2006.329691
[8] Chaharsooghi, S. K., Chaharsooghi, S. K., Meimand Kermani, A. H., & Meimand
Kermani, A. H. (2008). An intelligent multi-colony multi-objective ant colony
optimization (ACO) for the 0-1 knapsack problem. 1195-1202.
doi:10.1109/CEC.2008.4630948
[9] Ke, L., Feng, Z., Ren, Z., & Wei, X. (2010). An ant colony optimization approach for the
multidimensional knapsack problem. Journal of Heuristics, 16(1), 65-83.
doi:10.1007/s10732-008-9087-x
16
Appendix
Figure 5 Image Processing Code
17
Country Coordinates and Name Data (Unit: pixels)
X-coordinate Y-Coordinate Country
98 915 Portugal
100 1134 Morocco
195 936 Spain
202 150 Iceland
218 549 Ireland
320 1121 Algeria
328 556 UK
377 775 France
435 685 Belgium
453 636 Netherlands
492 1133 Tunisia
496 795 Switzerland
538 513 Denmark
545 653 Germany
558 350 Norway
565 911 Italy
627 764 Austria
627 831 Slovenia
634 700 Czech Republic
657 265 Sweden
669 843 Croatia
706 898 Bosnia and Herzegovina
717 629 Poland
718 728 Slovakia
739 783 Hungary
758 996 Albania
763 879 Serbia
792 962 Macedonia
798 541 Lithuania
803 242 Finland
801 1008 Greece
810 430 Estonia
826 489 Latvia
835 806 Romania
867 898 Bulgaria
878 558 Belarus
956 683 Ukraine
1009 326 Russia
18
Graphical User Interface
Figure 6 User Interface before Selection
Figure 7 User Interface with An Example Selection
19
Program Output
Figure 8 Output to Workspace (Left) and to Excel File (Right)
Figure 9 Path Plan Graphical Result (Green dot is starting country, and blue is end country)
20
Instruction of running the MatLab code
1. Download all the files including “data.xlsx”, “search,m”, “userfront.fig”,
“userfront.m”, and “ImageProcessing.m” and save under the same folder.
Copy the folder directory.
2. Start MatLab program
3. Open “search.m” file and replaced directory in xlsread command with
the directory just copied, and then save and close “search.m” file.
4. Open “userfront.m” and click run.
5. Choosing start and end country on user interface as well as the must-visit
country section.
6. Click on “start” to run.
7. Once the program finished, the result can be reviewed either on
workspace or in the excel file named “path.xls”.
Note:
 Every time the program is opened, the user interface needs to be
“activated”. To do this, click on drop down menus and select any
countries to both starting and ending country, and check all the check box
followed by clicking the “start” button. Once the first run is done, the
following running does not require this step.
 After each running, created “guidata.xls” and “path.xls” are necessary to
deleted or moved to another folder in order to run the program
functionally.

More Related Content

Viewers also liked

Actividad 8 walter garcia
Actividad 8 walter garciaActividad 8 walter garcia
Actividad 8 walter garcia
Walter Garcia
 
Project Selection1
Project Selection1Project Selection1
Project Selection1
ricki burrows
 
Ajay Chavan CV
Ajay Chavan CVAjay Chavan CV
Ajay Chavan CV
Ajay Chavan
 
Rinchen_CV
Rinchen_CVRinchen_CV
Rinchen_CV
Rinchen Dorji
 
Facebook effect
Facebook effectFacebook effect
Facebook effect
LYKEIO KANALION
 
A^2_Poster
A^2_PosterA^2_Poster
A^2_Poster
avaninith
 
Application activity
Application activityApplication activity
Application activity
Nathy Martinez
 
Monica cabal actividad1 mapa_c.pdf
Monica cabal actividad1 mapa_c.pdfMonica cabal actividad1 mapa_c.pdf
Monica cabal actividad1 mapa_c.pdf
Monik291971
 
Sulma niño actividad1_mapa_c
Sulma niño actividad1_mapa_cSulma niño actividad1_mapa_c
Sulma niño actividad1_mapa_csulmanino
 
Mapa gerencia de proyectos
Mapa gerencia de proyectosMapa gerencia de proyectos
Mapa gerencia de proyectos
46451052
 
OSV-El Mundo 23 Febrero 2007
OSV-El Mundo 23 Febrero 2007OSV-El Mundo 23 Febrero 2007
OSV-El Mundo 23 Febrero 2007
Jorge Bern
 
Tools for teaching&learning..
Tools for teaching&learning..Tools for teaching&learning..
Tools for teaching&learning..
Putera Sampoerna Foundation
 
Ejemplos de funcionalidad de los Vocabularios Controlados
Ejemplos de funcionalidad de los Vocabularios ControladosEjemplos de funcionalidad de los Vocabularios Controlados
Ejemplos de funcionalidad de los Vocabularios Controlados
María Antonia Osés
 
Tendencia educativa (1)
Tendencia educativa (1)Tendencia educativa (1)
Tendencia educativa (1)
yayetri
 
Análisis documental - EL TESAURO
Análisis documental - EL TESAUROAnálisis documental - EL TESAURO
Análisis documental - EL TESAURO
Martha Ivonne Jiménez Homes
 
Sensation and perception
Sensation and perceptionSensation and perception
Sensation and perception
discoverccs-org
 

Viewers also liked (18)

Actividad 8 walter garcia
Actividad 8 walter garciaActividad 8 walter garcia
Actividad 8 walter garcia
 
Project Selection1
Project Selection1Project Selection1
Project Selection1
 
Ajay Chavan CV
Ajay Chavan CVAjay Chavan CV
Ajay Chavan CV
 
Rinchen_CV
Rinchen_CVRinchen_CV
Rinchen_CV
 
Facebook effect
Facebook effectFacebook effect
Facebook effect
 
A^2_Poster
A^2_PosterA^2_Poster
A^2_Poster
 
Application activity
Application activityApplication activity
Application activity
 
Monica cabal actividad1 mapa_c.pdf
Monica cabal actividad1 mapa_c.pdfMonica cabal actividad1 mapa_c.pdf
Monica cabal actividad1 mapa_c.pdf
 
Sulma niño actividad1_mapa_c
Sulma niño actividad1_mapa_cSulma niño actividad1_mapa_c
Sulma niño actividad1_mapa_c
 
Actividad1
Actividad1Actividad1
Actividad1
 
Mapa gerencia de proyectos
Mapa gerencia de proyectosMapa gerencia de proyectos
Mapa gerencia de proyectos
 
rachelle resume
rachelle resumerachelle resume
rachelle resume
 
OSV-El Mundo 23 Febrero 2007
OSV-El Mundo 23 Febrero 2007OSV-El Mundo 23 Febrero 2007
OSV-El Mundo 23 Febrero 2007
 
Tools for teaching&learning..
Tools for teaching&learning..Tools for teaching&learning..
Tools for teaching&learning..
 
Ejemplos de funcionalidad de los Vocabularios Controlados
Ejemplos de funcionalidad de los Vocabularios ControladosEjemplos de funcionalidad de los Vocabularios Controlados
Ejemplos de funcionalidad de los Vocabularios Controlados
 
Tendencia educativa (1)
Tendencia educativa (1)Tendencia educativa (1)
Tendencia educativa (1)
 
Análisis documental - EL TESAURO
Análisis documental - EL TESAUROAnálisis documental - EL TESAURO
Análisis documental - EL TESAURO
 
Sensation and perception
Sensation and perceptionSensation and perception
Sensation and perception
 

Similar to AI Final Report

Hybrid iterated local search algorithm for optimization route of airplane tr...
Hybrid iterated local search algorithm for optimization route of  airplane tr...Hybrid iterated local search algorithm for optimization route of  airplane tr...
Hybrid iterated local search algorithm for optimization route of airplane tr...
IJECEIAES
 
An Implementational approach to genetic algorithms for TSP
An Implementational approach to genetic algorithms for TSPAn Implementational approach to genetic algorithms for TSP
An Implementational approach to genetic algorithms for TSP
Sougata Das
 
D0353027043
D0353027043D0353027043
D0353027043
inventionjournals
 
10.1.1.34.7361
10.1.1.34.736110.1.1.34.7361
10.1.1.34.7361
Rahmat Fauzi
 
Comparative study of different algorithms
Comparative study of different algorithmsComparative study of different algorithms
Comparative study of different algorithms
ijfcstjournal
 
Medical diagnosis classification
Medical diagnosis classificationMedical diagnosis classification
Medical diagnosis classification
csandit
 
MEDICAL DIAGNOSIS CLASSIFICATION USING MIGRATION BASED DIFFERENTIAL EVOLUTION...
MEDICAL DIAGNOSIS CLASSIFICATION USING MIGRATION BASED DIFFERENTIAL EVOLUTION...MEDICAL DIAGNOSIS CLASSIFICATION USING MIGRATION BASED DIFFERENTIAL EVOLUTION...
MEDICAL DIAGNOSIS CLASSIFICATION USING MIGRATION BASED DIFFERENTIAL EVOLUTION...
cscpconf
 
A heuristic approach for optimizing travel planning using genetics algorithm
A heuristic approach for optimizing travel planning using genetics algorithmA heuristic approach for optimizing travel planning using genetics algorithm
A heuristic approach for optimizing travel planning using genetics algorithm
eSAT Publishing House
 
A heuristic approach for optimizing travel planning using genetics algorithm
A heuristic approach for optimizing travel planning using genetics algorithmA heuristic approach for optimizing travel planning using genetics algorithm
A heuristic approach for optimizing travel planning using genetics algorithm
eSAT Journals
 
Travelling Salesman Problem
Travelling Salesman ProblemTravelling Salesman Problem
Travelling Salesman Problem
Shikha Gupta
 
40120130405011
4012013040501140120130405011
40120130405011
IAEME Publication
 
COMPARATIVE STUDY OF DIFFERENT ALGORITHMS TO SOLVE N QUEENS PROBLEM
COMPARATIVE STUDY OF DIFFERENT ALGORITHMS TO SOLVE N QUEENS PROBLEMCOMPARATIVE STUDY OF DIFFERENT ALGORITHMS TO SOLVE N QUEENS PROBLEM
COMPARATIVE STUDY OF DIFFERENT ALGORITHMS TO SOLVE N QUEENS PROBLEM
ijfcstjournal
 
Final_Report.docx (2)
Final_Report.docx (2)Final_Report.docx (2)
Final_Report.docx (2)
Marinna Pivatto
 
Ijarcet vol-2-issue-2-352-358
Ijarcet vol-2-issue-2-352-358Ijarcet vol-2-issue-2-352-358
Ijarcet vol-2-issue-2-352-358
Editor IJARCET
 
bation-cs190-ieee
bation-cs190-ieeebation-cs190-ieee
bation-cs190-ieee
Carlo Luis Martinez Bation
 
Ijtra130517
Ijtra130517Ijtra130517
tAn improved genetic algorithm with a
tAn improved genetic algorithm with atAn improved genetic algorithm with a
tAn improved genetic algorithm with a
ijcseit
 
Two-Stage Eagle Strategy with Differential Evolution
Two-Stage Eagle Strategy with Differential EvolutionTwo-Stage Eagle Strategy with Differential Evolution
Two-Stage Eagle Strategy with Differential Evolution
Xin-She Yang
 
Genetic Algorithm 2 -.pptx
Genetic Algorithm 2 -.pptxGenetic Algorithm 2 -.pptx
Genetic Algorithm 2 -.pptx
TAHANMKH
 
AN IMPROVED GENETIC ALGORITHM WITH A LOCAL OPTIMIZATION STRATEGY AND AN EXTRA...
AN IMPROVED GENETIC ALGORITHM WITH A LOCAL OPTIMIZATION STRATEGY AND AN EXTRA...AN IMPROVED GENETIC ALGORITHM WITH A LOCAL OPTIMIZATION STRATEGY AND AN EXTRA...
AN IMPROVED GENETIC ALGORITHM WITH A LOCAL OPTIMIZATION STRATEGY AND AN EXTRA...
ijcseit
 

Similar to AI Final Report (20)

Hybrid iterated local search algorithm for optimization route of airplane tr...
Hybrid iterated local search algorithm for optimization route of  airplane tr...Hybrid iterated local search algorithm for optimization route of  airplane tr...
Hybrid iterated local search algorithm for optimization route of airplane tr...
 
An Implementational approach to genetic algorithms for TSP
An Implementational approach to genetic algorithms for TSPAn Implementational approach to genetic algorithms for TSP
An Implementational approach to genetic algorithms for TSP
 
D0353027043
D0353027043D0353027043
D0353027043
 
10.1.1.34.7361
10.1.1.34.736110.1.1.34.7361
10.1.1.34.7361
 
Comparative study of different algorithms
Comparative study of different algorithmsComparative study of different algorithms
Comparative study of different algorithms
 
Medical diagnosis classification
Medical diagnosis classificationMedical diagnosis classification
Medical diagnosis classification
 
MEDICAL DIAGNOSIS CLASSIFICATION USING MIGRATION BASED DIFFERENTIAL EVOLUTION...
MEDICAL DIAGNOSIS CLASSIFICATION USING MIGRATION BASED DIFFERENTIAL EVOLUTION...MEDICAL DIAGNOSIS CLASSIFICATION USING MIGRATION BASED DIFFERENTIAL EVOLUTION...
MEDICAL DIAGNOSIS CLASSIFICATION USING MIGRATION BASED DIFFERENTIAL EVOLUTION...
 
A heuristic approach for optimizing travel planning using genetics algorithm
A heuristic approach for optimizing travel planning using genetics algorithmA heuristic approach for optimizing travel planning using genetics algorithm
A heuristic approach for optimizing travel planning using genetics algorithm
 
A heuristic approach for optimizing travel planning using genetics algorithm
A heuristic approach for optimizing travel planning using genetics algorithmA heuristic approach for optimizing travel planning using genetics algorithm
A heuristic approach for optimizing travel planning using genetics algorithm
 
Travelling Salesman Problem
Travelling Salesman ProblemTravelling Salesman Problem
Travelling Salesman Problem
 
40120130405011
4012013040501140120130405011
40120130405011
 
COMPARATIVE STUDY OF DIFFERENT ALGORITHMS TO SOLVE N QUEENS PROBLEM
COMPARATIVE STUDY OF DIFFERENT ALGORITHMS TO SOLVE N QUEENS PROBLEMCOMPARATIVE STUDY OF DIFFERENT ALGORITHMS TO SOLVE N QUEENS PROBLEM
COMPARATIVE STUDY OF DIFFERENT ALGORITHMS TO SOLVE N QUEENS PROBLEM
 
Final_Report.docx (2)
Final_Report.docx (2)Final_Report.docx (2)
Final_Report.docx (2)
 
Ijarcet vol-2-issue-2-352-358
Ijarcet vol-2-issue-2-352-358Ijarcet vol-2-issue-2-352-358
Ijarcet vol-2-issue-2-352-358
 
bation-cs190-ieee
bation-cs190-ieeebation-cs190-ieee
bation-cs190-ieee
 
Ijtra130517
Ijtra130517Ijtra130517
Ijtra130517
 
tAn improved genetic algorithm with a
tAn improved genetic algorithm with atAn improved genetic algorithm with a
tAn improved genetic algorithm with a
 
Two-Stage Eagle Strategy with Differential Evolution
Two-Stage Eagle Strategy with Differential EvolutionTwo-Stage Eagle Strategy with Differential Evolution
Two-Stage Eagle Strategy with Differential Evolution
 
Genetic Algorithm 2 -.pptx
Genetic Algorithm 2 -.pptxGenetic Algorithm 2 -.pptx
Genetic Algorithm 2 -.pptx
 
AN IMPROVED GENETIC ALGORITHM WITH A LOCAL OPTIMIZATION STRATEGY AND AN EXTRA...
AN IMPROVED GENETIC ALGORITHM WITH A LOCAL OPTIMIZATION STRATEGY AND AN EXTRA...AN IMPROVED GENETIC ALGORITHM WITH A LOCAL OPTIMIZATION STRATEGY AND AN EXTRA...
AN IMPROVED GENETIC ALGORITHM WITH A LOCAL OPTIMIZATION STRATEGY AND AN EXTRA...
 

AI Final Report

  • 1. ME8107 Artificial Intelligence for Mechanical Engineers Prof. Vincent Chan Project Report Xuming Gao 500420541 Nov 26, 2014
  • 2. 2 Table of Contents 1. Introduction 3 2. State of the Problem 5 3. Literature Review 6 4. Solve by GA 8 5. Conclusion 14 6. Reference 15 7. Appendix 16
  • 3. 3 Introduction In many fields, looking for a shortest path is a need in order to achieve time and economic efficient. To an international company, a well-organized shipping plan means more cargoes could be shipped to their destination with the same amount of time, or the same amount of goods reaches their purchasers in a shorter time. To a family, a carefully designed travelling plan could be considered cheaper in cost on transportation or having time to visit more places, resulting a more enjoyable journey. Path planning is not new, and there are many experts from different fields solved this problem with very smart methods. Strangely, humans are never satisfied with their current status. Therefore, more elites have been joining in the study of the path planning problem, and more and more systems have been developed to solve the path planning problem more efficiently with better solutions. Genetic algorithm is one of the artificial algorithms that have been developed to solve not only the mathematical problem, but also other engineering and/or scientific problems such as path planning problem. The genetic algorithm is based on Charles Darwin’s biological theory of evolution in the mid-19th century (Hillier, Frederick S. and Lieberman, Gerald J., 2005). Features are depended based on genes, and chromosomes are carrying all genes that an object has. Two chromosome pairs a group of parents when it happens to create the next generation, and some part chromosomes, which is genius, will be passed from parents to children. Children having better genes will have a higher chance to survive and become parents and pass on genes. There is also a chance that a mutation happens. Most mutation causes
  • 4. 4 disadvantage or no effect; however, sometimes a mutation give a better feature to fit the environment, which means a higher chance to survive. The entire process happens randomly; as a result, the next generation is not guaranteed to be better than the current generation, but always children with more suitable features survive. Similar to the biological evolution theory, genetic algorithm contains randomly happening crossover, mutation, and selection (select children with better features). Because of its randomness, the local maxima and minima will be avoided; and this allows the answer is closer to the real optical solution.
  • 5. 5 State of the Problem There is a new couple are planning where to spend their honeymoons. They came across an idea that spend their days to visit Europe. They found a travel agency to plan a trip for them so that they do not spend too much money on the travelling. During the travel planner was trying to design a trip for the new couple, there is an unexpectable system shutdown at him. After he reboot his computer, he found that the must-visit countries that the couple mentioned were lost.; and he also could not recall the must-visit countries as well as the starting country and ending country. Because the flight-ticket are already booked, the first country and last country to visit cannot be changed due to they would not like to pay for the cancellation fee; but the order of the rest visiting countries are not important to them. No one country is planned to visit twice. Because the deadline to deliver the travelling plan is almost due and the planer cannot reach the couple with any method, he has no time to wait for contact them again. Therefore, he decided to write a program with a graphical user interface which allows the couple to select all the countries that they want to visit including the starting and ending country. As return, the best travel plan will be shown to them.
  • 6. 6 Literature Review The travelling salesman problem (TSP) is a classic example of path planning. The travelling salesman provides an optimal (shortest) path of the traveler to cover all stated places. There is no specific starting or ending point. The traveler could start in any place, but must return to the same place at the end of the journey. Except the starting place (also the ending place), there is no other place can be visited more than once. There is no limit on the sequence of the place to be visited. The next places can be chosen from any remaining (has-not-been-visited) places. The distance between any of the two places are known. One of the popular method is solving TSP by simulated annealing. This arithmetic is simulating annealing process in metallurgy. The entire process of annealing includes heating and slow cooling stages. Temperature is an important variable in simulated annealing algorithm, and temperature is usually manually set high to enlarge the searching area in order to find the most optimal solution. The internal energy is calculated at this temperature and recorded. Then, the cooling process starts. With slowly decreasing temperature, internal energy is calculated at each temperature and then comparing with the current minimum energy. The minimum energy updates itself during each iteration. If energy at new temperature is lower, the minimum energy gets updates; if the new temperature is higher, by predefined possibility, it will choose either update or eject the new value. Either iteration reaches its predefined number or the minimum energy decreases below the desired energy threshold, the program will stopped. [2]
  • 7. 7 There are two major problems in simulated annealing method. One is being the initial temperature setup. If the temperature is set high, there is higher chance to acquire the most optimal solution but taking longer computing time; or with reasonable low temperature, it might not find the most optimal solution but saving computational cost. Another major problem is rate of decreasing temperature. It always needs several times experiments to determine a suitable cooling rate. [3, 4] Overall, TSP problem could be solved by using simulated annealing algorithm, and it gives better optimal solution than by greedy method [4]. Another method is done by ant colony optimization algorithm. This algorithm simulates the ant finding shortest path to its colony during foraging. Ant returns colony the earliest it chose the shortest path, and pheromone is left on the path earliest. Following ants will select this path due to higher pheromone intensity, and this path will be reinforced to attract more ants. Eventually, the longer paths will be abandoned. Ant colony algorithm is a good candidate when dealing with problems such as travelling salesman problem and 0-1 knapsack problem although computation cost is relatively high. [5-9]
  • 8. 8 Solve by GA The real European map is used with manually marked European countries as shown in Figure 1. Each black spot represents a country. Figure 1 Marked European Country In order to acquire the relative position of all the spotted countries on the map, MatLab image toolbox is utilized to convince. First, the image is converted to a gray scale image from a regular RGB image, the gray image can be seen in figure 2. Then, the grayscale image is being further processed to be a binary image with threshold 0.99 as shown in figure 3. A matrix of x- y- coordinates of black spots are acquired, and the distance between any two countries could be calculated based on x- y- coordinates.
  • 9. 9 Figure 2 Gray Scale Image Figure 3 Binary Image with threshold 0.99
  • 10. 10 Figure 4 Centroid to acquire x-y coordinates Once all the countries’ coordinates are acquired, all data is transferred to an excel file along with the corresponding country name to store the original data. In this excel file, the numerical index (1, 2, 3…) can be used to index country name and coordinate. With the selection of user, all parameters are written to variables and these variables are corresponding parameters in the genetic algorithm. Starting country and ending country are passed on separately from must-visit countries since starting and ending country are fixed variables once the user select and the program is started. The coordinate and name of starting country and ending country are pulled from the original data and written to four variables (start country coordinate, start country name, end country coordinate, and end country name). User selected must-visit countries are stored in a one-dimensional array, and there will be no country index that the user did not select. Two new matrices are created by pulling selected countries coordinates and name, one matrix (n by 2) stores coordinates and
  • 11. 11 the other one (n by 1) stores name (n is the number of country selected). Selected countries’ coordinates and names have new indexes. With all the coordinates, distance between any two selected countries are calculated and stored for later use. And here, genetic algorithm starts. Initiation Firstly, population size, mutation rate are defined to be 20 and 1%, respectively. The gene used is the index of the country, and the chromosome (parent) is a string of country index. 20 parents are randomly generated. Evaluation The fitness function is applied to each parent to calculate the total distance of travelling based on the order of country index in the parent. All the fitness values are gathered. In this case, lower fitness value is better because lower fitness value means shorter distance. Grouping The fitness value is sorted from low to high in a row, and only the top ten lowest total distance will be kept and used in the next step. The parent in the i-th row is paired with the parent in the (11-i)th row to form five groups in total. Each group of parents creates four children to keep the population remains the same for the next generation. Children are created after mate and mutation.
  • 12. 12 Mating Two numbers are randomly generated: rand1 and rand2. Rand1 is responsable for the selection of parent, and rand2 is for gene. Parent 1: 0~0.4999 Parent 2: 0.5~0.9999 First Half Gene: 0~0.4999 Second Half Gene: 0.5~0.9999 If rand1 falls in the range of parent 1, then parent 1 is selected; otherwise parent 2 is selected. If rand2 falls in the first half gene’s range, then the first half gene is passed on to the child; otherwise, the second half gene is passed on. For example, rand1=0.2365 and rand2=0.9666, then the second half gene in parent 1 is passed on to the child. The remaining gene of this child is selected from the other parent in the group in the same order of this parent from available genes (numbers that have not been appeared in the child). Mutating The rate of mutation is predefined as 1%. A link is chosen to be the place when mutation happens. Whenever a mutation happens, the two numbers connected by the link will be exchanged. If there are in total 12 selected must-visit countries, there will be 12 numbers to represent each country and 11 links to connect all the numbers. Therefore, for one child, there are 11 links that possibly a mutation happens. Similar to select parent and gene, random numbers are generated to decide where the mutation happens. 11 random numbers are created and any number is less than 0.01 (1%) means mutation happens: switch two numbers connected by the corresponding link.
  • 13. 13 Once the mutation process is over, one iteration is done. Children become parents and next iteration starts. The entire process is repeated from evaluation to mutation until the maximum iteration is reached. In every iteration, after sorting the fitness value, the shortest fitness value in this iteration is compared with the global minimum: if global minimum is greater than this fitness value, then, the global minimum is updated to this fitness value and the corresponding path (index sequence is stored); if global minimum is smaller, then the process continues. The global minimum is initially set to be positive infinity to ensure it is bigger than any total travel distance of any possible travel sequence. After maximum iteration is reached, distances from starting country to the first index country in optimal solution and from the last index country to ending country are calculated and then added onto global minimum. In addition, starting and ending country names are inserted in the optimal solution sequence in the first and last place. Updated string of names and global minimum are returned to the user. String of names displays the best travel sequence, while the global minimum is showing the optimal travel distance. Output The output of this program is the sequence of visiting country. The path can be either seen in the MatLab workspace or in an Excel file that created by the program. In addition, a path map will also be shown for convenience.
  • 14. 14 Conclusion The genetic algorithm is quite suitable for traveling salesman problem. It is unlike heuristic search which needs much computational cost. Although the genetic algorithm method does not guarantee the best solution will be found, the result is close enough to the best solution. It also has potential to get even closer to the best answer. One method is adding more iterations. Because only the best results from iteration will be kept, the solution gets closer and closer to its ultimate optimal solution. So, by running more iterations, the answers become more optimal. Another method is applying different mating method. This may cause improve the answer, but also may decrease the performance. The mutation rate is another option to apply change which may either advance or dis-advance the performance. In conclusion, genetic algorithm suits problems that do not need the best solution, but a good-enough solution. Path planning or travelling salesman problem is one of the perfect example of genetic algorithm programming.
  • 15. 15 Reference [1] Hillier, Frederick S. and Lieberman, Gerald J. (2005). Introduction of Operations Research. Toronto; Boston: McGraw Hill. [2] Corana, A., Marchesi, M., Martini, C., & Ridella, S. (1987). Minimizing multimodal functions of continuous variables with the "simulated annealing" algorithm corrigenda ACM Transactions on Mathematical Software (TOMS), 13(3), 262-280. doi:10.1145/29380.29864 [3] Randelman, R. E., & Grest, G. S. (1986). N-city traveling salesman problem: Optimization by simulated annealings. Journal of Statistical Physics, 45(5-6), 885-890. doi:10.1007/BF01020579 [4] Ismail, Z., & Ibrahim, W. R. W. (2008). Traveling salesman approach for solving petrol distribution using simulated annealing. American Journal of Applied Sciences, 5(11), 1543-1546. doi:10.3844/ajassp.2008.1543.1546 [5] Ellis, J. F. (2002). Ant colony optimization for approximate solutions to the traveling salesman problem [6] Dorigo, M., & Blum, C. (2005). Ant colony optimization theory: A survey. Theoretical Computer Science, 344(2), 243-278. doi:10.1016/j.tcs.2005.05.020 [7] Dorigo, M., Dorigo, M., Birattari, M., Birattari, M., Stutzle, T., & Stutzle, T. (2006). Ant colony optimization. IEEE Computational Intelligence Magazine, 1(4), 28-39. doi:10.1109/MCI.2006.329691 [8] Chaharsooghi, S. K., Chaharsooghi, S. K., Meimand Kermani, A. H., & Meimand Kermani, A. H. (2008). An intelligent multi-colony multi-objective ant colony optimization (ACO) for the 0-1 knapsack problem. 1195-1202. doi:10.1109/CEC.2008.4630948 [9] Ke, L., Feng, Z., Ren, Z., & Wei, X. (2010). An ant colony optimization approach for the multidimensional knapsack problem. Journal of Heuristics, 16(1), 65-83. doi:10.1007/s10732-008-9087-x
  • 16. 16 Appendix Figure 5 Image Processing Code
  • 17. 17 Country Coordinates and Name Data (Unit: pixels) X-coordinate Y-Coordinate Country 98 915 Portugal 100 1134 Morocco 195 936 Spain 202 150 Iceland 218 549 Ireland 320 1121 Algeria 328 556 UK 377 775 France 435 685 Belgium 453 636 Netherlands 492 1133 Tunisia 496 795 Switzerland 538 513 Denmark 545 653 Germany 558 350 Norway 565 911 Italy 627 764 Austria 627 831 Slovenia 634 700 Czech Republic 657 265 Sweden 669 843 Croatia 706 898 Bosnia and Herzegovina 717 629 Poland 718 728 Slovakia 739 783 Hungary 758 996 Albania 763 879 Serbia 792 962 Macedonia 798 541 Lithuania 803 242 Finland 801 1008 Greece 810 430 Estonia 826 489 Latvia 835 806 Romania 867 898 Bulgaria 878 558 Belarus 956 683 Ukraine 1009 326 Russia
  • 18. 18 Graphical User Interface Figure 6 User Interface before Selection Figure 7 User Interface with An Example Selection
  • 19. 19 Program Output Figure 8 Output to Workspace (Left) and to Excel File (Right) Figure 9 Path Plan Graphical Result (Green dot is starting country, and blue is end country)
  • 20. 20 Instruction of running the MatLab code 1. Download all the files including “data.xlsx”, “search,m”, “userfront.fig”, “userfront.m”, and “ImageProcessing.m” and save under the same folder. Copy the folder directory. 2. Start MatLab program 3. Open “search.m” file and replaced directory in xlsread command with the directory just copied, and then save and close “search.m” file. 4. Open “userfront.m” and click run. 5. Choosing start and end country on user interface as well as the must-visit country section. 6. Click on “start” to run. 7. Once the program finished, the result can be reviewed either on workspace or in the excel file named “path.xls”. Note:  Every time the program is opened, the user interface needs to be “activated”. To do this, click on drop down menus and select any countries to both starting and ending country, and check all the check box followed by clicking the “start” button. Once the first run is done, the following running does not require this step.  After each running, created “guidata.xls” and “path.xls” are necessary to deleted or moved to another folder in order to run the program functionally.