22import matplotlib .pyplot as plt
33from matplotlib import colors
44import matplotlib as mpl
5+ from point import Point
56class pheromone (object ):
67 def __init__ (self ,obstacleData ,possible_moves ,decayRate = 0.7 ,dropOff = 0.1 ):
78 # initialize map size of obstacles and set obstacles position as -1
89 self .map = np .zeros (shape = obstacleData .shape , dtype = np .float32 ) - obstacleData
910 self .obstacleData = obstacleData
1011 self .dropOff = dropOff
1112 self .moves = possible_moves
12- self .moves .append ((0 ,0 ))
13+ self .moves .append (Point (0 ,0 ))
1314 self .multiplier = (1 - decayRate ) #normalize
1415 self .temp = np .zeros (shape = self .map .shape ,dtype = np .float32 )
1516 self .cmap = mpl .cm .Reds
@@ -20,6 +21,10 @@ def __init__(self,obstacleData,possible_moves,decayRate = 0.7,dropOff = 0.1):
2021 def addEnemy (self ,x ,y ):
2122 self .map [x ][y ] = 1.0
2223
24+
25+ def decay (self ):
26+ self .map = self .map * self .multiplier
27+
2328 def propogate (self ):
2429 for i ,rows in enumerate (self .map ):
2530 for j ,value in enumerate (rows ):
@@ -34,8 +39,8 @@ def propogate_point(self,value,x,y):
3439 delta = 0
3540 changes = []
3641 for move in self .moves :
37- finalx = x + move [ 0 ]
38- finaly = y + move [ 1 ]
42+ finalx = x + move . x
43+ finaly = y + move . y
3944 if (finalx >= 0 and finalx < self .map .shape [0 ]):
4045 if (finaly >= 0 and finaly < self .map .shape [1 ]):
4146 if (self .obstacleData [finalx ][finaly ] == False ):
0 commit comments