From 1369a216ddb5012e5d5507af337dcadb367d5dfb Mon Sep 17 00:00:00 2001 From: PaulCombal Date: Fri, 5 Jul 2019 09:08:11 +0200 Subject: [PATCH] all snake_case --- report.csv | 21 ++++++++++----------- sa.py | 14 +++++++------- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/report.csv b/report.csv index ef5ba27..5d236d8 100644 --- a/report.csv +++ b/report.csv @@ -1,12 +1,11 @@ iterations,temps,distance,temperature,memory -5000,27.38643765449524,30585.351928539098,0.6721111959865606,57221120 -10000,34.95672869682312,24959.320052117782,0.4520495689035214,78159872 -15000,42.36410355567932,22355.65496850863,0.3038679424228721,78770176 -20000,49.582820653915405,20586.442074826,0.20426018026358692,79192064 -25000,57.07359457015991,19330.841251950715,0.13730379357770844,79192064 -30000,64.29938006401062,18378.562686813006,9.23079397837336,79192064 -35000,71.69990468025208,17738.866524289828,6.204944249678936,79630336 -40000,78.93442893028259,17125.53794647948,4.170966574687698,79630336 -45000,86.24125695228577,16833.02906081847,2.8037257817525405,79630336 -50000,93.65385031700134,16518.501560679957,1.8846658486714118,79896576 -55000,101.00880336761475,16066.872733874745,1.2668733098884215,80166912 +5000,1.199178695678711,493.3990958005079,0.6721111959865606,56467456 +10000,1.9728262424468994,422.7406518985165,0.4520495689035214,70680576 +15000,2.555943727493286,422.7406518985165,0.3038679424228721,70975488 +20000,3.1493828296661377,419.07264385271634,0.20426018026358692,71512064 +25000,3.7523446083068848,419.07264385271634,0.13730379357770844,71782400 +30000,4.338656902313232,419.07264385271634,9.23079397837336,71782400 +35000,4.923287868499756,419.07264385271634,6.204944249678936,71782400 +40000,5.569959878921509,419.07264385271634,4.170966574687698,72101888 +45000,6.152648687362671,419.07264385271634,2.8037257817525405,72101888 +50000,6.784815311431885,419.07264385271634,1.8846658486714118,72368128 diff --git a/sa.py b/sa.py index a084934..4b51336 100755 --- a/sa.py +++ b/sa.py @@ -125,22 +125,22 @@ def SA(cities, temperatures): [i,j] = sorted(random.sample(range(city_count),2)) newTour = tour[:i] + tour[j:j+1] + tour[i+1:j] + tour[i:i+1] + tour[j+1:] - oldDistances = distance_between(tour, cities, i, j) - newDistances = distance_between(newTour, cities, i, j) - newTotalDist = distance(newTour, cities) + old_distances = distance_between(tour, cities, i, j) + new_distances = distance_between(newTour, cities, i, j) + new_tour_distance = distance(newTour, cities) - if math.exp( (oldDistances - newDistances) / temperature) > random.random(): + if math.exp( (old_distances - new_distances) / temperature) > random.random(): tour = copy.copy(newTour) - if newTotalDist < lowest_distance: - lowest_distance = newTotalDist + if new_tour_distance < lowest_distance: + lowest_distance = new_tour_distance lowest_tour = copy.copy(tour) if(iteration % 5000 == 0): seconds_elapsed = time.time() - time_start print("Iteration: " + str(iteration)) print("Elapsed: {:10.4f}s".format(seconds_elapsed)) - print("New distance: {:10.4f}".format(newTotalDist)) + print("New distance: {:10.4f}".format(new_tour_distance)) print("Best distance: {:10.4f}".format(lowest_distance)) print("Temperature: " + str(temperature)) print("Memory used: " + str(memory().rss))