as of now it has found an optimal tour through London, Amsterdam, Hamburg, Copenhagen, Prague, Frankfurt, Brussels, and Paris

#!/usr/bin/python

import random

from pyevolve import G1DList

from pyevolve import GSimpleGA

from pyevolve import GAllele

from pyevolve import Mutators

from pyevolve import Crossovers

from pyevolve import Consts

#ideal tour: London, Amsterdam, Hamburg, Copenhagen, Prague (Praha?), Frankfurt,

#Brussels, Paris, London, length 2,980 km

# Amsterdam - 0

# Brussels - 1

# Copenhagen - 2

# Frankfurt - 3

# Hamburg - 4

# London - 5

# Paris - 6

# Prague - 7

# what is homogeneous?? resolved

# use special initializer

# OX crossover understood

distances = {}

# Amsterdam

distances[0,1] = 176

distances[0,2] = 623

distances[0,3] = 365

distances[0,4] = 366

distances[0,5] = 347

distances[0,6] = 431

distances[0,7] = 710

# Brussels

distances[1,0] = 176

distances[1,2] = 769

distances[1,3] = 319

distances[1,4] = 490

distances[1,5] = 308

distances[1,6] = 263

distances[1,7] = 716

# Copenhagen

distances[2,0] = 623

distances[2,1] = 769

distances[2,3] = 671

distances[2,4] = 289

distances[2,5] = 948

distances[2,6] = 1031

distances[2,7] = 642

# Frankfurt

distances[3,0] = 365

distances[3,1] = 319

distances[3,2] = 671

distances[3,4] = 394

distances[3,5] = 627

distances[3,6] = 481

distances[3,7] = 405

# Hamburg

distances[4,0] = 366

distances[4,1] = 490

distances[4,2] = 289

distances[4,3] = 394

distances[4,5] = 711

distances[4,6] = 747

distances[4,7] = 497

# London

distances[5,0] = 347

distances[5,1] = 308

distances[5,2] = 948

distances[5,3] = 627

distances[5,4] = 711

distances[5,6] = 337

distances[5,7] = 1019

# Paris

distances[6,0] = 431

distances[6,1] = 263

distances[6,2] = 1031

distances[6,3] = 481

distances[6,4] = 747

distances[6,5] = 337

distances[6,7] = 879

# Prague

distances[7,0] = 710

distances[7,1] = 716

distances[7,2] = 642

distances[7,3] = 405

distances[7,4] = 497

distances[7,5] = 1019

distances[7,6] = 879

# Number of cities

NUM_OF_CITIES = 8

def eval_func(chromosome):

total = 0

for i in xrange(NUM_OF_CITIES):

j = (i + 1) % NUM_OF_CITIES

total += distances[chromosome[i],chromosome[j]]

return total

def G1DListTSPInitializator(chromosome, **args):

chromosome.clearList()

lst = [i for i in xrange(chromosome.listSize)]

for i in xrange(chromosome.listSize):

choice = random.choice(lst)

lst.remove(choice)

chromosome.append(choice)

setOfAlleles = GAllele.GAlleles(homogeneous=True)

lst = [ i for i in xrange(NUM_OF_CITIES) ]

a = GAllele.GAlleleList(lst)

setOfAlleles.add(a)

genome = G1DList.G1DList(NUM_OF_CITIES)

genome.setParams(allele=setOfAlleles)

genome.evaluator.set(eval_func)

genome.mutator.set(Mutators.G1DListMutatorSwap)

genome.crossover.set(Crossovers.G1DListCrossoverOX)

genome.initializator.set(G1DListTSPInitializator)

ga = GSimpleGA.GSimpleGA(genome)

ga.setGenerations(1000)

ga.setMinimax(Consts.minimaxType["minimize"])

ga.setCrossoverRate(1.0)

ga.setMutationRate(0.03)

ga.setPopulationSize(80)

ga.evolve(freq_stats=100)

best = ga.bestIndividual()

print best

**EVOLUTION IS A SATANIC LIE RIGHT**nah just kidding I wouldn't say something dumb like that and mean it

that's only eight cities though

give me like twenty cities

I will find a nearly optimal tour for them

out of 2.5 quintillion possible tours on my craputer I will find a nearly optimal tour

really go ahead