# Configure simulation
simulation = Simulation()
simulation.loadRunConfig("../config/run_batchruntests1.xml")
simulation.runConfig.setParameter("output_prefix", "BatchRunsTesting")

# Create forks with different values for RNG
RNG_values = []
for i in range(amount_of_runs):
    RNG_values.append(random.randint(0, 4294967294))

for rng in RNG_values:
    # Create fork
    fork = simulation.fork("rng_" + str(rng))
    fork.runConfig.setParameter("rng_seed", rng)

# Run all forks
simulation.runForks()

# Get attack rates
for rng in RNG_values:
    summary_file = os.path.join(pystride.workspace, "BatchRunsTesting",
                                "rng_" + str(rng), "summary.csv")
    with open(summary_file) as csvfile:
        reader = csv.DictReader(csvfile)
        print("RNG = " + str(rng) + ": Num cases = " +
              str(next(reader)['num_cases']))

t_end = time.perf_counter()
print("Total time elapsed: " + str(round(t_end - t_start)) + " seconds")
Esempio n. 2
0
sim = Simulation()
sim.loadRunConfig("config/common.xml")

# Set parameters that are the same for all simulations
sim.runConfig.setParameter("output_prefix", "Imitation")
sim.runConfig.setParameter("seeding_rate", 0)

# TODO natural immunity?
sim.runConfig.setParameter("immunity_rate", 0)
sim.runConfig.setParameter("vaccine_rate", 0)

sim.runConfig.setParameter("local_information_policy", "LocalDiscussion")
sim.runConfig.setParameter("global_information_policy", "NoLocalInformation")
sim.runConfig.setParameter("belief_policy/name", "Imitation")
sim.runConfig.setParameter("belief_policy/accept_threshold", 0.95)
sim.runConfig.setParameter("belief_policy/no_accept_threshold", -0.95)
sim.runConfig.setParameter("behaviour_policy", "Vaccination")

seeds = list(range(10))
# TODO belief and behaviour related parameters

# Create forks with varying seeds and behaviour parameters
for seed in list(itertools.product(seeds)):
    # Create fork
    fork = sim.fork(str(seed))
    fork.runConfig.setParameter("rng_seed", seed)

# Run all forks
sim.runForks()