Esempio n. 1
0
    # action ST
    u = U[4]
    c = C[4]
    if fd == 'S':
        t_nodes = [(fx, fy, 'W'), (fx, fy, 'S'), (fx, fy, 'E')]
    if fd == 'N':
        t_nodes = [(fx, fy, 'W'), (fx, fy, 'N'), (fx, fy, 'E')]
    if fd == 'W':
        t_nodes = [(fx, fy, 'S'), (fx, fy, 'W'), (fx, fy, 'N')]
    if fd == 'E':
        t_nodes = [(fx, fy, 'N'), (fx, fy, 'E'), (fx, fy, 'S')]   
    for k, tnode in enumerate(t_nodes):
        if tnode in robot_nodes.keys():
            robot_edges[(fnode, u, tnode)] = (P_ST[k], c)                    
#----
motion_mdp = Motion_MDP(robot_nodes, robot_edges, U, initial_node, initial_label)
t2 = time.time()
print '------------------------------'
print 'MDP done, time: %s' %str(t2-t0)

#----
all_base = '& G F base1 & G F base2 G F base3'
order1 = 'G i supply X U ! supply base'
order2 = 'G i base X U ! base supply'
order = '& %s %s' %(order1, order2)
task1 = '& %s & G ! obstacle %s' %(all_base, order2)
task2 = '& %s G F supply' %all_base
task3 = '& %s %s' %(all_base, order2)
dra = Dra(all_base)
t3 = time.time()
print '------------------------------'
Esempio n. 2
0
from MDP_TG.mdp import Motion_MDP
from MDP_TG.dra import Dra, Product_Dra
from ac_prod import ac_learn

import pickle

import time

start = time.time()

node_dict, edge_dict, U, initial_node, initial_label = pickle.load(
    open('./mdp.p', 'rb'))
#----
motion_mdp = Motion_MDP(node_dict, edge_dict, U, initial_node, initial_label)

print 'motion_mdp done by time %s' % str(time.time() - start)
#----
# task_formula = "& G F & r1 g1 & G F & r2 g2 G F & r4 g3"
task_formula = "& G F & r1 g1 & G F & r2 g2 & G F & r3 F & r4 g3 G F & r2 g1"
dra = Dra(task_formula)
print 'dra done by time %s' % str(time.time() - start)

#----
prod_dra = Product_Dra(motion_mdp, dra)
prod_dra.compute_S_f()
#prod_dra.dotify()

print 'prod_dra done by time %s' % str(time.time() - start)

clambda = 0.98  # a_c algorithm parameters
gamma = 1.0
Esempio n. 3
0
    # action ST
    u = U[4]
    c = C[4]
    if fd == 'S':
        t_nodes = [(fx, fy, 'W'), (fx, fy, 'S'), (fx, fy, 'E')]
    if fd == 'N':
        t_nodes = [(fx, fy, 'W'), (fx, fy, 'N'), (fx, fy, 'E')]
    if fd == 'W':
        t_nodes = [(fx, fy, 'S'), (fx, fy, 'W'), (fx, fy, 'N')]
    if fd == 'E':
        t_nodes = [(fx, fy, 'N'), (fx, fy, 'E'), (fx, fy, 'S')]
    for k, tnode in enumerate(t_nodes):
        if tnode in robot_nodes.keys():
            robot_edges[(fnode, u, tnode)] = (P_ST[k], c)
#----
motion_mdp = Motion_MDP(robot_nodes, robot_edges, U, initial_node,
                        initial_label)
t1 = time.time()
print '------------------------------'
print 'MDP done, time: %s' % str(t1 - t0)

print '------------------------------'
t2 = time.time()
clean_mdp = dict()
clean_mdp['name'] = 'size%d_motion_mdp' % N
clean_mdp['init'] = motion_mdp.graph['init_state']
clean_mdp['states'] = motion_mdp.nodes()
clean_mdp['state_label'] = networkx.get_node_attributes(motion_mdp, 'label')
clean_mdp['state_act'] = networkx.get_node_attributes(motion_mdp, 'act')
clean_mdp['edge_prop'] = networkx.get_edge_attributes(motion_mdp, 'prop')

pickle.dump(clean_mdp, open('nx_mdp_model.p', 'wb'))
Esempio n. 4
0
P = [P_FR, P_BK, P_TR, P_TL]
robot_edges = construct_edges(robot_nodes, l, U, C, P)

visualize_world_paths(l, N, robot_nodes, [
    initial_node,
    initial_node,
], [initial_label, initial_label], [], [0, 0], 'initial_robot_map')

visualize_world_paths(l, N, real_robot_nodes, [
    initial_node,
    initial_node,
], [initial_label, initial_label], [], [0, 0], 'real_map')

#-------------
print '---------- Construct robot mdp ----------'
robot_mdp = Motion_MDP(robot_nodes, robot_edges, U, initial_node,
                       initial_label, home_states)
#robot_mdp.verify()
print '---------- Construct real robot mdp ----------'
real_mdp = Motion_MDP(real_robot_nodes, robot_edges, U, initial_node,
                      initial_label, home_states)
t2 = time.time()
print '------------------------------'
print 'MDP done, time: %s' % str(t2 - t0)

# ----
radius = 6
decay = 0.05
slope = [radians(-60), radians(45)]
robot_sensor = sensor(real_mdp, radius, decay, slope)

# ----
Esempio n. 5
0
    # action ST
    u = U[4]
    c = C[4]
    if fd == 'S':
        t_nodes = [(fx, fy, 'W'), (fx, fy, 'S'), (fx, fy, 'E')]
    if fd == 'N':
        t_nodes = [(fx, fy, 'W'), (fx, fy, 'N'), (fx, fy, 'E')]
    if fd == 'W':
        t_nodes = [(fx, fy, 'S'), (fx, fy, 'W'), (fx, fy, 'N')]
    if fd == 'E':
        t_nodes = [(fx, fy, 'N'), (fx, fy, 'E'), (fx, fy, 'S')]   
    for k, tnode in enumerate(t_nodes):
        if tnode in robot_nodes.keys():
            robot_edges[(fnode, u, tnode)] = (P_ST[k], c)                    
#----
motion_mdp = Motion_MDP(robot_nodes, robot_edges, U, initial_node, initial_label)
t1 = time.time()
print '------------------------------'
print 'MDP done, time: %s' %str(t1-t0)


print '------------------------------'
t2 = time.time()
clean_mdp = dict()
clean_mdp['name'] = 'size%d_motion_mdp' %N
clean_mdp['init'] = motion_mdp.graph['init_state']
clean_mdp['states'] = motion_mdp.nodes()
clean_mdp['state_label'] = networkx.get_node_attributes(motion_mdp,'label')
clean_mdp['state_act'] = networkx.get_node_attributes(motion_mdp,'act')
clean_mdp['edge_prop'] = networkx.get_edge_attributes(motion_mdp,'prop')