def _simulate_task_meta(self, task, user_input, dilate=True): if self._config['mode'] == DEV_MODE: util.save_user_input(user_input, LAST_INPUT_PATH) if self._config['mode'] == DEMO_MODE: user_input.flattened_point_list = [] user_input.polygons = [] if user_input.balls: user_input.balls = user_input.balls[:self._config['max_balls']] task.scene = simulator.add_user_input_to_scene( task.scene, user_input, keep_space_around_bodies=dilate) print('Converted %d points, %d polygons, %d balls into %d bodies' ' with %d shapes' % (len(user_input.flattened_point_list or []) / 2, len(user_input.polygons or []), len( user_input.balls or []), len(task.scene.user_input_bodies), sum(len(b.shapes) for b in task.scene.user_input_bodies))) simulation = simulator.simulate_task(task, stride=3) if self._config['mode'] == DEV_MODE: rendered = [ get_scene_as_base64_image(scene) for scene in simulation.sceneList[::10] ] else: rendered = [] return task_if.TaskSimulationWithMeta(simulation=simulation, rendered_imgs=rendered)
def test_simulate_task(self): steps = 200 # Not too many steps, but more than steps_for_solution.. assert steps >= simulator.STEPS_FOR_SOLUTION result = simulator.simulate_task(self._task, steps=steps, stride=1) self.assertEqual(len(result.sceneList), simulator.STEPS_FOR_SOLUTION) # Empty solution should be valid. self.assertEqual(result.isSolution, True)
def test_add_input_and_simulate(self): steps = 10 # Check simulate_task_with_input is identical to add_user_input_to_scene # followed by simulate_task. combined_results = simulator.simulate_task_with_input( self._task, self._box_user_input, steps=steps) task = copy.copy(self._task) task.scene = simulator.add_user_input_to_scene(task.scene, self._box_user_input) bl_resuls = simulator.simulate_task(task, steps=steps) self.assertEqual(combined_results, bl_resuls)