From a091e81cfd366180df63a9648e18d0d649a27260 Mon Sep 17 00:00:00 2001 From: PaulCombal Date: Tue, 2 Jul 2019 15:51:05 +0200 Subject: [PATCH] added time --- dataset2 | 41 +++++++++++++++++++++++++++++++++++------ sa.py | 11 +++++++---- 2 files changed, 42 insertions(+), 10 deletions(-) diff --git a/dataset2 b/dataset2 index a89f658..5f56035 100644 --- a/dataset2 +++ b/dataset2 @@ -1,6 +1,35 @@ -10 10 -5 15 -10 13 -13 13 -9 3 -11 4 \ No newline at end of file +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 \ No newline at end of file diff --git a/sa.py b/sa.py index 01707a6..31a7a72 100755 --- a/sa.py +++ b/sa.py @@ -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): @@ -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 @@ -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) @@ -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: