Ant Algorithm Applied to the Quadratic Assignment Problem Steve Rogers, Diane Bishop Abstract Algorithms inspired by Ant Colony Systems (ACS) have been applied to various combinatorial optimization problems in the past. The results show good promise for further research and applications in that variation of ACS are very competitive with other nature inspired algorithms, such as simulated annealing and evolutionary computation. In the algorithms, the “Ants” are agents that cooperate to find improved solutions to a given optimization problem. The mechanism that ants use to cooperate is through pheromone deposited on the paths traveled. Pheromone accumulates as an ant travels a given solution path. More pheromone increases the probability that other ants will choose to traverse the same path and it becomes a stronger component for an overall solution. The quadratic assignment problem is to optimize a network consisting of distances and flows. Standard algorithms are given and demonstrated on a simple assignment problem.

Article Information Field of Study—Optimization Keywords—quadratic-assignment-problem ant-colony-systems

I. INTRODUCTION The Ant Colony Systems (ACS) algorithm is a distributed algorithm that has been applied to the traveling salesman problem [1], [2] (TSP) with some success. The TSP is a shortest path optimization problem in which an agent (salesman) must visit each node (city) only once in a given tour (closed path). The solution to the TSP is the tour with the minimum distance. At the lowest level of intelligence an individual agent must find the shortest path to accomplish an assigned task. In ACS a set of agents called “ants” cooperate to find good solutions to optimization problems. The mechanism of cooperation is an indirect broadcasting form of communication by means of “pheromone” that the ants “deposit” on previously traveled solution paths. Thus, an ant colony is the biological inspiration of ant algorithms. Real ants find the shortest path from a food source to the nest without visual cues by exploiting pheromone information. Figure 1 shows how an ant colony exploits pheromone to accomplish this. While moving across the ground ants deposit pheromone and follow, according to probability, pheromone previously deposited by other ants. In applications of computer science, routing and networking involves finding the shortest path for directing data and information [5]. An important concept derived from this is the necessity for backup plans. If a particular route is down due to communications failure or failed network lines, then there is a need to know of another route that is at least as efficient as the initial, desirable route. The study of ant colonies and their colonization habits has led to applications in the realm of computer science in the analysis of the classic traveling salesman problem and in transport networking applications pertaining to virtual wavelength path routing. Other applications include autonomous robotics, combinatorial optimization, and telecommunications networks. Ant Colony Optimization has been applied to many areas of computer science including sequential ordering

problems, graph ordering problems, quadratic assignment problems, vehicle routing problems, scheduling problems, partitioning problems, routing, wavelength-allocation, and the symmetric and asymmetric traveling salesman problem [5].

Figure 1 How Ants Exploit Pheromone to Find a Shortest Path The remainder of the paper will discuss how ACS may be applied to solving the Quadratic Assignment Problem (QAP). QAP is a type of combinatorial optimization in which values or flows must be matched with shortest paths through networks. QAP is an assignment problem in which network flows or capacities must be maximized while distances between tasks must be minimized. Tutorials on ACS applications are available in reference 7. QAPLIB [8] is a resource for test problems and algorithms for solving QAP. Mathematically, we can formulate the problem by defining two n by n matrices: a flow matrix, f, whose (i,j) element represents the flow between facilities i and j, and a distance matrix, d, whose (i,j) element represents the distance between locations i and j. A vector p(j) represents the location to which facility j is assigned. This vector is a permutation of the numbers {1, 2,..., n}. With these definitions, the QAP can be written as

The discussion is organized as follows: 1) Introduction, 2) ACS algorithm, 3) QAP application, 4) Conclusion, 5) References, and 6) Appendices.

II. ACS ALGORITHM It is assumed that ants are traveling on a graph from a city “r” to the next city “s”. Each edge (r,s) on this graph has a cost (length), δ(r,s), and a pheromone measure, τ(r,s), which is updated every time an ant walks over this edge. Each ant builds a complete tour, by choosing its next city according to a probabilistic transition rule. The transition rule implies that better odds are given to cities connected by short edges with high amounts of pheromone. Figure 2 shows conceptually how the pheromone concentrations may vary as the ants traverse the network. According to the transition rule, an ant located at city r, will choose its next city s, according to the equation

