def test_traversal_reward_with_missing_target(self): goal = MCS_Goal() goal.metadata['target'] = {'id': '111'} # missing target obj_list = [] for i in range(10): obj = {"objectId":str(i), "distanceXZ": 0.3 * i} agent = {'position': {'x':-0.9, 'y': 0.5, 'z':0.0}} reward = MCS_Reward._calc_traversal_reward(goal, obj_list, agent) self.assertEqual(reward, 0) self.assertIsInstance(reward, int)
def test_traversal_reward_outside_agent_reach(self): goal = MCS_Goal() goal.metadata['target'] = {'id': '0'} obj_list = [] for i in range(10): obj = {"objectId":str(i), "distanceXZ": 1.1} agent = {'position': {'x':-0.9, 'y': 0.5, 'z':-1.0}} reward = MCS_Reward._calc_traversal_reward(goal, obj_list, agent) self.assertEqual(reward, 0) self.assertIsInstance(reward, int)
def test_retrieval_reward_nothing_pickedup(self): goal = MCS_Goal() goal.metadata['target'] = {'id': '0'} obj_list = [] for i in range(10): obj = {"objectId": str(i), 'isPickedUp': False} obj_list.append(obj) reward = MCS_Reward._calc_retrieval_reward(goal, obj_list, agent={}) self.assertEqual(reward, 0) self.assertIsInstance(reward, int)
def test_retrieve_action_list(self): self.assertEqual(self.controller.retrieve_action_list(MCS_Goal(), 0), self.controller.ACTION_LIST) self.assertEqual(self.controller.retrieve_action_list(MCS_Goal(action_list=[]), 0), \ self.controller.ACTION_LIST) self.assertEqual(self.controller.retrieve_action_list(MCS_Goal(action_list=[[]]), 0), \ self.controller.ACTION_LIST) self.assertEqual(self.controller.retrieve_action_list(MCS_Goal(action_list=[['MoveAhead',\ 'RotateLook,rotation=180']]), 0), ['MoveAhead', 'RotateLook,rotation=180']) self.assertEqual(self.controller.retrieve_action_list(MCS_Goal(action_list=[['MoveAhead',\ 'RotateLook,rotation=180']]), 1), self.controller.ACTION_LIST) self.assertEqual(self.controller.retrieve_action_list(MCS_Goal(action_list=[['MoveAhead',\ 'RotateLook,rotation=180'], []]), 1), self.controller.ACTION_LIST) self.assertEqual(self.controller.retrieve_action_list(MCS_Goal(action_list=[[],['MoveAhead',\ 'RotateLook,rotation=180']]), 0), self.controller.ACTION_LIST) self.assertEqual(self.controller.retrieve_action_list(MCS_Goal(action_list=[[],['MoveAhead',\ 'RotateLook,rotation=180']]), 1), ['MoveAhead', 'RotateLook,rotation=180'])
def test_transferral_reward_on_top_of_with_pickedup_object(self): goal = MCS_Goal() goal.metadata['target_1'] = {'id': '0'} goal.metadata['target_2'] = {'id': '1'} goal.metadata['relationship'] = ['target_1', 'on top of', 'target_2'] obj_list = [] for i in range(10): obj = {"objectId":str(i), "objectBounds": {"objectBoundsCorners": []}, "isPickedUp": True} # create lower plane (y = 0) obj['objectBounds']['objectBoundsCorners'].append({'x':0.0, 'y': 0.0 + i, 'z': 0.0}) obj['objectBounds']['objectBoundsCorners'].append({'x':1.0, 'y': 0.0 + i, 'z': 0.0}) obj['objectBounds']['objectBoundsCorners'].append({'x':1.0, 'y': 0.0 + i, 'z': 1.0}) obj['objectBounds']['objectBoundsCorners'].append({'x':0.0, 'y': 0.0 + i, 'z': 1.0}) # create upper plane (y = 1) + i obj['objectBounds']['objectBoundsCorners'].append({'x':0.0, 'y': 1.0 + i, 'z': 0.0}) obj['objectBounds']['objectBoundsCorners'].append({'x':1.0, 'y': 1.0 + i, 'z': 0.0}) obj['objectBounds']['objectBoundsCorners'].append({'x':1.0, 'y': 1.0 + i, 'z': 1.0}) obj['objectBounds']['objectBoundsCorners'].append({'x':0.0, 'y': 1.0 + i, 'z': 1.0}) obj['position'] = {'x': 0.5, 'y': 0.0 + i, 'z': 0.5} obj_list.append(obj) agent = {'position': {'x':-0.9, 'y': 0.5, 'z':0.0}} reward = MCS_Reward._calc_transferral_reward(goal, obj_list, agent) self.assertEqual(reward, 0) self.assertIsInstance(reward, int)
def retrieve_goal(self, current_scene): goal_config = current_scene['goal'] if 'goal' in current_scene else {} return MCS_Goal(action_list=(goal_config['action_list'] if 'action_list' in goal_config else None), info_list=(goal_config['info_list'] if 'type_list' in goal_config else []), last_step=(goal_config['last_step'] if 'last_step' in goal_config else None), task_list=(goal_config['task_list'] if 'type_list' in goal_config else []), type_list=(goal_config['type_list'] if 'type_list' in goal_config else []), metadata=(goal_config['metadata'] if 'metadata' in goal_config else {}))
def __init__(self, action_list=[], depth_mask_list=[], goal=MCS_Goal(), head_tilt=0, image_list=[], object_list=[], object_mask_list=[], pose=MCS_Pose.UNDEFINED, return_status=MCS_Return_Status.UNDEFINED, step_number=0): self.action_list = action_list self.depth_mask_list = depth_mask_list self.goal = goal self.head_tilt = head_tilt self.image_list = image_list self.object_list = object_list self.object_mask_list = object_mask_list self.pose = pose self.return_status = return_status self.step_number = step_number
def test_default_reward(self): goal = MCS_Goal() reward = MCS_Reward.calculate_reward(goal, objects={}, agent={}) self.assertEqual(reward, 0) self.assertIsInstance(reward, int)