def startit(): global avg start = timer() old = start popn = init(POPULATION_SIZE, PERMUTATION_LENGTH) i=0 globmin = popn[0] while i<MAXITERATIONS and globmin.fitness>=118283: i+=1 natselect(popn, TOURNAMENT_SIZE) if i%1000==0: globmin = getbest() current = timer() print '\n-----------------------------' print 'elapsed time: ' + str(current-old) + '\niteration: ' + str(i) + '\nfitness: ' + str(globmin.fitness) + '\n' print globmin. route old = current print '\nCOMPLETE!\niteration: ' + str(i) print globmin. route end = timer() avg.append(end-start) print '\ntotal time: ' + str(end-start) del popn[:] return (end-start, i)
from selection import natselect, init, getglobbest from functions import getfitnesscount import sys from timeit import default_timer as timer XRANG = (-60, 40) YRANG = (-30, 70) POPULATION_SIZE = 30 INDIVIDUAL_LENGTH = 30 MAX_ITERATIONS = 10000 start = timer() popn = init(POPULATION_SIZE, INDIVIDUAL_LENGTH, XRANG, YRANG) for i in range(MAX_ITERATIONS): popn = natselect(popn, i + 1) if i % 200 == 0: getglobbest() if getfitnesscount() == 200000: getglobbest() end = timer() print('\ntotal time: ' + str(end - start) + ' seconds') sys.exit('\nPROGRAM STOPPED!\nmaximum fitness calculations')