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)
# Update plots model.update_plots() model.remove_destroyed_agents() # TODO: Stop after 1000 iterations if model.agent_count() == 0: model.pause() def close(model): if file_handle: file_handle.close() stupid_model = Model( "StupidModel w. population graph (stupid13)", 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.line_chart(["current_bugs"], [(0, 0, 0)]) stupid_model.on_close(close) run(stupid_model)
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)
model.Infectious -= 1 model.Recovered += 1 self.color = (0, 0, 200) self.category = 2 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)] ) run(epidemic_model)
other.update_visual() self.util = self.utility() def setup(model): model.reset() model.clear_plots() model.total_util = 0 model.movespeed = 0.2 people = set([Person() for i in range(20)]) model.add_agents(people) def step(model): model.total_util = 0 for a in model.agents: a.step(model) model.update_plots() model.remove_destroyed_agents() bnb_model = Model("Bread & butter economy", 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.1, 0.1, 1) bnb_model.line_chart(["total_util"], [(0, 0, 0)]) bnb_model.agent_line_chart("util") run(bnb_model)