当前位置: 首页>>代码示例>>Python>>正文


Python Agent.recover方法代码示例

本文整理汇总了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
         
#.........这里部分代码省略.........
开发者ID:bertybaums,项目名称:SPIR,代码行数:103,代码来源:MicroMethod.py


注:本文中的Agent.Agent.recover方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。