in which Jk(r) is the set of cities that remain to be visited by ant k positioned in city r. In equation (2), η(r,u) is defined by 1/δ(r,u), and [µ, β] are parameters that set the relative importance of pheromone vs. distance. Also in equation (2), q0 is constant parameter, defined by the range (0 < q0 < 1), which is selected to establish the exploitation vs. exploration. As q0 decreases the ant chooses more according to pheromone concentrations (more exploitation). As q0 increases the ant chooses more according to probability (more exploration). Exploration would tend to keep the ants out of local minimums. Thus, q0 may be related to risk tolerance; higher values suggest more risk tolerance. Thus, exploration (high values of q0) would be appropriate at the beginning of a search and exploitation at the end of a search. In addition, q is a random number defined by the range (0 < q < 1). Higher values of q improve the richness of the search paths chosen by the ants. If q is less than q0, the ant simply chooses the best path according to pheromone and η. If q is greater than or equal to q0, the ant will choose its next city according to the probability equation

Figure 2 How Ants Exploit Pheromone to Find a Shortest Path In equation (3), Pk(r,s) is the chance of city s to be chosen by ant k positioned in city r. Since the pheromone on the edge is multiplied by η, which depends on δ, better odds are given to shorter edges with more pheromone. After each ant relocation step, the pheromone on all edges is updated according to a local pheromone-updating rule given by

in which ρ, a parameter defined in the range (0 > ρ > 1), describes the local evaporation of pheromone, and ∆τ(r,s) is the sum of all pheromone left by ants that used this edge in their last step. Normally ρ is fixed during the path search. An ant using edge (r,s), normally leaves 1/δ(r,s) pheromone on the edge. Once all ants have completed a tour, a global pheromone-updating rule is applied. The global updating rule is described by the equation

in which α is the global evaporation parameter defined by the range (0 > α > 1). In equation (5), if (r,s) belongs to this global best tour then ∆τ(r,s) is 1/(length of global best tour) and 0 otherwise. Equation (5) is only applied to the global best solution. Normally, α is not varied during the search. In addition to this, according to a boolean parameter,

each ant may leave a global trail, adding 1/(length of their tour) to each edge belonging to its last tour. One important factor in considering ACS over other algorithms is its efficiency compared to those other algorithms. It is assumed that in each step, each ant has to decide which way to go. It is further assumed that “n” is the number of cities that may be visited by “m” ants for “k” cycles. From every city, an ant can go to any city it hasn't visited yet. This means it has to decide from among ~n cities. Before deciding, it has to calculate the probability of each path, according to equation (3). This part requires ~n calculations. Thus for all ants combined, one step requires ~m*n calculations. To complete 1 cycle, one ant must go through all n cities, which means it has to complete n steps. This requires ~m*n*n calculations for each cycle. Run time for the ACS algorithm is, therefore, O(m*n2*k), which is much better for big graphs than the recursive solution - O(n!)3. It is obvious that there are also a constant number of calculations each ant has to perform in each step.

III. QAP APPLICATION The ACS algorithm was applied to 8x8 QAP. The details of the problem are given in the matlab code of Appendix A. As mentioned briefly above a QAP is the solution of a flow network. The objective is to optimize a node tour where all nodes are serviced with minimum distance and maximum flow (value). Said network has a distance matrix between each node and a flow matrix (data transfer, material, human, goods, etc.) associated with each node (task or assignment). The objective is to maximize flow while minimizing distance. In a system where the matrices are diagonally symmetric, the distance and flow matrices may be combined for input to the ACS algorithm. The test input matrix is

DF is the combined distance/flow matrix, where the upper triangular matrix is the distance data and the lower triangular matrix is the flow data. Figure 3 shows a solution iteration trial for the above input matrix. To demonstrate the ACS algorithm a Matlab code freely available from the web [9] was used (see Appendix A). It was modified slightly as follows for comparison: 1) a B matrix was constructed to incorporate the flow value matrix F, and 2) increasing the number of ants to the number of nodes.

