def main(): config = gs.ConfigParser('simple_config.yml') print(config.get('name')) grid_width = config.get('grid_width') num_robots = config.get('num_robots') # You can specify a default value in case a parameter isn't in the # configuration file num_steps = config.get('num_steps', default=100) # Create a few robots to place in your world robots = [] # Configuration values can also be lists, not just single values. x_pos = config.get('robot_x_pos') for n in range(num_robots): robots.append(RandomRobot(x_pos[n], grid_width / 2 - n * 2)) # Create a 50 x 50 World with the Robots world = gs.World(grid_width, grid_width, robots=robots) # Run the simulation for n in range(num_steps): # Execute a simulation step world.step() # To make sure it works, print the tick (world time) print('Time:', world.get_time()) print('SIMULATION FINISHED')
def main(): grid_width = 50 # Number of cells for the width & height of the world num_robots = 5 num_steps = 100 # simulation steps to run # Create a few robots to place in your world robots = [] for n in range(num_robots): robots.append(RandomRobot(grid_width/2 - n*2, grid_width/2 - n*2)) # Create a 50 x 50 World with the Robots world = gs.World(grid_width, grid_width, robots=robots, environment="ex_env.png") # Create a Viewer to display the World viewer = gs.Viewer(world) # Run the simulation for n in range(num_steps): # Execute a simulation step world.step() # Draw the world viewer.draw() # To make sure it works, print the tick (world time) print('Time:', world.get_time()) print('SIMULATION FINISHED')
def main(config_file: str): # Import configuration config = gs.ConfigParser(config_file) print('STARTING', config.get('name')) # Number of cells in the width/height of the square grid grid_w = config.get('grid_width') num_robots = config.get('num_robots') # Use a default communication range if one is not in the configuration comm_range = config.get('comm_range', default=6) overwrite_trials = config.get('overwrite_trials', default=False) start_trial = config.get('start_trial', default=1) end_trial = config.get('end_trial') for trial in range(start_trial, end_trial + 1): robots = [] for n in range(num_robots): robots.append( RandomRobot(randint(0, grid_w - 1), randint(0, grid_w - 1), comm_range=comm_range)) # Create the World, with the robots in it world = gs.World(grid_w, grid_w, robots=robots) # Add the image to the World world.add_environment(config.get('environment_img')) # Create the viewer viewer = gs.Viewer(world, display_rate=10, show_grid=False, window_width=1000) # Logger log_filename = config.get('log_filename') logger = gs.Logger(world, log_filename, trial_num=trial, overwrite_trials=overwrite_trials) logger.add_aggregator('green', green_agg) logger.log_config(config) num_steps = config.get('num_steps') # Run the simulation for n in range(num_steps): # Run a single step of the world.step() # Draw the updated world state viewer.draw() # Save the state of the World using the aggregators logger.log_state() print(f'TRIAL {trial} FINISHED') print('SIMULATION FINISHED')
def main(): config = gs.ConfigParser('simple_config.yml') print(config.get('name')) grid_width = config.get('grid_width') num_robots = config.get('num_robots') # You can specify a default value in case a parameter isn't in the # configuration file num_steps = config.get('num_steps', default=100) # Create a few robots to place in your world robots = [] # Configuration values can also be lists, not just single values. x_pos = config.get('robot_x_pos') for n in range(num_robots): robots.append(RandomRobot(x_pos[n], grid_width / 2 - n * 2)) # Create a 50 x 50 World with the Robots world = gs.World(grid_width, grid_width, robots=robots) # Logger trial_num = config.get('trial_num', default=1) # Create a logger for this world that saves to the `test.h5` file logger = gs.Logger(world, 'test.h5', trial_num=trial_num, overwrite_trials=True) # Tell the logger to run the `green_agg` function every time that # `log_state` is called logger.add_aggregator('green', green_agg) # Save the contents of the configuration, but leave out the 'name' parameter logger.log_config(config, exclude='name') # Save the date/time that the simulation was run logger.log_param('date', str(datetime.now())) # Run the simulation for n in range(num_steps): # Execute a simulation step world.step() # Log the state every step logger.log_state() # To make sure it works, print the tick (world time) print('Time:', world.get_time()) print('SIMULATION FINISHED')