Skip to content

Commit

Permalink
Merge pull request #29 from perrygeo/0.5release
Browse files Browse the repository at this point in the history
0.5 release
  • Loading branch information
perrygeo authored Aug 3, 2019
2 parents 5405975 + be72c9c commit aa69b2e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
9 changes: 5 additions & 4 deletions examples/salesman.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import print_function
import math
import random
Expand Down Expand Up @@ -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."""
Expand All @@ -37,7 +40,6 @@ def energy(self):
return e



if __name__ == '__main__':

# latitude and longitude for the twenty largest U.S. cities
Expand Down Expand Up @@ -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()
Expand All @@ -89,5 +91,4 @@ def energy(self):

print()
print("%i mile route:" % e)
for city in state:
print("\t", city)
print(" ➞ ".join(state))
2 changes: 1 addition & 1 deletion simanneal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
from .anneal import Annealer

__all__ = ['Annealer']
__version__ = "0.4.2"
__version__ = "0.5.0"

0 comments on commit aa69b2e

Please sign in to comment.