scml.scml2020.services.controllers ================================== .. py:module:: scml.scml2020.services.controllers Classes ------- .. autoapisummary:: scml.scml2020.services.controllers.StepController scml.scml2020.services.controllers.SyncController Module Contents --------------- .. py:class:: StepController(*args, target_quantity: int, is_seller: bool, step: int, urange: Tuple[int, int], product: int, partners: List[str], negotiator_type: negmas.sao.SAONegotiator, horizon: int, awi: negmas.AgentWorldInterface, parent_name: str, negotiations_concluded_callback: Callable[[int, bool], None], negotiator_params: Dict[str, Any] = None, max_retries: int = 2, **kwargs) Bases: :py:obj:`negmas.sao.SAOController`, :py:obj:`negmas.events.Notifier` A controller for managing a set of negotiations about selling or buying (but not both) starting/ending at some specific time-step. :param target_quantity: The quantity to be secured :param is_seller: Is this a seller or a buyer :param parent_name: Name of the parent :param horizon: How many steps in the future to allow negotiations for selling to go for. :param step: The simulation step that this controller is responsible about :param urange: The range of unit prices used for negotiation :param product: The product that this controller negotiates about :param partners: A list of partners to negotiate with :param negotiator_type: The type of the single negotiator used for all negotiations. :param negotiator_params: The parameters of the negotiator used for all negotiations :param max_retries: How many times can the controller try negotiating with each partner. :param negotiations_concluded_callback: A method to be called with the step of this controller and whether is it a seller when all negotiations are concluded :param \*args: Position arguments passed to the base Controller constructor :param \*\*kwargs: Keyword arguments passed to the base Controller constructor Remarks: - It uses whatever negotiator type on all of its negotiations and it assumes that the ufun will never change - Once it accumulates the required quantity, it ends all remaining negotiations - It assumes that all ufuns are identical so there is no need to keep a separate negotiator for each one and it instantiates a single negotiator that dynamically changes the AMI but always uses the same ufun. .. py:attribute:: parent_name .. py:attribute:: awi .. py:attribute:: horizon .. py:attribute:: negotiations_concluded_callback .. py:attribute:: is_seller .. py:attribute:: target .. py:attribute:: urange .. py:attribute:: partners .. py:attribute:: product .. py:attribute:: __negotiator :value: None .. py:attribute:: secured :value: 0 .. py:attribute:: completed .. py:attribute:: step .. py:attribute:: retries :type: Dict[str, int] .. py:attribute:: max_retries :value: 2 .. py:method:: join(negotiator_id: str, nmi: negmas.common.NegotiatorMechanismInterface, state: negmas.MechanismState, *, preferences: Optional[negmas.Preferences] = None, ufun: Optional[negmas.UtilityFunction] = None, role: str = 'agent') -> bool Called by the mechanism when the agent is about to enter a negotiation. It can prevent the agent from entering :param negotiator_id: The negotiator ID :param nmi: The negotiation. :type nmi: AgentMechanismInterface :param state: The current state of the negotiation :type state: TState :param preferences: The preferences. :type preferences: Preferences :param ufun: The ufun function to use before any discounting (overrides preferences) :type ufun: BaseUtilityFunction :param role: role of the agent. :type role: str :returns: bool indicating whether or not the agent accepts to enter.If False is returned it will not enter the negotiation. .. py:method:: propose(negotiator_id: str, state: negmas.MechanismState) -> Optional[negmas.Outcome] .. py:method:: respond(negotiator_id: str, state: negmas.MechanismState, source: str = '') -> negmas.ResponseType .. py:method:: __str__() .. py:method:: create_negotiator(negotiator_type: Union[str, Type[negmas.ControlledNegotiator]] = None, name: str = None, cntxt: Any = None, **kwargs) -> negmas.ControlledNegotiator Creates a negotiator passing it the context :param negotiator_type: Type of the negotiator to be created :param name: negotiator name :param cntxt: The context to be associated with this negotiator. :param \*\*kwargs: any key-value pairs to be passed to the negotiator constructor :returns: The negotiator to be controlled. None for failure .. py:method:: time_range(step, is_seller) .. py:method:: on_negotiation_end(negotiator_id: str, state: negmas.MechanismState) -> None A call back called at each negotiation end :param negotiator_id: The negotiator ID :param state: `TState` or one of its descendants giving the state at which the negotiation ended. .. py:class:: SyncController(*args, is_seller: bool, parent: scml.scml2020.components.trading.PredictionBasedTradingStrategy, price_weight=0.7, utility_threshold=0.9, time_threshold=0.9, **kwargs) Bases: :py:obj:`negmas.sao.SAOSyncController` Will try to get the best deal which is defined as being nearest to the agent needs and with lowest price .. py:attribute:: _is_seller .. py:attribute:: __parent .. py:attribute:: _time_threshold :value: 0.9 .. py:attribute:: _price_weight :value: 0.7 .. py:attribute:: _utility_threshold :value: 0.9 .. py:attribute:: _best_utils :type: Dict[str, float] .. py:method:: utility(offer: Tuple[int, int, int], max_price: int) -> float A simple utility function Remarks: - If the time is invalid or there is no need to get any more agreements at the given time, return -1000 - Otherwise use the price-weight to calculate a linear combination of the price and the how much of the needs is satisfied by this contract .. py:method:: is_valid(negotiator_id: str, offer: negmas.Outcome) -> bool .. py:method:: counter_all(offers: Dict[str, negmas.Outcome], states: Dict[str, negmas.sao.SAOState]) -> Dict[str, negmas.sao.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. Remarks: - The response type CANNOT be WAIT. .. py:method:: best_proposal(nid: str) -> Tuple[Optional[negmas.Outcome], float] Finds the best proposal for the given negotiation :param nid: Negotiator ID :returns: The outcome with highest utility and the corresponding utility .. py:method:: first_proposals() -> Dict[str, negmas.Outcome] Gets a set of proposals to use for initializing the negotiation.