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


Python Network.setInfected方法代码示例

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


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

示例1: DSNSimulation

# 需要导入模块: from Network import Network [as 别名]
# 或者: from Network.Network import setInfected [as 别名]
class DSNSimulation(object):

    def __init__(self):
        self.totalInfected = 0
        self.runtime = 150
	self.graphStatistics = []

    def initializeSimulation(self, recoveryRate):
        self.network = Network(recoveryRate)

    def initializeSimulation2(self, percentVaccinated):
        self.network.setInfected()
	self.network.noVaccinated = percentVaccinated
        self.network.setVaccinated()
        self.totalInfected = len(self.network.infectedNodes)

    def runSimulation(self):
        timeInstant = 0
        
        while timeInstant < self.runtime:
            self.graphStatistics[timeInstant].timeInstant = (timeInstant + 1)
            self.network.runSimulationForTimeInstant(self.graphStatistics[timeInstant])
            self.graphStatistics[timeInstant].displayStatistics()
            self.totalInfected += self.graphStatistics[timeInstant].numberOfNewlyInfectedNodes
            timeInstant += 1    

    def endSimulation(self):
        print "------------------------- Ending Simulation -------------------------"
        print "Total number of nodes infected during simulation : " , self.totalInfected
开发者ID:yeswanth,项目名称:flunetwork,代码行数:31,代码来源:DSNimulation.py

示例2: DSNSimulation

# 需要导入模块: from Network import Network [as 别名]
# 或者: from Network.Network import setInfected [as 别名]
class DSNSimulation(object):

    def __init__(self):
        self.totalInfected = 0
        self.runtime = 100

    def initializeSimulation(self):
        self.network = Network()
        self.network.setInfected()
        self.network.setVaccinated()
        self.totalInfected = len(self.network.infectedNodes)

    def runSimulation(self):
        # for-while
        timeInstant = 0
        allstats = []
        json_outfile = open('stats.json', 'w')
        
        while timeInstant < self.runtime:
            graphStatistics = GraphStatistics()
            graphStatistics.resetStatistics()
            graphStatistics.timeInstant = timeInstant
            self.network.runSimulationForTimeInstant(graphStatistics)
            graphStatistics.displayStatistics()
            self.totalInfected += graphStatistics.numberOfNewlyInfectedNodes
            timeInstant += 1
            allstats.append(graphStatistics)
        
        json.dump(allstats, json_outfile, default=GraphStatistics_encoder, indent=4)
        json_outfile.write("\n")
        json_outfile.close()
        
        print("\n\nWrote statistics to " + json_outfile.name + "\n\n")

    def endSimulation(self):
        print("------------------------- Ending Simulation -------------------------")
        print("Total number of nodes infected during simulation : " , self.totalInfected)
开发者ID:jineshkj,项目名称:flunetwork,代码行数:39,代码来源:DNSimulation.py


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