scml.scml2020.agent =================== .. py:module:: scml.scml2020.agent .. autoapi-nested-parse:: Implements the world class for the SCML2020 world Classes ------- .. autoapisummary:: scml.scml2020.agent.SCML2020Agent scml.scml2020.agent.OneShotAdapter Module Contents --------------- .. py:class:: SCML2020Agent(name: str | None = None, type_postfix: str = '', preferences: negmas.preferences.Preferences | None = None, ufun: negmas.preferences.UtilityFunction | None = None) Bases: :py:obj:`negmas.Agent` Base class for all SCML2020 agents (factory managers) .. py:method:: reset() .. py:method:: is_clean() -> bool .. py:method:: init() Called to initialize the agent **after** the world is initialized. the AWI is accessible at this point. .. py:method:: before_step() .. py:method:: step_() Called at every time-step. This function is called directly by the world. .. py:method:: step() Called by the simulator at every simulation step .. py:method:: to_dict() .. py:method:: _respond_to_negotiation_request(initiator: str, partners: List[str], issues: List[negmas.Issue], annotation: Dict[str, Any], mechanism: negmas.NegotiatorMechanismInterface, role: Optional[str], req_id: Optional[str]) -> Optional[negmas.Negotiator] Called by the mechanism to ask for joining a negotiation. The agent can refuse by returning a None :param initiator: The ID of the agent that initiated the negotiation request :param partners: The partner list (will include this agent) :param issues: The list of issues :param annotation: Any annotation specific to this negotiation. :param mechanism: The mechanism that started the negotiation :param role: The role of this agent in the negotiation :param req_id: The req_id passed to the AWI when starting the negotiation (only to the initiator). :returns: None to refuse the negotiation or a `Negotiator` object appropriate to the given mechanism to accept it. Remarks: - It is expected that world designers will introduce a better way to respond and override this function to call it .. py:method:: on_contract_breached(contract: negmas.Contract, breaches: List[negmas.Breach], resolution: Optional[negmas.Contract]) -> None Called after complete processing of a contract that involved a breach. :param contract: The contract :param breaches: All breaches committed (even if they were resolved) :param resolution: The resolution contract if re-negotiation was successful. None if not. .. py:method:: on_contract_executed(contract: negmas.Contract) -> None Called after successful contract execution for which the agent is one of the partners. .. py:method:: set_renegotiation_agenda(contract: negmas.Contract, breaches: List[negmas.Breach]) -> Optional[negmas.RenegotiationRequest] Received by partners in ascending order of their total breach levels in order to set the renegotiation agenda when contract execution fails :param contract: The contract being breached :param breaches: All breaches on `contract` :returns: Renegotiation agenda (issues to negotiate about to avoid reporting the breaches). .. py:method:: respond_to_renegotiation_request(contract: negmas.Contract, breaches: List[negmas.Breach], agenda: negmas.RenegotiationRequest) -> Optional[negmas.Negotiator] Called to respond to a renegotiation request :param agenda: :param contract: :param breaches: Returns: .. py:method:: on_neg_request_rejected(req_id: str, by: Optional[List[str]]) Called when a requested negotiation is rejected :param req_id: The request ID passed to _request_negotiation :param by: A list of agents that refused to participate or None if the failure was for another reason .. py:method:: on_neg_request_accepted(req_id: str, mechanism: negmas.NegotiatorMechanismInterface) Called when a requested negotiation is accepted .. py:property:: internal_state :type: Dict[str, Any] Returns the internal state of the agent for debugging purposes .. py:method:: on_negotiation_failure(partners: List[str], annotation: Dict[str, Any], mechanism: negmas.NegotiatorMechanismInterface, state: negmas.MechanismState) -> None Called whenever a negotiation ends without agreement .. py:method:: on_negotiation_success(contract: negmas.Contract, mechanism: negmas.NegotiatorMechanismInterface) -> None Called whenever a negotiation ends with agreement .. py:method:: on_agent_bankrupt(agent: str, contracts: List[negmas.Contract], quantities: List[int], compensation_money: int) -> None Called whenever a contract is nullified (because the partner is bankrupt) :param agent: The ID of the agent that went bankrupt. :param contracts: All future contracts between this agent and the bankrupt agent. :param quantities: The actual quantities that these contracts will be executed at. :param compensation_money: The compensation money that is already added to the agent's wallet (if ANY). Remarks: - compensation_money will be nonzero iff immediate_compensation is enabled for this world .. py:method:: on_failures(failures: List[scml.scml2020.common.Failure]) -> None Called whenever there are failures either in production or in execution of guaranteed transactions :param failures: A list of `Failure` s. .. py:method:: respond_to_negotiation_request(initiator: str, issues: List[negmas.Issue], annotation: Dict[str, Any], mechanism: negmas.NegotiatorMechanismInterface) -> Optional[negmas.Negotiator] Called whenever another agent requests a negotiation with this agent. :param initiator: The ID of the agent that requested this negotiation :param issues: Negotiation issues :param annotation: Annotation attached with this negotiation :param mechanism: The `NegotiatorMechanismInterface` interface to the mechanism to be used for this negotiation. :returns: None to reject the negotiation, otherwise a negotiator .. py:method:: confirm_production(commands: numpy.ndarray, balance: int, inventory) -> numpy.ndarray Called just before production starts at every time-step allowing the agent to change what is to be produced in its factory :param commands: an n_lines vector giving the process to be run at every line (NO_COMMAND indicates nothing to be processed :param balance: The current balance of the factory :param inventory: an n_products vector giving the number of items available in the inventory of every product type. :returns: an n_lines vector giving the process to be run at every line (NO_COMMAND indicates nothing to be processed Remarks: - Not called in SCML2020 competition. - The inventory will contain zero items of all products that the factory does not buy or sell - The default behavior is to just retrun commands confirming production of everything. .. py:method:: sign_all_contracts(contracts: List[negmas.Contract]) -> List[Optional[str]] Signs all contracts .. py:class:: OneShotAdapter(oneshot_type: Union[str, scml.oneshot.agent.OneShotAgent], oneshot_params: Dict[str, Any], obj: Optional[scml.oneshot.agent.OneShotAgent] = None, name=None, type_postfix='', ufun=None) Bases: :py:obj:`scml.scml2020.components.signing.SignAll`, :py:obj:`scml.scml2020.components.production.DemandDrivenProductionStrategy`, :py:obj:`scml.scml2020.components.trading.MarketAwareTradePredictionStrategy`, :py:obj:`SCML2020Agent`, :py:obj:`negmas.situated.Adapter`, :py:obj:`scml.oneshot.mixins.OneShotUFunCreatorMixin` An adapter allowing agents developed for SCML-OneShot to run in `SCML2020World` simulations. .. py:attribute:: _obj :type: SCML2020Agent .. py:method:: init() Called to initialize the agent **after** the world is initialized. the AWI is accessible at this point. .. py:property:: price_multiplier .. py:method:: _make_issues(product) .. py:method:: before_step() .. py:method:: step() Called by the simulator at every simulation step .. py:method:: make_ufun(add_exogenous: bool) .. py:method:: to_dict() .. py:method:: respond_to_negotiation_request(initiator, issues, annotation, mechanism) Called whenever another agent requests a negotiation with this agent. :param initiator: The ID of the agent that requested this negotiation :param issues: Negotiation issues :param annotation: Annotation attached with this negotiation :param mechanism: The `NegotiatorMechanismInterface` interface to the mechanism to be used for this negotiation. :returns: None to reject the negotiation, otherwise a negotiator .. py:method:: get_disposal_cost() -> float .. py:method:: get_shortfall_penalty_mean() .. py:method:: get_disposal_cost_mean() .. py:method:: get_shortfall_penalty_dev() .. py:method:: get_disposal_cost_dev() .. py:method:: get_storage_cost_mean() .. py:method:: get_storage_cost_dev() .. py:method:: get_profile() .. py:method:: get_shortfall_penalty() .. py:method:: get_current_balance() .. py:method:: get_exogenous_output() -> Tuple[int, int] .. py:method:: get_exogenous_input() -> Tuple[int, int] .. py:property:: is_perishable :type: bool Are all products perishable (original design of OneShot) .. py:property:: current_disposal_cost :type: float Cost of storing one unit (penalizes buying too much/ selling too little) .. py:property:: current_storage_cost :type: float Cost of storing one unit (penalizes buying too much/ selling too little) .. py:property:: current_shortfall_penalty :type: float Cost of failure to deliver one unit (penalizes buying too little / selling too much) .. py:property:: allow_zero_quantity :type: bool Does negotiations allow zero quantity?