From 88d44457929ba1d39980100bd0d3c0256d3a637d Mon Sep 17 00:00:00 2001 From: Nitish Bhupathi Raju Date: Sun, 31 Mar 2024 23:59:00 -0500 Subject: [PATCH] sensor changes --- sense.py | 39 +++++++++++++++++++++++++++++++------- sensedl.py | 10 +++++----- verse/analysis/dryvr.py | 2 ++ verse/analysis/verifier.py | 11 +++++++++-- 4 files changed, 48 insertions(+), 14 deletions(-) diff --git a/sense.py b/sense.py index a584c058..c094ce4e 100644 --- a/sense.py +++ b/sense.py @@ -66,7 +66,10 @@ def sense(self, agent: BaseAgent, state_dict, lane_map): x = cont['ego.x'] y = cont['ego.y'] position = np.array([x,y]) - lateral = lane_map.get_lateral_distance("T0", position) + true_lateral = lane_map.get_lateral_distance("T0", position) + + blowup = true_lateral + np.random.uniform(low=-0.25, high=0.25, size=5) + lateral = random.choice(blowup) if(lateral < -1): cont['ego.s'] = 0 @@ -77,6 +80,9 @@ def sense(self, agent: BaseAgent, state_dict, lane_map): else: cont['ego.s'] = 1 + + #perception contract: blow up lateral array and randomly sample + else: if agent.id == 'car': cont['ego.x'] = [state_dict['car'][0][0][1], state_dict['car'][0][1][1]] @@ -86,14 +92,21 @@ def sense(self, agent: BaseAgent, state_dict, lane_map): cont['ego.t'] = [state_dict['car'][0][0][5], state_dict['car'][0][1][5]] disc['ego.agent_mode'] = state_dict['car'][1][0] - lateral = [] + true_lateral = [] + #print("new four") for x in cont['ego.x']: for y in cont['ego.y']: position = np.array([x,y]) - print(position) - lateral.append(lane_map.get_lateral_distance("T0", position)) + #print(position) + true_lateral.append(lane_map.get_lateral_distance("T0", position)) - min_lateral = min(lateral) + blowup = [] + for l in true_lateral: + blowup += list(l + np.random.uniform(low=-0.25, high=0.25, size=5)) + + min_lateral = min(blowup) #+ 0.1 + + #perception contract: blow up lateral array and choose minimum if(min_lateral < -1): cont['ego.s'] = [0,0] @@ -113,7 +126,7 @@ def __init__(self): segment0 = CircularLane("Seg0", [14, 14], 12, np.pi * 3 / 2, np.pi, True, 4) segment1 = StraightLane("Seg1", [2, 14], [2, 24], 4) segment2 = CircularLane("Seg2", [14, 24], 12, np.pi, 0, True, 4) - segment3 = StraightLane("Seg3", [26, 24], [26, 14], 4) + #segment3 = StraightLane("Seg3", [26, 24], [26, 14], 4) lane0 = Lane("T0", [segment0, segment1, segment2])# segment3]) self.add_lanes([lane0]) self.h_dict = {("T0", "Left", "Right"): "T0", ("T0", "Right", "Left"): "T0", @@ -192,7 +205,19 @@ def __init__(self, id, code=None, file_name=None): #traces_simu = scenario.simulate(60,0.01) traces_veri = scenario.verify(10, 0.01) -traces_veri.dump("out.json") +nodes = traces_veri._get_all_nodes(traces_veri.root) +#print(len(nodes)) +# for n in nodes: +# print("new node") +# for l in n.trace['car']: +# print(l[1:3]) + +#traces_veri.visualize() +#print(nodes) +#print("height") +#print(traces_veri.height) + +#traces_veri.dump("out.json") # fig = go.Figure() # fig = simulation_tree(traces_simu, None, fig, 1, 2, [0, 1], "lines", "trace") diff --git a/sensedl.py b/sensedl.py index c9a3fed4..8b260fe1 100644 --- a/sensedl.py +++ b/sensedl.py @@ -53,12 +53,12 @@ def decisionLogic(ego: State, track_map): output.track_mode = TrackMode.T0 - x = ego.x - y = ego.y - position = [x,y] - lateral = track_map.get_lateral_distance("T0", position) + # x = ego.x + # y = ego.y + # position = [x,y] + # lateral = track_map.get_lateral_distance("T0", position) - # assert -2 <= lateral and lateral <= 2 + #assert -2 <= lateral and lateral <= 2 #assert ((ego.x-14)**2 + (ego.y-14)**2 >= 10**2 and (ego.x-14)**2 + (ego.y-14)**2 <= 14**2 and ego.y <= 14) or (ego.x > 0 and ego.x < 4 and ego.y > 14 and ego.y <= 24) or ((ego.x-14)**2 + (ego.y-24)**2 >= 10**2 and (ego.x-14)**2 + (ego.y-24)**2 <= 14**2 and ego.y > 24) assert True diff --git a/verse/analysis/dryvr.py b/verse/analysis/dryvr.py index 4c4a97e5..3b941b5a 100644 --- a/verse/analysis/dryvr.py +++ b/verse/analysis/dryvr.py @@ -285,6 +285,8 @@ def calc_bloated_tube( traces = [sim_func(mode_label, cur_center, time_horizon, time_step, lane_map)] # Simulate SIMTRACENUM times to learn the sensitivity for i in range(sim_trace_num): + # modified + random.seed(i) new_init_point = randomPoint(initial_set[0], initial_set[1]) traces.append(sim_func(mode_label, new_init_point, time_horizon, time_step, lane_map)) diff --git a/verse/analysis/verifier.py b/verse/analysis/verifier.py index c6673d68..39e4176b 100644 --- a/verse/analysis/verifier.py +++ b/verse/analysis/verifier.py @@ -231,6 +231,7 @@ def compute_full_reachtube_step( uncertain_param = node.uncertain_param[agent_id] if consts.reachability_method == ReachabilityMethod.DRYVR: # pp(('tube', agent_id, mode, inits)) + #exact rectangles ( cur_bloated_tube, cache_tube_update, @@ -666,6 +667,8 @@ def compute_full_reachtube( # print(f">>>>>>>> Number of transitions happening: {num_transitions}") self.num_transitions = num_transitions + #print(len(self.nodes)) + return self.reachtube_tree @staticmethod @@ -789,11 +792,15 @@ def get_transition_verify_opt( guard_hits = [] guard_hit = False reduction_rate = 10 - reduction_queue = [(0, trace_length, trace_length)] + reduction_queue = [] + for i in range(trace_length): + reduction_queue.append((i,i+1,1)) + #reduction_queue = [(0, trace_length, trace_length)] # for idx, end_idx,combine_len in reduction_queue: hits = [] while reduction_queue: - idx, end_idx, combine_len = reduction_queue.pop() + #don't over approximate rectangles + idx, end_idx, combine_len = reduction_queue.pop(0) reduction_needed = False # print((idx, combine_len)) any_contained = False