Skip to content

Commit

Permalink
added report
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulCombal committed Jul 2, 2019
1 parent a091e81 commit 416ad78
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
20 changes: 20 additions & 0 deletions report.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
iterations,temps,distance,temperature
5000,0.8734149932861328,531.336692757079,6.72111195986558e+22
10000,1.7511818408966064,531.336692757079,4.517334597704838e+20
15000,2.6096198558807373,531.336692757079,3.0361511591348495e+18
20000,3.1840765476226807,531.336692757079,2.0406311867621052e+16
25000,3.774092435836792,530.2540355970141,137153106750214.94
30000,4.3614349365234375,519.3970429499193,921821386111.5916
35000,4.940872430801392,519.3970429499193,6195664743.054478
40000,5.5195512771606445,519.3970429499193,41641756.40386099
45000,6.093926906585693,519.3970429499193,279878.90699579957
50000,6.668205738067627,509.5391975508921,1881.097469123573
55000,7.243402481079102,444.4752762304771,12.643066697399366
60000,7.820054292678833,385.4240854560903,85037.22756378895
65000,8.402299642562866,385.4240854560903,571.5447272127949
70000,9.005159616470337,385.4240854560903,3.841416101668043
75000,9.638052701950073,385.4240854560903,25828.87971370019
80000,10.278730630874634,385.4240854560903,173.59879235368004
85000,10.86140489578247,385.4240854560903,1.1667769195065443
90000,11.435190916061401,385.4240854560903,7845.164363623655
95000,12.020253896713257,385.4240854560903,52.72822803146234
11 changes: 10 additions & 1 deletion sa.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
parser.add_argument("-n", help="noninteractive", default=False)
args = parser.parse_args()
time_start = None
report_file = open("report.csv", "w")

# Déclaration de fonctions
def generate_cities(howmany = 15, max_coordinates = 100):
Expand Down Expand Up @@ -83,13 +84,17 @@ def live_plot(tour, cities):
plt.plot(cities_x, cities_y, 'xb-')
plt.pause(0.1)

def report(what):
report_file.write(what + "\n")


def SA(cities, temperatures):
iteration = 0
tour = generate_good_random_tour(cities)
city_count = len(cities)
lowest_tour = None
lowest_distance = np.inf
report("iterations,temps,distance,temperature")
try:
for temperature in temperatures():
iteration = iteration + 1
Expand All @@ -108,12 +113,14 @@ def SA(cities, temperatures):
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(time.time() - time_start))
print("Elapsed: {:10.4f}s".format(seconds_elapsed))
print("New distance: {:10.4f}".format(newTotalDist))
print("Best distance: {:10.4f}".format(lowest_distance))
print("Temperature: " + str(temperature))
print("======")
report("{},{},{},{}".format(iteration, seconds_elapsed, lowest_distance, temperature))
live_plot(lowest_tour, cities)

except KeyboardInterrupt:
Expand Down Expand Up @@ -148,5 +155,7 @@ def SA(cities, temperatures):
print("Run interactif, Ctrl+c quand fini")
tour = SA(cities, temperature_interactive)

report_file.close()

# Affichage de détails
explain_tour(tour, cities)

0 comments on commit 416ad78

Please sign in to comment.