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 beta = 1.0 D = 0.5 actor_critic_learner = ac_learn(prod_dra, clambda, gamma, beta, D)
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 '------------------------------' print 'DRA done, time: %s' %str(t3-t2) #---- prod_dra = Product_Dra(motion_mdp, dra) t41 = time.time() print '------------------------------' print 'Product DRA done, time: %s' %str(t41-t3) #---- prod_dra.compute_S_f() t42 = time.time() print '------------------------------' print 'Compute MEC done, time: %s' %str(t42-t41)
# ---- radius = 6 decay = 0.05 slope = [radians(-60), radians(45)] robot_sensor = sensor(real_mdp, radius, decay, slope) # ---- print '------------------------------' base = '& G F b G F w' #order = 'G i h X U ! w b' order = 'G F h' safe = 'G ! o' task = '& %s & %s %s' % (base, order, safe) #task = '& G F b G F h' print 'Formula received: %s' % str(task) dra = Dra(task) t3 = time.time() print 'DRA done, time: %s' % str(t3 - t2) #---- print '------------------------------' gamma = [0.8, 0.5] # gamma_o, gamma_r prod_dra = Product_Dra(mdp=robot_mdp, dra=dra, gamma=gamma) #prod_dra.dotify() t41 = time.time() print 'Product DRA constructed, time: %s' % str(t41 - t3) #prod_dra.verify() #---- prod_dra.init_dirichlet() t42 = time.time()
#---- motion_mdp = Motion_MDP(robot_nodes, robot_edges, U, initial_node, initial_label) t2 = time.time() print 'MDP done, time: %s' % str(t2 - t0) #---- ordered_reach = '& F G base3 & F base1 & F base2 & F base3 G ! obstacle' all_base = '& G F base1 & G F base2 & G F base3 G ! obstacle' 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(task1) t3 = time.time() print 'DRA done, time: %s' % str(t3 - t2) #---- prod_dra = Product_Dra(motion_mdp, dra) #prod_dra.dotify() t41 = time.time() print 'Product DRA done, time: %s' % str(t41 - t3) #---- prod_dra.compute_S_f() t42 = time.time() print 'Compute accepting MEC done, time: %s' % str(t42 - t41) #------ gamma = 0.0
import networkx import time import pickle t0 = time.time() #---- 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) t1 = time.time() print '------------------------------' print 'DRA done, time: %s' % str(t1 - t0) print '------------------------------' t2 = time.time() clean_dra = dict() clean_dra['name'] = 'dra_all_base' clean_dra['init'] = dra.graph['initial'] clean_dra['states'] = dra.nodes() clean_dra['symbols'] = dra.graph['symbols'] clean_dra['edge_guard'] = networkx.get_edge_attributes(dra, 'guard_string') clean_dra['accept'] = dra.graph['accept'] pickle.dump(clean_dra, open('nx_dra_model.p', 'wb'))
import networkx import time import pickle t0 = time.time() #---- 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) t1 = time.time() print '------------------------------' print 'DRA done, time: %s' %str(t1-t0) print '------------------------------' t2 = time.time() clean_dra = dict() clean_dra['name'] = 'dra_all_base' clean_dra['init'] = dra.graph['initial'] clean_dra['states'] = dra.nodes() clean_dra['symbols'] = dra.graph['symbols'] clean_dra['edge_guard'] = networkx.get_edge_attributes(dra,'guard_string') clean_dra['accept'] = dra.graph['accept']
('s4', U[1], 's2'): (qf2, C[1]), ('s4', U[1], 's1'): (qf1, C[1]), ('s4', U[1], 's4'): (1 - qf1 - qf2, C[1]), } #---- motion_mdp = Motion_MDP(node_dict, edge_dict, U, initial_node, initial_label) #---- seq_formula1 = "& F a & F b F c" seq_formula2 = "F & a F & b F c" sur_formula1 = "& G F a & G F b G F c" sur_formula2 = "& G F a G F b" seq_sur_formula1 = "G F i a F i b F c" seq_sur_formula2 = "G F & a F & b F c" dra = Dra(sur_formula1) #---- prod_dra = Product_Dra(motion_mdp, dra) prod_dra.compute_S_f() #prod_dra.dotify() allowed_risk = 0.0 best_all_plan = syn_full_plan(prod_dra, allowed_risk) #---------------------------------------- print "----------------------------------------" print "||||||||Simulation start||||||||||||||||" print "----------------------------------------" total_T = 20 state_seq = [