From 08fe2f191b909407c33fe7a4a227641371d7602f Mon Sep 17 00:00:00 2001 From: Matthew Perry Date: Sat, 3 Aug 2019 14:19:43 -0600 Subject: [PATCH 1/2] update salesman.py example to use auto schedule --- examples/salesman.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/examples/salesman.py b/examples/salesman.py index 128a843..63dda84 100644 --- a/examples/salesman.py +++ b/examples/salesman.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- from __future__ import print_function import math import random @@ -28,6 +29,8 @@ def move(self): a = random.randint(0, len(self.state) - 1) b = random.randint(0, len(self.state) - 1) self.state[a], self.state[b] = self.state[b], self.state[a] + # no efficiency gain, just proof of concept + return self.energy() def energy(self): """Calculates the length of the route.""" @@ -37,7 +40,6 @@ def energy(self): return e - if __name__ == '__main__': # latitude and longitude for the twenty largest U.S. cities @@ -79,7 +81,7 @@ def energy(self): distance_matrix[ka][kb] = distance(va, vb) tsp = TravellingSalesmanProblem(init_state, distance_matrix) - tsp.steps = 100000 + tsp.set_schedule(tsp.auto(minutes=0.2)) # since our state is just a list, slice is the fastest way to copy tsp.copy_strategy = "slice" state, e = tsp.anneal() @@ -89,5 +91,4 @@ def energy(self): print() print("%i mile route:" % e) - for city in state: - print("\t", city) + print(" ➞ ".join(state)) From be72c9caec9de73ae81e49ee626fd308a14093be Mon Sep 17 00:00:00 2001 From: Matthew Perry Date: Sat, 3 Aug 2019 14:20:57 -0600 Subject: [PATCH 2/2] update --- CHANGES.md | 3 +++ simanneal/__init__.py | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index c0eca39..b2eaa83 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,6 @@ +### 0.5.0 +- Allow move function to return energy delta for efficiency gains in some cases (#28) + ### 0.4.2 - Fix bug in load_state (#23) diff --git a/simanneal/__init__.py b/simanneal/__init__.py index c5797ef..e685cfb 100644 --- a/simanneal/__init__.py +++ b/simanneal/__init__.py @@ -2,4 +2,4 @@ from .anneal import Annealer __all__ = ['Annealer'] -__version__ = "0.4.2" +__version__ = "0.5.0"