from pystride.Simulation import Simulation


def vaccinate(sim, timestep):
    if timestep == 20:
        print("Vaccinating everyone who is not yet infected")
        pop = sim.GetSimulator().GetPopulation()
        for pIndex in range(pop.size()):
            if pop[pIndex].GetHealth().IsSusceptible():
                pop[pIndex].GetHealth().SetImmune()


# Build simulation
simulation = Simulation()
simulation.loadRunConfig("../config/run_default.xml")

# Register the "vaccinate" callback
simulation.registerCallback(vaccinate)

simulation.run()
import pystride

from pystride.Simulation import Simulation

pystride.workspace = "simulations"


def checkFinished(sim, timestep):
    pop = sim.GetSimulator().GetPopulation()
    infected = pop.GetInfectedCount()
    print("Amount infected: ", infected)
    if infected >= 4000:
        sim.Stop()


# Configure simulation
simulation = Simulation()
simulation.loadRunConfig("../config/run_default.xml")
simulation.runConfig.setParameter("generate_person_file", 0)
simulation.registerCallback(checkFinished)

simulation.run()
from pystride.Simulation import Simulation

# The callback function
def printInfected(sim, timestep):
    if (timestep % 2)  == 0:
        print("Amount infected at timestep {}: {}".format(
            timestep, sim.GetSimulator().GetPopulation().GetInfectedCount()))

# Build simulation
simulation = Simulation()
simulation.loadRunConfig("../config/run_default.xml")

# Register callback
simulation.registerCallback(printInfected)

simulation.run()