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
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)