當前位置: 首頁>>代碼示例>>Python>>正文


Python Agent.setState方法代碼示例

本文整理匯總了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))]
                
開發者ID:bertybaums,項目名稱:SPIR,代碼行數:69,代碼來源:GillespieMethod.py


注:本文中的Agent.Agent.setState方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。