Skip to content

Commit a8a19b4

Browse files
committed
Explain parts of iterated local search for simple hoomans.
1 parent 9cc995b commit a8a19b4

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

python/stochastic/iterated_local_search.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@
2424
"""
2525

2626
def stochastic_two_opt(permutation):
27+
"""
28+
Looks for a random subsequence in the permutation and reverses them.
29+
30+
See also: https://en.wikipedia.org/wiki/2-opt
31+
"""
2732
perm = [permutation[i] for i in range(len(permutation))]
2833
upper_bound = len(perm) - 1
2934
c1, c2 = random.randint(0, upper_bound), random.randint(0, upper_bound)
@@ -70,7 +75,11 @@ def local_search(best, cities, max_no_improv):
7075

7176
return best
7277

73-
def double_bridge_move(perm):
78+
def double_bridge_move(perm):
79+
"""
80+
Partitions the permutation into 4 subsequences and then shuffles those
81+
subsequences to create a new permutation.
82+
"""
7483
pos1 = 1 + random.randint(0, math.floor(len(perm) / 4))
7584
pos2 = pos1 + 1 + random.randint(0, math.floor(len(perm) / 4))
7685
pos3 = pos2 + 1 + random.randint(0, math.floor(len(perm) / 4))

0 commit comments

Comments
 (0)