def work(self, belief):
        """Primary response function of HDC policy
        """
        global_summary = SummaryMapping.globalSummary(belief, domainUtil=self.domainUtil)
        array_slot_summary = SummaryMapping.arraySlotSummary(belief, self.domainUtil)
        logger.debug(str(global_summary))
        logger.debug('HDC policy: getGlobal')
        done, output = self._getGlobal(belief, global_summary)

        if not done:
            logger.debug('HDC policy: getConfirmSelect')
            done, output = self._getConfirmSelect(belief, array_slot_summary)
        if not done:
            logger.debug('HDC policy: getInform')
            inform_summary = []
            for num_accepted in range(1, MAX_NUM_ACCEPTED+1):
                temp = SummaryMapping.actionSpecificInformSummary(belief, num_accepted, self.domainUtil)
                inform_summary.append(temp)
                       
            done, output = self._getInform(belief, global_summary, inform_summary)
        if not done:
            logger.debug('HDC policy: getRequest')
            done, output = self._getRequest(belief, array_slot_summary)
        if not done:
            logger.warning("HDCPolicy couldn't find action: execute reqmore().")
            output = 'reqmore()'

        if output == 'badact()' or output == 'null()':
            logger.warning('HDCPolicy chose bad or null action')
            output = 'null()'

        if self.use_confreq:
            #TODO - known problem here if use_confreq is True (ie being used)  FIXME
            output = DMUtils.add_venue_count(output, belief)
        return output
Example #2
0
    def work(self, belief):
        '''
        This base Policy class performs pre- and post-processing of system action selection.
        1. Preprocessing: It converts all summary actions to master actions and checks whether they are executable.
        2. Action selection: This is done in overridden "select" method of a child class,
                             which returns an index of selected action.
        3. Postprocessing: Converts selected action index to master action and adds count=.
        If the policy doesn't need these pre- and post-processing, It can override this work method.
        :return: system action in string
        '''
        # 1. Preprocessing: Get executable actions.
        executable = []
        all_action_list = []
        for a in range(self.numActions):
            summary, sys_act = self.to_master_action(a, belief, self.last_act)
            all_action_list.append(sys_act)
            if not sys_act.startswith('null'):
                executable.append(a)

        # 2. Action selection.
        self.last_belief = self.belief
        self.last_act = self.act
        act_index = self.select(belief, executable)
        self.belief = belief
        self.act = act_index

        # 3. Postprocessing.
        output = all_action_list[act_index]
        if self.use_confreq:
            output = DMUtils.add_venue_count(output, belief, self.domainUtil)
        return output
    def work(self, belief):
        '''
        This base Policy class performs pre- and post-processing of system action selection.
        1. Preprocessing: It converts all summary actions to master actions and checks whether they are executable.
        2. Action selection: This is done in overridden "select" method of a child class,
                             which returns an index of selected action.
        3. Postprocessing: Converts selected action index to master action and adds count=.
        If the policy doesn't need these pre- and post-processing, It can override this work method.
        :return: system action in string
        '''
        # 1. Preprocessing: Get executable actions.
        executable = []
        all_action_list = []
        for a in range(self.numActions):
            summary, sys_act = self.to_master_action(a, belief, self.last_act)
            all_action_list.append(sys_act)
            if not sys_act.startswith('null'):
                executable.append(a)

        # 2. Action selection.
        self.last_belief = self.belief
        self.last_act = self.act
        act_index = self.select(belief, executable)
        self.belief = belief
        self.act = act_index

        # 3. Postprocessing.
        output = all_action_list[act_index]
        if self.use_confreq:
            output = DMUtils.add_venue_count(output, belief, self.domainUtil)
        return output
    def work(self, belief):
        """Primary response function of HDC policy
        """
        global_summary = SummaryMapping.globalSummary(
            belief, domainUtil=self.domainUtil)
        array_slot_summary = SummaryMapping.arraySlotSummary(
            belief, self.domainUtil)
        logger.debug(str(global_summary))
        logger.debug('HDC policy: getGlobal')
        done, output = self._getGlobal(belief, global_summary)

        if not done:
            logger.debug('HDC policy: getConfirmSelect')
            done, output = self._getConfirmSelect(belief, array_slot_summary)
        if not done:
            logger.debug('HDC policy: getInform')
            inform_summary = []
            for num_accepted in range(1, MAX_NUM_ACCEPTED + 1):
                temp = SummaryMapping.actionSpecificInformSummary(
                    belief, num_accepted, self.domainUtil)
                inform_summary.append(temp)

            done, output = self._getInform(belief, global_summary,
                                           inform_summary)
        if not done:
            logger.debug('HDC policy: getRequest')
            done, output = self._getRequest(belief, array_slot_summary)
        if not done:
            logger.warning(
                "HDCPolicy couldn't find action: execute reqmore().")
            output = 'reqmore()'

        if output == 'badact()' or output == 'null()':
            logger.warning('HDCPolicy chose bad or null action')
            output = 'null()'

        if self.use_confreq:
            #TODO - known problem here if use_confreq is True (ie being used)  FIXME
            output = DMUtils.add_venue_count(output, belief)
        return output