def get_filter_crit()

in grolp/gen/game_states/task_game_state.py [0:0]


    def get_filter_crit(self, goal_type):

        # helper functions
        def is_obj_pickupable(x):
            return x['pickupable'] and x['objectType'] in constants.OBJECTS

        def is_receptacle(x):
            return x['receptacle'] and x['objectType'] in constants.OBJECTS

        def does_have_duplicates(x):
            num_instances = len(game_util.get_objects_of_type(x['objectType'], self.env.last_event.metadata))
            return num_instances > 1

        def does_have_atleast_n_duplicates(x, n):
            num_instances = len(game_util.get_objects_of_type(x['objectType'], self.env.last_event.metadata))
            return num_instances >= n

        def does_any_recep_type_have_obj_of_type(r, ot):
            all_recep_of_type = [o for o in self.env.last_event.metadata['objects'] if
                                 o['objectType'] == r['objectType']]
            valid_recep = []
            for recep in all_recep_of_type:
                receptacle_obj_ids = recep['receptacleObjectIds']
                if receptacle_obj_ids is not None:
                    objs_of_type = [obj_id for obj_id in receptacle_obj_ids if ot in obj_id]
                    if len(objs_of_type) > 0:
                        valid_recep.append(recep)
            return len(valid_recep) > 0

        def does_recep_have_enough_space(r):
            # TODO: how to check this with THOR 2.1.0?
            return True

        def is_recep_full(r):
            # TODO: how to check this with THOR 2.1.0?
            return False

        def can_recep_hold_obj(o, r):
            return o in constants.VAL_RECEPTACLE_OBJECTS[r['objectType']]

        def is_of_type(x, type):
            return x['objectType'] == type

        def is_movable_recep(o):
            return o['objectType'] in constants.MOVABLE_RECEPTACLES

        def is_obj_type_in_recep(x, recep):
            obj_types_in_recep = [o['objectType'] for o in self.env.last_event.metadata['objects']
                                  if (o['parentReceptacles'] is not None and
                                      any(recep in r for r in o['parentReceptacles']))]
            return x['objectType'] in obj_types_in_recep

        def is_obj_in_recep(o, r):
            return o['objectId'] in r['receptacleObjectIds']

        def is_obj_prop(x, prop):
            return x['objectType'] in constants.VAL_ACTION_OBJECTS[prop]

        def is_obj_off(x):
            return x['objectType'] in constants.VAL_ACTION_OBJECTS['Toggleable'] and \
                   x['toggleable'] \
                   and (not x['isToggled'])

        def is_obj_on(x):
            return x['objectType'] in constants.VAL_ACTION_OBJECTS['Toggleable'] and \
                   x['toggleable'] and \
                   x['isToggled']

        # specialized filters for each specific task
        if goal_type == "init":
            return lambda o: is_obj_pickupable(o), \
                   lambda r: is_receptacle(r) and \
                             (can_recep_hold_obj(self.rand_chosen_object_class, r)) and \
                             (not is_recep_full(r)) and \
                             (is_obj_in_recep(self.rand_chosen_object, r))
        elif goal_type == "place_all_obj_type_into_recep":
            return lambda o: does_have_duplicates(o), \
                   lambda r: does_recep_have_enough_space(r)
        elif goal_type == "pick_two_obj_and_place":
            return lambda o: does_have_atleast_n_duplicates(o, 2), \
                   lambda r: does_recep_have_enough_space(r) and \
                             (not does_any_recep_type_have_obj_of_type(r, self.rand_chosen_object_class))
        elif goal_type == "pick_clean_then_place_in_recep":
            return lambda o: (not is_obj_type_in_recep(o, "SinkBasin")) and \
                             (is_obj_prop(o, "Cleanable")), \
                   lambda r: (not is_of_type(r, "SinkBasin"))
        elif goal_type == "pick_heat_then_place_in_recep":
            return lambda o: (not is_obj_type_in_recep(o, "Microwave")) and \
                             (is_obj_prop(o, "Heatable")), \
                   lambda r: (not is_of_type(r, "Microwave"))
        elif goal_type == "pick_cool_then_place_in_recep":
            return lambda o: (not is_obj_type_in_recep(o, "Fridge")) and \
                             (is_obj_prop(o, "Coolable")), \
                   lambda r: (not is_of_type(r, "Fridge"))
        elif goal_type == "look_at_obj_in_light":
            return lambda o: is_obj_pickupable(o), \
                   lambda r: r
        elif goal_type == "pick_and_place_with_movable_recep":
            return lambda o: is_obj_pickupable(o) and \
                             (not is_movable_recep(o)), \
                   lambda r: is_receptacle(r) and \
                             (not is_movable_recep(r)) and \
                             (not does_any_recep_type_have_obj_of_type(r, self.rand_chosen_val_moveable_recep_class))
        elif goal_type == "pick_heat_and_place_with_movable_recep":
            return lambda o: is_obj_pickupable(o) and \
                             (is_obj_prop(o, "Heatable")) and \
                             (not is_movable_recep(o)), \
                   lambda r: is_receptacle(r) and \
                             (not is_movable_recep(r)) and \
                             (not is_of_type(r, "Microwave")) and \
                             (not does_any_recep_type_have_obj_of_type(r, self.rand_chosen_val_moveable_recep_class))
        else:
            return lambda o: is_obj_pickupable(o), \
                   lambda r: is_receptacle(r)