Exemple #1
0
def test_simpleAgent(agentType, expected_monitor_results):
    #start agent network server
    agentNetwork = AgentNetwork(dashboard_modules=False)

    #init agents by adding into the agent network
    simple_agent = agentNetwork.add_agent(agentType=agentType)
    monitor_agent_1 = agentNetwork.add_agent(agentType=MonitorAgent)

    #shorten n wait loop time
    simple_agent.init_agent_loop(0.01)

    #connect agents
    agentNetwork.bind_agents(simple_agent, monitor_agent_1)

    # set all agents states to "Running"
    agentNetwork.set_running_state()
    time.sleep(test_timeout)

    # test to see if monitor agents have received the correct data
    assert str(
        monitor_agent_1.get_attr('memory')) == str(expected_monitor_results)

    # shutdown agent network
    agentNetwork.shutdown()
    time.sleep(3)

if __name__ == '__main__':
    # start agent network server
    agentNetwork = AgentNetwork()

    # init agents
    gen_agent = agentNetwork.add_agent(agentType=DataStreamAgent)
    trainer_agent = agentNetwork.add_agent(agentType=Trainer)
    predictor_agent = agentNetwork.add_agent(agentType=Predictor)
    evaluator_agent = agentNetwork.add_agent(agentType=Evaluator)
    monitor_agent_1 = agentNetwork.add_agent(agentType=MonitorAgent)
    monitor_agent_2 = agentNetwork.add_agent(agentType=MonitorAgent)

    gen_agent.init_parameters(stream=SineGenerator(),
                              pretrain_size=1000,
                              batch_size=1)
    trainer_agent.init_parameters(ml_model=HoeffdingTree())
    # connect agents : We can connect multiple agents to any particular agent
    # However the agent needs to implement handling multiple input types
    agentNetwork.bind_agents(gen_agent, trainer_agent)
    agentNetwork.bind_agents(gen_agent, predictor_agent)
    agentNetwork.bind_agents(trainer_agent, predictor_agent)
    agentNetwork.bind_agents(predictor_agent, evaluator_agent)

    agentNetwork.bind_agents(evaluator_agent, monitor_agent_1)
    agentNetwork.bind_agents(predictor_agent, monitor_agent_2)

    # set all agents states to "Running"
    agentNetwork.set_running_state()