scml.oneshot.policy =================== .. py:module:: scml.oneshot.policy Classes ------- .. autoapisummary:: scml.oneshot.policy.OneShotPolicy Module Contents --------------- .. py:class:: OneShotPolicy(*args, **kwargs) Bases: :py:obj:`scml.oneshot.agent.OneShotSyncAgent`, :py:obj:`abc.ABC` A oneshot agent structured in three components, state encoder, policy (action) and action decoder. The agent is divided into three components: 1. State encoder (encode_state()) which takes the current state of all negotiation mechanisms, access the awi as needed, and generates a **state** which can be of any type to be passed to the next component. 2. Policy (act()) which takes the state generated from the state encoder and returns an action which may be encoded as any type to be passed to the next component. *The policy (i.e. `act` () method) is not supposed to access the AWI or any other members of the class. It is preferred to be a pure function*. This makes it easy to test the policy at predefined conditions (i.e. states) without having to construct a simulation. 3. Action decoder (decode_action()) which takes the action generated from the policy and generates the appropriate set of responses to all partners. Remarks: - The simplest form of state encoder which is implemented by default is to return the `state` member of the AWI. - The simplest form of action encoding is to simply return the responses as a `dict[str, SAOResponse]` from `act` which is then passed as it is by `decode_action` . This is the default implementation of `decode_action` .. py:method:: encode_state(mechanism_states: dict[str, negmas.sao.common.SAOState]) -> Any Called to generate a state to be passed to the act() method. The default is all of `awi` of type `OneShotState` .. py:method:: act(state: Any) -> Any :abstractmethod: The main policy. Generates an action given a state .. py:method:: decode_action(action: Any) -> dict[str, negmas.sao.common.SAOResponse] Generates offers to all partners from an encoded action. Default is to return the action as it is assuming it is a `dict[str, SAOResponse]` .. py:method:: encode_action(responses: dict[str, negmas.sao.common.SAOResponse]) -> dict[str, negmas.sao.common.SAOResponse] Receives offers for all partners and generates the corresponding action. Used mostly for debugging and testing. .. py:method:: __call__(state) A policy is a callable that receives a state and generates an action .. py:method:: counter_all(offers: dict[str, negmas.outcomes.Outcome | None], states: dict[str, negmas.sao.common.SAOState]) -> dict[str, negmas.sao.common.SAOResponse] Calculate a response to all offers from all negotiators (negotiator ID is the key). :param offers: Maps negotiator IDs to offers :param states: Maps negotiator IDs to offers AT the time the offers were made. :returns: A dictionary mapping negotiator ID to an `SAOResponse`. The response per agent consist of a tuple. In case of acceptance or ending the negotiation the second item of the tuple should be None. In case of rejection, the second item should be the counter offer. Remarks: - The response type CANNOT be WAIT. - If the system determines that a loop is formed, the agent may receive this call for a subset of negotiations not all of them. .. py:method:: first_proposals() -> dict[str, negmas.outcomes.Outcome | None] Gets a set of proposals to use for initializing the negotiation. :returns: A dictionary mapping each negotiator (in self.negotiators dict) to an outcome to be used as the first proposal if the agent is to start a negotiation.