def define_settings(unsafe_box): 'get the hylaa settings object' step = math.pi / 6 max_time = 3 * math.pi settings = HylaaSettings(step, max_time) settings.process_urgent_guards = True settings.aggstrat.deaggregate = True # use deaggregation settings.aggstrat.deagg_preference = Aggregated.DEAGG_LEAVES_FIRST settings.aggstrat.agg_type = Aggregated.AGG_CONVEX_HULL plot_settings = settings.plot plot_settings.plot_mode = PlotSettings.PLOT_IMAGE plot_settings.xdim_dir = 0 plot_settings.ydim_dir = 1 plot_settings.label.x_label = '$x$' plot_settings.label.y_label = '$y$' cols = [] line = [(-10, -3), (10, -3)] cols.append( collections.LineCollection([line], animated=True, colors=('gray'), linewidths=(2), linestyle='dashed')) line = [] line.append((unsafe_box[0][0], unsafe_box[1][0])) line.append((unsafe_box[0][1], unsafe_box[1][0])) line.append((unsafe_box[0][1], unsafe_box[1][1])) line.append((unsafe_box[0][0], unsafe_box[1][1])) line.append((unsafe_box[0][0], unsafe_box[1][0])) cols.append( collections.LineCollection([line], animated=True, colors=('red'), linewidths=(2), linestyle='dashed')) settings.plot.extra_collections = cols plot_settings.plot_mode = PlotSettings.PLOT_VIDEO plot_settings.filename = 'ha_deagg.mp4' plot_settings.video_fps = 4 plot_settings.video_extra_frames = 12 # extra frames at the end of a video so it doesn't end so abruptly plot_settings.video_pause_frames = 2 # frames to render in video whenever a 'pause' occurs plot_settings.label.axes_limits = [-6, 6, -4, 6] plot_settings.label.y_label = '$y$' plot_settings.label.x_label = '$x$' plot_settings.label.title = 'Deaggregation Demo' return settings
def test_over_time_range(): 'test plotting over time with aggergation (time range)' ha = HybridAutomaton() mode_a = ha.new_mode('A') mode_b = ha.new_mode('B') # dynamics: x' = a, a' = 0 mode_a.set_dynamics([[0, 1], [0, 0]]) mode_b.set_dynamics([[0, 1], [0, 0]]) # invariant: x <= 2.5 mode_a.set_invariant([[1, 0]], [2.5]) trans1 = ha.new_transition(mode_a, mode_b, 'first') trans1.set_guard_true() # initial set has x0 = [0, 0] init_lpi = lputil.from_box([(0, 0), (1, 1)], mode_a) init_list = [StateSet(init_lpi, mode_a)] # settings, step size = 1.0 settings = HylaaSettings(1.0, 4.0) settings.stdout = HylaaSettings.STDOUT_DEBUG settings.process_urgent_guards = True settings.plot.plot_mode = PlotSettings.PLOT_NONE settings.plot.store_plot_result = True settings.plot.xdim_dir = None settings.plot.ydim_dir = 0 result = Core(ha, settings).run(init_list) polys = [obj[0] for obj in result.plot_data.mode_to_obj_list[0][mode_b.name]] # expected with aggegregation: [0, 2.5] -> [1, 3.5] -> [2, 4.5] -> [3, 5.5] -> [4, 6.5] # 4 steps because invariant is allowed to be false for the final step assert len(polys) == 5, "expected invariant to become false after 5 steps" for i in range(5): assert_verts_is_box(polys[i], [[i, i + 3.0], [i, i + 3.0]])
def test_agg_ha(): 'test aggregation with the harmonic oscillator dynamics' ha = HybridAutomaton('Deaggregation Example') m1 = ha.new_mode('green') m1.set_dynamics([[0, 1], [-1, 0]]) m2 = ha.new_mode('cyan') m2.set_dynamics([[0, 0, 0], [0, 0, -2], [0, 0, 0]]) t1 = ha.new_transition(m1, m2) t1.set_guard_true() reset_mat = [[1, 0], [0, 1], [0, 0]] t1.set_reset(reset_mat, [[0], [0], [1]], [[1], [-1]], [1, -1]) # create 3rd variable with a0 = 1 mode = ha.modes['green'] init_lpi = lputil.from_box([(-5, -4), (-0.5, 0.5)], mode) init_list = [StateSet(init_lpi, mode)] step = math.pi/4 settings = HylaaSettings(step, 2*step) settings.process_urgent_guards = True settings.plot.plot_mode = PlotSettings.PLOT_NONE settings.stdout = HylaaSettings.STDOUT_DEBUG core = Core(ha, settings) core.setup(init_list) core.do_step() # pop #xs, ys = zip(*core.cur_state.verts(core.plotman)) #plt.plot(xs, ys, 'k-') core.do_step() # 0 #xs, ys = zip(*core.cur_state.verts(core.plotman)) #plt.plot(xs, ys, 'k-') core.do_step() # 1 #xs, ys = zip(*core.cur_state.verts(core.plotman)) #plt.plot(xs, ys, 'k-') core.do_step() # 2 assert len(core.aggdag.waiting_list) > 1 #for state in core.waiting_list: # xs, ys = zip(*state.verts(core.plotman)) # plt.plot(xs, ys, 'k-') core.do_step() # pop assert not core.aggdag.waiting_list lpi = core.aggdag.get_cur_state().lpi # 3 constraints from basis matrix # 2 aggregation directions from premode arnoldi, +1 from null space # + 2 more aggregation directions from box (3rd is omited since it's exactly the same as null space direction) #print(lpi) #xs, ys = zip(*core.cur_state.verts(core.plotman)) #plt.plot(xs, ys, 'r--') #plt.show() assert lpi.get_num_rows() == 3 + 2 * (5) assert lputil.is_point_in_lpi((-5, 2, 1), lpi)
def make_settings(unsafe_box): 'make the reachability settings object' # see hylaa.settings for a list of reachability settings settings = HylaaSettings(1.0, 20.0) settings.process_urgent_guards = True settings.stdout = HylaaSettings.STDOUT_VERBOSE settings.plot.video_pause_frames = 5 settings.plot.video_fps = 5 settings.plot.plot_mode = PlotSettings.PLOT_NONE settings.plot.interactive_skip_count = 5 #settings.plot.plot_mode = PlotSettings.PLOT_VIDEO #settings.plot.filename = "deagg_example.mp4" settings.stop_on_aggregated_error = False settings.aggstrat.deaggregate = True # use deaggregation settings.aggstrat.deagg_preference = Aggregated.DEAGG_LEAVES_FIRST settings.plot.extra_collections = [] settings.plot.label = [] ls = LabelSettings() ls.axes_limits = [-1, 12, -1, 6] settings.plot.label.append(ls) ls.big(size=24) ls.x_label = '$x$' ls.y_label = '$y$' cols = [] line = [(3.5, -20), (3.5, 20)] cols.append( collections.LineCollection([line], animated=True, colors=('gray'), linewidths=(2), linestyle='dashed')) line = [(-20, 3.5), (20, 3.5)] cols.append( collections.LineCollection([line], animated=True, colors=('gray'), linewidths=(2), linestyle='dashed')) # x >= 1.1 x <= 1.9, y >= 2.7, y <= 4.3 line = [] line.append((unsafe_box[0][0], unsafe_box[1][0])) line.append((unsafe_box[0][1], unsafe_box[1][0])) line.append((unsafe_box[0][1], unsafe_box[1][1])) line.append((unsafe_box[0][0], unsafe_box[1][1])) line.append((unsafe_box[0][0], unsafe_box[1][0])) cols.append( collections.LineCollection([line], animated=True, colors=('red'), linewidths=(2), linestyle='dashed')) settings.plot.extra_collections.append(cols) return settings
def make_settings(safe): 'make the reachability settings object' # see hylaa.settings for a list of reachability settings settings = HylaaSettings(1.0, 200.0) # step: 0.1, bound: 200.0 settings.stop_on_aggregated_error = False settings.process_urgent_guards = True #settings.aggstrat = MyAggergated() settings.aggstrat.deaggregate = True # use deaggregation settings.aggstrat.deagg_preference = Aggregated.DEAGG_LEAVES_FIRST settings.stdout = HylaaSettings.STDOUT_VERBOSE settings.plot.plot_mode = PlotSettings.PLOT_NONE settings.plot.filename = "rendezvous_full_passivity.png" settings.plot.plot_size = (8, 9) #settings.plot.video_pause_frames = 10 #settings.plot.plot_mode = PlotSettings.PLOT_VIDEO #settings.plot.filename = "rendezvous_full_passivity.mp4" settings.plot.xdim_dir = [0] * 3 settings.plot.ydim_dir = [1] * 3 settings.plot.grid = False settings.plot.label = [] settings.plot.extra_collections = [] for _ in range(3): ls = LabelSettings() settings.plot.label.append(ls) ls.big(size=24) ls.x_label = '$x$' ls.y_label = '$y$' y = 57.735 line = [(-100, y), (-100, -y), (0, 0), (-100, y)] c1 = collections.LineCollection([line], animated=True, colors=('gray'), linewidths=(1), linestyle='dashed') rad = 0.2 line = [(-rad, -rad), (-rad, rad), (rad, rad), (rad, -rad), (-rad, -rad)] c2 = collections.LineCollection([line], animated=True, colors=('red'), linewidths=(2)) settings.plot.extra_collections.append([c1, c2]) settings.plot.label[0].axes_limits = [-950, 400, -450, 70] #settings.plot.label[1].axes_limits = [-150, 50, -70, 70] settings.plot.label[1].axes_limits = [-80, 5, -30, 5] settings.plot.label[2].axes_limits = [-3, 1.5, -1.5, 1.5] return settings