本文整理匯總了Python中Agent.Agent.recover方法的典型用法代碼示例。如果您正苦於以下問題:Python Agent.recover方法的具體用法?Python Agent.recover怎麽用?Python Agent.recover使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Agent.Agent
的用法示例。
在下文中一共展示了Agent.recover方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: execute
# 需要導入模塊: from Agent import Agent [as 別名]
# 或者: from Agent.Agent import recover [as 別名]
def execute(self):
##
## Initialize agents
##
pDisease = {Constant.BETA: 1 - math.exp(-self.disease[Constant.BETA]),
Constant.RHO: self.disease[Constant.RHO],
Constant.GAMMA: 1 - math.exp(-self.disease[Constant.GAMMA])}
self.decision = 1 - math.exp(-self.decision)
N = 0
agents = []
infected = []
for state in self.nAgents:
for x in range(self.nAgents[state]):
agent = Agent(N, state, pDisease, self.fear, self.timeHorizon, self.payoffs)
agents.append(agent)
if (state == State.I):
infected.append(agent)
N += 1
##
## Output variables
##
num = []
num.append([0,
self.nAgents[State.S],
self.nAgents[State.P],
0,
self.nAgents[State.I],
0,
0,
self.nAgents[State.R],
0,
0,
self.nAgents[State.S] * self.payoffs[State.S],
self.nAgents[State.P] * self.payoffs[State.P],
self.nAgents[State.I] * self.payoffs[State.I],
self.nAgents[State.R] * self.payoffs[State.R]])
##
## Run the simulation
##
t = 1
i = self.nAgents[State.I] / float(N)
while ((t < self.timeSteps) and (i > 0)):
numagents = [0, 0, 0, 0]
##
## Interaction
##
shuffle(agents)
n = N
infected = []
while(n > 1):
a1 = agents[n - 1]
a2 = agents[n - 2]
a1State = a1.getState()
a2State = a2.getState()
a1S = a1State
a2S = a2State
if (a1State == State.I):
infected.append(a1)
a2S = a2.interact(a1State)
if (a2State == State.I):
infected.append(a2)
a1S = a1.interact(a2State)
numagents[a1S] += 1
numagents[a2S] += 1
n = n - 2
##
## Decision
##
for agent in agents:
if (uniform(0.0, 1.0) < self.decision):
state = agent.getState()
numagents[state] -= 1
state = agent.decide(i)
numagents[state] += 1
##
## Recover
##
for agent in infected:
if (agent.recover() == State.R):
numagents[State.I] -= 1
numagents[State.R] += 1
#.........這裏部分代碼省略.........