agents.py 35,1 ko
Newer Older
Aman Deep Singh's avatar
Aman Deep Singh a validé
    >>> agents = [ModelBasedVacuumAgent, ReflexVacuumAgent]
    >>> result = compare_agents(environment, agents)
    >>> performance_ModelBasedVacummAgent = result[0][1]
    >>> performance_ReflexVacummAgent = result[1][1]
    >>> performance_ReflexVacummAgent <= performance_ModelBasedVacummAgent
    True
    """
    envs = [EnvFactory() for i in range(n)]
withal's avatar
withal a validé
    return [(A, test_agent(A, steps, copy.deepcopy(envs)))
def test_agent(AgentFactory, steps, envs):
Aman Deep Singh's avatar
Aman Deep Singh a validé
    """Return the mean score of running an agent in each of the envs, for steps
    >>> def constant_prog(percept):
    ...     return percept
    ...
    >>> agent = Agent(constant_prog)
    >>> result = agent.program(5)
    >>> result == 5
    True
    """
withal's avatar
withal a validé
    def score(env):
withal's avatar
withal a validé
        return agent.performance
    return mean(map(score, envs))
# _________________________________________________________________________
__doc__ += """
>>> a = ReflexVacuumAgent()
>>> a.program((loc_A, 'Clean'))
'Right'
>>> a.program((loc_B, 'Clean'))
'Left'
>>> a.program((loc_A, 'Dirty'))
'Suck'
>>> a.program((loc_A, 'Dirty'))
'Suck'

>>> e = TrivialVacuumEnvironment()
>>> e.add_thing(ModelBasedVacuumAgent())