def agent_action(agent, **kwargs): """ The action determines what state the agent is in. If CALM, and lots of panic about, flip to PANIC. If PANICKED, but lots of CALM about, flip to CALM. """ mdl = get_model(agent.exec_key) if mdl.get_periods() == 0: print("In start panic condition") start_panic(agent.exec_key) if agent.group_name() == CALM: ratio = neighbor_ratio(agent, lambda agent: agent.group_name() == PANIC) if ratio > PANIC_THRESHHOLD: if DEBUG.debug: print("Changing the agent's group to panic!") agent.has_acted = True mdl.add_switch(str(agent), CALM, PANIC) elif agent.group_name() == PANIC: ratio = neighbor_ratio(agent, lambda agent: agent.group_name() == CALM) if ratio > CALM_THRESHHOLD: if DEBUG.debug: print("Changing the agent's group to calm!") agent.has_acted = True get_model(agent.exec_key).add_switch(str(agent), PANIC, CALM) return DONT_MOVE
def agent_action(agent, **kwargs): """ This is what agents do each turn of the model. """ agent_group = agent.group_name() ratio_num = neighbor_ratio(agent, # noqa F841 lambda agent: agent.group_name() == agent_group, size=1) tol = get_tolerance(DEF_TOLERANCE, DEF_SIGMA) favorable = env_favorable(ratio_num, tol) if favorable: return DONT_MOVE else: agent.move() return MOVE
def agent_action(agent, **kwargs): """ This is what trees do each turn in the forest. """ # we need ration of panic neighbours to calm to be 1/2 in order for the # agent to start panicking ratio = neighbor_ratio(agent, pred_one=is_calm, pred_two=is_panicking) # print("The ratio is ", ratio) if ratio > THRESHHOLD: if DEBUG2: print("Changing the agent's state to panic!") # print("Agent's state is being changed to Panic") agent["state"] = PN agent.has_acted = True agent.add_switch(agent, CALM, PANIC) return DONT_MOVE
def agent_action(agent, **kwargs): """ This is what agents do each turn of the model. """ if DEBUG.debug: print("The agent is called", agent) global first_period if first_period: start_panic(agent.exec_key) first_period = False if agent.group_name() == CALM: ratio = neighbor_ratio(agent, lambda agent: agent.group_name() == PANIC) if ratio > THRESHHOLD: if DEBUG.debug: print("Changing the agent's group to panic!") agent.has_acted = True get_model(agent.exec_key).add_switch(str(agent), CALM, PANIC) return DONT_MOVE