Traveling Salesman Problem with Time Windows Solved with Genetic Algorithms Assistant lecturer, László Illyés EMTE Sapientia University, Miercurea-Ciuc Romania, Department of Mathematics and Informatics Abstract: The Traveling Salesman Problem (TSP) is a very common problem in many applications. It appears in the transportation of goods and not only. As we know this problem is NP hard. Time Windows (TW) brings us some additional constraints to solve. In case there are many Time Windows the problem constraints determine almost the whole solution of the problem and in some cases we can solve the problem. We restrict the cardinality of Time Windows. In our work we define the following conditions without loss of generality: 1. The salesman has to visit one town each day 2. The distance between two towns can be performed in a day 3. We have maximum two Time Windows 4. We have routes between every two towns, but the cost of the routes may differ in case we go from town A to town B, or we go from town B to town A. Genetic algorithms are powerful tools for solving NP hard problems. They utilize search and optimization procedures that operate in a similar way to the evolutionary processes observed in nature. We have to code the problem data structure in a structure (chromosome), which allows us to make some genetic operations over this chromosome. Genes constitute chromosomes. A chromosome represents a possible solution in the space of solutions. We can code the problem of time windows in some chain of chromosome where the first chain segment starts with the town from where the salesman starts his journey and the end of the segment, the first constraint of time window, the town specified in the first time window. The second chain starts from the town reached from the first time window, and ends with the second town specified in the second Time Window constraint and so on. The chains connected together form the desired chromosome. None of the towns appears twice in the chromosome, the length of this chromosome equals with n, the desired cardinality of the towns to visit. Even if we reach an optimal solution, we can t prove that it is optimal because of NP hardness. Keywords: Traveling Salesman Problem, Time Window, genetic algorithms, chromosome, genes
1. Introduction The traveling salesman problem (TSP) is to find a minimum-cost Hamiltonian cycle that visits node of n exactly once and returns to the starting node, given a network G(V,E), node set V={1,2,,n}, arc set E={(i,j):i j, i,j V}, and cost c from node i to node j [SHM05]. Our paper refers to the asymmetric type of the problem, where c c ji. We can find real-world instances of the TSP in a variety of areas, i.e. delivery, scheduling, network designs etc. The TSP is one of the first optimization problems proved as NP hard. Time constraint introduces other problems in solving the main problem. 2. Mathematical model in a given network G(V,E) [SHM05] Minimize c x i V Subject to i V j V j V x =1, j V, (1) x =1, i V, (2) x =0,1, (i,j) E, (3) x 1, S, S 2 (4) i S j V S We assume, that none of two time windows overlap. We order the time windows in the natural order, where TW 1 <TW 2 <TW m. We consider TW k =[t kmin,t kmax ], the k-th time window. k=1,2 m and A k the town corresponding to this time window. According to our problem definition, where every town is visited in a single day, and time windows are referring to a release day and a deadline day, time constraints are transformed in a structural problem for the proposed data. Day windows DW k =[D kmin,d kmax ]. D kmin is the minimum of the relative day from the beginning of the journey to reach the town A k. D kmax is the deadline. We have two limit conditions in this problem. If there is no time window, we have n! possibilities to perform the route and we reach the classical TSP. In case that all towns has time windows with one possible day for every town, the problem is obvious, and not NP hard. 2. Data structure for genetic approach. Generating chains We use the 2 TW model and some concrete data for easy understanding, and make the desired generalization. We choose the following chromosome: (g 1,g 2, g j..g k g n-1,g n,g 1 ), where g 1 =A 0, g j =A j town and
g k =A k town. A 0 is the starting and ending town, A j and A k are the towns with Time Windows. The rest of chromosome consists of the nonconstrained towns. The first town has to be the last one too; else we have the WSP (wandering salesman problem). Genes represent the towns and the locus of the genes the order of the TS arrival (day). We generate the first population in order to satisfy the TW constraints. We can generate this in the following way: We randomly choose from the first time window the day, when the TS have to be in the first constrained town. We randomly generate the day for the second TW in the same way. Next we generate randomly the remaining string for the 3 chains of chromosome. In this case we know the length of each chromosome. We show this with concrete dates: let it be n=100, the first Time Window: [25,27], the second Time Window: [35,38]. In case, that the randomized value of the first time constraint is 26 and for the second is 36. We have the first chain length 26, the second equals width 11, the last with 65, the structure of chromosome is: (g 1, g 2, g 26..g 36 g 99, g 100,g 1 ). The first chain is (g 1, g 2, g 26 ), the second chain is (g 26,g 27, g 36 ) and the third (g 36, g 37, g 100,g 1 ). The chains length may differ from one chromosome to another, because the randomized generation of desired day of Time Window. 3. The 2 Level genetic approaches. Bottom up technique. In this case we apply genetic algorithm for the chains occur as an individual from the first population. This we apply for every individual and for every chain occurred. This will be the first level of the genetic approach. On the next level we have some problems to solve. One of them is, that the chain lengths may differ from a chromosome to another. In this case we have to define different genetic operators from the well known ones. Genetic operators are the reproduction, crossover and mutation. We have to show the operators for both levels. First level (chain optimization): Selection for reproduction based on roulette wheel, fitness based selection; Crossover operators used are from the classical operators: order crossover (OX), partially matched crossover (PMX), cycle crossover (CX), Stefan Jakobs crossover (SJX), and edge recombination crossover (ERC). Because the asymmetry the ERC operator we can use only in an adequate mode, i.e. the order in the chain must be the same in both parents. Mutation operator can be reciprocal exchange, inversion,
displacement and heuristic. The fitness function can be the quadratic 1 inversion of the cost. f = 2 1+ C. Second level (global optimization). After we made the optimization for the chains we can make the global optimization in different ways. We assume that we have some piece of chain with good proprieties. We have to define here the genetic operators. These operators have to work even if the chains have not equal lengths. The best method in this approach we consider not a genetic algorithm but an evolutionary algorithm. In this case we have to look after the biggest changeable chain between every sub chain obtained because time windows. We consider that we have 15 towns with 2 time windows. Let s have town 1 the origin town, town 2 and town 3 with time windows. Time windows should be [4,6] and [8,10], meaning that the 2 nd town has to be reached in the 4 th day, but not least then in the 6 th day, and so on. In this case the first chain length is [4,6], the second [2,6] and the last [5,7] because of the time windows. We define some mutation operators. The first changes between 2 parts of the chains. The second makes rotational changes. We take from every chain a sub chain and put in another chain in clockwise order or in counter-clockwise order. 4. Another point of view (global optimization from the beginning): We can view the problem like the m+1 MTSP (Multiple Traveling Salesperson Problem) where m is the number of the time windows. Here we have the constraint that every salesman has to travel from one specific town to another specific town. The first and last towns are fixed, and to have the global TSP, the starting town of the first salesman and the ending town of the last salesman is the same. We can use the twopart chromosome technique from [CAR05]. The difference between our chromosome and the MTSP is that we introduce the starting town and the TW towns only in the calculus. These towns are not in the first part of the chromosome. In the second part we have the number of days. The first gene from the second part is the number of days performed by the salesman to reach the first time-constrained town. And so on. Constraints on the second part of the chromosome are more than in the [CAR05].
The data structure for chromosome we consider could be: 1 4 6 11 2 5 14 10 9 3 15 12 8 13 7 1 But similarly to the two-part chromosome technique used we don t introduce in the chromosome the starting town and the time windows towns: 4 6 11 5 14 10 9 15 12 8 13 7 5 10 Chromosome splitter The chromosome doesn t correspond with the real positions, we have to subtract the subtracted positions too, and from the first time window we extract 2, from the second 3 positions. In this case we can proceed in different ways. Or we transform time windows, or we make transformations only when we make the calculus. In the first case, TW 1 =[4,6][2,4], and in the second case TW 1 =[8,10][5,7]. With this kind of notation we have the chromosome in another form: 4 6 11 5 14 10 9 15 12 8 13 7 3 7 Genetic operators: In the first part of chromosome we can use the classical operators that were enumerated in the first approach. In the second part of the chromosome we can use another approach: the covering approach or we can simply choose one of the gene from the first parent, the second from the second. A possible reproduction scheme with CX operator The parents involved: P1 4 6 11 5 14 10 9 15 12 8 13 7 5 10 P2 6 9 8 10 11 13 7 5 4 12 15 14 4 9 The offsprings: O1 4 6 11 10 14 13 9 5 12 8 15 7 5 9 O2 6 9 8 5 11 10 7 15 4 12 13 14 4 10
Conclusions: The appropriate data structure for the chromosome was found, with genetic operators too to solve the problem. We transform a sophisticated problem in a problem with easy genetic approach. References [ALA02] Álmos, A. et.all., (2002), Genetikus algoritmusok, Typotex Kiadó Budapest [BOI04] Borgulya, I., (2004), Evolúciós algoritmusok, Dialóg Campus Kiadó Budapest-Pécs [CAR05] Carter A.E., Ragsdale C.T., (2005), A new approach to solving the multiple traveling salesperson problem using genetic algorithms, European Journal of Operational Research xxx (2005) xxx-xxx [FAB02] Fabian, Cs. B., (2002), Generalized Simple and Crossover Mutations for Evolutionary Algorithms, International Conference on Economic Cybernetics Bucharest [HES02] Heung-Suk H., (2002), An improved model for vehicle routing problem with time constraint based on genetic algorithm, Computers & Industrial Engineering 42, pp.361-369 [ILP05] Illyés, L.; Pál, L., (2005) Generalized particular covering problem with genetic algorithms, AMO Advanced Modeling and Optimization, Volume 7, Number 1, 2005, pp.1-7 [SHM05] Sang-Ho K., Hun-Tae K., Main-Kyu K., (2005), Determination of the candidate arc set for the asymmetric traveling salesman problem, Computers & Operations Research 32 (2005) pp.1045-1057 [SMK05] Mitrovic-Minic S., Krishnamuri R., (2005), The multiple TSP with time windows: vehicle bounds based on precedence graphs, Operations Research accepted work.