Ejemplo n.º 1
0
def test_transitions():
    """
    Ensure that actions result in expected state transition behavior.
    Note that if the agent attempts to leave the edge
    (select LEFT from s0 or RIGHT from s49) then the state should not change.
    NOTE: assume p_action_failure is only noise term.

    """
    # [[initialize domain]]
    domain = FiftyChain()
    domain.p_action_failure = 0.0  # eliminate stochasticity
    dummyS = domain.s0()
    domain.state = 2  # state s2
    left = domain.LEFT
    right = domain.RIGHT
    goals = domain.GOAL_STATES

    # Check basic step
    r, ns, terminal, possibleA = domain.step(left)
    assert ns == 1 and terminal == False
    assert np.all(possibleA == np.array([left,
                                         right]))  # all actions available
    if ns in goals: assert r > 0
    else: assert r <= 0

    # Check another basic step
    r, ns, terminal, possibleA = domain.step(left)
    assert ns == 0 and terminal == False
    assert np.all(possibleA == np.array([left,
                                         right]))  # all actions available
    if ns in goals: assert r > 0
    else: assert r <= 0

    # Ensure state does not change or wrap around and that all actions
    # remain availableon corner case, per domain spec
    r, ns, terminal, possibleA = domain.step(left)
    assert ns == 0 and terminal == False
    assert np.all(possibleA == np.array([left,
                                         right]))  # all actions available
    if ns in goals: assert r > 0
    else: assert r <= 0

    # A final basic step
    r, ns, terminal, possibleA = domain.step(right)
    assert ns == 1 and terminal == False
    assert np.all(possibleA == np.array([left,
                                         right]))  # all actions available
    if ns in goals: assert r > 0
    else: assert r <= 0
Ejemplo n.º 2
0
def test_transitions():
    """
    Ensure that actions result in expected state transition behavior.
    Note that if the agent attempts to leave the edge
    (select LEFT from s0 or RIGHT from s49) then the state should not change.
    NOTE: assume p_action_failure is only noise term.

    """
    # [[initialize domain]]
    domain = FiftyChain()
    domain.p_action_failure = 0.0 # eliminate stochasticity
    dummyS = domain.s0()
    domain.state = 2 # state s2
    left = domain.LEFT
    right = domain.RIGHT
    goals = domain.GOAL_STATES

    # Check basic step
    r,ns,terminal,possibleA = domain.step(left)
    assert ns == 1 and terminal == False
    assert np.all(possibleA == np.array([left, right])) # all actions available
    if ns in goals: assert r > 0
    else: assert r <= 0

    # Check another basic step
    r,ns,terminal,possibleA = domain.step(left)
    assert ns == 0 and terminal == False
    assert np.all(possibleA == np.array([left, right])) # all actions available
    if ns in goals: assert r > 0
    else: assert r <= 0

    # Ensure state does not change or wrap around and that all actions
    # remain availableon corner case, per domain spec
    r,ns,terminal,possibleA = domain.step(left)
    assert ns == 0 and terminal == False
    assert np.all(possibleA == np.array([left, right])) # all actions available
    if ns in goals: assert r > 0
    else: assert r <= 0

    # A final basic step
    r,ns,terminal,possibleA = domain.step(right)
    assert ns == 1 and terminal == False
    assert np.all(possibleA == np.array([left, right])) # all actions available
    if ns in goals: assert r > 0
    else: assert r <= 0