|
23 | 23 | from pathlib import Path
|
24 | 24 |
|
25 | 25 | from smarts.sstudio import gen_scenario
|
26 |
| -from smarts.sstudio.types import Flow, Mission, Route, Scenario, Traffic, TrafficActor |
| 26 | +from smarts.sstudio.types import ( |
| 27 | + Flow, |
| 28 | + Mission, |
| 29 | + Route, |
| 30 | + Scenario, |
| 31 | + Traffic, |
| 32 | + TrafficActor, |
| 33 | + TrapEntryTactic, |
| 34 | +) |
27 | 35 |
|
28 | 36 | normal = TrafficActor(
|
29 | 37 | name="car",
|
30 | 38 | )
|
31 | 39 |
|
32 |
| -horizontal_routes = [ |
33 |
| - ("E4", 0, "E1", 0), |
34 |
| - ("E4", 1, "E1", 1), |
35 |
| - ("-E1", 0, "-E4", 0), |
36 |
| - ("-E1", 1, "-E4", 1), |
37 |
| -] |
38 |
| - |
39 |
| -turn_left_routes = [ |
40 |
| - ("E0", 0, "E1", 1), |
41 |
| - ("E4", 1, "-E0", 0), |
| 40 | +# flow_name = (start_lane, end_lane) |
| 41 | +route_opt = [ |
| 42 | + (0, 0), |
| 43 | + (1, 1), |
| 44 | + (2, 2), |
42 | 45 | ]
|
43 | 46 |
|
44 |
| -turn_right_routes = [ |
45 |
| - ("E0", 0, "-E4", 0), |
46 |
| - ("-E1", 0, "-E0", 0), |
47 |
| -] |
48 |
| - |
49 |
| -# Total route combinations = 8C1 + 8C2 + 8C3 + 8C4 + 8C5 = 218 |
50 |
| -# Repeated route combinations = 218 * 2 = 436 |
51 |
| -all_routes = horizontal_routes + turn_left_routes + turn_right_routes |
| 47 | +# Traffic combinations = 3C2 + 3C3 = 3 + 1 = 4 |
| 48 | +# Repeated traffic combinations = 4 * 100 = 400 |
| 49 | +min_flows = 2 |
| 50 | +max_flows = 3 |
52 | 51 | route_comb = [
|
53 |
| - com for elems in range(1, 6) for com in combinations(all_routes, elems) |
54 |
| -] * 2 |
| 52 | + com |
| 53 | + for elems in range(min_flows, max_flows + 1) |
| 54 | + for com in combinations(route_opt, elems) |
| 55 | +] * 100 |
| 56 | + |
55 | 57 | traffic = {}
|
56 | 58 | for name, routes in enumerate(route_comb):
|
57 | 59 | traffic[str(name)] = Traffic(
|
58 | 60 | flows=[
|
59 | 61 | Flow(
|
60 | 62 | route=Route(
|
61 |
| - begin=(start_edge, start_lane, 0), |
62 |
| - end=(end_edge, end_lane, "max"), |
| 63 | + begin=("gneE3", start_lane, 0), |
| 64 | + end=("gneE4", end_lane, "max"), |
63 | 65 | ),
|
64 | 66 | # Random flow rate, between x and y vehicles per minute.
|
65 |
| - rate=60 * random.uniform(5, 10), |
| 67 | + rate=60 * random.uniform(10, 20), |
66 | 68 | # Random flow start time, between x and y seconds.
|
67 |
| - begin=random.uniform(0, 3), |
| 69 | + begin=random.uniform(0, 5), |
68 | 70 | # For an episode with maximum_episode_steps=3000 and step
|
69 | 71 | # time=0.1s, the maximum episode time=300s. Hence, traffic is
|
70 | 72 | # set to end at 900s, which is greater than maximum episode
|
71 | 73 | # time of 300s.
|
72 | 74 | end=60 * 15,
|
73 | 75 | actors={normal: 1},
|
| 76 | + randomly_spaced=True, |
74 | 77 | )
|
75 |
| - for start_edge, start_lane, end_edge, end_lane in routes |
| 78 | + for start_lane, end_lane in routes |
76 | 79 | ]
|
77 | 80 | )
|
78 | 81 |
|
79 |
| -route = Route(begin=("E0", 0, 5), end=("E1", 0, "max")) |
| 82 | + |
80 | 83 | ego_missions = [
|
81 | 84 | Mission(
|
82 |
| - route=route, |
83 |
| - start_time=4, # Delayed start, to ensure road has prior traffic. |
84 |
| - ) |
| 85 | + Route(begin=("gneE6", 0, 10), end=("gneE4", 2, "max")), |
| 86 | + entry_tactic=TrapEntryTactic( |
| 87 | + entry_tactic=TrapEntryTactic(start_time=15, wait_to_hijack_limit_s=0.1), |
| 88 | + wait_to_hijack_limit_s=1, |
| 89 | + ), |
| 90 | + ), |
| 91 | + Mission( |
| 92 | + Route(begin=("gneE3", 0, 10), end=("gneE4", 0, "max")), |
| 93 | + entry_tactic=TrapEntryTactic( |
| 94 | + entry_tactic=TrapEntryTactic(start_time=15, wait_to_hijack_limit_s=0.1), |
| 95 | + wait_to_hijack_limit_s=1, |
| 96 | + ), |
| 97 | + ), |
85 | 98 | ]
|
86 | 99 |
|
87 | 100 | gen_scenario(
|
|
0 commit comments