-
Notifications
You must be signed in to change notification settings - Fork 4
/
Pheromone.py
57 lines (42 loc) · 1.23 KB
/
Pheromone.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
import abc
import collections
class Pheromone(abc.ABC):
@abc.abstractmethod
def getPheromoneValue(self, component):
pass
@abc.abstractmethod
def setPheromoneValue(self, component, value):
pass
@abc.abstractmethod
def sharePheromoneStructure(self, other):
pass
@abc.abstractmethod
def pheromoneDecay(self):
pass
@abc.abstractmethod
def getRho(self):
pass
@abc.abstractmethod
def getTau0(self):
pass
@abc.abstractmethod
def getComponents(self):
pass
class PheromoneDict(Pheromone):
def __init__(self, **kwargs):
self.P = collections.defaultdict(self.getCurrentTau)
self.P['currentTau'] = self.getTau0()
super().__init__(**kwargs)
def getPheromoneValue(self, component):
return self.P[component]
def setPheromoneValue(self, component, value):
self.P[component] = value
def sharePheromoneStructure(self, other):
other.P = self.P
def getCurrentTau(self):
return self.P['currentTau']
def pheromoneDecay(self):
for component in self.P:
self.P[component] *= (1-self.getRho())
def getComponents(self):
return (c for c in self.P)