[ieee 2007 sixth mexican international conference on artificial intelligence, special session micai...

12
A Comparative Study of three Metaheuristics applied to the Traveling Salesman Problem Jérôme Leboeuf Pasquier 1 , Ivica Kalichanin Balich 1 , Donald W. Carr 1 , Cuauhtémoc López-Martín 2 1 Centro Universitario de Ciencias Exactas e Ingenierías, Universidad de Guadalajara, Mexico 2 National Polytechnic Institute, Center for Computing Research, Mexico [email protected], [email protected], [email protected], [email protected] Abstract This paper presents a comparative study of three metaheuristics: Genetic Algorithm (GA), Ant Colony Optimization (AC) and Simulated Annealing (SA), implemented to solve the classical Traveling Salesman Problem (TSP). The efficiency of each approach is evaluated taking into account the execution time of the algorithm and the quality of the generated solution. Additionally, metrics of the program, including McCabe Complexity, Development effort and Lines of Code, are calculated to complete the comparative study. Finally, an evaluation of the difficulty of implementation and the quality of the results corresponding to each metaheuristic is given. The present research will help programmers understand, evaluate and implement the three Metaheuristics. 1. Introduction The initial challenge that motivated this paper was aimed at finding a solution to a Load Profiling Problem (LPP) in a real-time distributed system; i.e. optimizing the distribution of a set of processes on a network of nodes while satisfying some specific constraints that include: periodic deadlines, shared access to resources, interdependencies and communication between processes. LPP belongs to a category of NP-hard problems, which implies that the implementation of common procedural algorithmic solution faces the risk of combinatory explosion. Therefore, the resolution of this type of problem, leads to the implementation of alternative solutions labeled as intelligent systems. The three metaheuristics: Genetic Algorithm (GA), Ant Colony Optimization (AC) and Simulated Annealing (SA) were to be applied and their results compared. As the first stage, the metaheuristics were to be compared when applied to Traveling Salesman Problem (TSP). A recursive algorithm that implements an exhaustive search for the Traveling Salesman Problem was also implemented as a reference. In the exhaustive search, cities were switched orderly beginning with the last one and this allowed estimating the processing time required to perform the whole treatment: 1.18x10 14 centuries! This paper presents the part of the research where the TSP problem is to be solved by the three metaheuristics. Our particular interest was to estimate the stability in the quality of the solution for each of these intelligent systems, after exploring the alternatives of implementation and the optimization of their parameters. In order, to evaluate their respective efficiency, the response time, quality of the solution, and implementation simplicity were analyzed. Sixth Mexican International Conference on Artificial Intelligence, Special Session 978-0-7695-3124-3/08 $25.00 © 2008 IEEE DOI 10.1109/MICAI.2007.14 243

Upload: cuauhtemoc

Post on 13-Mar-2017

214 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: [IEEE 2007 Sixth Mexican International Conference on Artificial Intelligence, Special Session MICAI - Aquascalientes, Mexico (2007.11.4-2007.11.10)] 2007 Sixth Mexican International

A Comparative Study of three Metaheuristics applied to the Traveling Salesman Problem

Jérôme Leboeuf Pasquier1, Ivica Kalichanin Balich1, Donald W. Carr1, Cuauhtémoc López-Martín2

1 Centro Universitario de Ciencias Exactas e Ingenierías,

Universidad de Guadalajara, Mexico 2 National Polytechnic Institute,

Center for Computing Research, Mexico [email protected], [email protected],

[email protected], [email protected]

Abstract

This paper presents a comparative study of three metaheuristics: Genetic Algorithm (GA), Ant Colony Optimization (AC) and Simulated Annealing (SA), implemented to solve the classical Traveling Salesman Problem (TSP). The efficiency of each approach is evaluated taking into account the execution time of the algorithm and the quality of the generated solution. Additionally, metrics of the program, including McCabe Complexity, Development effort and Lines of Code, are calculated to complete the comparative study. Finally, an evaluation of the difficulty of implementation and the quality of the results corresponding to each metaheuristic is given. The present research will help programmers understand, evaluate and implement the three Metaheuristics. 1. Introduction

The initial challenge that motivated this paper was aimed at finding a solution to a Load Profiling Problem (LPP) in a real-time distributed system; i.e. optimizing the distribution of a set of processes on a network of nodes while satisfying some specific constraints that include: periodic deadlines, shared access to resources, interdependencies and communication between processes. LPP belongs to a category of NP-hard problems, which implies that the implementation of common procedural algorithmic solution faces the risk of combinatory explosion. Therefore, the resolution of this type of problem, leads to the implementation of alternative solutions labeled as intelligent systems. The three metaheuristics: Genetic Algorithm (GA), Ant Colony Optimization (AC) and Simulated Annealing (SA) were to be applied and their results compared. As the first stage, the metaheuristics were to be compared when applied to Traveling Salesman Problem (TSP). A recursive algorithm that implements an exhaustive search for the Traveling Salesman Problem was also implemented as a reference. In the exhaustive search, cities were switched orderly beginning with the last one and this allowed estimating the processing time required to perform the whole treatment: 1.18x1014 centuries! This paper presents the part of the research where the TSP problem is to be solved by the three metaheuristics. Our particular interest was to estimate the stability in the quality of the solution for each of these intelligent systems, after exploring the alternatives of implementation and the optimization of their parameters. In order, to evaluate their respective efficiency, the response time, quality of the solution, and implementation simplicity were analyzed.

Sixth Mexican International Conference on Artificial Intelligence, Special Session

978-0-7695-3124-3/08 $25.00 © 2008 IEEEDOI 10.1109/MICAI.2007.14

243

Page 2: [IEEE 2007 Sixth Mexican International Conference on Artificial Intelligence, Special Session MICAI - Aquascalientes, Mexico (2007.11.4-2007.11.10)] 2007 Sixth Mexican International

Therefore, this comparative study will allow us to determine the best alternative among the three algorithms proposed, when applied to the traveling salesman problem.

Consequently, the present study has two practical purposes. The first is to help novice programmers to understand and implement the three metaheuristics. The second is to demonstrate and compare their efficiency. In particular, the proposed algorithms have been designed to optimize the processing time. Following, each implementation is explained.

2. Genetic Algorithm 2.1. Implementation

Genetic algorithms, formalized by [1], constitute a global search heuristic whose technique consists of evolving a population of potential solutions referred as “individuals”. Genetic Algorithms are commonly applied to solve the traveling salesman, an archetype of combinatory explosion problems. In such implementations, each individual-solution represents a particular path connecting all the cities and its codification called “chromosome” corresponds to a sequence of symbols, each one identifying a specific city.

For each cycle of the main algorithm, a new population referred as a “generation”, is computed from the previous one. Commonly, two individuals of the next generation are obtained combining the chromosomes of two individuals of the actual generation in a process called “crossover”. When applied to the traveling salesman problem, two selected path-chromosomes are merged to produce two new ones. Many crossover operators have been defined that presently produce new sequences of cities. A selection operator is essential to sustain the convergence of the algorithm: two individuals of the current generation are selected taking into account their quality called “fitness”. A better fitness increases the probability of being selected. Presently, the fitness of a solution is obtained calculating the length of the path codified by the chromosome: the lowest, the best. Besides, at each cycle, the chromosomes of some individuals are randomly altered providing thus a higher diversity to the population; again, many operators have been proposed to realize this process called “mutation”. Hence, in our context, the order of the cities codified in a randomly selected chromosome is altered to generate a new individual.

Lastly, several conditions may finalize the cycles of the main algorithm; a convenient one stipulates that the population did not show any improvement during a fixed delay. Presently, the previous condition also integrates a maximum number of cycles to ensure the return of a solution in a finite time. Detailed information concerning genetic algorithms’ operators may be consulted in [2].

A preliminary aspect to the implementation concerns data representation: “city” constitutes a specific class that contains their coordinates in a plan; a symbol as an identifier and a two dimension static array that is initially assigned distances between cities. A second class “individual” contains a field “chromosome” defined as an array of characters and a floating point value corresponding to its calculated “distance”; its most relevant methods includes Chrom_Distance(), Chrom_Crossover() and Chrom_Mutation(). At last, a higher class “population” contains two arrays of instances “individual” and the associated methods including: Fitness(), Crossover() and Mutation().

Then, the implementation of the metaheuristic is described in the following algorithm: Initialize( Population ) ; Cycle ← 1 ; Idle_Cycle ← 0 ; Population.Fitness(Min_Dist) ;

244

Page 3: [IEEE 2007 Sixth Mexican International Conference on Artificial Intelligence, Special Session MICAI - Aquascalientes, Mexico (2007.11.4-2007.11.10)] 2007 Sixth Mexican International

WHILE Cycle < Max_Cycle AND Idle_Cycle < Max_Idle_Cycle DO Population.Selection() ; Population.Crossover() ; Population.Mutation() ; Population.Fitness(Min_Cur_Dist); IF Min_Dist > Min_Cur_Dist THEN Min_Dist ← Min_Cur_Dist ; Display_Result() ; Idle_Cycle ← 0 ; ELSE Idle_Cycle ← Idle_Cycle + 1 ; Cycle ← Cycle + 1 ; 2.2 Operators and Parameters

Nonetheless, the previous description ignores all the implementation alternatives including firstly, the selection of the operators in charge of crossover, mutation and selection and secondly, the parameters involved in these processes including the size of the population and the percentages of crossover and mutation. The following describes our choices of mutation, selection and crossover operators.

The first choice concerns the mutation operator for the TSP with 30 cities. According to several authors the most convenient mutation operator is the one that performs a random permutation of a small number of adjacent genes. Todd [2] recommends that mutation by swapping adjacent genes is the best mutation for TSP and that swapping only two adjacent genes is enough. We apply mutation where a random number from 2 to 10 adjacent genes are chosen and then a random permutation of those genes is performed. Thus, on the average we have 6 adjacent genes random permutation mutation. We found that this gives us better solutions than swapping just two genes. The percentage of the population to undergo mutation is left variable and was explored during the GA parameters optimization phase.

Secondly, the Boltzmann Selection (BS) is considered as one of the most used and investigated selection operators by Michalewicz [3]. It is based on the Boltzmann distribution formula. For the minimization problems, the probability that the solution k is chosen for the next generation P(sk) is:

where Ek is the evaluation or fitness value for the individual k. For the high values of temperature T selective pressure is very small, as the temperature

decreases, the selective pressure increases and forces a convergence. As will be shown in tables below, the BS is able to produce optimal results, but is relatively slow. Thus we have also developed a Linear Ranking operator.

Thirdly, in absence of a unanimity concerning the crossover operator, three implementations are proposed: partial mapping crossover (PMX) for its simplicity, and also cyclic crossover (CX) and a version of the Enhanced Edge Recombination operator. According to Michalewicz [3], the CX operator produces better results than the PMX operator for TSP. Our results confirm that, as shown in the tables below. Todd [2] claims that the EERX operator gives the best results for the TSP among 15 other evaluated crossover operators. As we could not find an

( )

∑−

N

=i

i

k

k

TE

e

TE

e=sP

1

245

Page 4: [IEEE 2007 Sixth Mexican International Conference on Artificial Intelligence, Special Session MICAI - Aquascalientes, Mexico (2007.11.4-2007.11.10)] 2007 Sixth Mexican International

exact description of the EERX we have developed a crossover operator EERX* that complies with the identified requirements for the EERX operator. The EERX* produces offspring in such a way that it recombines edges of the parents, preserving the common edges of the parents and introducing a minimum of new edges in the offspring. We have also added requirements that the number of alterations between parents should be minimized when choosing edges for the offspring, and that the offspring should not end up having the same path among cities as either of its parents.

The EERX* operator shows much more stability over the wide range of parameter values than the PMX operator and the CX operator. Moreover, it has shown to be much faster than PMX and CX operators. The EERX* operator gets close to optimal solutions in less than thousand cycles while PMX and CX use hundreds of thousands of cycles to get to the same quality of solutions.

There are two weaknesses of the EERX* operator: first, it needs improvement in fine tuning, as it frequently stays very close to the best know solutions but does not reach them and, second, it will need revision to make it faster since, even though being much faster in terms of number of cycles it does not show much improvement over the PMX and CX operators when measured in units of time.

We have applied the Genetic Algorithm with different combinations of operators to five maps of thirty cities, and searched for minimum total minimum distance. Some of the results are shown in table 1. The numbers represent pairs (distance, time in seconds).

Table 1. Boltzmann selection (BS) and cyclic crossing (CX) operators; population 90.

Crossover \ Mutation 60% 70% 80%

1% (2866,399) (3135,385) (3034,484) 5% (2727,365) (2776,400) (2904,535)

33% (2195,331) (2219,352) (2218,413) 67% (2212,374) (2207,405) (2200,433)

As a reference, during extensive testing with genetic algorithms, ant colonies and simulated

annealing the minimum distance found was 2,195. The Boltzmann selection together with cyclic crossing on the population of 90 individuals

(solutions) showed the best results and better stability than other combinations of operators, so it was our final choice for the GA for the TSP. Finally, the optimal set of parameters chosen as best parameters were:

Population size: 90, Selection operator: Boltzmann selection, Crossover operator: Cyclic crossover (CX), Crossover rate: 60% Mutation operator: Random reorder of 2 to 10 cities, Mutation rate: 33%

3. Ant Colony Optimization 3.1. Implementation

Inspired from an example of self-organization in a biological system [4], ACO introduced in [5] perfectly illustrates how the collaboration of simple entities may lead to the emergence of a global solution.

This metaheuristic consists of using a colony of artificial ants (elementary entities) to explore a specific space of solutions. Each step of an entity is randomly determined but influenced by a sense of distance to the goal (assimilated to a primitive vision) as well as, by the pheromone trails left by previous ants. Trails play a preponderant role: they are reinforced each time an entity follows them (in the real world the ant lays a pheromone provided with an

246

Page 5: [IEEE 2007 Sixth Mexican International Conference on Artificial Intelligence, Special Session MICAI - Aquascalientes, Mexico (2007.11.4-2007.11.10)] 2007 Sixth Mexican International

attractive effect); they vanish with time (due to the evaporation phenomena in the real world). As a result, the most attractive trails emerge gradually and so attract a higher number of ants (entities); however, a good alternative path continues to have a chance to contend. Such emergent behavior allows the helps avoid local optimum solutions. This can be observed in the nature when real ants virtually always succeed in finding one of the shortest paths between their nest and a food source.

The preliminary aspect to the implementation concerns data representation: for efficiency reasons, two matrices “Dist” and “Visib” are declared to contain respectively distances and visibilities between cities; initialized at the beginning of the process, they remain unchanged until the end but provide some required data. Two more arrays “CurTrails” and “GlobTrails” allow storing the pheromones laid down during each cycle and their accumulation through cycles.

Presently, solving the traveling salesman problem consists in applying ACO to a complete weighted graph. Dorigo [6] shows the convenience of using a similar number of ants and cities and placing an ant in each city; hence, the ant will conclude its path in the graph when reaching the same city. At each step, the ant chooses the next city amongst the ones that have still not been visited. This choice is induced by two factors: the visibility and the presence of pheromone. The visibility is computed as the inverse of the distance; the pheromones have been laid down by previous ants that follow the current path. The visibility remains unchanged but the pheromones evaporate over time; thus, a high density of pheromones reflects both the quantity of traversals and their “freshness”. Such mechanism favors shorter paths that accordingly present a higher density and allows the algorithm to “forget” previously attractive paths. Therefore, at each cycle, each ant generates a prospective path partially based on the most recent decisions of the whole colony; in turn, doing this, the ant leaves some evidence of its own decision. Finally, the iterated process must lead to, at least, a local minimum. The iterating process is ended when no improvement of the distance occurs during a fixed delay. Nonetheless, to ensure a solution will arise in a finite time, the algorithm will also terminate after a fixed maximum number of cycles.

The implementation summarized in the following algorithm.

Init(Dist[],Visib[],GlobTrails[]) ; Min_Dist ← Max_Value ; Cycle ← 1 ; WHILE Cycle < Max_Cycle Init_Cycle( Colony, CurTrails[] ) ; FOR EACH City DO //An ant per city FOR EACH Ant DO NextStep_Probab(Visib[], GlobTrails[]) ; RandomlySelect_NextStep() ; Actualize(Ant.Path,CurTrails[]); Complete_Path() ; Actualize( GlobTrails[] ) ; FOR EACH Ant DO IF Min_Dist > Ant.Cur_Dist THEN Min_Dist ← Ant.Cur_Dist ; Display_Result() ; Cycle ← Cycle + 1 ;

247

Page 6: [IEEE 2007 Sixth Mexican International Conference on Artificial Intelligence, Special Session MICAI - Aquascalientes, Mexico (2007.11.4-2007.11.10)] 2007 Sixth Mexican International

v = Vd

LQk

ij =∆τ

3.2. Functions and Parameters

Ant Colony, compared with Genetic Algorithm, offers only a few implementation alternatives, and parameter values are proposed by Dorigo [6]. Furthermore, the relevant alternatives concern the methods in charge of computing the probability of the next steps and of updating the pheromone trials.

As an ant at the city i is choosing its next city j to move to, it takes into account the evaluation of each available city. The evaluation is calculated as:

Tv βijijij =E ⋅α

The vij is visibility of the city j from the city i and the Tij is an intensity of pheromone trail left by other ants in previous cycles between cities i and j. The exponents α and β are constants. The visibility is calculated as reciprocal to the distance between cities i and j.

where V is a constant and d is the distance.

On the other hand, the intensity of the pheromone trails between cities i and j is calculated at the end of each cycle in which ants visit all of the cities as: =+ρ ( ) ( ) ijijij TcTcT ∆+⋅=+ ρ1

where c is a number of cycle and ρ is a coefficient of evaporation with value from 0 to 1. The pheromone trail created in the last cycle, ∆Tij is a sum of trails of the ants that moved from city i to the city j in the last cycle.

∑=

∆=∆N

k

kijijT

1

τ.

Each ant has a quantity Q of the pheromones per cycle. So if an ant k has moved from the city i to the city j in the last cycle, the pheromones left by the ant will be

where L is the length of distance that the ant covered in the cycle.

If there are no pheromone trails between two cities, a small positive constant value ε is assigned. The value of ε was chosen to be 1.0.

3.3 Parameters Optimization

The first results of running the ACO algorithm showed that the values of constants V and Q did not affect the results significantly. Various values were tested and finally they were both fixed at 10,000.

That left us with the need to adjust only three parameters: ρ, α and β. Performing experiments, the best results were always obtained for α = 1.0. Varying ρ from 0.1 to 0.9 and β through the set of values 0.0 to 4.0, the results showed that ρ = 0.1 and β = 3.5 give the best results.

The table 2 shows some of the results obtained during experiments; the minimum value obtained in experiments with various meta-algorithms is 2195.

Table 2. Results from running ACO with V = Q = 10000 and α = 1.0

ρ\ β 2.0 3.0 4.0 5.0 0.1 2220 2203 2203 2210 0.3 2213 2203 2204 2210 0.5 2217 2207 2207 2205

248

Page 7: [IEEE 2007 Sixth Mexican International Conference on Artificial Intelligence, Special Session MICAI - Aquascalientes, Mexico (2007.11.4-2007.11.10)] 2007 Sixth Mexican International

Finally, the optimal set of parameters was chosen as follows: V = Q = 10,000, α = 1.0, ρ = 0.1, β = 3.5 These parameters were used to compare the Ant Colony with the other two metaheuristics.

4. Simulated Annealing 4.1. Implementation

This metaheuristic, introduced in [7] and employed for optimization, has been created as adaptation of the Metropolis-Hastings algorithm. The inspiration came form the annealing process in metallurgy and therefore the name. A high temperature increases the movements of molecules and then, a slow cooling improves their mutual configuration, reducing defects in crystal structure.

The corresponding optimization process behaves as follows. At each cycle of the main algorithm, the current path is modified the following way: two contiguous cities are randomly selected and swapped producing thus a new path. Todd [2] has shown that any possible path may be reached when applying a sequence of these local swaps. After that, the new path is saved if it is shorter than the current one. Such behavior known as “greedy” is inefficient as the solution almost always gets caught in a local minimum. Nevertheless, SA generally escapes these local minimums allowing also bad solutions (i.e. a new paths longer than the current one) some probability of being selected. This probability is high at the beginning but decreases slowly in accordance with the temperature parameter. When temperature is sufficiently low, only the greedy behavior may affect the path.

Lastly, the cycles of the main algorithm finalize when the temperature value reaches zero. As the temperature decrease is fully deterministic, the whole process is always performed in a fixed number of cycles. Thus, the return of a solution in any finite time may be obtained by altering the decreasing function of the temperature. Contrary to the other implementations, no maximum number of cycles is required.

A preliminary aspect of the implementation concerns data representation: “city” constitutes a specific class that contains their coordinates in a plan; a symbol as an identifier and a two dimensional static array that is initially assigned distances between cities. Next, an array of classified “cities” contains the current path. Similar to data, the main algorithm offers great simplicity. The only awkward implementation concerns the function that decreases temperature.

The implementation is summarized in the following algorithm.

Initialize( Temperature, Path ); Min_Dist ← Dist( Path ) ; WHILE Temperature > 0 DO New_Path ← Apply_Swap( Path); IF Dist(New_Path) < Dist(Path)OR Probabilty(Temperature)> Umbral THEN Min_Dist ← Dist( New_Path); Path Dist ← New_Path ; Display_Result() ; Decrease( Temperature ) ;

249

Page 8: [IEEE 2007 Sixth Mexican International Conference on Artificial Intelligence, Special Session MICAI - Aquascalientes, Mexico (2007.11.4-2007.11.10)] 2007 Sixth Mexican International

4.2. Operators and Parameters

The Simulated Annealing was programmed so that in each cycle one possible solution is evaluated and then a neighbor solution is chosen at random. If the neighbor chosen brings an improvement in the result, the neighbor is accepted with the probability one. Otherwise the probability of acceptance P(k) of the neighbor k as a new solution is calculated according to the following formula:

( )| |T∆EF

e=kP

⋅−

where ∆E is a change in solution evaluation, the T is referred to as temperature and the F is a

factor adjustable to fit a particular SA application. In accordance with the previous description of the Simulated Annealing program’s main

process, the only implementation alternative concerns the function in charge of decreasing the temperature. Two versions were implemented and tested; the first version decreases the temperature exponentially:

HC)(

eT=T

⋅−

2ln

0 where the T0 is the initial temperature, the H is the temperature half-life in cycles and the C

is the number of cycles. This version was executed for different initial temperatures and different values of half-life.

In the second version, the temperature decreases linearly, executing N cycles for every degree of decrease in temperature. The adjustable parameters in this version are initial temperature and the number of cycles per degree of temperature.

The preceding versions were applied to Traveling Salesman Problem with 30 cities; a low number sufficient to validate comparison tests while simultaneously allowing a high number of executions.

4.3 Parameters Optimization

In the tests the parameter F ranged from 10-5 to 105, multiplied by 10 in every step. The initial temperature was varied through the interval 2,000 to 20,000, in increments of 2,000. In the first version, the half-life parameter varied from 1,000,000 cycles to 8,000,000 cycles, in increments 1,000,000 cycles. In the second version, the number of cycles per degree had values from 2,000 to 20,000, with increments of 2,000. In particular, values of the parameter F appear to produce the best results in the range 0 to 2,000, associated to a temperature T of 10,000. Nevertheless, the results do not show a significant improvement for a precise range of parameter values. Good paths are produced from time to time without any obvious correlation with the parameters. Moreover, from one map to another, the experiment shows a lack of any stability in the quality of the results. The only efficient way to improve the solutions is to slow the process, increasing the number of cycles per degree of temperature. Consequently, to produce a better solution, the processing time is between one minute and three minutes; but, to be competitive with the others metaheuristics, this processing time should not exceed two minutes. The “a priori” optimal range of parameter values shown in table 3, produce the convergence toward the minimum obtained value of 2,195.

The first version did not show a stable convergence, the results oscillated between 2,300 and 3,300, without apparent pattern of convergence over the range of the parameters mentioned. The second version converged toward the minimum obtained value 2,195 as shown in the next table.

250

Page 9: [IEEE 2007 Sixth Mexican International Conference on Artificial Intelligence, Special Session MICAI - Aquascalientes, Mexico (2007.11.4-2007.11.10)] 2007 Sixth Mexican International

Table 3. The values of parameters for the best results obtained, where F is 300. (Initial temperature, cycles per degree ) 2nd version

( 6 000, 20 000) 2,195 (10 000, 18 000) 2,195 (12 000, 16 000) 2,195 (14 000, 18 000) 2,196

All other experimental results were increasing as the parameters were distancing themselves

from those given in the table 3. After extensive testing with the Genetic Algorithm, Ant Colony, and Simulated Annealing, 2,195 is the best minimum distance ever obtained by any of the meta-heuristics.

Finally, the optimal set of parameters was chosen to be: F = 200, T0 = 10,000 5. Measures and Metrics Software 5.1. Software Size Measures

In spite of the availability of a wide range of software product size measures, source lines of code (SLOC) remains the most used of the many models [9]. There are two measures of source code size: physical source lines of code, and logical source lines of code. The measure used in this paper is the physical source lines of code, but with comments, blank lines, and delimiters not counted. The count of physical lines of course code, gives the size in terms of the physical length of the code as it appears when printed [10].

The implementation of the algorithms for this paper was based upon the following two types of code [11]: 1. New and changed code (N&C): integrated by added plus modified code. The added code is

the SLOC added during current program, while the modified code is the SLOC reused from the base program, but modified (when modifying a previously developed program, the base program is the total SLOC of the previous program).

2. Reused code: the SLOC of the previously developed programs that are reused without modification.

A coding standard is used for establishing a consistent set of coding practices as a provided

criterion for judging the quality of the produced code [11]. In this study, the program was developed based upon a coding standard. The C++ programming language was used for coding the program. With the following characteristics of coding the standard used: each compiler directive, variable declaration, constant definition, assignment statement, flow control statement (if, switch, case, while, do, for) was written as a single line of code. Table 4 depicts the considered counting standard.

Table 4. Counting standard

Count type Type Physical/logical Physical Statement type Included Executable Yes Non-executable Declarations an compiler directives One by text line Comments or Blank lines No Delimiters { and } No

251

Page 10: [IEEE 2007 Sixth Mexican International Conference on Artificial Intelligence, Special Session MICAI - Aquascalientes, Mexico (2007.11.4-2007.11.10)] 2007 Sixth Mexican International

5.2. Complexity Metrics

Cyclomatic Complexity is software metric that provides a quantitative measure of the logical complexity of a program. It defines the number of independent paths in the basis set of a program. An independent path is any path through the program that introduces at least one new set of processing statements or a new condition.

Complexity can be computed in one of three following ways [8]: 1. The number of regions of the flow graph that corresponds to the cyclomatic complexity. 2. The cyclomatic complexity V(G) for a flow graph G is defined as V(G) = E–N+2 where E is the number of flow graph edges, and N is the number of flow graph nodes. 3. V(G) = P+1, where P is the number of predicate nodes contained in the flow graph G.

The software metrics comparison between the algorithms implemented for this paper has been done. The three programs were developed with both the same coding and counting standards, moreover in the following order (the chronology order is relevant for considering the reused code): Genetic algorithm, Ant Colony Optimization and Simulated Annealing. The results are provided in the next section.

6. Comparative Study

To apply a comparative study, ten random maps of thirty cities each were randomly generated. All tests were performed on a computer equipped with a 2.8 GHz Pentium IV processor with 1 GB of random access memory. The best configuration obtained for each of the three heuristics including GA, ACO and SA were applied five times to each of these maps to thus, obtain a complete set of generated distances and processing times.

2800

2900

3000

3100

3200

3300

3400

3500

3600

1 2 3 4 5 6 7 8 9 10

D at a se t

S.A.

A.C.

G.A.

Fig. 1. Minimum distance generated by SA, ACO and GA for each map over five runs.

Figure 1 shows the minimum path found with each metaheuristic over the five runs for all of

the 10 maps. Only for the 8th map, all generated solutions are very close. Eight out of ten times ACO produces the best solution while nine out of ten times SA produces the worst one; nevertheless, the relative difference between SA and the best obtained solution is less than 4.8%. On average, the distances provided by ACO improved the worst minimal paths by 4.5%. GA produces the best solution only one time (map 4) but, its solutions are often close to the best encountered one: on average, the minimal distances provided by GA are only 1.8% higher than the best minimal paths.

252

Page 11: [IEEE 2007 Sixth Mexican International Conference on Artificial Intelligence, Special Session MICAI - Aquascalientes, Mexico (2007.11.4-2007.11.10)] 2007 Sixth Mexican International

0

60

120

180

1 2 3 4 5 6 7 8 9 10

Data set

Ave

rage

Tim

e [s

econ

ds]

S.A.

A.C.

G.A.

Figure 2 that gives the average distances over the five runs applied to the ten maps shows a clear tendency: ACO presents the best solutions for all maps meaning that it offers the highest stability. This time, the relative difference between ACO and the worst average solutions is close to 12.9%. In particular, GA presents the worst solution for maps 3, 8 and 9; the relative difference between GA and the best average solutions is about 11%. This phenomenon is explained by the lack of stability experienced within GA solutions. Finally, SA globally presents the worst performance: the relative difference between SA and the best average solutions is close to 13.6%.

Fig. 2. Average distance generated by SA, ACO and GA for each map over five runs.

Fig. 3. Average processing time required by SA, ACO to solve each map.

Figure 3 presents processing time, once again the performance of SA is poor, with an average processing time almost three times higher than the performance of GA. The performance of ACO is more regular, with an average processing time 30% higher than the performance of GA but 55% lower than the performance of SA. Meanwhile, GA has the best performance, with an average processing time of 54.3 seconds, which is 75% of the average time of ACO and only 35% of the average time of SA.

On another hand, table 5 shows the results from software metrics comparison between the SA, ACO and GA implementations.

2800

3000

3200

3400

3600

3800

4000

1 2 3 4 5 6 7 8 9 10

Data set

Ave

rage

Dis

tanc

e Tr

avel

led S.A.

A.C.

G.A.

253

Page 12: [IEEE 2007 Sixth Mexican International Conference on Artificial Intelligence, Special Session MICAI - Aquascalientes, Mexico (2007.11.4-2007.11.10)] 2007 Sixth Mexican International

Table 5. Measures gathered from software metrics application Lines of code Algorithm McCabe

Complexity N&C Reused Total GA 162 812 0 812 ACO 48 382 56 438 SA 65 460 57 517

According to table 5 the SA implementation complexity is higher the ACO one. In the

opinion of the authors, SA appears to be a much easier to implement, especially when compared with GA. This is an obvious consequence of its conceptual simplicity which also leads to the simplification of the optimization phase which only required defining the temperature function. Concerning optimization of its functions and parameters, ACO requires more effort than SA.

7. Conclusions

The present paper presents an extensive study concerning the implementation of Simulated Annealing, Ant Colony Optimization and Genetic Algorithm to solve the traveling Salesman Problem.

During a preliminary phase, each metaheuristic’s parameters and functions have been optimized. The main set of results jointly with the C++ programs is provided at http://matisse.dip.udg.mx/TSPdownload/ so all the experiments may be verified and expanded.

During a second phase, a comparative study between the three metaheuristics is realized. Various aspects are evaluated including processing time, development effort and quality of the solution. Concerning SA, the relevant aspects are its simplicity of implementation and ease of optimization. Nevertheless, the quality of its results and processing time are respectively 13.6% and 3 times higher than the best average solutions obtained. Concerning GA, the study concludes that the results are acceptable, however, this GA version lacks stability and overall its implementation was exceptionally complicated compared with the other two metaheuristics. However, GA offers the best processing time: 35% of the average of SA and 60% of that of ACO. The study concludes on the advantage of applying ACO that offers the best quality of results: 4.2% improvement over others minimums, a relatively simple implementation and a relative ease of optimization though, not the best processing time: 1.7 times slower in average then GA.

8. References 1. Holland J.: Adaptation in Natural and Artificial Systems. University of Michigan Press (1975) 2. Todd D.: Multiple Criteria Algorithms in Engineering and Operation. Ph.D. thesis, Engineering Design Centre,

Department of Marine Technology, University of Newcastle upon Tyne (1997) 3. Michalevic, Zbigniev: Genetic Algorithms + Data Structures = Evolution Programs. editorial Springer (1995) 4. Deneubourg J.L., Goss S.: Collective patterns and Decision-Making. Ethology, Ecology and Evolution, V.1

(1989) 295-311 5. Dorigo M.: Optimization, Learning and Natural Algorithms, PhD Thesis, Politecnico di Milano, Italy (1992) 6. Dorigo M., Maniezzo V. y Colorni A.: The Ant System: Optimization by a Colony of Cooperating Agents. IEEE

Transactions on Systems, Man and Cybernetics Part B, Vol. 26, N. 1 (1996) 1-13 7. Kirkpatrick S., Gelatt C. D. and Vecchi P. M.: Optimization by Simulated Annealing. Science Vol. 220, N. 4598

(1983) 671-680 8. Pressman R. S.: Software Engineering. Mc Graw Hill (2006) 9. Mc Donell S. G.: Software Source Code Sizing using Fuzzy Logic Modelling. Elsevier Science (2003) 10.Park. R. E.: Software Size Measurement: A Framework for Counting Source Statements. Software Engineering

Institute, Carnegie Mellon University (1992) 11.Humphrey W. A.: Discipline for Software Engineering. Addison Wesley (1995)

254