Exemplo n.º 1
0
def move_successor_state(sym_str, x, y, t, valid_action_strs):
    """
    Successor state axiom for state (x,y,t) (from t-1), given the valid actions at state t.
    Current <==> (causes to stay) | (causes of current)
    A[x,y,t] <==> (A[x,y,t-1] & ~(any valid action)) |
                    (A[x,y+1,t-1] & S[t-1]) |  # If N is a valid action
                    (A[x,y-1,t-1] & N[t-1]) |  # If S is a valid action
                    (A[x+1,y,t-1] & W[t-1]) |  # If E is a valid action
                    (A[x-1,y,t-1] & E[t-1]) |  # If W is a valid action
    """
    
    change_list = []
    if 'N' in valid_action_strs:
        change_list += [logic.PropSymbolExpr(sym_str,x,y+1,t-1) & logic.PropSymbolExpr('S',t-1)]
    if 'S' in valid_action_strs:
        change_list += [logic.PropSymbolExpr(sym_str,x,y-1,t-1) & logic.PropSymbolExpr('N',t-1)]
    if 'E' in valid_action_strs:
        change_list += [logic.PropSymbolExpr(sym_str,x+1,y,t-1) & logic.PropSymbolExpr('W',t-1)]
    if 'W' in valid_action_strs:
        change_list += [logic.PropSymbolExpr(sym_str,x-1,y,t-1) & logic.PropSymbolExpr('E',t-1)]
    change_exp = reduce((lambda a,b: a|b), change_list)
        
    stay_list = [~reduce((lambda a,b: a|b), logicPlan.expression_list(valid_action_strs,[t-1]))]
#     stay_list += [logic.PropSymbolExpr('G',x,y,t-1)]
    stay_exp = logic.PropSymbolExpr(sym_str,x,y,t-1) & (reduce((lambda a,b: a|b), stay_list))
    
    # Successor state axiom
    # Current <==> (causes of current) V (causes to stay)
    return logic.PropSymbolExpr(sym_str,x,y,t) % (change_exp | stay_exp)
Exemplo n.º 2
0
def move_successor_state(sym_str, x, y, t, valid_action_strs):
    """
    Successor state axiom for state (x,y,t) (from t-1), given the valid actions at state t.
    Current <==> (causes to stay) | (causes of current)
    A[x,y,t] <==> (A[x,y,t-1] & ~(any valid action)) |
                    (A[x,y+1,t-1] & S[t-1]) |  # If N is a valid action
                    (A[x,y-1,t-1] & N[t-1]) |  # If S is a valid action
                    (A[x+1,y,t-1] & W[t-1]) |  # If E is a valid action
                    (A[x-1,y,t-1] & E[t-1]) |  # If W is a valid action
    """

    change_list = []
    if 'N' in valid_action_strs:
        change_list += [
            logic.PropSymbolExpr(sym_str, x, y + 1, t - 1)
            & logic.PropSymbolExpr('S', t - 1)
        ]
    if 'S' in valid_action_strs:
        change_list += [
            logic.PropSymbolExpr(sym_str, x, y - 1, t - 1)
            & logic.PropSymbolExpr('N', t - 1)
        ]
    if 'E' in valid_action_strs:
        change_list += [
            logic.PropSymbolExpr(sym_str, x + 1, y, t - 1)
            & logic.PropSymbolExpr('W', t - 1)
        ]
    if 'W' in valid_action_strs:
        change_list += [
            logic.PropSymbolExpr(sym_str, x - 1, y, t - 1)
            & logic.PropSymbolExpr('E', t - 1)
        ]
    change_exp = reduce((lambda a, b: a | b), change_list)

    stay_list = [
        ~reduce((lambda a, b: a | b),
                logicPlan.expression_list(valid_action_strs, [t - 1]))
    ]
    #     stay_list += [logic.PropSymbolExpr('G',x,y,t-1)]
    stay_exp = logic.PropSymbolExpr(sym_str, x, y, t - 1) & (reduce(
        (lambda a, b: a | b), stay_list))

    # Successor state axiom
    # Current <==> (causes of current) V (causes to stay)
    return logic.PropSymbolExpr(sym_str, x, y, t) % (change_exp | stay_exp)
Exemplo n.º 3
0
if __name__ == '__main__' :

    width = 2
    height = 2
    max_time = 3

    agent_str = 'P'
    action_strs = ['N','E','S','W']

    # Axioms

    rules = []

    # Exactly one agent at each time
    for t in xrange(max_time) :
        agent_positions_t = logicPlan.expression_list(agent_str,range(0,width),range(0,height),[t])
        rules += [logicPlan.exactlyOne(agent_positions_t)]
    
    # At most one action at each time
    for t in xrange(max_time-1):
        actions_t = logicPlan.expression_list(action_strs,[t])
        rules += [logicPlan.atMostOne(actions_t)]

    # Movement successor state axioms
    for t in xrange(1,max_time):
        rules += [move_successor_state(agent_str,0,0,t,['N','E'])]
        rules += [move_successor_state(agent_str,1,0,t,['N','W'])]
        rules += [move_successor_state(agent_str,0,1,t,['S','E'])]
        rules += [move_successor_state(agent_str,1,1,t,['S','W'])]
        
    print "Rules:"
Exemplo n.º 4
0
    width = 2
    height = 2
    max_time = 3

    agent_str = 'P'
    action_strs = ['N', 'E', 'S', 'W']

    # Axioms

    rules = []

    # Exactly one agent at each time
    for t in xrange(max_time):
        agent_positions_t = logicPlan.expression_list(agent_str,
                                                      range(0, width),
                                                      range(0, height), [t])
        rules += [logicPlan.exactlyOne(agent_positions_t)]

    # At most one action at each time
    for t in xrange(max_time - 1):
        actions_t = logicPlan.expression_list(action_strs, [t])
        rules += [logicPlan.atMostOne(actions_t)]

    # Movement successor state axioms
    for t in xrange(1, max_time):
        rules += [move_successor_state(agent_str, 0, 0, t, ['N', 'E'])]
        rules += [move_successor_state(agent_str, 1, 0, t, ['N', 'W'])]
        rules += [move_successor_state(agent_str, 0, 1, t, ['S', 'E'])]
        rules += [move_successor_state(agent_str, 1, 1, t, ['S', 'W'])]