Figure 3 Typical Iteration to Solution Figure 3 shows a typical ACS solution for the QAP input matrix shown above. Note that this is a sub optimal solution at 110, whereas the ideal solution is 107. Figures 4 and 5 compare Monte Carlo trials with 8 (the same number of nodes) and 4 ants (agents). There were 50 trials and for each trial two values are given: one for the downloaded version and one for a modified version. The cost is the basis of comparison. In our case the flow value (lower triangular part of the matrix) must be maximized, while the distance value (upper triangular part of the matrix) must be minimized. It was expected that additional agents would aid in avoiding local minimums, but there was no improvement in solution quality for the particular problem studied. Minor modifications aided the solution quality slightly, but since the initial â€œantâ€? locations for each search are random, no such conclusion can be made without numerous other trials.

Figure 4 Comparison with the Number of Ants Equal to Number of Nodes (8)

Figure 5 Comparison with Number of Ants Fixed at Four

IV. CONCLUSION The Ant Colony System (ACS) is a distributed algorithm that can be applied to multiple areas of computer science in the realm of combinatorial optimization, quadratic

assignment, networking, and routing problems. ACS has been reviewed and current code has been provided in the appendices [2]. ACS has been utilized for many combinatorial optimization applications with some success. Further research on more practical applications is necessary for evaluation and development. Practical applications include team assignment optimization for cooperative control, switch assignments for networks threat avoidance path selection for minimum time traversal of a region.

V. REFERENCES [1] Bonabeau, E. etal, Swarm Intelligence from Natural to Artificial Systems, Oxford University Press, 1999, ISBN 0-19-513159-2. [2] Dorigo, M. and Gambardella, L., “Ant Colony System: A Cooperative Learning Approach to the Traveling Salesman Problem,” IEEE Transactions on Evolutionary Computation, v. 1, no. 1, 1997. [3] Perez-Uribe, A. Et al, “Effects of group composition and level of selection in the evolution of cooperation in artificial ants”, Proceedings of the 7th European Conference on Artificial Life, ECAL'2003, W. Banzhaf et al. (Eds.), LNAI 2801, Springer, pp. 128-137. [4] Perez-Uribe, Andres, “Ant Colony System for Solving a 14-city TSP Problem”, January, 2002, Last Updated June 6, 2003, Last Accessed June 2, 2004, http://www.geocities.com/fastiland/Teaching/acs/acs-tsp.c. [5] Wilson, Nancy M., “Ant Colony Optimization as Applied to Networking Issues”, Christopher Newport University, Newport News, VA, Last Accessed June 2, 2004, http://users.cnu.edu/~nawilson/ants.html. [6] Strauss, C. & Bullnheimer, R., "An Improved Ant System Algorithm for the Vehicle Routing Problem." Institute of Management Science, preprint 1 (19997) 1-11. University of Vienna, Austria. [7] Dorigo, Marco, “Ant Colony Optimization: Tutorials and Plenary Talks”, Universite Libre De Bruxelles, Institut de Recherches Interdisciplinaires et de Developpements en Intelligence Artificielle (IRIDIA), Last Modified June 20, 2003, Last Accessed June 2, 2003, http://iridia.ulb.ac.be/~mdorigo/ACO/tutorials-courses.html. [8] Burkard, R.E. Et al, “QAPLIB—A Quadratic Assignment Problem Library”, Institut fur Mathematik B, Technische Universitat Graz, Last Modified February, 2002, Last Accessed June 2, 2004, http://www.opt.math.tu-graz.ac.at/qaplib/. [9] http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=1663&objectType=file

VI. ABOUT THE AUTHORS Steve Rogers is with the Institute for Scientific Research, srogers@isr.us. Diane Bishop is with Custom Manufacturing & Engineering, Inc., dbishop@custom-mfg-eng.com.

VII. APPENDICES A. Appendix A Matlab code used in these studies: % QAP_scr.m % Ant Algorithm for the Quadratic Assignment Problem % By Kyriakos Tsourapas % email : kyriakos_t@yahoo.com % University of Essex 2002 % modified by Steve Rogers % Institute for Scientific Research, 5/2004 % clc; clear;

