diff --git a/negmas/negotiators/controller.py b/negmas/negotiators/controller.py index 3b363e6f..db90f42d 100644 --- a/negmas/negotiators/controller.py +++ b/negmas/negotiators/controller.py @@ -79,6 +79,10 @@ def __init__( self.__parent = parent self._auto_kill = auto_kill + def is_clean(self) -> bool: + """Checks that the agent has no negotiators and that all its intermediate data-structures are reset""" + return len(self._negotiators) == 0 + def reset(self): """ Resets the controller and kills any negotiators it may have diff --git a/negmas/sao/controllers.py b/negmas/sao/controllers.py index 030be400..4c0aff15 100755 --- a/negmas/sao/controllers.py +++ b/negmas/sao/controllers.py @@ -197,6 +197,25 @@ def reset(self): self.__first_proposals_collected = False super().reset() + def _reset_for(self, negotiator_id: str): + self.__offers.pop(negotiator_id, None) + self.__offer_states.pop(negotiator_id, None) + self.__responses.pop(negotiator_id, None) + self.__proposals.pop(negotiator_id, None) + self.__n_waits.pop(negotiator_id, None) + + def is_clean(self) -> bool: + """Checks that the agent has no negotiators and that all its intermediate data-structures are reset""" + return ( + super().is_clean() + and not self.__offers + and not self.__responses + and not self.__proposals + and not self.__offer_states + and not self.__n_waits + and not self.__first_proposals_collected + ) + def first_offer(self, negotiator_id: str) -> Outcome | None: """ Finds the first offer for this given negotiator. By default it will be the best offer @@ -313,7 +332,7 @@ def respond( for nid, ninfo in self._negotiators.items(): s__ = ninfo.negotiator.nmi.state if s__.ended: - self._reset_internal(nid) + self._reset_for(nid) # we arrive here if we already have all the offers to counter. WE may though not have proposed yet if not self.__first_proposals_collected: self._set_first_proposals() @@ -339,15 +358,8 @@ def respond( return ResponseType.REJECT_OFFER return self.__responses.pop(negotiator_id, ResponseType.REJECT_OFFER) - def _reset_internal(self, negotiator_id: str): - self.__offers.pop(negotiator_id, None) - self.__offer_states.pop(negotiator_id, None) - self.__responses.pop(negotiator_id, None) - self.__proposals.pop(negotiator_id, None) - self.__n_waits.pop(negotiator_id, None) - def on_negotiation_end(self, negotiator_id: str, state: SAOState) -> None: - self._reset_internal(negotiator_id) + self._reset_for(negotiator_id) results = super().on_negotiation_end(negotiator_id, state) if not self.negotiators: self.reset()