Skip to content

Commit

Permalink
added time
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulCombal committed Jul 2, 2019
1 parent fce632d commit a091e81
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 10 deletions.
41 changes: 35 additions & 6 deletions dataset2
Original file line number Diff line number Diff line change
@@ -1,6 +1,35 @@
10 10
5 15
10 13
13 13
9 3
11 4
14 47
74 78
13 20
45 25
93 36
13 30
14 5
12 62
74 12
17 23
14 95
10 37
73 29
56 99
20 88
45 41
78 15
35 60
82 4
98 40
35 31
34 39
80 72
19 88
91 11
12 81
11 40
16 11
52 49
66 39
62 35
69 50
13 49
79 96
96 40
11 changes: 7 additions & 4 deletions sa.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#!/bin/env python

import random, numpy as np, math, copy, sys, argparse, matplotlib.pyplot as plt
import random, time, numpy as np, math, copy, sys, argparse, matplotlib.pyplot as plt

parser = argparse.ArgumentParser()
parser.add_argument("-d", help="dataset file", default=False)
parser.add_argument("-n", help="noninteractive", default=False)
args = parser.parse_args()
time_start = None

# Déclaration de fonctions
def generate_cities(howmany = 15, max_coordinates = 100):
Expand Down Expand Up @@ -53,7 +54,7 @@ def distance(tour, cities):
return sum([math.sqrt(sum([(cities[tour[(k+1) % city_count]][d] - cities[tour[k % city_count]][d])**2 for d in [0,1] ])) for k in range(city_count)])

def temperature_noninteractive():
return numpy.logspace(0,5,num=100000)[::-1]
return np.logspace(0,5,num=100000)[::-1]

def temperature_interactive():
alpha = 0.999
Expand Down Expand Up @@ -108,8 +109,9 @@ def SA(cities, temperatures):

if(iteration % 5000 == 0):
print("Iteration: " + str(iteration))
print("New distance: " + str(newTotalDist))
print("Best distance: " + str(lowest_distance))
print("Elapsed: {:10.4f}s".format(time.time() - time_start))
print("New distance: {:10.4f}".format(newTotalDist))
print("Best distance: {:10.4f}".format(lowest_distance))
print("Temperature: " + str(temperature))
print("======")
live_plot(lowest_tour, cities)
Expand All @@ -128,6 +130,7 @@ def SA(cities, temperatures):
plt.ion()
plt.show()
external_dataset = dataset_name()
time_start = time.time()
if external_dataset:
cities = import_dataset(external_dataset)
else:
Expand Down

0 comments on commit a091e81

Please sign in to comment.