def test_main(): # # Define Messages # belief_input_1 = Belief('hostile_neighbourhood', ['hostility_index']) belief_input_2 = Belief('i_am_followed', ['probability']) belief_output = Belief('i_am_about_to_be_mugged', ['best_guess']) belief_merge_input = MessageOperator([belief_input_1, belief_input_2], extend=True) # # Define Organs and their associated messages # interpreter = Interpreter('about_to_be_mugged', evaluate, belief_merge_input, belief_output) # # Initialize Agent # agent = Agent('test_agent', strict_engine=True) agent.set_organ(interpreter) agent._set('belief', 'hostile_neighbourhood', belief_input_1) agent._set('belief', 'i_am_followed', belief_input_2) belief_input_1.set_values(0.8) belief_input_2.set_values(0.95) agent.interpret('about_to_be_mugged') outcome_1 = agent.belief['i_am_about_to_be_mugged'].values() belief_input_1.set_values(0.0) belief_input_2.set_values(0.0) agent.interpret('about_to_be_mugged') outcome_2 = agent.belief['i_am_about_to_be_mugged'].values() belief_input_1.set_values(0.9) belief_input_2.set_values(1.0) agent.interpret('about_to_be_mugged') outcome_3 = agent.belief['i_am_about_to_be_mugged'].values() assert (outcome_1[0] == REFVALUES[0]) assert (outcome_2[0] == REFVALUES[1]) assert (outcome_3[0] == REFVALUES[2])
def test_main(): # # Define Messages # buzz = Buzz('nerve_endings', ('first', 'second')) belief_1 = Belief('chance_of_rain', ('probability', )) belief_2 = Belief('ambiguity_kills_me', ('mood', )) direction = Direction('get_which_umbrella', ('any', 'colour')) # # Define Scaffold and Map for it # agent_resources = Resource('internal_resource', ('energy', )) agent_resources.set_values([100.0]) change_energy = ResourceMap('adjust_energy', 'delta', 'energy', ('how_much', )) # # Define Organs and their associated messages # interpreter_1 = Interpreter('will_it_rain', rain_predictor, buzz, belief_1, resource_map_output=change_energy) interpreter_2 = Interpreter('am_i_unlucky', mood_maker, belief_1, belief_2, resource_map_output=change_energy) total_belief = MessageOperator([belief_1, belief_2], extend=True) moulder = Moulder('fetch_umbrella_type', make_decision, total_belief, direction, change_energy) # # Initialize Agent # agent = Agent('test_agent', strict_engine=True) agent._set('buzz', 'nerve_endings', buzz) agent.set_organ(moulder) agent.set_organ(interpreter_1) agent.set_organ(interpreter_2) agent.set_scaffold(agent_resources) # # Decide on direction and execute action # agent.buzz['nerve_endings'].set_values([0.2, 0.2]) agent.interpret('will_it_rain') agent.interpret('am_i_unlucky') agent.mould('fetch_umbrella_type') assert (agent.direction['get_which_umbrella'].values() == REF[0]) assert (agent.resource.values()[0] == pytest.approx(REF_RESOURCE[0])) agent.buzz['nerve_endings'].set_values([1.0, 0.6]) agent.interpret('will_it_rain') agent.interpret('am_i_unlucky') agent.mould('fetch_umbrella_type') assert (agent.direction['get_which_umbrella'].values() == REF[1]) assert (agent.resource.values()[0] == pytest.approx(REF_RESOURCE[1])) agent.buzz['nerve_endings'].set_values([1.0, 2.6]) agent.interpret('will_it_rain') agent.interpret('am_i_unlucky') agent.mould('fetch_umbrella_type') assert (agent.direction['get_which_umbrella'].values() == REF[2]) assert (agent.resource.values()[0] == pytest.approx(REF_RESOURCE[2]))