Ejemplo n.º 1
0
    # Write min, average and max bug size to file
    file_handle.write(
        str(bug_min) + " " + str(bug_mean) + " " + str(bug_max) + "\n")

    # Update plots
    model.update_plots()


def close(model):
    if file_handle:
        file_handle.close()


stupid_model = Model("StupidModel w. file output (stupid08)",
                     100,
                     100,
                     tile_size=5)
stupid_model.add_button("setup", setup)
stupid_model.add_button("step", step)
stupid_model.add_toggle_button("go", step)
stupid_model.add_controller_row()
stupid_model.add_slider("initial_bugs", 100, 10, 300)
stupid_model.add_controller_row()
stupid_model.add_slider("max_food_eat", 1.0, 0.1, 1.0)
stupid_model.add_controller_row()
stupid_model.add_slider("max_food_prod", 0.01, 0.01, 0.1)
stupid_model.histogram("grow_size", 0, 10, 5, (0, 0, 0))
stupid_model.on_close(close)
run(stupid_model)
Ejemplo n.º 2
0
    for x in range(10):
        model.add_agent(Robot())
    model.speed_factor = 1
    for t in model.tiles:
        if randint(0, 50) == 50:
            t.color = (0, 255, 255)
            t.info["has_mineral"] = True
        else:
            t.color = (200, 100, 0)
            t.info["has_mineral"] = False
    model.add_agent(Homebase())
    model.clear_plots()
    model.minerals_collected = 0


def step(model):
    for ag in model.agents:
        ag.step(model)
    model.update_plots()


miner_model.add_button("Setup", setup)

miner_model.add_toggle_button("Go", step)

miner_model.add_slider("speed_factor", 1, 1, 5)

miner_model.line_chart(["minerals_collected"], [(0, 200, 200)])

run(miner_model)
    if model.agent_count() == 0:
        model.pause()


def close(model):
    if file_handle:
        file_handle.close()


stupid_model = Model(
    "StupidModel w. gauss distribution of sizes (stupid14)",
    100,
    100,
    tile_size=5,
)
stupid_model.add_button("setup", setup)
stupid_model.add_button("step", step)
stupid_model.add_toggle_button("go", step)
stupid_model.add_controller_row()
stupid_model.add_slider("initial_bugs", 100, 10, 300)
stupid_model.add_controller_row()
stupid_model.add_slider("max_food_eat", 1.0, 0.1, 1.0)
stupid_model.add_slider("max_food_prod", 0.01, 0.01, 0.1)
stupid_model.add_controller_row()
stupid_model.add_slider("initialBugSizeMean", 1, 0, 10)
stupid_model.add_slider("initialBugSizeSD", 5, 0, 10)
stupid_model.histogram("grow_size", 0, 10, 5, (0, 0, 0))
stupid_model.line_chart(["current_bugs"], [(0, 0, 0)])
stupid_model.on_close(close)
run(stupid_model)
Ejemplo n.º 4
0

def setup(model):
    model.reset()
    model.clear_plots()
    model.total_util = 0
    model.BNP = 0
    people = set([Person() for i in range(20)])
    model.add_agents(people)


def step(model):
    model.BNP = 0
    for a in model.agents:
        a.step(model)
        model.BNP += a.utility()
    model.update_plots()
    model.remove_destroyed_agents()


bnb_model = Model("Bread & butter economy during pandemic", 50, 50)
bnb_model.add_button("Setup", setup)
bnb_model.add_button("Step", step)
bnb_model.add_button("Go", step, toggle=True)
bnb_model.add_controller_row()
bnb_model.add_slider("movespeed", 0.5, 0.1, 1)
bnb_model.add_checkbox("Decay")
bnb_model.line_chart(["BNP"], [(0, 0, 0)])
bnb_model.show_direction = False
run(bnb_model)
Ejemplo n.º 5
0

def model_setup(model):
    model.reset()
    model.Susceptible = 0
    model.Infectious = 0
    model.Recovered = 0
    for person in range(100):
        model.add_agent(Person())


def model_step(model):
    for person in model.agents:
        person.step(model)
    model.update_plots()


epidemic_model = Model("Epidemimodel", 100, 100)

epidemic_model.add_button("Setup", model_setup)
epidemic_model.add_button("Go", model_step, toggle=True)
epidemic_model.line_chart(["Susceptible", "Infectious", "Recovered"],
                          [(0, 200, 0), (200, 0, 0), (0, 0, 200)])
epidemic_model.add_checkbox("enable_groups")
epidemic_model.add_controller_row()
epidemic_model.add_slider("social_distance", 50, 0, 80)
epidemic_model.add_controller_row()
epidemic_model.add_slider("infection_distance", 15, 0, 40)

run(epidemic_model)
Ejemplo n.º 6
0
    file_handle.write(
        str(counter) + "," + str(model.Susceptible) + "," +
        str(model.Infectious) + "," + str(model.Recovered) + "," +
        str(model.Vaccinated) + "\n")
    file_handle.close()

    counter += 1
    model.update_plots()


epidemic_model = Model("Epidemimodel", 100, 100)

epidemic_model.add_button("Setup", model_setup)
epidemic_model.add_button("Go", model_step, toggle=True)

epidemic_model.line_chart(
    ["Susceptible", "Infectious", "Recovered", "Vaccinated"],
    [(0, 200, 0), (200, 0, 0), (0, 0, 200), (100, 100, 200)])
epidemic_model.bar_chart(
    ["Susceptible", "Infectious", "Recovered", "Vaccinated"], (200, 200, 200))
epidemic_model.add_checkbox("enable_groups")
epidemic_model.add_checkbox("Vaccine_exponential")
epidemic_model.add_controller_row()
epidemic_model.add_slider("Social_distance", 50, 0, 80)
epidemic_model.add_controller_row()
epidemic_model.add_slider("Infection_distance", 15, 0, 40)
epidemic_model.add_controller_row()
epidemic_model.add_slider("Vaccine_rate", 0.2, 0.1, 1.0)

run(epidemic_model)