本文整理汇总了Python中Agent.Agent.setState方法的典型用法代码示例。如果您正苦于以下问题:Python Agent.setState方法的具体用法?Python Agent.setState怎么用?Python Agent.setState使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Agent.Agent
的用法示例。
在下文中一共展示了Agent.setState方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: execute
# 需要导入模块: from Agent import Agent [as 别名]
# 或者: from Agent.Agent import setState [as 别名]
#.........这里部分代码省略.........
iSwitch = self.calcISwitch(self.timeHorizon, pDisease, self.payoffs)
c = {self.INT_SP: self.decision / float(N),
self.INT_PS: self.decision / float(N),
self.INT_SI: self.disease[Constant.BETA] / (float(N) * float(N)),
self.INT_PI: (self.disease[Constant.BETA] * self.disease[Constant.RHO]) / (float(N) * float(N)),
self.INT_IR: self.disease[Constant.GAMMA] / float(N)}
a = {self.INT_SP: c[self.INT_SP] * self.nAgents[State.S],
self.INT_PS: c[self.INT_PS] * self.nAgents[State.P],
self.INT_SI: c[self.INT_SI] * self.nAgents[State.S] * self.nAgents[State.I],
self.INT_PI: c[self.INT_PI] * self.nAgents[State.P] * self.nAgents[State.I],
self.INT_IR: c[self.INT_IR] * self.nAgents[State.I]}
A = a[self.INT_SP] + a[self.INT_PS] + a[self.INT_SI] + a[self.INT_PI] + a[self.INT_IR]
prevT = 0
t = math.log(1 / uniform(0.0, 1.0)) / float(A)
while ((t < self.timeSteps) and (i > 0)):
cumA = uniform(0.0, 1.0) * A
index = 0
x = a[index]
while(x <= cumA):
index += 1
x += a[index]
if ((index == self.INT_SP) and (self.nAgents[State.S] > 0)):
## Decide
agent = S[int(uniform(0, self.nAgents[State.S] - 1))]
S.remove(agent)
self.nAgents[State.S] -= 1
agent.setState(State.P)
P.append(agent)
self.nAgents[State.P] += 1
elif ((index == self.INT_PS) and (self.nAgents[State.P] > 0)):
## Decide
agent = P[int(uniform(0, self.nAgents[State.P] - 1))]
P.remove(agent)
self.nAgents[State.P] -= 1
agent.setState(State.S)
S.append(agent)
self.nAgents[State.S] += 1
elif ((index == self.INT_SI) and (self.nAgents[State.S] > 0)):
## Infect
agent = S[int(uniform(0, self.nAgents[State.S] - 1))]
S.remove(agent)
self.nAgents[State.S] -= 1
agent.setState(State.I)
I.append(agent)
self.nAgents[State.I] += 1
elif ((index == self.INT_PI) and (self.nAgents[State.P] > 0)):
## Infect
agent = P[int(uniform(0, self.nAgents[State.P] - 1))]