本文整理匯總了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