From 14a04b7db5d8ce89c7d8f78fba32af1a6221b80c Mon Sep 17 00:00:00 2001 From: crides <zhuhaoqing@live.cn> Date: Thu, 13 Oct 2022 22:11:57 -0500 Subject: [PATCH] expr --- demo/vehicle/controller/inc-expr-fsw4.py | 4 ++-- demo/vehicle/inc-expr.py | 3 ++- inc-expr.py | 11 +++++++---- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/demo/vehicle/controller/inc-expr-fsw4.py b/demo/vehicle/controller/inc-expr-fsw4.py index 3e166c6e..647a54fd 100644 --- a/demo/vehicle/controller/inc-expr-fsw4.py +++ b/demo/vehicle/controller/inc-expr-fsw4.py @@ -52,13 +52,13 @@ def controller(ego:State, others:List[State], lane_map): output = copy.deepcopy(ego) if ego.vehicle_mode == VehicleMode.Normal: # Switch left if left lane is empty - if car_front(ego, others, lane_map, 4, 3): + if car_front(ego, others, lane_map, 4.5, 3): if lane_map.has_left(ego.lane_mode) and \ not car_left(ego, others, lane_map): output.vehicle_mode = VehicleMode.SwitchLeft # Switch right if right lane is empty - if car_front(ego, others, lane_map, 4, 3): + if car_front(ego, others, lane_map, 4.5, 3): if lane_map.has_right(ego.lane_mode) and \ not car_right(ego, others, lane_map): output.vehicle_mode = VehicleMode.SwitchRight diff --git a/demo/vehicle/inc-expr.py b/demo/vehicle/inc-expr.py index 039d937b..67cd2ec8 100644 --- a/demo/vehicle/inc-expr.py +++ b/demo/vehicle/inc-expr.py @@ -52,7 +52,7 @@ if 'p' in arg: def run(sim, meas=False): time = timeit.default_timer() if sim: - traces = scenario.simulate(60, 0.05) + traces = scenario.simulate(60, 0.1) else: traces = scenario.verify(60, 0.1) @@ -78,6 +78,7 @@ def run(sim, meas=False): "dur": timeit.default_timer() - time, "cache_size": cache_size, "node_count": len(traces.nodes), + "hits": scenario.simulator.cache_hits if sim else (scenario.verifier.tube_cache_hits, scenario.verifier.trans_cache_hits), }) if __name__ == "__main__": diff --git a/inc-expr.py b/inc-expr.py index 6c068b17..3e94f1a2 100644 --- a/inc-expr.py +++ b/inc-expr.py @@ -3,6 +3,7 @@ from itertools import product from pprint import pp import re from subprocess import PIPE, Popen +from typing import Tuple, Union @dataclass class ExperimentResult: @@ -12,10 +13,11 @@ class ExperimentResult: cache_size: float node_count: int ret_code: int + cache_hits: Union[Tuple[int, int], Tuple[Tuple[int, int], Tuple[int, int]]] xprms = [ - "v" + - "".join(l) for l in product("n8", ("", "i"))] + # "v" + + "".join(l) for l in product("brn8", ("", "i"))] rslts = [] for xprm in xprms: cmd = Popen(f"/usr/bin/time -v -- python3.8 demo/vehicle/inc-expr.py {xprm}", stdout=PIPE, stderr=PIPE, shell=True) @@ -30,7 +32,7 @@ for xprm in xprms: print(b"".join(stderr)) exit(2) info = eval(filtered_info[0]) - rslt = ExperimentResult(xprm, max_mem, info["dur"], info["cache_size"] / 1_000_000, info["node_count"], ret) + rslt = ExperimentResult(xprm, max_mem, info["dur"], info["cache_size"] / 1_000_000, info["node_count"], ret, info["hits"]) pp(rslt) if rslt.ret_code != 0: print(f"uh oh, var={xprm} ret={rslt.ret_code}") @@ -50,4 +52,5 @@ for i in range(0, len(rslts), 2): elif "8" in var: name = "change ctlr" - print(" & " + " & ".join([name] + [str(i) for i in [inc.node_count, round(no.duration, 2), round(no.max_mem), round(inc.duration, 2), round(inc.max_mem), round(inc.cache_size, 2)]]) + " \\\\") + cache_hit_rate = inc.cache_hits[0] / (inc.cache_hits[0] + inc.cache_hits[1]) if "v" not in var else (inc.cache_hits[0][0] + inc.cache_hits[1][0]) / (inc.cache_hits[0][0] + inc.cache_hits[0][1] + inc.cache_hits[1][0] + inc.cache_hits[1][1]) + print(" & " + " & ".join([name] + [str(i) for i in [inc.node_count, round(no.duration, 2), round(no.max_mem), round(inc.duration, 2), round(inc.max_mem), round(inc.cache_size, 2), round(cache_hit_rate * 100, 2)]]) + " \\\\") -- GitLab