disp('Please wait...'); disp(' '); % THE DISTANCE/FLOW MATRIX % UPPER HALF = DISTANCE, LOWER HALF = FLOW DF = [NaN 10 4 2; 3 NaN 6 4; 8 2 NaN 1; 3 4 5 NaN]; DF = [NaN 1 2 3 1 2 3 4; 5 NaN 1 2 2 1 2 3; 2 3 NaN 1 3 2 1 2; 4 0 0 NaN 4 3 2 1; 1 2 0 5 NaN 1 2 3; 0 2 0 2 10 NaN 1 2; 0 2 0 2 0 5 NaN 1; 6 0 5 10 0 1 10 NaN]; % PROBLEM SIZE (NUMBER OF SITES OR DEPTS) pr_size = size(DF, 1); ants = pr_size; % NUMBER OF ANTS % ants = ceil(pr_size/2); % NUMBER OF ANTS max_assigns = 2500; % NUMBER OF ASSIGNMENTS (WHEN TO STOP) % optimal = 107; % OPTIMAL SOLUTION optimal = 70; % OPTIMAL SOLUTION a = 1; % WEIGHT OF PHEROMONE b = 6; % WEIGHT OF HEURISTIC INFO lamda = 0.8; % EVAPORATION PARAMETER % lamda = 0.9; % EVAPORATION PARAMETER Q = 10; % CONSTANT FOR PHEROMONE UPDATING AM = ones(ants,pr_size); % ASSIGNMENTS OF EACH ANT min_cost = -1; % HEURISTIC INFO - SUM OF DISTANCES BETWEEN SITES for i=1:pr_size D(i) = sum( DF(1:i-1,i) ) + sum( DF(i,i+1:pr_size) ); F(i) = sum( DF(i,1:i-1) ) + sum( DF(i+1:pr_size,i) ); end Dinv = 1./D; B = F'*Dinv; niter = 1; % START THE ALGORITHM assign = 1; while (assign <= max_assigns) & ( (min_cost > optimal) | (min_cost == -1) ) % =============== FIND PHEROMONE =============== % AT FIRST LOOP, INITIALIZE PHEROMONE if assign==1 % SET INITIAL PHEROMONE LEVELS % pher = ones(pr_size);

pher = ones(pr_size)*1e-6; % IN THE REST OF LOOPS, COMPUTE PHEROMONE else for i=1:pr_size for j=1:pr_size tmp = zeros(ants,pr_size); tmp( find(AM==j)) = 1; tmp = tmp(:,i); tmp = tmp .* costs'; tmp( find(tmp==0) ) = []; tmp = Q ./ tmp; delta(i,j) = sum(tmp); end end pher = lamda * pher + delta; end % ============ ASSIGN DEPTS TO SITES ============ % EACH ANT MAKES ASSIGNMENTS for ant=1:ants % GET RANDOM DEPT ORDER depts = rand(pr_size, 2); for i=1:pr_size depts(i,1) = i; end depts = sortrows(depts,2); % KEEP AVAILABLE SITES IN A VECTOR for i=1:pr_size free_sites(i) = i; end pref = ones(pr_size,1); % PREFERENCE FOR EACH SITE prob = ones(pr_size,1); % PROBABILITIES FOR EACH DEPT for dept_index=1:pr_size % GET SUM OF THE PREFERENCES % AND THE PREFERENCE FOR EACH SITE pref_sum = 0; for site_index=1:size(free_sites,2) tmp_pher = pher(depts(dept_index), free_sites(site_index)); % pref(site_index) = tmp_pher^a * ( 1/D(free_sites(site_index)) )^b; % pref(site_index) = tmp_pher^a * ... % ( F(depts(dept_index))/D(free_sites(site_index)) )^b; pref(site_index) = tmp_pher^a * ... ( B(depts(dept_index),free_sites(site_index)) )^b; pref_sum = pref_sum + pref(site_index); end % GET PROBABILITIES OF ASSIGNING THE DEPT % TO EACH FREE SITE

prob = free_sites'; prob(:,2) = pref / pref_sum; % GET THE SITE WHERE THE DEPT WILL BE ASSIGNED prob = sortrows(prob,2); AM(ant,dept_index) = prob(1); % ELIMINATE THE SELECTED SITE FROM THE FREE SITES index = find(free_sites==prob(1)); prob(1,:) = []; free_sites(index) = []; pref(index) = []; end % GET THE COST OF THE ANT'S ASSIGNMENT costs(ant) = 0; for i=1:pr_size for j=1:i-1 dept_flow = DF(i,j); site1 = AM(ant,i); site2 = AM(ant,j); if site1 < site2 sites_distance = DF(site1, site2); else sites_distance = DF(site2, site1); end costs(ant) = costs(ant) + dept_flow * sites_distance; end end if (costs(ant) < min_cost) | (min_cost == -1) min_cost = costs(ant); ch_assign = AM(ant,:); end if mod(assign,100) == 0 disp( sprintf('Assignments so far : %d Cheapest cost : %d', assign, min_cost)); end assign = assign + 1; X_min_cost(niter) = min_cost; niter = niter + 1; end end clc; disp( sprintf('Cheapest Cost : %d', min_cost)); disp( sprintf('Assignments : %d', assign-1)); disp(' '); disp('Assignment'); disp('----------'); ant_index = find(costs==min(costs)); for i=1:pr_size

