Browse Source

removing secrets.py due to incompatibility

tarfeef101 6 years ago
parent
commit
47dd13174f
1 changed files with 6 additions and 5 deletions
  1. 6 5
      a2/tsp_local.py

+ 6 - 5
a2/tsp_local.py

@@ -2,8 +2,7 @@ import sys
 import copy
 import math
 from heapq import heappush, heappop
-from secrets import randbelow
-from random import shuffle, sample
+from random import shuffle, sample, randint, SystemRandom
 import matplotlib.pyplot as plt
 
 distances = []
@@ -79,11 +78,13 @@ def bester_child(cities, cost, tabu):
 # returns a random child for simulated annealing search
 # returns the ordering and the cost of it
 def random_child(cities):
-    i = randbelow(len(cities) - 3) + 1
+    #i = randbelow(len(cities) - 3) + 1
+    i = randint(1, len(cities) - 2)
     j = i
     
     while (j == i):
-        j = randbelow(len(cities) - 3) + 1
+        #j = randbelow(len(cities) - 3) + 1
+        j = randint(1, len(cities) - 2)
         
     temporder = copy.deepcopy(cities)
     tempcity = temporder[i]
@@ -174,7 +175,7 @@ def reinhold_messner(cities, x):
 
 # returns true or false randomly, based on the distribution e^(delta / temp)
 def bad_weather(delta, temp):
-    return secrets.SystemRandom().random() < math.exp(delta / temp)
+    return random.SystemRandom().random() < math.exp(delta / temp)
 
 
 # decrements temp by the option specified by opt: 1 is linear, 2 is logarithmic, 3 is exponential