lb=float(time_bound), ub=float(time_bound))) global_prog = RMPyL(name='run()') global_prog *= global_prog.parallel(prog.plan,*activation_episodes,start=global_start) activation_tcs.append(TemporalConstraint(start=global_start,end=prog.first_event, ctype='controllable',lb=0.0,ub=0.005)) for tc in activation_tcs: global_prog.add_temporal_constraint(tc) # rmpyl_policy.to_ptpn(filename=output_file) #ipdb.set_trace() global_prog.to_ptpn(filename=output_file+'_test') paris = PARIS() # risk_bound,sc_schedule = paris.stnu_reformulation(rmpyl_policy,makespan=True,cc=0.001) risk_bound,sc_schedule = paris.stnu_reformulation(global_prog,makespan=True,cc=0.001) if risk_bound != None: risk_bound = min(risk_bound,1.0) print('\nSuccessfully performed STNU reformulation with scheduling risk %f %%!'%(risk_bound*100.0)) for tc in global_prog.temporal_constraints: if tc.type == 'uncontrollable_bounded': tc.type = 'controllable'
#Searches for the optimal policy policy,explicit,performance = planner.search(b0) #Converts policy to graphical SVG format dot_policy = policy_to_dot(explicit,policy) dot_policy.write('flightgear_policy.svg',format='svg') #Converts optimal exploration policy into an RMPyL program exploration_policy = policy_to_rmpyl(explicit,policy) #The flight policy has the additional actions of taking off and landing. flight_policy = RMPyL(name='run()') flight_policy *= flight_policy.sequence(Episode(action='(takeoff plane)'), exploration_policy, Episode(action='(land plane)')) #Eliminates probabilistic choices from the policy, since Pike (in fact, the #Lisp tpn package) cannot properly handle them. for obs in flight_policy.observations: if obs.type=='probabilistic': obs.type = 'uncontrollable' del obs.properties['probability'] #Converts the program to a TPN flight_policy.to_ptpn(filename='flightgear_rmpyl.tpn') # Writes control program to pickle file with open('flightgear_rmpyl.pickle','wb') as f: pickle.dump(flight_policy,f,protocol=2)
plan = sat_plans[0] print('\n##### Plan found!\n') for t, action in enumerate(plan): print('%d: %s' % (t, action)) prog = RMPyL(name='run()') prog.plan = prog.sequence(*[ Episode(start=Event(name='start-of-' + op), end=Event(name='end-of-' + op), action=op, duration=rss_duration_func(op)) for op in plan ]) prog.add_overall_temporal_constraint(ctype='controllable', lb=0.0, ub=2000.0) prog.to_ptpn(filename='rss_pysat_before_stnu_reform.tpn') paris = PARIS() risk_bound, sc_sched = paris.stnu_reformulation(prog, makespan=True, cc=0.001) if risk_bound != None: risk_bound = min(risk_bound, 1.0) print( '\nSuccessfully performed STNU reformulation with scheduling risk %f %%!' % (risk_bound * 100.0)) prog.to_ptpn(filename='rss_pysat_after_stnu_reform.tpn') print('\nThis is the schedule:') for e, t in sorted([(e, t) for e, t in sc_sched.items()], key=lambda x: x[1]):
repetitions = int(sys.argv[1]) if len(sys.argv)==2 else 3 prog*= try_try_again(prog,rob.do_action,rob.stop,loop_utility=1, stop_utility=0,repetitions=repetitions) prog.add_overall_temporal_constraint(ctype='controllable',lb=0.0,ub=10.0) print('\n***** Start event\n') print(prog.first_event) print('\n***** Last event\n') print(prog.last_event) print('\n***** Primitive episodes\n') for i,p in enumerate(prog.primitive_episodes): print('%d: %s\n'%(i+1,str(p))) print('\n***** Events\n') for i,e in enumerate(prog.events): print('%d: %s'%(i+1,str(e))) # print('\n***** Event successors\n') # for i,(ev,successors) in enumerate(prog.event_successors.items()): # print('%d: %s -> %s'%(i+1,ev.name,str([e.name for e in successors]))) print('\n***** Temporal constraints\n') for i,tc in enumerate(prog.temporal_constraints): print('%d: %s\n'%(i+1,str(tc))) prog.to_ptpn(filename='recursive_rmpyl_ptpn.tpn')
#Searches for the optimal policy policy, explicit, performance = planner.search(b0) #Converts policy to graphical SVG format dot_policy = policy_to_dot(explicit, policy) dot_policy.write('flightgear_policy.svg', format='svg') #Converts optimal exploration policy into an RMPyL program exploration_policy = policy_to_rmpyl(explicit, policy) #The flight policy has the additional actions of taking off and landing. flight_policy = RMPyL(name='run()') flight_policy *= flight_policy.sequence(Episode(action='(takeoff plane)'), exploration_policy, Episode(action='(land plane)')) #Eliminates probabilistic choices from the policy, since Pike (in fact, the #Lisp tpn package) cannot properly handle them. for obs in flight_policy.observations: if obs.type == 'probabilistic': obs.type = 'uncontrollable' del obs.properties['probability'] #Converts the program to a TPN flight_policy.to_ptpn(filename='flightgear_rmpyl.tpn') # Writes control program to pickle file with open('flightgear_rmpyl.pickle', 'wb') as f: pickle.dump(flight_policy, f, protocol=2)
""" return Episode(duration={'ctype':'controllable','lb':5,'ub':30}, action='(relay %s)'%(self.name)) loc={'start':(8.751,-8.625), 'minerals':(0.0,-10.0), 'funny_rock':(-5.0,-2.0), 'relay':(0.0,0.0), 'alien_lair':(0.0,10.0)} rov1 = Rover(name='spirit') prog = RMPyL(name='run()')#name=run() is a requirement for Enterprise at the moment prog *= prog.sequence( rov1.go_to(start=loc['start'],goal=loc['minerals'],risk=0.01), rov1.go_to(start=loc['minerals'],goal=loc['funny_rock'],risk=0.01), rov1.go_to(start=loc['funny_rock'],goal=loc['alien_lair'],risk=0.01), rov1.go_to(start=loc['alien_lair'],goal=loc['relay'],risk=0.01)) tc=prog.add_overall_temporal_constraint(ctype='controllable',lb=0.0,ub=2000.0) cc_time = ChanceConstraint(constraint_scope=[tc],risk=0.1) prog.add_chance_constraint(cc_time) #Option to export the RMPyL program to an Enterprise-compliant TPN. prog.to_ptpn(filename='picard_rovers_rmpyl.tpn') #Writes RMPyL program to pickle file. with open('picard_rovers_rmpyl.pickle','wb') as f: print('Writing RMPyL program to pickle file.') pickle.dump(prog,f)
start=global_start) activation_tcs.append( TemporalConstraint(start=global_start, end=prog.first_event, ctype='controllable', lb=0.0, ub=0.005)) for tc in activation_tcs: global_prog.add_temporal_constraint(tc) # rmpyl_policy.to_ptpn(filename=output_file) #ipdb.set_trace() global_prog.to_ptpn(filename=output_file + '_test') paris = PARIS() # risk_bound,sc_schedule = paris.stnu_reformulation(rmpyl_policy,makespan=True,cc=0.001) risk_bound, sc_schedule = paris.stnu_reformulation(global_prog, makespan=True, cc=0.001) if risk_bound != None: risk_bound = min(risk_bound, 1.0) print( '\nSuccessfully performed STNU reformulation with scheduling risk %f %%!' % (risk_bound * 100.0)) for tc in global_prog.temporal_constraints: