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


Python Agent.setID方法代码示例

本文整理汇总了Python中Agent.Agent.setID方法的典型用法代码示例。如果您正苦于以下问题:Python Agent.setID方法的具体用法?Python Agent.setID怎么用?Python Agent.setID使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Agent.Agent的用法示例。


在下文中一共展示了Agent.setID方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: addFamilies

# 需要导入模块: from Agent import Agent [as 别名]
# 或者: from Agent.Agent import setID [as 别名]
    def addFamilies(self):    
        while self.popSize < self.popLimit: # create new agents in bundles of families while the population is less than the maximum size
            startVert = len(self.agents.vs)            
            popLeft = self.popLimit - self.popSize
            newVerts = random.randint(self.minFam, self.maxFam)
            
            # ensure that the final family group added does not exceed the maximum population size
            if newVerts < popLeft:
                addVerts = newVerts
            else: addVerts = popLeft
            
            #create new set of verticies that will represent a family in the pouplation
            self.agents.add_vertices(addVerts)
            endVert = len(self.agents.vs)
            newFam = []
            groupNum = random.randint(1,2)
            
            # initialize instances of Class:Agent to be stored at each vertex, and assign necessary properties to each agent / vertex
            for i in range(startVert, endVert):
                newAgent = Agent()
                newAgent.setID(i) # unique ID for each agent
                self.agents.vs(i)["Agent"] = newAgent # store the agent at the vertex
                self.agents.vs(i)["Index"] = str(i) # create a string representation of the unique ID for logging and reporting
                self.agents.vs(i)["Status"] = "H" # set the current disease status of the agent to 'H' (Healthy)
                self.agents.vs(i)["Family"] = str(self.numFamilies) # set an identifier of the family that the agent belongs to (family number increments with each new group created)
                # designate the agent as a member of 'Group A' or 'Group B' based on the randomly generated number above                
                if groupNum == 1:
                    self.agents.vs(i)["Group"] = "A"
                else: self.agents.vs(i)["Group"] = "B"
                newFam.append(i)
#                print "Added agent " + str(i) #debugging                
            
            # Create connections between all members of the family and designate those as family connections
            for i in range(startVert, endVert-1):
                for j in range(i+1, endVert):
                    self.agents.add_edge(i, j)
                    self.agents.es(len(self.agents.es)-1)["Relation"] = "Family"
                    
            self.families.append(newFam) # store the family in the family list            
            self.numFamilies+=1 # update the total number of families in the population
            self.popSize += addVerts # update the total number of agents in the population
开发者ID:drRussClay,项目名称:Simulation,代码行数:43,代码来源:Population.py


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