-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelicase.py
77 lines (61 loc) · 2.15 KB
/
helicase.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#Code for DNA-inspired search algorithm
from main_func import unvisited
from random import randint
from city import City
from main_dist import distData
class Enzyme:
def __init__(self, path, allCities):
self.path = path
self.allCities = allCities
self.unvisited = allCities minus path #NEED TO LOOK UP ACTUAL SET NOTATION
self.mistake = [] #keeps track of the one step that is not allowed if a mistake happens
#initialize helicase and bind to a random city
self.start = randint(len(allCities))
Helicase = Helicase(path, self.start, allCities)
Checker = Checker(path)
mistakeLag = 40
while self.unvisited != []:
#bind to next that isn't in the mistake category
Helicase.next(self.mistake)
checkerLocation = Checker.getLocation()
if len(path)>= checkerLocation + mistakeLag:
#makes sure that helicase is atleast bind length away before moving checker
if Checker.check():
#if there's a mistake
for i in range(mistakeLag-1):
#pop out a length of the the mistakes minus 1
temp = path.pop()
temp.unvisit()
#add the last one to be popped to mistake list
mistake.append(path.pop())
mistake[0].unvisit()
Helicase.bind(checkerLocation)
class Helicase:
def __init__(self,path, startCityNum, allCities):
self.allCities = allCities
self.city = startCityNum
self.path = path
def next(self, mistake):
'''implements the greedy algorithm on the path'''
self.unvisited = self.allCities minus self.path #set notation
closest = self.best() #best needs to return two just in case one is the mistake
if closest[0]==mistake[0]:
#if the closest city is the old mistake, use the second one
closest[0] = closest[1]
path.append(closest) #adds best to the path
mistake.pop() #cleans out the mistake que
def best(self):
self.city #minimum distance solution
def bind(self,cityNum):
'''moves the Helicase to a different part of the path'''
self.city = cityNum
class Checker:
def __init__(self, path):
self.path = path
self.binded = 0
def check(self):
self.n = len(path)
def bind(self, num):
self.binded = num
def getLocation(self):
return self.binded