disp( sprintf('Dept %d to Site %d', i, ch_assign(i))); end figure(1) plot([X_min_cost' X_min_cost']),grid on title('cost vs. iteration') ylabel('cost in distance * flow') xlabel('iteration') Appendix B C source code from ref 4: /* Ant Colony System for solving a 14-city TSP problem By Andres Perez-Uribe LSA2 - STI - EPFL January, 2002 Email: Andres.Perez-Uribe AT a3.epfl.ch Based on: Dorigo and Gambardella, Ant Colony System: A Cooperative Learning Approach to the Traveling Salesman Problem, IEEE, Trans Evol. Comp. 1, 1997, 53-66 WARNING: This is not a 100% implementation of Dorigo et al. algorithm, I have only used the basic idea. In particular, I have used a simpler exploration-exploitation strategy, and the value of the initial pheromone level is based on what I've called the 'naive-distance'. Please, refer to Dorigo et al. for the original algorithm. I think mine is simpler, but may not work as well as theirs (especially because of random exploration instead of their biased exploration. There is no guarantee that the code will do what you expect or that it is error free. It is simply meant to provide a useful way to experiment with a ACS-like algorithm. Modification:June 6, 2002. global update only for the best path so far thanks to Luc-Olivier de Charri'e8re Update: June 6, 2003. change of srand48(), lrand48(), and drand48() by srand() and rand() Last Update: Oct 16, 2003 change definition of BIG... the previous value produced incorrect behavior when using some compilers or a warning message as follows: warning: integer constant is too large for "long" type */ #include #include #include #define BIG 999999 #define NumCities 14 #define NumAnts 4

/* initial pheromone level (NumCities*NearestNeighTourLength)^-1 */ /* #define Tao0 : defined as (NumCities*SumNaiveDist)^-1 /* learning rate */ #define RHO 0.8 /* exploitation rate */ #define q0 0.5 /* number of iterations */ #define MAXITER 10 float Tao[NumCities][NumCities]; int Tour[NumAnts][NumCities+1]; int BestTour[NumCities+1]; int StartCity[NumAnts]; int VisitedCities[NumAnts][NumCities]; int AntInitInCity[NumCities]; float dist[NumCities][NumCities]; float SumLen[NumAnts]; float MinLenTour; float Tao0; int finished; int randcity; int i,j,k,t; int iter; /* predeclarations */ float Burma14TSPproblem(float dist[NumCities][NumCities]); float FindNewBestSolution(float MinLenTour, int Tour[NumAnts][NumCities+1], float SumLen[NumAnts], int BestTour[NumCities+1]); void PrintBestPath(int BestTour[NumCities+1]); int main() { /* Initialization phase */ /* Init random number generator */ srand(12345); /* Init. Min Tour length value */ MinLenTour = BIG; /* Init. TSP and initial pheromone value */ Tao0 = 1.0/(Burma14TSPproblem(dist)*NumCities); printf("Tao0 = %f Naivedist=%f\n",Tao0,Burma14TSPproblem(dist)); /* Init. pheromone level of each link */ for(i=0;i WeightedPheromone[antpos][ArgMaxWeightedPhero]) ArgMaxWeightedPhero = i; } else WeightedPheromone[antpos][i] = 0; /* exploration-exploitation */ prob_explore = rand()/RAND_MAX; if(prob_explore < q0)

NextCity = ArgMaxWeightedPhero; else { if(nonvisited==1) RndCity = 1; else RndCity = 1+rand()%(nonvisited-1); i=-1; j=0; do { i++; if(!VisitedCities[k][i]) j++; } while((i< NewMinLenTour) { for(i=0;i