def case_1(): # Read the vehicle model vehicle = lomap.Ts() vehicle.read_from_file('./vehicle_1.txt') # Convert the vehicle model to an MDP vehicle_mdp = lomap.Markov() vehicle_mdp.mdp_from_det_ts(vehicle) # Read the models of the pedestrians targets = [] for i in range(1, 6): t = lomap.Markov() t.read_from_file('./target_%d.txt' % i) targets.append(t) formula = '! col U end' # Construct the full-state fsa using scheck # (full-state ensures proper MDP after product) logger.info('Formula: %s' % formula) fsa = lomap.Fsa() fsa.fsa_from_cosafe_formula(formula) fsa.add_trap_state() # Classical with lomap.Timer( 'Classical (non-incremental) Method: Case 1 - Avoid pedestrians'): lomap.classical_synthesis(vehicle_mdp, fsa, targets, set_props_1) pass # Incremental with lomap.Timer('Incremental Method: Case 1 - Avoid pedestrians'): lomap.incremental_synthesis(vehicle_mdp, fsa, targets, set_props_1)
def case_2b(): # Read the vehicle model vehicle = lomap.Ts() vehicle.read_from_file('./vehicle_1.txt') # Convert the vehicle model to an MDP vehicle_mdp = lomap.Markov() vehicle_mdp.mdp_from_det_ts(vehicle) # Read the models of the pedestrians targets = [] for i in range(1, 6): t = lomap.Markov() t.read_from_file('./target_%d.txt' % i) targets.append(t) formula = '( F catch0 | F catch1 | F catch2 | F catch3 ) & ( ! col4 U end )' # Construct the full-state fsa using scheck # (full-state ensures proper MDP after product) logger.info('Formula: %s' % formula) fsa = lomap.Fsa() fsa.fsa_from_cosafe_formula(formula) fsa.add_trap_state() # Classical with lomap.Timer( 'Classical (non-incremental) Method: Case 2b - Save at least one friendly' ): lomap.classical_synthesis(vehicle_mdp, fsa, targets, set_props_2) pass # Incremental targets_inc = [targets[-1]] + targets[:-1] assumed_props = [('ped0c2', 'ped1c2', 'ped2c2', 'ped3c2'), ('ped1c2', 'ped2c2', 'ped3c2'), ('ped2c2', 'ped3c2'), ('ped3c2'), ()] with lomap.Timer( 'Incremental Method: Case 2b - Save at least one friendly'): lomap.incremental_synthesis(vehicle_mdp, fsa, targets_inc, set_props_2, assumed_props) pass
def case_3b(): # Read the vehicle model vehicle = lomap.Ts() vehicle.read_from_file('./vehicle_2.txt') # Convert the vehicle model to an MDP vehicle_mdp = lomap.Markov() vehicle_mdp.mdp_from_det_ts(vehicle) # Read the models of the guards targets = [] for i in range(1, 7): t = lomap.Markov() t.read_from_file('./trap_%d.txt' % i) targets.append(t) # Reach end safely formula = '! unsafe U end' # Construct the full-state fsa using scheck # (full-state ensures proper MDP after product) logger.info('Formula: %s' % formula) fsa = lomap.Fsa() fsa.fsa_from_cosafe_formula(formula) fsa.add_trap_state() #fsa.visualize() # Classical with lomap.Timer('Classical (non-incremental) Method: Case 3b - Order 2'): lomap.classical_synthesis(vehicle_mdp, fsa, targets, set_props_3) pass # Incremental targets_inc = [ targets[2], targets[3], targets[0], targets[1], targets[5], targets[4] ] with lomap.Timer('Incremental Method: Case 3b - Order 2'): lomap.incremental_synthesis(vehicle_mdp, fsa, targets_inc, set_props_3) pass
def animate(i): global quad, view, planner, cmd, anim_state logger.debug('Vehicle location - Frame %d: %s' % (i, (quad.x, quad.y))) toggle_local_reqs(i) quad.sense() if not i % 2: # Draw the quad view.draw_quad() else: # Plan and the draw the path for the next time step with lomap.Timer('Online Computation - Frame %d:' % i): cmd, path = planner.next_command() view.draw_path(path) quad.move_quad(cmd)
def main(): Rho = namedtuple('Rho', ['lower', 'upper']) rhos = [Rho(lower=0.98, upper=1.04), Rho(lower=0.98, upper=1.04)] pdb.set_trace() # Case Study 1 # with lomap.Timer('IJRR 2013 Case-Study 1'): # r1 = lomap.Ts() # r2 = lomap.Ts() # r1.read_from_file('./robot_1.txt') # r2.read_from_file('./robot_2.txt') # ts_tuple = (r1, r2) # formula = '[]<>gather && [](r1gather -> X(!r1gather U r1upload)) && [](r2gather -> X(!r2gather U r2upload))' # opt_prop = set(['gather']) # logger.info('Formula: %s', formula) # logger.info('opt_prop: %s', opt_prop) # prefix_length, prefixes, suffix_cycle_cost, suffix_cycles = lomap.multi_agent_optimal_run(ts_tuple, formula, opt_prop) # logger.info('Cost: %d', suffix_cycle_cost) # logger.info('Prefix length: %d', prefix_length) # # Find the controls that will produce this run # control_prefixes = [] # control_suffix_cycles = [] # for i in range(0, len(ts_tuple)): # ts = ts_tuple[i] # control_prefixes.append(ts.controls_from_run(prefixes[i])) # control_suffix_cycles.append(ts.controls_from_run(suffix_cycles[i])) # logger.info('%s run prefix: %s', ts.name, prefixes[i]) # logger.info('%s control perfix: %s', ts.name, control_prefixes[i]) # logger.info('%s suffix cycle: %s', ts.name, suffix_cycles[i]) # logger.info('%s control suffix cycle: %s', ts.name, control_suffix_cycles[i]) # # logger.info('<><><> <><><> <><><>') # Case Study 4 with lomap.Timer('IJRR 2013 Case-Study 4'): r1 = lomap.Ts() r2 = lomap.Ts() r1.read_from_file('./robot_1.txt') r2.read_from_file('./robot_2.txt') ts_tuple = (r1, r2) pdb.set_trace() formula = '[]<>gather && [](gather->(r1gather4 && r2gather2)) && [](r1gather -> X(!r1gather U r1upload)) && [](r2gather -> X(!r2gather U r2upload))' opt_prop = set(['r1gather4', 'r2gather2']) logger.info('Formula: %s', formula) logger.info('opt_prop: %s', opt_prop) prefix_length, prefixes, suffix_cycle_cost, suffix_cycles = lomap.multi_agent_optimal_run( ts_tuple, formula, opt_prop) logger.info('Cost: %d', suffix_cycle_cost) logger.info('Prefix length: %d', prefix_length) # Find the controls that will produce this run control_prefixes = [] control_suffix_cycles = [] for i in range(0, len(ts_tuple)): ts = ts_tuple[i] control_prefixes.append(ts.controls_from_run(prefixes[i])) control_suffix_cycles.append(ts.controls_from_run( suffix_cycles[i])) logger.info('%s run prefix: %s', ts.name, prefixes[i]) logger.info('%s control perfix: %s', ts.name, control_prefixes[i]) logger.info('%s suffix cycle: %s', ts.name, suffix_cycles[i]) logger.info('%s control suffix cycle: %s', ts.name, control_suffix_cycles[i]) logger.info('<><><> <><><> <><><>')
# Select the case-study to run case = 'case2' # Set the mission specification global_spec, local_spec, prio, init_x, init_y, sensing_range = case_studies[ case] # Create the environment env = Environment(case) # Create the quadrotor quad = Quadrotor(env, init_x, init_y, sensing_range) # Create the view view = View(env, quad) with lomap.Timer('Offline Computation'): planner = Planner(env, quad, global_spec, local_spec, prio) # Animation anim = animation.FuncAnimation(view.fig, animate, frames=list(range(0, 200)), interval=250, repeat=False) if video_name: anim.save(video_name) exit(0) plt.show()