print print tour.score lscore = tour.score deltaE = -0.01 iterationsOfNoChange = 0 reheat = False try: while True: prevScore = tour.score if tour.annealKOpt(): #tour.annealSwap(): print "score = %i, heat = %f, all time best = %i" % (tour.score,tour.heat,lscore) iterationsOfNoChange = 0 if tour.score < lscore: lscore = tour.score if tour.score == prevScore: iterationsOfNoChange += 1 if reheat and iterationsOfNoChange > 1 and tour.heat <= 0: tour.heat = random.random() print "reheating to %s" % tour.heat time.sleep(2)