International Journal of Engineering Technology, Management and Applied Sciences
www.ijetmas.com February 2017, Volume 5, Issue 2, ISSN 2349-4476
139
Raja Chınna Karuppanan B,Saravanan M
Genetic Algorithm for TSP in Optimizing CNC Tool Path
Raja Chınna Karuppanan B,
Anna Unıversıty,Chennaı,Indıa.
Saravanan M,
Anna Unıversıty,Chennaı,Indıa
.
ABSTRACT
The optimization of CNC machining parameters is a major researcharea in which more number of research works
are done. The tool path is considered to be the most important element in CNC Machining operations. The various Tool
movement activities are studied for further improvements. Finding the optimum tool pathof a CNC Machine is
analogous to Traveling salesman problem.Evolutionary Algorithms are adapted for solving this problem. The GA is one
among the popular algorithms applied to find the best solutions for this problem.The solution found by genetic
algorithm is self evolved. This paper details the application of MATLAB in solving the TSP using Genetic Algorithm.
Keywords:CNC, Tool path ,Machiningparameters ,Optimization, TSP , Genetic Algorithm , Matlab, Tool Box,Energy
1 INTRODUCTION
The problem of finding the minimum distance travelled by the cutting tool in a Computer Numerically
controlled machine is very important for the minimization of the cost. The complexity of the problem
increases with the number of axis and the number of tool destinations. The nodes are the points where the tool
stops for an operation or exit to travel to the next entry point. These locations in CNC machiningoperations
are determined by the work piece and the type of machining required. The near best tool path is found by
searching solutions in an exhaustive search space. These problems are known as TravelingSalesman Problem
(TSP).
The Traveling salesman problem is a combinatorial problem in which a salesmanis given a tour programto
visit a number of cities within a geographical boundary.The tour map contains a number of
locationsdepending upon the itinerary. It's the job of the salesman to visit each of these locations to make a
sale.Before settingoff on the journey the sales man has to plan a route such that the total tour time is
minimized. It is impossible to find the best route manually if there are more number of locations.The number
of possibleroutes are a factorial of the number of locations to be visited.
For example, if the number of locations to be visited are 10, then thefactorial of 10 is 3628800 which means
the number of possible routes are 36,28,800.Finding the best route among these 36,28,800 routes is beyond
the imagination of a human. If even one city is added to the tour the difficulty of a solution becomes
manifold. For the 11 locations the possible number of routes are 3,99,16,800. The number of new routes
increased by 3,62,88,000. Finding the shortestroute is impractical even by the present day‟s state of art
computing techniques.
2 FINDING THE SOLUTION FOR TSP
It may not be practically possible to find the best solution for a problem like this.There are algorithms which
discover close to optimum solutions. Genetic Algorithm,Simulated annealing algorithm,Tabusearch,Ant
Colony algorithm,Artificial Neural Network (ANN) ,Fuzzy logic approach ,Branch and Bound method are the
commonly used algorithms for TSP problems.
International Journal of Engineering Technology, Management and Applied Sciences
www.ijetmas.com February 2017, Volume 5, Issue 2, ISSN 2349-4476
140
Raja Chınna Karuppanan B,Saravanan M
These algorithms are capable of finding a 'good-enough' solution to the Traveling salesman problem quickly.
The Genetic Algorithmapproach is selected for our study due to the ease ofprogramming, robustness and
versatility.
2.1 Genetic Algorithm
Genetic algorithms are part of evolutionary computing, which is a rapidly growing area of artificial
intelligence. Genetic algorithms are biological basedand inspired by Darwin's theory about evolution in which
solution to a problem is evolved. Fig.1 shows the flow chart of a simple GA.
Fig.1
The traditional way of presenting an algorithm for the TSP problem is not done with GA due to the reason that
every city must be unique in a gene and shall not be duplicated. A valid solution would need to represent a
route where every location is included at least once. The coding shall be such that the route does not contain a
single location more than once, or missed out a location completely.For a gene presentation, a sequential
representation is used where the cities are listed in the order in which they are visited. It's common way for
TSP Genome.
Example: [ 12 7 6 10 3 8 4 0 1 2 5 9]
2.1.1 Create a Random Initial Population
Creation of InitialSolutions randomly
Creation of Newer Generation
Evaluation of Fitness of Solutions
Stop
Conditions Met?
Crossover & Mutation
International Journal of Engineering Technology, Management and Applied Sciences
www.ijetmas.com February 2017, Volume 5, Issue 2, ISSN 2349-4476
141
Raja Chınna Karuppanan B,Saravanan M
An initial population is created from a random selection of solutions ,which are known as chromosomes.
2.1.2 Evaluate Fitness
A value for fitness is assigned to each solution (chromosome) depending on how close it is actually in solving
the problem. The answer to the problem is arrived in this way. These "solutions" are part of the possible
characteristics that the system would employ in order to reach the answer.
2.1.3 Reprodution& Mutation
Mutation
The mutation method is applied for shuffling the route, and it does not add or remove a location from
the route, otherwise it would risk creating an invalid solution. If swap mutation is employed the gene
Before mutationis [0 1 2 3 4 5 6 ] . After mutation is after mutation [0 1 3 2 4 5 6 ]. Many methods are
applied for a swapping operation. Random swap is commonly used due to the simplicity.This strategy is
unable to achieve an optimum quickly but it can prevent convergence into a local optimum.The basic idea of
greedy-swap is to randomly select two cities from one chromosome and swap them if the new tour length is
shorter than the old one.
2.1.4 SELECTION
The Routlette rank, roulette cost and tournament and elitism methods are used for the selection of
chromosomes.
Cost Selection
Parents are selected according to their fitness. The better the chromosomes are, the more chances to be
selected they have. In a roulette wheel all chromosomes are placed in the population, the chances of selection
are high accordingly to the fitness .
Rank Selection
The cost selection will have problems when the fitness differ very much. If the best chromosome fitness is
90% of all the roulette wheel then the other chromosomes will have very few chances to be selected. In rank
selection, the ranking is done for the population and then every chromosome receives fitness from this
ranking. The worst will have fitness 1, second worst 2 etc. and the best will get the number of chromosomes in
the population as its rank.
Tournamnet Selection and Elitism
It is a mechanism for choosing individuals from a population. A group of characters selected at random from
the population and the best (normally only one, but possibly more) is chosen. An elitist genetic algorithm is
one that always retains in the population the best individual found so far.Tournamnet Selection is naturally
elitist.The chromosomes with a higher fitness value are more likely to reproduce offspring (which can mutate
after reproduction). The offspring is a product of the father and mother, whose composition consists of a
combination of genes from them. This process is known as "crossing over".
Next Generation
If the new generation contains a solution that produces an output that is close enough or equal to the desired
answer then the problem has been solved. If this is not the case, then the new generation will go through the
same process as their parents did. This will continue until a desired solution is reached.
3 MATLAB
MATLAB, stands for MATrixLABoratory, is a powerful, general-purpose system or environment for
doing mathematics, scientific and engineering calculations. MATLAB is a "High-Performance Numeric
Computation and Visualization Software" package. MATLAB is an interactive system whose basic data is a
matrix that does not require dimensioning.
International Journal of Engineering Technology, Management and Applied Sciences
www.ijetmas.com February 2017, Volume 5, Issue 2, ISSN 2349-4476
142
Raja Chınna Karuppanan B,Saravanan M
Matlab has two toolboxes that contain optimization algorithmsi) Optimization Toolbox ii) Genetic Algorithm
and Direct Search Toolbox. Optimization Toolboxis applied to solve Unconstrained nonlinear, Constrained
nonlinear,Simple convex: LP, QP,Least Squares,Binary Integer Programming, Multiobjective
problems.Genetic Algorithm and Direct Search Toolbox is used to solve generaloptimization problems
Direct search algorithms (directional) for generalized pattern,Genetic algorithm,Simulated annealing and
Threshold acceptanceproblems.There are two methods the Genetic Algorithm is applied in MATLAB
optimization.
3.1 . Calling the Genetic Algorithm Function
The Genetic Algorithm is invoked at the command line, by the function „ga‟with the syntax mentioned
below.
[xfval]=ga(@fitnessfun, nvars, options)
Where „@fitnessfun‟ is a handle to the Fitness Function.„nvars‟ is the number of independent variables for the
Fitness Function.„options‟ is a structure containing options for the genetic algorithm.The syntax returns the
following things.“fval“ the final Value of the Fitness Function.
_ reason – Reason for which the algorithm terminates.
_ output - Structure containing information about the performance of the algorithm.
_ population – Final population.
_ scores – Final scores.
“options = gaoptimset” command set the options. This returns the structure of options with the default
values for its fields. To edit an option structurewith a different value of an option such as ‟Elite Count‟, we
can use the function
Options= gaoptimst(„Elite Count‟, 1)
This will return an options structure with an „Elite Count‟ of 1 instead if its default value 2.
3.2. Using The Genetic Algorithm Tool
The optimization toolbox includes a graphical user interface. Fig.2 shows the GA Toolbox. .
The genetic algorithm tool is a graphical user interface that enables to use the genetic algorithm without
working at the command line. This will open the gatool window. To use this tool we must first enter the
following information,
“Fitness Function”- The objective function that we want to minimize. The fitness function is entered in
theform of „@fitnessfun‟, where „fitnessfun.m‟ is an M file that computes the fitness function.
“Number of variables “- This is the length of the input vector of the fitness function.
To run the genetic algorithm is run by the „start‟ button. The tool displays the result of the optimization
process in the „Status and Result‟ pane.The „plot‟ pane displays various plots that provide the status of the
genetic algorithmwhile it is running. This data displayed is useful to improve the performance of the
algorithm.
International Journal of Engineering Technology, Management and Applied Sciences
www.ijetmas.com February 2017, Volume 5, Issue 2, ISSN 2349-4476
143
Raja Chınna Karuppanan B,Saravanan M
Fig.2
4 STUDYEXPERIMENT
For the study the problem shown in fig 3 is chosen. The figure shows the drawing of a work piece with
holes to be drilled at different locations.
Fig.3
The aim of the experiment is to reduce the time taken by the Tool to travel between the various drill hole
locations. The number of axis movements are only two namely the x and y axis. Each hole is assigned a
number so that it is refered in the algorithm as a city( Fig .4) Since we are trying to minimize the total
distance that the salesman travels, the fitness function will be the total distance D:
D = d(c𝑛𝑘−1 k, ck+1)
Where city n + 1 = city 1 (the starting city). Xi; yes denote the coordinates of city chi, then the
Fitness function becomes
D = (xi - ax) 2 + (yes – in)
2 -------A
International Journal of Engineering Technology, Management and Applied Sciences
www.ijetmas.com February 2017, Volume 5, Issue 2, ISSN 2349-4476
144
Raja Chınna Karuppanan B,Saravanan M
The shown Expression (A) ensures that each city has visited only once, within the constaints , there are no
sub-tours, i.e., eliminates the possibility that in the solution appears more than one contour. A binary
represntationofsolutions is not suitable for this type of problem, and the solutions are represented as vector or
matrix.
Fig.4
The number of possible solutions are permutation of 1, 2, 3,..., n where n is number of cities.In this problem
it is the number of holes. The Matlabprogramme for the problem is shown in fig4.
5 GA MATLAB IMPLEMENTATION
The parameters shown in the Table 1. Are selected after several experimental runs by applying several
population size , mutation and cross over fractions. The number of Iterations also varied for consistent results.
GA Parameters Le Values
Number of Holes (Cities) 32
No of Generations 16000
Population Size 400
Cross Over fraction 0.5
Mutation fraction .08
Table 1.
International Journal of Engineering Technology, Management and Applied Sciences
www.ijetmas.com February 2017, Volume 5, Issue 2, ISSN 2349-4476
145
Raja Chınna Karuppanan B,Saravanan M
Fig.5
6 RESULTS AND DISCUSSION
The shortest tool path is shown in fig .5. The best result achieved is 36.129 units.Increasing the number
of iterations improved the results. For randomly placed drill holes and profile milling operations the
optimization tool is found to be more effective. The best possible route for minimizing the cost is achieved
by interactive process . The best solution generated by the optimization programme is given as the input for
Generating Gcodes . It is found that the cost of machining can be reduced considering the Toolpath travel
distance. By adding the required constraints and modifying the fitness function the above programme can be
used for optimizing different models like tool wear, tool life , minimum energy requirement, tool selection
etc..
ACKNOWLEDGEMENT
The authors wish to thank the MathworksInc, Lee Jacobson, a Freelance code writer for the support
in code development and Octave.org for the free license software to test the Matlab Codes.
REFERENCES
1. Genetic Algorithm ToolBox for Matlab By Andrew Chipperfield 2. Octave 4.2 Documentation
3. Wikipedia
4. D.E.Goldberg, (1989) “Genetic Algorithms in search,Optimization and Machine Learning”, AddisonWesley
Publishing Company, Ind. U.S.A.
5. Melanie Mitchell,(1998) ”An introduction to genetic Algorithm”, MIT press
6. DanijelaPezer ,”Efficiency of Tool Path Optimization Using Genetic Algorithm in Relation to the Optimization
Achieved with the CAM software”Procedia Engineering 149(2016)
7. Yusuke Koike, AtsushiMatsubara,IwaoYamaji ,” Optimization of Cutting path for Minimizing Workpiece
Displacement at the Cutting Point : Changing the Material Removal Process, Feed Direction and Tool Orienation
“, Procedia CIRP 5 (2013) 31-36.
8. NabeelKadimAbid Al-Sahib ,Hasan Fahad Abdulrazzaq, “Tool Path Optimization of Drilling Sequence in CNC
Machine Using Genetic Algorithm”, Innovative Systems Design and Engineering, Vol. 5,No.1,2014.
9. Daeyoung Kong , Seungchoun Choi, Yusuke Yasui, SushrutPavanaskar , David Dornfeld, Paul Wright, “Software-
based tool path evaluation for environmental sustainability”,Journal of Manufacturing Systems (2011),
doi:10.1016/j.jmsy.2011.08.005.
International Journal of Engineering Technology, Management and Applied Sciences
www.ijetmas.com February 2017, Volume 5, Issue 2, ISSN 2349-4476
146
Raja Chınna Karuppanan B,Saravanan M
10. Arun Kumar Gupta , Pankaj Chandna&PuneetTandon,“Hybrid genetic algorithm for minimizing non productive
machining time during 2.5 D milling”,International Journal of Engineering , science and Technology, Vol . 3, No. 1
, 2011, pp.183-190.
11. A.Rangarajan ,D.Dornfeld, “Efficient Tool Paths and Part Orientation for Face Milling”,CIRP Annals –
Manufacturing Technology , Volume 53, Issue 1, 2004 , Pages 73-76 12. P.L.S.C Alwis, A.S Premarathna, Y.P Fonseka, S.M Samarasinghe, J.V. Wijayakulasooriya,” Automated Printed
Circuit Board (PCB) Drilling Machine with Efficient Path Planning”,SAITM Research Symposium on
Engineering Advancements 2014.
13. Jack Barclay, VimalDhokia, Aydin Nassehi,”Generating milling tool paths for prismatic Parts using genetic
programming“,Procedia CIRP 33 ( 2015 ) 490 – 495.
14. Shaikh NoorFarooque1 , Ansari Mohammed Faizan , Javed Shaikh , Pragati Pal, “Automated Pcb Drilling Machine
With Efficient Path Planning”, International Journal of Advanced Research in Computer and Communication
Engineering ,”Vol. 4, Issue 4, April 2015.
15. MiranBrezocnik, MihaKovacic, JozeBalic and Bogdan Sovilj,” PROGRAMING CNCMEASURING MACHINES BY
GENETIC ALGORITHMS”,Academic Journal of Manufacturing Engineering, Vol. 2, NO.2/2004.