I am trying to simulate points moving in 2D which have a probability of dying at every step. I am trying to learn SimPy and this is my first programming experience. Why do I get this error? and how to fix it? Thank you
from SimPy.SimulationTrace import *
import random as RD
import scipy as SP
import math
import matplotlib.pyplot as plt
N=100
r1=0.02
r2=0.03
maxTime=100
class Point(Process):
def __init__(self,coord,rate1,rate2):
Process.__init__(self)
self.x=coord[0]
self.y=coord[1]
self.rate1=r1
self.rate2=r2
def Move(self):
RD.uniform(coord[0]-0.1,coord[0]+0.1)
RD.uniform(coord[1]-0.1,coord[1]+0.1)
yield hold,self,0.5
self.x=coord[0]
self.y=coord[1]
yield hold,self,0.5
# reactivate(self,now())
def die(self):
if RD.random() < self.rate2:
N-=1
m.observe(N)
yield cancel,self
initialize()
m=Monitor()
circular=[RD.uniform(0,100),RD.uniform(0,100)]
for object in xrange(N):
object=Point(circular,r1,r2)
activate(object,object.Move())
simulate(until=maxTime)
activate(object,object.die())
simulate(until=maxTime)
h=m.histogram(low=0.0,high=100,nbins=100)
g=m.yseries()
plt.plot(g)
plt.show()
Error
Traceback (most recent call last):
File "C:\Users\dell\Desktop\ask.py", line 46, in <module>
simulate(until=maxTime)
File "C:\Python27\lib\site-packages\SimPy\Globals.py", line 61, in simulate
return sim.simulate(until = until)
File "C:\Python27\lib\site-packages\SimPy\SimulationTrace.py", line 96, in simulate
return Simulation.simulate(self, until)
File "C:\Python27\lib\site-packages\SimPy\Simulation.py", line 581, in simulate
step()
File "C:\Python27\lib\site-packages\SimPy\Simulation.py", line 525, in step
resultTuple = proc._nextpoint.next()
File "C:\Users\dell\Desktop\ask.py", line 23, in Move
RD.uniform(coord[0]-0.3,coord[0]+0.3)
NameError: global name 'coord' is not defined
Coord not defined in move function You don't give it as argument, in my view