Skip to content
Snippets Groups Projects
Commit 14a04b7d authored by crides's avatar crides
Browse files

expr

parent 9840ebf0
No related branches found
No related tags found
1 merge request!9Tutorial
...@@ -52,13 +52,13 @@ def controller(ego:State, others:List[State], lane_map): ...@@ -52,13 +52,13 @@ def controller(ego:State, others:List[State], lane_map):
output = copy.deepcopy(ego) output = copy.deepcopy(ego)
if ego.vehicle_mode == VehicleMode.Normal: if ego.vehicle_mode == VehicleMode.Normal:
# Switch left if left lane is empty # 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 \ if lane_map.has_left(ego.lane_mode) and \
not car_left(ego, others, lane_map): not car_left(ego, others, lane_map):
output.vehicle_mode = VehicleMode.SwitchLeft output.vehicle_mode = VehicleMode.SwitchLeft
# Switch right if right lane is empty # 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 \ if lane_map.has_right(ego.lane_mode) and \
not car_right(ego, others, lane_map): not car_right(ego, others, lane_map):
output.vehicle_mode = VehicleMode.SwitchRight output.vehicle_mode = VehicleMode.SwitchRight
......
...@@ -52,7 +52,7 @@ if 'p' in arg: ...@@ -52,7 +52,7 @@ if 'p' in arg:
def run(sim, meas=False): def run(sim, meas=False):
time = timeit.default_timer() time = timeit.default_timer()
if sim: if sim:
traces = scenario.simulate(60, 0.05) traces = scenario.simulate(60, 0.1)
else: else:
traces = scenario.verify(60, 0.1) traces = scenario.verify(60, 0.1)
...@@ -78,6 +78,7 @@ def run(sim, meas=False): ...@@ -78,6 +78,7 @@ def run(sim, meas=False):
"dur": timeit.default_timer() - time, "dur": timeit.default_timer() - time,
"cache_size": cache_size, "cache_size": cache_size,
"node_count": len(traces.nodes), "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__": if __name__ == "__main__":
......
...@@ -3,6 +3,7 @@ from itertools import product ...@@ -3,6 +3,7 @@ from itertools import product
from pprint import pp from pprint import pp
import re import re
from subprocess import PIPE, Popen from subprocess import PIPE, Popen
from typing import Tuple, Union
@dataclass @dataclass
class ExperimentResult: class ExperimentResult:
...@@ -12,10 +13,11 @@ class ExperimentResult: ...@@ -12,10 +13,11 @@ class ExperimentResult:
cache_size: float cache_size: float
node_count: int node_count: int
ret_code: int ret_code: int
cache_hits: Union[Tuple[int, int], Tuple[Tuple[int, int], Tuple[int, int]]]
xprms = [ xprms = [
"v" + # "v" +
"".join(l) for l in product("n8", ("", "i"))] "".join(l) for l in product("brn8", ("", "i"))]
rslts = [] rslts = []
for xprm in xprms: 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) 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: ...@@ -30,7 +32,7 @@ for xprm in xprms:
print(b"".join(stderr)) print(b"".join(stderr))
exit(2) exit(2)
info = eval(filtered_info[0]) 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) pp(rslt)
if rslt.ret_code != 0: if rslt.ret_code != 0:
print(f"uh oh, var={xprm} ret={rslt.ret_code}") print(f"uh oh, var={xprm} ret={rslt.ret_code}")
...@@ -50,4 +52,5 @@ for i in range(0, len(rslts), 2): ...@@ -50,4 +52,5 @@ for i in range(0, len(rslts), 2):
elif "8" in var: elif "8" in var:
name = "change ctlr" 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)]]) + " \\\\")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment