|
| 1 | +""" |
| 2 | +Generates large number of random environments |
| 3 | +""" |
| 4 | + |
| 5 | +# @ file env_generator.py |
| 6 | +# @brief Generates large number of random environments |
| 7 | + |
| 8 | +import os |
| 9 | +import pathlib |
| 10 | +import argparse |
| 11 | + |
| 12 | +from coverage_control import Parameters |
| 13 | +from coverage_control import CoverageSystem |
| 14 | +from coverage_control import IOUtils |
| 15 | + |
| 16 | + |
| 17 | +def main(env_config_file: str, num_envs: int, env_dir: str): |
| 18 | + """ |
| 19 | + Generates large number of random environments |
| 20 | + """ |
| 21 | + |
| 22 | + env_config_file = IOUtils.sanitize_path(env_config_file) |
| 23 | + cc_params = Parameters(env_config_file) |
| 24 | + |
| 25 | + envs_path = pathlib.Path(IOUtils.sanitize_path(env_dir)) |
| 26 | + |
| 27 | + if not os.path.exists(envs_path): |
| 28 | + print(f"Creating directory {envs_path}") |
| 29 | + os.makedirs(envs_path) |
| 30 | + |
| 31 | + for i in range(num_envs): |
| 32 | + pos_file = str(envs_path / f"{i:04}.pos") |
| 33 | + env_file = str(envs_path / f"{i:04}.env") |
| 34 | + cc_system = CoverageSystem(cc_params) |
| 35 | + cc_system.WriteEnvironment(pos_file, env_file) |
| 36 | + |
| 37 | + |
| 38 | +if __name__ == "__main__": |
| 39 | + parser = argparse.ArgumentParser( |
| 40 | + description="Generates large number of random environments" |
| 41 | + ) |
| 42 | + parser.add_argument("config", type=str, help="Environment configuration file") |
| 43 | + parser.add_argument("num_envs", type=int, help="Number of environments to generate") |
| 44 | + parser.add_argument("env_dir", type=str, help="Directory to save the environments") |
| 45 | + args = parser.parse_args() |
| 46 | + |
| 47 | + main(args.config, args.num_envs, args.env_dir) |
0 commit comments