本文整理汇总了Python中Population.Population.getSize方法的典型用法代码示例。如果您正苦于以下问题:Python Population.getSize方法的具体用法?Python Population.getSize怎么用?Python Population.getSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Population.Population
的用法示例。
在下文中一共展示了Population.getSize方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from Population import Population [as 别名]
# 或者: from Population.Population import getSize [as 别名]
#.........这里部分代码省略.........
return self.totalInts
def getTimeLog(self):
return self.timeLog
def getStartTime(self):
return self.startTime
def getEndTime(self):
return self.endTime
def getTimePerInt(self):
return self.timePerInt
def getRunTime(self):
return self.runTime
def getRunVals(self):
return self.runVals
# --- Additional Functions
def preSimSetup(self):
self.newPop.setPop()
self.newPop.logStart()
self.newPop.createInitialGraph()
self.runVals = [(self.popSize), (self.intsPerTime * self.popSize), self.meanPosVal, self.meanAvoidVal,
self.newDisease.getSickValue(), self.newDisease.getSickTime(), self.disRisk,
self.newDisease.getTransRate(), self.immuneProb]
timeLogFirstRow = ["Time", "PopSize", "NumSick", "NumImmune", "New Disease Transmissions", "Effective R0", "NumInteractions"]
self.timeLog.append(timeLogFirstRow)
timeLogStartRow = [0, self.newPop.getSize(), self.newPop.getInitialSick(),
self.newPop.getInitialImmune(), 0, 0, 0]
self.timeLog.append(timeLogStartRow)
self.startTime = time.time()
self.writeInitialPop()
def runSim(self):
lowPopFlag = False
for i in range(1, self.numTimePeriods+1):
if lowPopFlag: break
newTrans = 0
numInts = int(round(self.intsPerTime * self.newPop.getSize()))
for j in range(1,numInts+1):
deadCheck = True
while deadCheck:
edgeNum = random.randint(0, len(self.newPop.agents.es)-1)
randEdge = self.newPop.agents.es[edgeNum]
vert1 = self.newPop.agents.vs[randEdge.source]
vert2 = self.newPop.agents.vs[randEdge.target]
agent1 = vert1["Agent"]
agent2 = vert2["Agent"]
newInt = Interaction(agent1, agent2)
deadCheck = newInt.deadCheck()
newInt.setStartVals()
newRule = Rules([agent1, agent2])
newResult = newRule.gameResult(self.meanPosVal, self.meanAvoidVal)
if newResult[0] == "Avoid":
vert1["Agent"].updateValue(newResult[1])
vert2["Agent"].updateValue(newResult[2])
else:
newTrans = newTrans + vert1["Agent"].updateDisease(vert2["Agent"], newResult[1])
示例2: __init__
# 需要导入模块: from Population import Population [as 别名]
# 或者: from Population.Population import getSize [as 别名]
#.........这里部分代码省略.........
return self.timePerInt
def getRunTime(self):
return self.runTime
def getRunVals(self):
return self.runVals
#-------------------------
# --- Class Functions
#-------------------------
def preSimSetup(self):
# Create initial Population
self.newPop.setPop()
# Select 1 random member of the population to be infected with disease
randInfect = random.randint(0, len(self.newPop.agents.vs))
self.newPop.agents.vs[randInfect]["Agent"].setDisease(self.newDisease)
# Log the starting population values
self.newPop.logStart()
self.newPop.createGraph(0)
self.runVals = [(self.popSize), len(self.newPop.agents.es), self.meanPosVal, self.meanAvoidVal,
self.newDisease.getSickValue(), self.newDisease.getSickTime(),
self.newDisease.getTransRate(), self.immuneProb]
timeLogFirstRow = ["Time", "PopSize", "NumSick", "NumImmune", "New Disease Transmissions", "Effective R0", "NumInteractions"]
self.timeLog.append(timeLogFirstRow)
if self.logInteractions == True:
self.writeFirstIntLogRow()
timeLogStartRow = [0, self.newPop.getSize(), self.newPop.getInitialSick(),
self.newPop.getInitialImmune(), 0, 0, 0]
self.timeLog.append(timeLogStartRow)
self.startTime = time.time()
self.writeInitialPop()
def runSim(self):
# iterate through the following steps for the defined number of time periods
for i in range(1, self.numTimePeriods+1):
numInts = 0
# generate a new group of random outgroup connections each time period
self.newPop.clearOutgroupConnects()
self.newPop.addOutgroupConnects()
self.newPop.clearTransmissions()
newTransStack = [] # initialize stack of potential disease transmission interactions - necessary so that agents can only spread disease a maximum of one connection away during each time period
# iterate through the following steps for each connection (graph edge) in the population
for j in self.newPop.agents.es:
# print('Edge #' + str(j.index)) # debugging
# extract agents from the connection
vert1 = self.newPop.agents.vs[j.source]
vert2 = self.newPop.agents.vs[j.target]
agent1 = vert1["Agent"]
agent2 = vert2["Agent"]
newInt = Interaction(agent1, agent2)
intType = j["Relation"]
# check to see if either of the agents are dead
deadCheck = newInt.deadCheck()