I have two populations Pop1 of N1 agents and Pop2 of N2 agents. SIR Infection dynamics is taking place within Pop1 and Pop2. Now at each time step, a randomly chosen agent is removed from Pop1 and added to Pop2 and vice versa. Removed agent could be in S or I or R state and it preserves its state when added to another Pop. The code is bit lengthy so I i pasted it in pastebin http://pastebin.com/PdmJTUhs.
In my code 'oAgent' is the randomly chosen agent which is being removed from Pop1 or Pop2. Now the state (S=0 or I=1 or R=2) of oAgent is returned by class method set_state(self, oAgent)
def set_state(self, oAgent):
if SW_SIR.oAgent in self.sAgent:
return (0)
if SW_SIR.oAgent in self.iAgent:
return (1)
if SW_SIR.oAgent in self.rAgent:
return (2)
In my code class Pop1_SW and Pop2_SW are class objects for Pop1 and Pop2 respectively. The state of oAgent of Pop1 is the state of the agent which is being added in Pop2, and vice versa. Now Pop1_SW should get state2(which is state of oAgent of Pop1) as an input parameter, and Pop2_SW should get state1(which is state of oAgent of Pop2).
So my question is how can I assign properly the state for the removed and added agents ? Problem is where inside the class oAgent should be defined and how outside the class its state should be the input for another class object ?
My code runs fine for a SIR dynamics for a single Population. I have added three methods set_state(), removingAgents() and addingAgents for two Populations, which are the cause of error.
mto your class constructor that you do not use - and your random choice ofoAgentshould be within the range of whatever length is of your populations.@propertyof your class:@property def oAgent(self): return ...