Vous êtes sur la page 1sur 4

1

Renee Dale CSC 4700 Solve travelling salesman problem using a genetic algorithm and the NXT simulator Environment Cities were to be recognized by grey scale colors. First the robot output light sensor values while over arbitrarily chosen grey scale color blocks. This data was used to generate ranges of values. From the initial ranges a gradient was created with black

Grey Scale Color Blocks

Ranges

Values obtained from gradient

Gradients and resultant initial city map

Final set of ranges

2 bars separating each individual color. A table with each value output by the nxt was analyzed to make another gradient with only colors the nxt was able to distinguish from one another as well as a table of ranges the nxt had recognized consistently.

Robot on gradient

Robot on initial city map

Nine greyscale colors were selected to use as the 9 cities, and were connected by black (lightsensor values 0-15) roads approximately as big as the nxt.

Map with more complex connections

Run; map with slightly larger roads

Behaviors If a city is found, robot should inspect all 4 sides of square for a road. If a road is found, the robot should travel down the entire road until it reaches the next city,

3 while measuring the distance via a count variable. The start city, the next city, and the road length should be recorded in the node object. This should continue until all 9 cities have been found, indicated by an array wherein a slot is filled each time a new city is found (city number x would be saved in slot x-1); once all 9 slots contain no zeros the genetic algorithm should begin to find a solution to the problem. Genetic Algorithm Chromosomes and genes The genetic algorithm should run for a maximum of 1000 generations, with each generation having 50 chromosomes, and
Gene selection loop

each chromosome with 9 genes, each gene representing a city

connection. All possible city connections were saved when the robot discovered them. To generate a chromosome, each connection should be randomly chosen with the exception of the initial run beginning at the origin city. This would be accomplished by a loop; using the start city, a random next city would be selected from the possible city connections, and then the next city would be set as the start city. Crossover and mutation Crossover would be accomplished by generating 3 random numbers 2 random chromosomes, and 1 random gene. Of the first chromosome, gene x would be switched with the other chromosomes gene x+1, and so on. Mutation would be primarily to fix any incorrect tours in a chromosome. If the start city of gene x+1 didnt match the next city of gene x, then a random gene would be chosen to replace gene x+1 with the correct start city. The mutation function would be utilized after cross over. Total value and elite set

4 The total fitness of each chromosome would be the sum of each road length saved into a totalFitness object. The smallest total fitness would be set as the minimum fitness. If a total fitness was within .75 of this value, it would be added to the elite set of chromosomes, and directly copied over into the next generation. If half of the population is in the elite set, then it is assumed that the best value has been found for that run and the program is ended. The generation number, chromosome number, gene sequence, and total value of each chromosome is displayed on the screen at the end of each generation.