Skip to content

Commit

Permalink
Allow random routes to vary across traffic groups.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gamenot committed Nov 16, 2023
1 parent c164c5c commit 8f65dde
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 4 additions & 2 deletions scenarios/sumo/intersections/4lane/scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,20 @@
),
]

variations = 40
scenario = Scenario(
traffic={
"basic": Traffic(
f"t{i}": Traffic(
flows=[
Flow(
route=RandomRoute(),
repeat_route=True,
rate=3600,
randomly_spaced=True,
actors={TrafficActor(name="car"): 1.0},
)
]
)
for i in range(variations)
},
ego_missions=ego_missions,
map_spec=MapSpec(
Expand Down
6 changes: 5 additions & 1 deletion smarts/sstudio/genscenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import logging
import os
import pickle
import random
import sqlite3
from dataclasses import dataclass, replace
from pathlib import Path
Expand All @@ -35,6 +36,7 @@
import cloudpickle
import yaml

import smarts.core
from smarts.core.default_map_builder import find_mapfile_in_dir
from smarts.core.utils.file import file_md5_hash, path2hash, pickle_hash
from smarts.core.utils.logging import timeit
Expand Down Expand Up @@ -164,6 +166,7 @@ def gen_scenario(
"""
# XXX: For now this simply coalesces the sub-calls but in the future this allows
# us to simplify our serialization between SStudio and SMARTS.
smarts.core.seed(seed)

scenario_dir = os.path.abspath(str(output_dir))
build_dir = os.path.join(scenario_dir, "build")
Expand Down Expand Up @@ -243,11 +246,12 @@ def gen_scenario(
):
with timeit("traffic", logger.info):
for name, traffic in scenario.traffic.items():
derived_seed = random.randint(-0b111111111111111, 0b111111111111111)
gen_traffic(
scenario=scenario_dir,
traffic=traffic,
name=name,
seed=seed,
seed=derived_seed,
map_spec=map_spec,
)
_update_artifacts(db_conn, artifact_paths, obj_hash)
Expand Down

0 comments on commit 8f65dde

Please sign in to comment.