def _next_action(self, belief_state: BeliefState): """Determines the next system action based on the current belief state and previous action. When implementing a new type of policy, this method MUST be rewritten Args: belief_state (HandCraftedBeliefState): system values on liklihood of each possible state Return: (SysAct): the next system action --LV """ method = self._get_method(belief_state) # Assuming this happens only because domain is not actually active --LV if method == 'none': sys_act = SysAct() sys_act.type = SysActionType.Bad return sys_act elif method == 'byalternatives' and not self._get_constraints( belief_state)[0]: sys_act = SysAct() sys_act.type = SysActionType.Bad return sys_act elif method == 'byprimarykey' and not self._get_requested_slots( belief_state): sys_act = SysAct() sys_act.type = SysActionType.InformByName sys_act.add_value(self.domain.get_primary_key(), self._get_name(belief_state)) belief_state['system']['lastInformedPrimKeyVal'] = self._get_name( belief_state) return sys_act # Otherwise we need to query the db to determine next action results = self._query_db(belief_state) sys_act = self._raw_action(results, method, belief_state) # requests are fairly easy, if it's a request, return it directly if sys_act.type == SysActionType.Request: if len(list(sys_act.slot_values.keys())) > 0: # update the belief state to reflec the slot we just asked about belief_state['system']['lastRequestSlot'] = list( sys_act.slot_values.keys())[0] # otherwise we need to convert a raw inform into a one with proper slots and values elif sys_act.type == SysActionType.InformByName: self._convert_inform(method, results, sys_act, belief_state) # update belief state to reflect the offer we just made values = sys_act.get_values(self.domain.get_primary_key()) if values: belief_state['system']['lastInformedPrimKeyVal'] = values[0] else: sys_act.add_value(self.domain.get_primary_key(), 'none') return sys_act
def _next_action(self, beliefstate: BeliefState): """Determines the next system action based on the current belief state and previous action. When implementing a new type of policy, this method MUST be rewritten Args: beliefstate (BeliefState): BeliefState object; contains all user constraints to date of each possible state Return: (SysAct): the next system action --LV """ sys_state = {} # Assuming this happens only because domain is not actually active --LV if UserActionType.Bad in beliefstate['user_acts'] or beliefstate['requests'] \ and not self._get_name(beliefstate): sys_act = SysAct() sys_act.type = SysActionType.Bad return sys_act, {'last_act': sys_act} elif UserActionType.RequestAlternatives in beliefstate['user_acts'] \ and not self._get_constraints(beliefstate)[0]: sys_act = SysAct() sys_act.type = SysActionType.Bad return sys_act, {'last_act': sys_act} elif self.domain.get_primary_key() in beliefstate['informs'] \ and not beliefstate['requests']: sys_act = SysAct() sys_act.type = SysActionType.InformByName sys_act.add_value(self.domain.get_primary_key(), self._get_name(beliefstate)) return sys_act, {'last_act': sys_act} # Otherwise we need to query the db to determine next action results = self._query_db(beliefstate) sys_act = self._raw_action(results, beliefstate) # requests are fairly easy, if it's a request, return it directly if sys_act.type == SysActionType.Request: if len(list(sys_act.slot_values.keys())) > 0: sys_state['lastRequestSlot'] = list( sys_act.slot_values.keys())[0] # otherwise we need to convert a raw inform into a one with proper slots and values elif sys_act.type == SysActionType.InformByName: self._convert_inform(results, sys_act, beliefstate) # update belief state to reflect the offer we just made values = sys_act.get_values(self.domain.get_primary_key()) if values: # belief_state['system']['lastInformedPrimKeyVal'] = values[0] sys_state['lastInformedPrimKeyVal'] = values[0] else: sys_act.add_value(self.domain.get_primary_key(), 'none') sys_state['last_act'] = sys_act return (sys_act, sys_state)