scml.oneshot ============ .. py:module:: scml.oneshot Submodules ---------- .. toctree:: :maxdepth: 1 /autoapi/scml/oneshot/adapter/index /autoapi/scml/oneshot/agent/index /autoapi/scml/oneshot/agents/index /autoapi/scml/oneshot/awi/index /autoapi/scml/oneshot/common/index /autoapi/scml/oneshot/context/index /autoapi/scml/oneshot/helper/index /autoapi/scml/oneshot/mixins/index /autoapi/scml/oneshot/policy/index /autoapi/scml/oneshot/rl/index /autoapi/scml/oneshot/sysagents/index /autoapi/scml/oneshot/ufun/index /autoapi/scml/oneshot/world/index Attributes ---------- .. autoapisummary:: scml.oneshot.__all__ scml.oneshot.QUANTITY scml.oneshot.UNIT_PRICE scml.oneshot.TIME scml.oneshot.INFINITE_COST scml.oneshot.SYSTEM_BUYER_ID scml.oneshot.SYSTEM_SELLER_ID scml.oneshot.__all__ scml.oneshot.DefaultActionManager scml.oneshot.RLState scml.oneshot.RLAction scml.oneshot.RLModel scml.oneshot.DefaultObservationManager scml.oneshot.PLACEHOLDER_AGENT_PREFIX scml.oneshot.__all__ Classes ------- .. autoapisummary:: scml.oneshot.OneShotAgent scml.oneshot.OneShotSyncAgent scml.oneshot.OneShotSingleAgreementAgent scml.oneshot.OneShotIndNegotiatorsAgent scml.oneshot.EndingNegotiator scml.oneshot.SingleAgreementAspirationAgent scml.oneshot.GreedyOneShotAgent scml.oneshot.GreedySyncAgent scml.oneshot.GreedySingleAgreementAgent scml.oneshot.OneshotDoNothingAgent scml.oneshot.Placeholder scml.oneshot.RandomOneShotAgent scml.oneshot.RandDistOneShotAgent scml.oneshot.EqualDistOneShotAgent scml.oneshot.SyncRandomOneShotAgent scml.oneshot.SingleAgreementRandomAgent scml.oneshot.OneShotAWI scml.oneshot.OneShotState scml.oneshot.OneShotExogenousContract scml.oneshot.OneShotProfile scml.oneshot.FinancialReport scml.oneshot.Context scml.oneshot.GeneralContext scml.oneshot.ANACContext scml.oneshot.LimitedPartnerNumbersContext scml.oneshot.FixedPartnerNumbersContext scml.oneshot.ANACOneShotContext scml.oneshot.LimitedPartnerNumbersOneShotContext scml.oneshot.FixedPartnerNumbersOneShotContext scml.oneshot.SupplierContext scml.oneshot.ConsumerContext scml.oneshot.StrongSupplierContext scml.oneshot.StrongConsumerContext scml.oneshot.WeakSupplierContext scml.oneshot.WeakConsumerContext scml.oneshot.BalancedSupplierContext scml.oneshot.BalancedConsumerContext scml.oneshot.RepeatingContext scml.oneshot.ContextParams scml.oneshot.MonopolicContext scml.oneshot.SingleAgentPerLevelSupplierContext scml.oneshot.EutopiaContext scml.oneshot.EutopiaConsumerContext scml.oneshot.EutopiaSupplierContext scml.oneshot.OneShotPolicy scml.oneshot.ActionManager scml.oneshot.FlexibleActionManager scml.oneshot.OneShotRLAgent scml.oneshot.OneShotEnv scml.oneshot.ObservationManager scml.oneshot.FlexibleObservationManager scml.oneshot.RewardFunction scml.oneshot.DefaultRewardFunction scml.oneshot.DefaultOneShotAdapter scml.oneshot._StdSystemAgent scml.oneshot.OneShotUFun scml.oneshot.UFunLimit scml.oneshot.UtilityInfo scml.oneshot.SCMLBaseWorld scml.oneshot.OneShotWorld scml.oneshot.SCML2020OneShotWorld scml.oneshot.SCML2021OneShotWorld scml.oneshot.SCML2022OneShotWorld scml.oneshot.SCML2023OneShotWorld scml.oneshot.SCML2024OneShotWorld Functions --------- .. autoapisummary:: scml.oneshot.is_system_agent scml.oneshot.is_system_agent scml.oneshot.model_wrapper scml.oneshot.random_action scml.oneshot.random_policy scml.oneshot.greedy_policy scml.oneshot.builtin_agent_types Package Contents ---------------- .. py:class:: OneShotAgent(owner=None, ufun: scml.oneshot.OneShotUFun | None = None, name=None) Bases: :py:obj:`negmas.SAOController`, :py:obj:`negmas.Entity`, :py:obj:`abc.ABC` Base class for all agents in the One-Shot game. Remarks: - You can access all of the negotiators associated with the agent using `self.negotiators` which is a dictionary mapping the `negotiator_id` to a tuple of two values: The `SAONegotiator` object and a key-value context dictionary. In 2021, the context will always be empty. - The `negotiator_id` associated with a negotiation with some partner will be the same as the agent ID of that partner. This means that all negotiators engaged with some partner over all simulation steps will have the same ID which is useful if you are keeping information about past negotiations and partner behavior. .. py:attribute:: _awi :value: None .. py:attribute:: _owner :value: None .. py:property:: awi :type: scml.oneshot.OneShotAWI Returns a `OneShotAWI` object for accessing the simulation. .. py:property:: running_negotiations :type: list[negmas.situated.RunningNegotiationInfo] The negotiations currently requested by the agent. :returns: A list of negotiation information objects (`RunningNegotiationInfo`) .. py:property:: unsigned_contracts :type: list[negmas.Contract] All contracts that are not yet signed. .. py:method:: init() Called once after the AWI is set. Remarks: - Use this for any proactive initialization code. .. py:method:: make_ufun(add_exogenous=False) Creates a utility function for the agent. :param add_exogenous: If `True` then the exogenous contracts of the agent will be automatically added whenever the ufun is evaluated for any set of contracts, offers or otherwise. Remarks: - You can always as assume that self.ufun returns the ufun for your. You will not need to directly use this method in most cases. .. py:method:: before_step() Called at the beginning of every step. Remarks: - Use this for any proactive code that needs to be done every simulation step. .. py:method:: step() Called at the end of every step. Remarks: - Use this for any proactive code that needs to be done every simulation step. .. py:method:: connect_to_oneshot_adapter(owner) Connects the agent to its adapter (used internally) .. py:method:: connect_to_2021_adapter(owner) Connects the agent to its adapter (used internally) .. py:method:: propose(negotiator_id: str, state: negmas.SAOState) -> negmas.Outcome | None :abstractmethod: Proposes an offer to one of the partners. :param negotiator_id: ID of the negotiator (and partner) :param state: Mechanism state including current step :returns: an outcome to offer. .. py:method:: respond(negotiator_id: str, state: negmas.SAOState, source=None) -> negmas.ResponseType Responds to an offer from one of the partners. :param negotiator_id: ID of the negotiator (and partner) :param state: Mechanism state including current step :returns: A response type which can either be reject, accept, or end negotiation. Remarks: default behavior is to accept only if the current offer is the same or has a higher utility compared with what the agent would have proposed in the given state and reject otherwise .. py:property:: internal_state :type: dict[str, Any] Returns the internal state of the agent for debugging purposes. Remarks: - In your agent, you can add any key-value pair to this dict and then use agent_log_* methods to log this information at any point. .. py:method:: on_negotiation_failure(partners: list[str], annotation: dict[str, Any], mechanism: negmas.sao.SAONMI, state: negmas.SAOState) -> None Called whenever a negotiation ends without agreement. :param partners: List of the partner IDs consisting from self and the opponent. :param annotation: The annotation of the negotiation including the seller ID, buyer ID, and the product. :param mechanism: The `NegotiatorMechanismInterface` instance containing all information about the negotiation. :param state: The final state of the negotiation of the type `SAOState` including the agreement if any. .. py:method:: on_negotiation_success(contract: negmas.Contract, mechanism: negmas.sao.SAONMI) -> None Called whenever a negotiation ends with agreement. :param contract: The `Contract` agreed upon. :param mechanism: The `NegotiatorMechanismInterface` instance containing all information about the negotiation that led to the `Contract` if any. .. py:method:: sign_all_contracts(contracts: list[negmas.Contract]) -> list[str | None] Signs all contracts (used internally) .. py:method:: on_contract_executed(contract) -> None .. py:method:: on_contract_breached(contract, breaches, resolution) -> None .. py:method:: get_negotiator(partner_id: str) -> negmas.sao.SAONegotiator Returns the negotiator corresponding to the given partner ID. Remarks: - Note that the negotiator ID and the partner ID are always the same. .. py:method:: get_ami(partner_id: str) -> negmas.sao.SAONMI Returns the `SAONMI` (Agent Mechanism Interface) connecting the agent to the negotiation mechanism for the given partner. .. py:method:: get_nmi(partner_id: str) -> negmas.sao.SAONMI Returns the `SAONMI` (Agent Mechanism Interface) connecting the agent to the negotiation mechanism for the given partner. .. py:class:: OneShotSyncAgent(*args, **kwargs) Bases: :py:obj:`negmas.SAOSyncController`, :py:obj:`OneShotAgent`, :py:obj:`abc.ABC` An agent that automatically accumulate offers from opponents and allows you to control all negotiations centrally in the `counter_all` method. .. py:method:: counter_all(offers: dict[str, negmas.Outcome | None], states: dict[str, negmas.SAOState]) -> dict[str, negmas.SAOResponse] :abstractmethod: 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.Outcome | None] :abstractmethod: 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. .. py:method:: sign_all_contracts(contracts: list[negmas.Contract]) -> list[str | None] Signs all contracts (used internally) .. py:class:: OneShotSingleAgreementAgent(*args, strict: bool = False, **kwargs) Bases: :py:obj:`negmas.SAOSingleAgreementController`, :py:obj:`OneShotSyncAgent` A synchronized agent that tries to get no more than one agreement. This controller manages a set of negotiations from which only a single one -- at most -- is likely to result in an agreement. To guarantee a single agreement, pass `strict=True` The general algorithm for this controller is something like this: - Receive offers from all partners. - Find the best offer among them by calling the abstract `best_offer` method. - Check if this best offer is acceptable using the abstract `is_acceptable` method. - If the best offer is acceptable, accept it and end all other negotiations. - If the best offer is still not acceptable, then all offers are rejected and with the partner who sent it receiving the result of `best_outcome` while the rest of the partners receive the result of `make_outcome`. - The default behavior of `best_outcome` is to return the outcome with maximum utility. - The default behavior of `make_outcome` is to return the best offer received in this round if it is valid for the respective negotiation and the result of `best_outcome` otherwise. :param strict: If True the controller is **guaranteed** to get a single agreement but it will have to send no-response repeatedly so there is a higher chance of never getting an agreement when two of those controllers negotiate with each other .. py:method:: is_acceptable(offer: negmas.Outcome, source: str, state: negmas.SAOState) -> bool :abstractmethod: Should decide if the given offer is acceptable :param offer: The offer being tested :param source: The ID of the negotiator that received this offer :param state: The state of the negotiation handled by that negotiator Remarks: - If True is returned, this offer will be accepted and all other negotiations will be ended. .. py:method:: best_offer(offers: dict[str, negmas.Outcome]) -> str | None :abstractmethod: Return the ID of the negotiator with the best offer :param offers: A mapping from negotiator ID to the offer it received :returns: The ID of the negotiator with best offer. Ties should be broken. Return None only if there is no way to calculate the best offer. .. py:method:: is_better(a: negmas.Outcome | None, b: negmas.Outcome | None, negotiator: str, state: negmas.SAOState) -> bool :abstractmethod: Compares two outcomes of the same negotiation :param a: "Outcome" :param b: "Outcome" :param negotiator: The negotiator for which the comparison is to be made :param state: Current state of the negotiation :returns: True if utility(a) > utility(b) .. py:class:: OneShotIndNegotiatorsAgent(*args, default_negotiator_type='negmas.sao.AspirationNegotiator', default_negotiator_params=None, normalize_ufuns=False, set_reservation=False, **kwargs) Bases: :py:obj:`OneShotAgent` A one-shot agent that deligates all of its decisions to a set of independent negotiators (one per partner per day). :param default_negotiator_type: An `SAONegotiator` descendent to be used for creating all negotiators. It can be passed either as a class object or a string with the full class name (e.g. "negmas.sao.AspirationNegotiator"). :param default_negotiator_type: A dict specifying the paratmers used to create negotiators. :param normalize_ufuns: If true, all utility functions will be normalized to have a maximum of 1.0 (the minimum value may be negative). :param set_reservation: If given, the reserved value of all ufuns will be guaranteed to be between the minimum and maximum of the ufun. This is needed to avoid failures of some GeniusNegotiators. Remarks: - To use this class, you need to override `generate_ufuns`. If you want to change the negotiator type used depending on the partner, you can also override `generate_negotiator`. - If you are using a `GeniusNegotiator` you must guarantee the following: - All ufuns are of the type `LinearAdditiveUtilityFunction`. - All ufuns are normalized with a maximum value of 1.0. You can use `normalize_ufuns=True` to gruarantee that. - All ufuns have a finite reserved value and at least one outcome is above it. You can guarantee that by using `set_reservation=True`. - All weights of the `LinearAdditiveUtilityFunction` must be between zero and one and the weights must sum to one. .. py:attribute:: _default_negotiator_type :value: 'negmas.sao.AspirationNegotiator' .. py:attribute:: _default_negotiator_params .. py:attribute:: _ufuns .. py:attribute:: _normalize :value: False .. py:attribute:: _set_reservation :value: False .. py:method:: generate_ufuns() -> dict[str, negmas.preferences.UtilityFunction] :abstractmethod: Returns a utility function for each partner. All ufuns **MUST** be of type `LinearAdditiveUtilityFunction` if a genius negotiator is used. .. py:method:: generate_negotiator(partner_id: str) -> negmas.sao.SAONegotiator Returns a negotiator to be used with some partner. Remarks: The default implementation will use the `default_negotiator_type` and `default_negotiator_params`. .. py:method:: _urange(u: negmas.preferences.UtilityFunction, issues: tuple[negmas.Issue, Ellipsis]) .. py:method:: _unorm(u: negmas.preferences.UtilityFunction, mn, mx) .. py:method:: _get_ufuns() Internal method that makes sure the reservation value is set to a meaningful value and that the ufun is normalized if needed .. py:method:: init() Called once after the AWI is set. Remarks: - Use this for any proactive initialization code. .. py:method:: step() Called at the end of every step. Remarks: - Use this for any proactive code that needs to be done every simulation step. .. py:method:: make_negotiator(negotiator_type=None, name: str | None = None, **kwargs) -> negmas.ControlledSAONegotiator Creates a negotiator but does not add it to the controller. Call `add_negotiator` to add it. :param negotiator_type: Type of the negotiator to be created. :param name: negotiator name :param \*\*kwargs: any key-value pairs to be passed to the negotiator constructor :returns: The negotiator to be controlled. None for failure Remarks: If you would like not to negotiate, just return `EndingNegotiator()` instead of None. The value None should only be returned if an exception is to be thrown. .. py:method:: propose(negotiator_id, state) Proposes an offer to one of the partners. :param negotiator_id: ID of the negotiator (and partner) :param state: Mechanism state including current step :returns: an outcome to offer. .. py:class:: EndingNegotiator(preferences: negmas.preferences.preferences.Preferences | None = None, ufun: negmas.preferences.base_ufun.BaseUtilityFunction | None = None, name: str | None = None, parent: negmas.negotiators.Controller | None = None, owner: negmas.situated.Agent | None = None, id: str | None = None, type_name: str | None = None, can_propose: bool = True, **kwargs) Bases: :py:obj:`negmas.sao.SAONegotiator`, :py:obj:`negmas.ControlledNegotiator` Base class for all SAO negotiators. Implemented by implementing propose() and respond() methods. :param name: Negotiator name :param parent: Parent controller if any :param preferences: The preferences of the negotiator :param ufun: The utility function of the negotiator (overrides preferences if given) :param owner: The `Agent` that owns the negotiator. Remarks: - The only method that **must** be implemented by any SAONegotiator is `propose`. - The default `respond` method, accepts offers with a utility value no less than whatever `propose` returns with the same mechanism state. - A default implementation of respond() is provided which simply accepts any offer better than the last offer I gave or the next one I would have given in the current state. .. seealso:: `SAOCallNegotiator` .. py:method:: propose(state) Propose an offer or None to refuse. :param state: `GBState` giving current state of the negotiation. :returns: The outcome being proposed or None to refuse to propose Remarks: - This function guarantees that no agents can propose something with a utility value .. py:method:: respond(state, source=None) Called to respond to an offer. This is the method that should be overriden to provide an acceptance strategy. :param state: a `SAOState` giving current state of the negotiation. :param source: The ID of the negotiator that gave this offer :returns: The response to the offer :rtype: ResponseType Remarks: - The default implementation never ends the negotiation - The default implementation asks the negotiator to `propose`() and accepts the `offer` if its utility was at least as good as the offer that it would have proposed (and above the reserved value). - The current offer to respond to can be accessed through `state.current_offer` .. py:data:: __all__ .. py:class:: SingleAgreementAspirationAgent(*args, **kwargs) Bases: :py:obj:`scml.oneshot.agent.OneShotSyncAgent` Uses a time-based strategy to accept a single agreement from the set it is considering. .. py:method:: before_step() Called at the beginning of every step. Remarks: - Use this for any proactive code that needs to be done every simulation step. .. py:method:: counter_all(offers, states) 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:: choose_agents(offers, outcome) Selects an appropriate way to distribute this outcome to agents with given IDs. .. py:method:: first_proposals() -> Dict[str, negmas.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. .. py:class:: GreedyOneShotAgent(*args, concession_exponent=None, acc_price_slack=float('inf'), step_price_slack=None, opp_price_slack=None, opp_acc_price_slack=None, range_slack=None, **kwargs) Bases: :py:obj:`scml.oneshot.agent.OneShotAgent` A greedy agent based on OneShotAgent :param concession_exponent: A real number controlling how fast does the agent concede on price. :param acc_price_slack: The allowed slack in price limits compared with best prices I got so far :param step_price_slack: The allowed slack in price limits compared with best prices I got this step :param opp_price_slack: The allowed slack in price limits compared with best prices I got so far from a given opponent in this step :param opp_acc_price_slack: The allowed slack in price limits compared with best prices I got so far from a given opponent so far :param range_slack: Always consider prices above (1-`range_slack`) of the best possible prices *good enough*. Remarks: - A `concession_exponent` greater than one makes the agent concede super linearly and vice versa .. py:attribute:: _e :value: None .. py:attribute:: _acc_price_slack .. py:attribute:: _step_price_slack :value: None .. py:attribute:: _opp_price_slack :value: None .. py:attribute:: _opp_acc_price_slack :value: None .. py:attribute:: _range_slack :value: None .. py:method:: init() Initialize the quantities and best prices received so far .. py:method:: before_step() Initialize the quantities and best prices received for next step .. py:method:: on_negotiation_success(contract, mechanism) Record sales/supplies secured .. py:method:: propose(negotiator_id: str, state, source=None) -> negmas.Outcome | None Proposes an offer to one of the partners. :param negotiator_id: ID of the negotiator (and partner) :param state: Mechanism state including current step :returns: an outcome to offer. .. py:method:: respond(negotiator_id, state, source=None) -> negmas.ResponseType Responds to an offer from one of the partners. :param negotiator_id: ID of the negotiator (and partner) :param state: Mechanism state including current step :returns: A response type which can either be reject, accept, or end negotiation. Remarks: default behavior is to accept only if the current offer is the same or has a higher utility compared with what the agent would have proposed in the given state and reject otherwise .. py:method:: best_offer(negotiator_id) .. py:method:: _needed(negotiator_id) .. py:method:: _is_selling(nmi) .. py:method:: _is_good_price(nmi, state, price) Checks if a given price is good enough at this stage .. py:method:: _find_good_price(nmi, state) Finds a good-enough price conceding linearly over time .. py:method:: _price_range(nmi) Limits the price by the best price received .. py:method:: _th(step, n_steps) calculates a descending threshold (0 <= th <= 1) .. py:class:: GreedySyncAgent(*args, threshold=None, **kwargs) Bases: :py:obj:`scml.oneshot.agent.OneShotSyncAgent`, :py:obj:`GreedyOneShotAgent` A greedy agent based on OneShotSyncAgent .. py:attribute:: _threshold :value: None .. py:attribute:: ufun :type: scml.oneshot.ufun.OneShotUFun Returns the preferences if it is a `BaseUtilityFunction` else None .. py:method:: before_step() Called at the beginning of every step. Remarks: - Use this for any proactive code that needs to be done every simulation step. .. py:method:: first_proposals() Decide a first proposal on every negotiation. Returning None for a negotiation means ending it. .. py:method:: counter_all(offers, states) -> dict Respond to a set of offers given the negotiation state of each. .. py:method:: _needs() Returns both input and output needs .. py:method:: propose(negotiator_id, state) Proposes an offer to one of the partners. :param negotiator_id: ID of the negotiator (and partner) :param state: Mechanism state including current step :returns: an outcome to offer. .. py:method:: respond(negotiator_id, state, source='') Responds to an offer from one of the partners. :param negotiator_id: ID of the negotiator (and partner) :param state: Mechanism state including current step :returns: A response type which can either be reject, accept, or end negotiation. Remarks: default behavior is to accept only if the current offer is the same or has a higher utility compared with what the agent would have proposed in the given state and reject otherwise .. py:class:: GreedySingleAgreementAgent(*args, **kwargs) Bases: :py:obj:`scml.oneshot.agent.OneShotSingleAgreementAgent` A greedy agent based on `OneShotSingleAgreementAgent` .. py:attribute:: ufun :type: scml.oneshot.ufun.OneShotUFun Returns the preferences if it is a `BaseUtilityFunction` else None .. py:method:: before_step() Called at the beginning of every step. Remarks: - Use this for any proactive code that needs to be done every simulation step. .. py:method:: is_acceptable(offer, source, state) -> bool Should decide if the given offer is acceptable :param offer: The offer being tested :param source: The ID of the negotiator that received this offer :param state: The state of the negotiation handled by that negotiator Remarks: - If True is returned, this offer will be accepted and all other negotiations will be ended. .. py:method:: best_offer(offers) Return the ID of the negotiator with the best offer :param offers: A mapping from negotiator ID to the offer it received :returns: The ID of the negotiator with best offer. Ties should be broken. Return None only if there is no way to calculate the best offer. .. py:method:: is_better(a, b, negotiator, state) Compares two outcomes of the same negotiation :param a: "Outcome" :param b: "Outcome" :param negotiator: The negotiator for which the comparison is to be made :param state: Current state of the negotiation :returns: True if utility(a) > utility(b) .. py:class:: OneshotDoNothingAgent(owner=None, ufun: scml.oneshot.OneShotUFun | None = None, name=None) Bases: :py:obj:`scml.oneshot.agent.OneShotAgent` An agent that does nothing. Remarks: Note that this agent will lose money whenever it is at the edges (i.e. it is an input or an output agent trading in raw material or final product). .. py:method:: propose(negotiator_id, state) Proposes an offer to one of the partners. :param negotiator_id: ID of the negotiator (and partner) :param state: Mechanism state including current step :returns: an outcome to offer. .. py:method:: respond(negotiator_id, state, source=None) Responds to an offer from one of the partners. :param negotiator_id: ID of the negotiator (and partner) :param state: Mechanism state including current step :returns: A response type which can either be reject, accept, or end negotiation. Remarks: default behavior is to accept only if the current offer is the same or has a higher utility compared with what the agent would have proposed in the given state and reject otherwise .. py:class:: Placeholder(*args, **kwargs) Bases: :py:obj:`scml.oneshot.policy.OneShotPolicy` An agent that always raises an exception if called to negotiate. It is useful as a placeholder (for example for RL and MARL exposition) .. py:method:: act(state) The main policy. Generates an action given a state .. py:class:: RandomOneShotAgent(*args, p_accept=PROB_ACCEPTANCE, p_end=PROB_END, **kwargs) Bases: :py:obj:`scml.oneshot.agent.OneShotAgent` An agent that randomly leaves the negotiation, accepts or counters with random outcomes .. py:method:: _random_offer(negotiator_id: str) .. py:method:: propose(negotiator_id, state) -> negmas.outcomes.Outcome | None Proposes an offer to one of the partners. :param negotiator_id: ID of the negotiator (and partner) :param state: Mechanism state including current step :returns: an outcome to offer. .. py:method:: respond(negotiator_id, state, source=None) -> negmas.ResponseType Responds to an offer from one of the partners. :param negotiator_id: ID of the negotiator (and partner) :param state: Mechanism state including current step :returns: A response type which can either be reject, accept, or end negotiation. Remarks: default behavior is to accept only if the current offer is the same or has a higher utility compared with what the agent would have proposed in the given state and reject otherwise .. py:class:: RandDistOneShotAgent(*args, **kwargs) Bases: :py:obj:`SyncRandomOneShotAgent` An agent that distributes its needs over its partners randomly. :param equal: If given, it tries to equally distribute its needs over as many of its suppliers/consumers as possible :param overordering_max: Maximum fraction of needs to over-order. For example, it the agent needs 5 items and this is 0.2, it will order 6 in the first negotiation step. :param overordering_min: Minimum fraction of needs to over-order. Used in the last negotiation step. :param overordering_exp: Controls how fast does the over-ordering quantity go from max to min. :param concession_exp: Controls how fast does the agent concedes on matching its needs exactly. :param mismatch_max: Maximum mismtach in quantity allowed between needs and accepted offers. If a fraction, it is will be this fraction of the production capacity (n_lines). .. py:class:: EqualDistOneShotAgent(*args, **kwargs) Bases: :py:obj:`SyncRandomOneShotAgent` Same as RandDistOneShotAgent but defaulting to equal distribution of needs :param equal: If given, it tries to equally distribute its needs over as many of its suppliers/consumers as possible :param overordering_max: Maximum fraction of needs to over-order. For example, it the agent needs 5 items and this is 0.2, it will order 6 in the first negotiation step. :param overordering_min: Minimum fraction of needs to over-order. Used in the last negotiation step. :param overordering_exp: Controls how fast does the over-ordering quantity go from max to min. :param concession_exp: Controls how fast does the agent concedes on matching its needs exactly. :param mismatch_max: Maximum mismtach in quantity allowed between needs and accepted offers. If a fraction, it is will be this fraction of the production capacity (n_lines). .. py:class:: SyncRandomOneShotAgent(*args, equal: bool = False, overordering_max: float = 0.2, overordering_min: float = 0.0, overordering_exp: float = 0.4, mismatch_exp: float = 4.0, mismatch_max: float = 0.3, **kwargs) Bases: :py:obj:`scml.oneshot.agent.OneShotSyncAgent` An agent that distributes its needs over its partners randomly. :param equal: If given, it tries to equally distribute its needs over as many of its suppliers/consumers as possible :param overordering_max: Maximum fraction of needs to over-order. For example, it the agent needs 5 items and this is 0.2, it will order 6 in the first negotiation step. :param overordering_min: Minimum fraction of needs to over-order. Used in the last negotiation step. :param overordering_exp: Controls how fast does the over-ordering quantity go from max to min. :param concession_exp: Controls how fast does the agent concedes on matching its needs exactly. :param mismatch_max: Maximum mismtach in quantity allowed between needs and accepted offers. If a fraction, it is will be this fraction of the production capacity (n_lines). .. py:attribute:: equal_distribution :value: False .. py:attribute:: overordering_max :value: 0.2 .. py:attribute:: overordering_min :value: 0.0 .. py:attribute:: overordering_exp :value: 0.4 .. py:attribute:: mismatch_exp :value: 4.0 .. py:attribute:: mismatch_max :value: 0.3 .. py:method:: init() Called once after the AWI is set. Remarks: - Use this for any proactive initialization code. .. py:method:: distribute_needs(t: float) -> dict[str, int] Distributes my needs randomly over all my partners .. py:method:: first_proposals() 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. .. py:method:: counter_all(offers, states) 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:: _allowed_mismatch(r: float) .. py:method:: _overordering_fraction(t: float) .. py:method:: _step_and_price(best_price=False) Returns current step and a random (or max) price .. py:class:: SingleAgreementRandomAgent(*args, p_accept: float = PROB_ACCEPTANCE, **kwargs) Bases: :py:obj:`scml.oneshot.agent.OneShotSingleAgreementAgent` A controller that agrees randomly to one offer .. py:attribute:: _p_accept :value: 0.1 .. py:method:: is_acceptable(offer: negmas.outcomes.Outcome, source: str, state: negmas.sao.SAOState) -> bool Should decide if the given offer is acceptable :param offer: The offer being tested :param source: The ID of the negotiator that received this offer :param state: The state of the negotiation handled by that negotiator Remarks: - If True is returned, this offer will be accepted and all other negotiations will be ended. .. py:method:: best_offer(offers: dict[str, negmas.outcomes.Outcome]) -> str | None Return the ID of the negotiator with the best offer :param offers: A mapping from negotiator ID to the offer it received :returns: The ID of the negotiator with best offer. Ties should be broken. Return None only if there is no way to calculate the best offer. .. py:method:: is_better(a: negmas.outcomes.Outcome | None, b: negmas.outcomes.Outcome | None, negotiator: str, state: negmas.sao.SAOState) -> bool Compares two outcomes of the same negotiation :param a: "Outcome" :param b: "Outcome" :param negotiator: The negotiator for which the comparison is to be made :param state: Current state of the negotiation :returns: True if utility(a) > utility(b) .. py:class:: OneShotAWI(world: scml.oneshot.world.SCMLBaseWorld, agent: scml.oneshot.agent.OneShotAgent) Bases: :py:obj:`negmas.situated.AgentWorldInterface` The agent world interface for the one-shot game. This class contains all the methods needed to access the simulation to extract information which are divided into 4 groups: Static World Information: Information about the world and the agent that does not change over time. These include: A. Market Information: - **n_products**: Number of products in the production chain. - **n_processes**: Number of processes in the production chain. - **n_competitors**: Number of other factories on the same production level. - **all_suppliers**: A list of all suppliers by product. - **all_consumers**: A list of all consumers by product. - **proudction_capacities**: The total production capacity (i.e. number of lines) for each production level (i.e. manufacturing process). - **is_system**: Is the given system ID corresponding to a system agent? - **is_bankrupt**: Is the given agent bankrupt? None asks about self - **catalog_prices**: A list of the catalog prices (by product). - **price_multiplier**: The multiplier multiplied by the trading/catalog price when the negotiation agendas are created to decide the maximum and lower quantities. - **is_exogenous_forced**: Are exogenous contracts always forced or can the agent decide not to sign them. - **current_step**: Current simulation step (inherited from `negmas.situated.AgentWorldInterface` ). - **n_steps**: Number of simulation steps (inherited from `negmas.situated.AgentWorldInterface` ). - **relative_time**: fraction of the simulation completed (inherited from `negmas.situated.AgentWorldInterface`). - **state**: The full state of the agent ( `OneShotState` ). - **settings* The system settings (inherited from `negmas.situated.AgentWorldInterface` ). - **quantity_range* The maximum quantity in all negotiation agendas (new in 0.6.1) - **price_range* The maximum number of different prices in any negotiation agenda (new in 0.6.1) B. Agent Information: - **profile**: Gives the agent profile including its production cost, number of production lines, input product index, mean of its delivery penalties, mean of its disposal costs, standard deviation of its shortfall penalties and standard deviation of its disposal costs. See `OneShotProfile` for full description. This information is private information and no other agent knows it. - **n_lines**: the number of production lines in the factory (private information). - **is_first_level**: Is the agent in the first production level (i.e. it is an input agent that buys the raw material). - **is_last_level**: Is the agent in the last production level (i.e. it is an output agent that sells the final product). - **is_middle_level**: Is the agent neither a first level nor a last level agent - **my_input_product**: The input product to the factory controlled by the agent. - **my_output_product**: The output product from the factory controlled by the agent. - **level**: The production level which is numerically the same as the input product. - **my_suppliers**: A list of IDs for all suppliers to the agent (i.e. agents that can sell the input product of the agent). - **my_consumers**: A list of IDs for all consumers to the agent (i.e. agents that can buy the output product of the agent). - **penalties_scale**: The scale at which to calculate disposal cost/delivery penalties. "trading" and "catalog" mean trading and catalog prices. "unit" means the contract's unit price while "none" means that disposal cost/shortfall penalty are absolute. - **n_input_negotiations**: Number of negotiations with suppliers. - **n_output_negotiations**: Number of negotiations with consumers. Dynamic World Information: Information about the world and the agent that changes over time. A. Market Information: - **trading_prices**: The trading prices of all products. This information is only available if `publish_trading_prices` is set in the world. - **exogenous_contract_summary**: A list of n_products tuples each giving the total quantity and average price of exogenous contracts for a product. This information is only available if `publish_exogenous_summary` is set in the world. - **is_perishable**: Are all products perishable? B. Other Agents' Information: - **reports_of_agent**: Gives all past financial reports of a given agent. See `FinancialReport` for details. - **reports_at_step**: Gives all reports of all agents at a given step. See `FinancialReport` for details. C. Current Negotiations Information: - **current_input_outcome_space**: The current outcome-space for all negotiations to buy the input product of the agent. If the agent is at level zero, this will have no issues. - **current_output_outcome_space**: The current outcome-space for all negotiations to buy the output product of the agent. If the agent is at level n_products - 1, this will have no issues. - **current_negotiation_details**: Details on all current negotiations separated into "buy" and "sell" dictionaries. Useful helpers about current negotiations: - **current_input_issues**: The current issues for all negotiations to buy the input product of the agent. If the agent is at level zero, this will be empty. This is exactly the same as current_input_outcome_space.issues - **current_output_issues**: The current issues for all negotiations to buy the output product of the agent. If the agent is at level n_products - 1, this will be empty. This is exactly the same as current_output_outcome_space.issues - **current_buy_nmis**: All NMIs for current buy negotiations. - **current_sell_nmis**: All NMIs for current sell negotiations. - **current_nmis**: All states for current negotiations. - **current_buy_states**: All states for current buy negotiations. - **current_sell_states**: All states for current sell negotiations. - **current_states**: All states for current negotiations. - **current_buy_offers**: All offers for current buy negotiations. - **current_sell_offers**: All offers for current sell negotiations. - **current_offers**: All offers for current negotiations. - **running_buy_nmis**: All NMIs for running buy negotiations. - **running_sell_nmis**: All NMIs for running sell negotiations. - **running_nmis**: All states for running negotiations. - **running_buy_states**: All states for running buy negotiations. - **running_sell_states**: All states for running sell negotiations. - **running_states**: All states for running negotiations. D. Agent Information: - **current_exogenous_input_quantity**: The total quantity the agent have in its input exogenous contract. - **current_exogenous_input_price**: The total price of the agent's input exogenous contract. - **current_exogenous_output_quantity**: The total quantity the agent have in its output exogenous contract. - **current_exogenous_output_price**: The total price of the agent's output exogenous contract - **current_disposal_cost**: The disposal cost per unit item in the current step. - **current_shortfall_penalty**: The shortfall penalty per unit item in the current step. - **current_balance**: The current balance of the agent - **current_score**: The current score (balance / initial balance) of the agent - **current_inventory_input**: The total quantity remaining in the inventory of the input product - **current_inventory_output**: The total quantity remaining in the inventory of the output product - **current_inventory**: The total quantity remaining in the inventory of the input and output product E. Sales and Supplies (quantities) for today: - **sales**: Today's sales per customer so far. - **supplies**: Today's supplies per supplier so far. - **total_sales**: Today's total sales so far. - **total_supplies**: Today's total supplies so far. - **needed_sales**: Today's needed sales as of now (exogenous input + total supplies - exogenous output - total sales so far). - **needed_supplies**: Today's needed supplies as of now (exogenous output + total sales - exogenous input - total supplies so far). Services (All inherited from `negmas.situated.AgentWorldInterface`): - **logdebug/loginfo/logwarning/logerror**: Logs to the world log at the given log level. - **logdebug_agent/loginf_agnet/...**: Logs to the agent specific log at the given log level. - **bb_query**: Queries the bulletin-board. - **bb_read**: Read a section of the bulletin-board. .. py:attribute:: _world .. py:attribute:: agent .. py:attribute:: _future_sales :type: dict[int, dict[str, int]] .. py:attribute:: _future_supplies :type: dict[int, dict[str, int]] .. py:attribute:: _future_sales_cost :type: dict[int, dict[str, int]] .. py:attribute:: _future_supplies_cost :type: dict[int, dict[str, int]] .. py:property:: max_n_lines :type: int Maximum number of lines in the whole system .. py:property:: quantity_range :type: int The maximum cardinality of the quantity issue in all negotiations .. py:property:: price_range :type: int The maximum cardinality of the quantity issue in all negotiations .. py:property:: n_products :type: int Returns the number of products in the system .. py:property:: n_competitors :type: int Returns the number of factories/agents in the same production level .. py:property:: n_processes :type: int Returns the number of processes in the system .. py:property:: all_suppliers :type: list[list[str]] Returns a list of agent IDs for all suppliers for every product .. py:property:: production_capacities :type: list[int] Returns the total production capacity in the market for each process .. py:property:: all_consumers :type: list[list[str]] Returns a list of agent IDs for all consumers for every product .. py:method:: is_system(aid: str) -> bool Checks whether an agent is a system agent or not :param aid: Agent ID .. py:method:: is_bankrupt(aid: str | None = None) -> bool Checks whether an agent is a system agent or not :param aid: Agent ID .. py:property:: horizon :type: int Horizon for negotiations .. py:property:: catalog_prices :type: numpy.ndarray Returns the catalog prices of all products .. py:property:: price_multiplier :type: float Controls the minimum and maximum prices in the negotiation agendas Remarks: - The base price is either the catalog price if trading price information is not public or the trading price. - The minimum unit price in any negotiation agenda is the base price of the previous product in the chain ***divided* by the multiplier. If that is less than 1, the minimum unit price becomes 1. - The maximum unit price in any negotiation agenda is the base price of the previous product in the chain ***multiplied* by the multiplier. If that is less than 1, the minimum unit price becomes 1. .. py:property:: is_exogenous_forced :type: bool Are exogenous contracts forced in the sense that the agent cannot decide not to sign them? .. py:property:: allow_zero_quantity :type: bool Does negotiations allow zero quantity? .. py:property:: profile :type: scml.oneshot.common.OneShotProfile Gets the profile (static private information) associated with the agent .. py:property:: n_lines :type: int The number of lines in the corresponding factory. You can read `state` to get this among other information .. py:property:: n_input_negotiations :type: int Number of negotiations with suppliers at every step .. py:property:: n_output_negotiations :type: int Number of negotiations with consumers at every step .. py:property:: is_first_level Whether this agent is in the first production level .. py:property:: is_last_level Whether this agent is in the last production level .. py:property:: level The production level which is the index of the process for this factory (or the index of its input product) .. py:property:: is_middle_level Whether this agent is in neither in the first nor in the last level .. py:property:: my_input_product :type: int the product I need to buy .. py:property:: my_output_product :type: int the product I need to sell .. py:property:: my_competitors :type: list[str] Returns the names of all factories in the same level as me .. py:property:: my_suppliers :type: list[str] Returns a list of IDs for all of the agent's suppliers (agents that can supply the product I need). .. py:property:: my_consumers :type: list[str] Returns a list of IDs for all the agent's consumers (agents that can consume at least one product it may produce). .. py:property:: my_partners :type: list[str] Returns a list of IDs for all of the agent's partners starting with suppliers .. py:property:: penalties_scale :type: Literal['trading', 'catalog', 'unit', 'none'] .. py:property:: state :type: scml.oneshot.common.OneShotState Returns the private state of the agent in that world .. py:property:: current_balance .. py:property:: current_score :type: float Returns the current score (profit) of the agent .. py:property:: current_inventory :type: tuple[int, int] Current input and output inventory quantity .. py:property:: current_inventory_input :type: int Current input inventory quantity .. py:property:: current_inventory_output :type: int Current output inventory quantity .. py:property:: current_exogenous_input_quantity :type: int The exogenous contracts for the input (this step) .. py:property:: current_exogenous_input_price :type: int The exogenous contracts for the input (this step) .. py:property:: current_exogenous_output_quantity :type: int The exogenous contracts for the input (this step) .. py:property:: current_exogenous_output_price :type: int The exogenous contracts for the input (this step) .. py:method:: penalty_multiplier(is_input: bool, unit_price: float | None) -> float Returns the penalty multiplier for a contract with the give unit price. Remarks: - The unit price is only needed if the penalties_scale is unit. For all other options (trading, catalog, none), the penalty scale does not depend on the unit price. .. 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:: trading_prices :type: numpy.ndarray Returns the current trading prices of all products .. py:property:: exogenous_contract_summary :type: list[tuple[int, int]] The exogenous contracts in the current step for all products :returns: A list of tuples giving the total quantity and total price of all revealed exogenous contracts of all products at the current step. Will be empty if the world has "publish_exogenous_summary==False" .. py:method:: reports_of_agent(aid: str) -> dict[int, scml.oneshot.common.FinancialReport] Returns a dictionary mapping time-steps to financial reports of the given agent .. py:method:: reports_at_step(step: int) -> dict[str, scml.oneshot.common.FinancialReport] Returns a dictionary mapping agent ID to its financial report for the given time-step .. py:property:: current_input_issues :type: list[negmas.ContiguousIssue] .. py:property:: current_output_issues :type: list[negmas.ContiguousIssue] .. py:property:: current_input_outcome_space :type: negmas.outcomes.DiscreteCartesianOutcomeSpace .. py:property:: current_output_outcome_space :type: negmas.outcomes.DiscreteCartesianOutcomeSpace .. py:property:: current_negotiation_details :type: dict[str, dict[str, scml.oneshot.common.NegotiationDetails]] Details of current negotiations separated as two dicts for buying and selling. Remarks: - current_negotiation_details["buy"] gives details on all negotiations for buying - current_negotiation_details["sell"] gives details on all negotiations for selling .. py:property:: current_buy_states :type: dict[str, negmas.sao.SAOState] All running buy negotiations as a mapping from partner ID to current negotiation state .. py:property:: current_sell_states :type: dict[str, negmas.sao.SAOState] All running sell negotiations as a mapping from partner ID to current negotiation state .. py:property:: current_states :type: dict[str, negmas.sao.SAOState] All running negotiations as a mapping from partner ID to current negotiation state .. py:property:: current_buy_nmis :type: dict[str, negmas.sao.SAONMI] All running buy negotiations as a mapping from partner ID to current negotiation nmi .. py:property:: current_sell_nmis :type: dict[str, negmas.sao.SAONMI] All running negotiations as a mapping from partner ID to current negotiation state .. py:property:: current_nmis :type: dict[str, negmas.sao.SAONMI] All running negotiations as a mapping from partner ID to current negotiation nmi .. py:property:: current_buy_offers :type: dict[str, negmas.outcomes.Outcome] All current buy negotiations as a mapping from partner ID to current offer .. py:property:: current_sell_offers :type: dict[str, negmas.outcomes.Outcome] All current sell negotiations as a mapping from partner ID to current offer .. py:property:: current_offers :type: dict[str, negmas.outcomes.Outcome] All current negotiations as a mapping from partner ID to current offer .. py:property:: running_buy_states :type: dict[str, negmas.sao.SAOState] All running buy negotiations as a mapping from partner ID to current negotiation state .. py:property:: running_sell_states :type: dict[str, negmas.sao.SAOState] All running sell negotiations as a mapping from partner ID to current negotiation state .. py:property:: running_states :type: dict[str, negmas.sao.SAOState] All running negotiations as a mapping from partner ID to current negotiation state .. py:property:: running_sell_nmis :type: dict[str, negmas.sao.SAONMI] All running sell negotiations as a mapping from partner ID to current negotiation nmi .. py:property:: running_buy_nmis :type: dict[str, negmas.sao.SAONMI] All running buy negotiations as a mapping from partner ID to current negotiation nmi .. py:property:: running_nmis :type: dict[str, negmas.sao.SAONMI] All running negotiations as a mapping from partner ID to current negotiation nmi .. py:property:: sales :type: dict[str, int] Sales (quantity) per customer so far (this day) .. py:property:: supplies :type: dict[str, int] Supplies (quantity) per supplier so far (this day) .. py:property:: sales_cost :type: dict[str, int] Sales (total price) per customer so far (this day) .. py:property:: supplies_cost :type: dict[str, int] Supplies (total price) per supplier so far (this day) .. py:property:: future_sales :type: dict[int, dict[str, int]] Future sales (quantity) per customer so far (excluding this day) .. py:property:: future_supplies :type: dict[int, dict[str, int]] Future supplies (quantity) per supplier so far (excluding this day) .. py:property:: future_sales_cost :type: dict[int, dict[str, int]] Future sales (total price) per customer so far (excluding this day) .. py:property:: future_supplies_cost :type: dict[int, dict[str, int]] Future supplies (total price) per supplier so far (excluding this day) .. py:property:: total_sales :type: int Total sales so far (this day) .. py:property:: total_supplies :type: int Total supplies so far (this day) .. py:property:: total_future_sales :type: int Total sales so far (this day) .. py:method:: total_sales_from(start: int) -> int Total sales starting at start and ending at end (inclusive). Past days are ignored .. py:method:: total_supplies_from(start: int) -> int Total supplies starting at start and ending at end (inclusive). Past days are ignored .. py:method:: total_sales_between(start: int, end: int) -> int Total sales starting at start and ending at end (inclusive). Past days are ignored .. py:method:: total_supplies_between(start: int, end: int) -> int Total supplies starting at start and ending at end (inclusive). Past days are ignored .. py:method:: total_supplies_until(step: int) -> int Total supplies starting today until the given step (inclusive). Past days are ignored .. py:method:: total_sales_until(step: int) -> int Total sales starting today until the given step (inclusive). Past days are ignored .. py:method:: total_sales_at(step: int) -> int Total sales already signed at a future step .. py:method:: total_supplies_at(step: int) -> int Total supplies already signed at a future step .. py:property:: total_future_supplies :type: int Total supplies so far (this day) .. py:property:: needed_sales :type: int Sales that need to be secured (exogenous input + total supplies - exogenous output - total sales so far) .. py:property:: needed_supplies :type: int Supplies that need to be secured (exogenous output + total sales - exogenous input - total supplies so far) .. py:method:: _register_sale(customer: str, quantity: int, unit_price: int, step: int) -> None .. py:method:: _register_supply(supplier: str, quantity: int, unit_price: int, step: int) -> None .. py:method:: _reset_sales_and_supplies() -> None .. py:data:: QUANTITY :value: 0 Index of quantity in negotiation issues .. py:data:: UNIT_PRICE :value: 2 Index of unit price in negotiation issues .. py:data:: TIME :value: 1 Index of time in negotiation issues .. py:class:: OneShotState State of a one-shot agent .. py:attribute:: exogenous_input_quantity :type: int Exogenous input quantity for the current step .. py:attribute:: exogenous_input_price :type: int Exogenous input unit price for the current step .. py:attribute:: exogenous_output_quantity :type: int Exogenous output quantity for the current step .. py:attribute:: exogenous_output_price :type: int Exogenous output unit price for the current step .. py:attribute:: disposal_cost :type: float Current unit disposal cost .. py:attribute:: shortfall_penalty :type: float Current unit shortfall penalty .. py:attribute:: current_balance :type: int Current balance of the agent. .. py:attribute:: total_sales :type: int Total quantity registered as sales today using `awi.register_sale`. .. py:attribute:: total_supplies :type: int Total quantity registered as supplies today using `awi.register_supply`. .. py:attribute:: total_future_sales :type: int Total quantity registered as sales in the future using `awi.register_sale`. .. py:attribute:: total_future_supplies :type: int Total quantity registered as supplies in the future using `awi.register_supply`. .. py:attribute:: n_products :type: int Number of products in the production chain. .. py:attribute:: n_processes :type: int Number of processes in the production chain. .. py:attribute:: n_competitors :type: int Number of other factories on the same production level. .. py:attribute:: all_suppliers :type: list[list[str]] A list of all suppliers by product. .. py:attribute:: all_consumers :type: list[list[str]] A list of all consumers by product. .. py:attribute:: production_capacities :type: list[int] A list of total production capacity per production level. .. py:attribute:: bankrupt_agents :type: list[str] list of bankrupt agents .. py:attribute:: catalog_prices :type: list[float] A list of the catalog prices (by product). .. py:attribute:: price_multiplier :type: float The multiplier multiplied by the trading/catalog price when the negotiation agendas are created to decide the maximum and lower quantities. .. py:attribute:: is_exogenous_forced :type: bool exogenous contracts always forced or can the agent decide not to sign them. .. py:attribute:: current_step :type: int Current simulation step (inherited from `negmas.situated.AgentWorldInterface` ). .. py:attribute:: n_steps :type: int Number of simulation steps (inherited from `negmas.situated.AgentWorldInterface` ). .. py:attribute:: relative_simulation_time :type: float Fraction of the simulation completed (inherited from `negmas.situated.AgentWorldInterface`). .. py:attribute:: profile :type: OneShotProfile Gives the agent profile including its production cost, number of production lines, input product index, mean of its delivery penalties, mean of its disposal costs, standard deviation of its shortfall penalties and standard deviation of its disposal costs. See `OneShotProfile` for full description. This information is private information and no other agent knows it. .. py:attribute:: n_lines :type: int The number of production lines in the factory (private information). .. py:attribute:: is_first_level :type: bool Is the agent in the first production level (i.e. it is an input agent that buys the raw material). .. py:attribute:: is_last_level :type: bool Is the agent in the last production level (i.e. it is an output agent that sells the final product). .. py:attribute:: is_middle_level :type: bool Is the agent neither a first level nor a last level agent .. py:attribute:: my_input_product :type: int The input product to the factory controlled by the agent. .. py:attribute:: my_output_product :type: int The output product from the factory controlled by the agent. .. py:attribute:: level :type: int The production level which is numerically the same as the input product. .. py:attribute:: my_suppliers :type: list[str] A list of IDs for all suppliers to the agent (i.e. agents that can sell the input product of the agent). .. py:attribute:: my_consumers :type: list[str] A list of IDs for all consumers to the agent (i.e. agents that can buy the output product of the agent). .. py:attribute:: my_partners :type: list[str] A list of IDs for all negotiation partners of the agent (in the order suppliers then consumers). .. py:attribute:: penalties_scale :type: Literal['trading', 'catalog', 'unit', 'none'] The scale at which to calculate disposal cost/delivery penalties. "trading" and "catalog" mean trading and catalog prices. "unit" means the contract's unit price while "none" means that disposal cost/shortfall penalty are absolute. .. py:attribute:: n_input_negotiations :type: int Number of negotiations with suppliers. .. py:attribute:: n_output_negotiations :type: int Number of negotiations with consumers. .. py:attribute:: trading_prices :type: list[float] The trading prices of all products. This information is only available if `publish_trading_prices` is set in the world. .. py:attribute:: exogenous_contract_summary :type: list[tuple[int, int]] A list of n_products lists each giving the total quantity and average price of exogenous contracts for a product. This information is only available if `publish_exogenous_summary` is set in the world. .. py:attribute:: reports_of_agents :type: dict[str, dict[int, FinancialReport]] Gives all past financial reports of a given agent. See `FinancialReport` for details. .. py:attribute:: current_input_outcome_space :type: negmas.outcomes.DiscreteCartesianOutcomeSpace The current issues for all negotiations to buy the input product of the agent. If the agent is at level zero, this will be empty. This is exactly the same as current_input_outcome_space.issues .. py:attribute:: current_output_outcome_space :type: negmas.outcomes.DiscreteCartesianOutcomeSpace The current issues for all negotiations to buy the output product of the agent. If the agent is at level n_products - 1, this will be empty. This is exactly the same as current_output_outcome_space.issues .. py:attribute:: current_negotiation_details :type: dict[str, dict[str, NegotiationDetails]] Details on all current negotiations separated into "buy" and "sell" dictionaries. .. py:attribute:: sales :type: dict[str, int] Today's sales per customer so far. .. py:attribute:: supplies :type: dict[str, int] Today supplies per supplier so far. .. py:attribute:: needed_sales :type: int Today's needed sales as of now (exogenous input - exogenous output - total sales so far). .. py:attribute:: needed_supplies :type: int Today needed supplies as of now (exogenous output - exogenous input - total supplies). .. py:attribute:: perishable :type: bool :value: True Is this a perishable domain (oneshot) of not (std) .. py:attribute:: allow_zero_quantity :type: bool :value: False Does this world allow zero quantity in negotiated offers .. py:attribute:: storage_cost :type: float :value: 0.0 Current unit storage cost. Only used in standard worlds where products are not perishable .. py:property:: running_buy_states :type: dict[str, negmas.sao.common.SAOState] All running buy negotiations as a mapping from partner ID to current negotiation state .. py:property:: current_sell_states :type: dict[str, negmas.sao.common.SAOState] All running sell negotiations as a mapping from partner ID to current negotiation state .. py:property:: current_states :type: dict[str, negmas.sao.common.SAOState] All running negotiations as a mapping from partner ID to current negotiation state .. py:property:: current_buy_nmis :type: dict[str, negmas.sao.SAONMI] All running buy negotiations as a mapping from partner ID to current negotiation nmi .. py:property:: current_sell_nmis :type: dict[str, negmas.sao.SAONMI] All running sell negotiations as a mapping from partner ID to current negotiation nmi .. py:property:: current_nmis :type: dict[str, negmas.sao.SAONMI] All running negotiations as a mapping from partner ID to current negotiation state .. py:property:: current_buy_offers :type: dict[str, negmas.outcomes.Outcome] All current buy negotiations as a mapping from partner ID to current offer .. py:property:: current_sell_offers :type: dict[str, negmas.outcomes.Outcome] All current sell negotiations as a mapping from partner ID to current offer .. py:property:: current_offers :type: dict[str, negmas.outcomes.Outcome] All current negotiations as a mapping from partner ID to current offer .. py:method:: random(oneshot: bool | None = None) -> OneShotState :classmethod: .. py:class:: OneShotExogenousContract Exogenous contract information .. py:attribute:: __slots__ :value: ['quantity', 'unit_price', 'product', 'seller', 'buyer', 'time', 'revelation_time'] .. py:attribute:: quantity :type: int Contract quantity .. py:attribute:: unit_price :type: int Contract unit price .. py:attribute:: product :type: int Product index .. py:attribute:: seller :type: str Seller ID (when passing contrtacts to the constructor of SCML2020OneShotWorld, you can also pass an interged index referring to the agent's index in the `agent_types` list) .. py:attribute:: buyer :type: str Buyer ID (when passing contrtacts to the constructor of SCML2020OneShotWorld, you can also pass an interged index referring to the agent's index in the `agent_types` list) .. py:attribute:: time :type: int Simulation step at which the contract is exceucted .. py:attribute:: revelation_time :type: int Simulation step at which the contract is revealed to its owner. Should not exceed `time` and the default `generate()` method sets it to time .. py:class:: OneShotProfile Defines all private information of a factory .. py:attribute:: cost :type: float The cost of production .. py:attribute:: input_product :type: int The index of the input product (x for $L_x$ factories) .. py:attribute:: n_lines :type: int Number of lines for this factory .. py:attribute:: shortfall_penalty_mean :type: float A positive number specifying the average penalty for selling too much. .. py:attribute:: disposal_cost_mean :type: float A positive number specifying the average penalty buying too much. .. py:attribute:: shortfall_penalty_dev :type: float A positive number specifying the std. dev. of penalty for selling too much. .. py:attribute:: disposal_cost_dev :type: float A positive number specifying the std. dev. penalty buying too much. .. py:attribute:: storage_cost_mean :type: float A positive number specifying the average cost for keeping inventory for one step. This is only used if the products are not `perishable`. .. py:attribute:: storage_cost_dev :type: float A positive number specifying the std. dev. cost for keeping inventory for one step. This is only used if the products are not `perishable`. .. py:property:: level .. py:property:: output_product .. py:property:: process .. py:method:: random(input_product: int, oneshot: bool) -> OneShotProfile :classmethod: .. py:class:: FinancialReport A report published periodically by the system showing the financial standing of an agent .. py:attribute:: __slots__ :value: ['agent_id', 'step', 'cash', 'assets', 'breach_prob', 'breach_level', 'is_bankrupt', 'agent_name'] .. py:attribute:: agent_id :type: str Agent ID .. py:attribute:: step :type: int Simulation step at the beginning of which the report was published. .. py:attribute:: cash :type: int Cash in the agent's wallet. Negative numbers indicate liabilities. .. py:attribute:: assets :type: int Value of the products in the agent's inventory @ catalog prices. .. py:attribute:: breach_prob :type: float Number of times the agent breached a contract over the total number of contracts it signed. .. py:attribute:: breach_level :type: float Sum of the agent's breach levels so far divided by the number of contracts it signed. .. py:attribute:: is_bankrupt :type: bool Whether the agent is already bankrupt (i.e. incapable of doing any more transactions). .. py:attribute:: agent_name :type: str Agent name for printing purposes .. py:method:: __str__() .. py:function:: is_system_agent(aid: str) -> bool Checks whether an agent is a system agent or not :param aid: Agent ID :returns: True if the ID is for a system agent. .. py:data:: INFINITE_COST :value: 4611686018427387903 A constant indicating an invalid cost for lines incapable of running some process .. py:data:: SYSTEM_BUYER_ID :value: 'BUYER' ID of the system buyer agent .. py:data:: SYSTEM_SELLER_ID :value: 'SELLER' ID of the system seller agent .. py:function:: is_system_agent(aid: str) -> bool Checks whether an agent is a system agent or not :param aid: Agent ID :returns: True if the ID is for a system agent. .. py:class:: Context Bases: :py:obj:`abc.ABC` A context used for generating worlds satisfying predefined conditions and testing for them .. py:method:: __call__(*args, **kwargs) .. py:method:: generate(types: tuple[type[scml.oneshot.agent.OneShotAgent], Ellipsis] | None = None, params: tuple[dict[str, Any], Ellipsis] | None = None, name: str | None = None) -> tuple[scml.oneshot.world.SCMLBaseWorld, tuple[scml.oneshot.agent.OneShotAgent]] :abstractmethod: Generates a world with one or more agents to be controlled externally and returns both :param agent_types: The types of a list of agents to be guaranteed to exist in the world :param agent_params: The parameters to pass to the constructors of these agents. None means no parameters for any agents :param name: The name of the worlds to generate. Uses a random name if not given :returns: The constructed world and a tuple of the agents created corresponding (in order) to the given agent types/params .. py:method:: is_valid_world(world: scml.oneshot.world.SCMLBaseWorld) -> bool :abstractmethod: Checks that the given world could have been generated from this context .. py:method:: is_valid_awi(awi: scml.oneshot.awi.OneShotAWI) -> bool :abstractmethod: Checks that the given AWI is connected to a world that could have been generated from this context .. py:method:: contains_context(context: Context) -> bool :abstractmethod: Checks that the any world generated from the given `context` could have been generated from this context .. py:method:: __contains__(other: Union[SCMLBaseWorld, OneShotAWI, Context]) -> bool .. py:class:: GeneralContext Bases: :py:obj:`BaseContext` A context that generates oneshot worlds with agents of a given `types` with predetermined structure and settings .. py:attribute:: perishable :type: bool :value: True .. py:attribute:: price_multiplier :type: numpy.ndarray | tuple[float, float] | float :value: (1.5, 2.0) .. py:attribute:: force_signing :value: True .. py:attribute:: n_steps :type: tuple[int, int] | int :value: (20, 200) .. py:attribute:: n_processes :type: tuple[int, int] | int :value: 2 .. py:attribute:: n_lines :type: tuple[int, int] | int :value: 10 .. py:attribute:: n_agents_per_process :type: numpy.ndarray | list[int] | tuple[int, int] | int .. py:attribute:: production_costs :type: numpy.ndarray | tuple[int, int] | int :value: (1, 4) .. py:attribute:: cash_availability :type: tuple[float, float] | float :value: (1.5, 2.5) .. py:attribute:: shortfall_penalty :type: tuple[float, float] | float :value: (0.2, 1.0) .. py:attribute:: shortfall_penalty_dev :type: tuple[float, float] | float :value: (0.0, 0.1) .. py:attribute:: disposal_cost :type: tuple[float, float] | float :value: (0.0, 0.2) .. py:attribute:: disposal_cost_dev :type: tuple[float, float] | float :value: (0.0, 0.02) .. py:attribute:: storage_cost :type: tuple[float, float] | float :value: (0.0, 0.02) .. py:attribute:: storage_cost_dev :type: tuple[float, float] | float :value: 0 .. py:attribute:: cost_increases_with_level :value: True .. py:attribute:: penalties_scale :type: str | list[str] :value: 'trading' .. py:attribute:: process_inputs :type: tuple[int, int] | int :value: 1 .. py:attribute:: process_outputs :type: numpy.ndarray | tuple[int, int] | int :value: 1 .. py:attribute:: exogenous_generation_method :value: 'profitable' .. py:attribute:: profit_means :type: numpy.ndarray | tuple[float, float] | float :value: (0.1, 0.2) .. py:attribute:: profit_stddevs :type: numpy.ndarray | tuple[float, float] | float :value: 0.05 .. py:attribute:: max_productivity :type: numpy.ndarray | tuple[float, float] | float :value: (0.8, 1.0) .. py:attribute:: initial_balance :type: numpy.ndarray | tuple[int, int] | int | None :value: None .. py:attribute:: exogenous_supply_predictability :type: tuple[float, float] | float :value: (0.6, 0.9) .. py:attribute:: exogenous_sales_predictability :type: tuple[float, float] | float :value: (0.6, 0.9) .. py:attribute:: exogenous_control :type: tuple[float, float] | float :value: -1 .. py:attribute:: exogenous_price_dev :type: tuple[float, float] | float :value: (0.1, 0.2) .. py:attribute:: equal_exogenous_supply :value: False .. py:attribute:: equal_exogenous_sales :value: False .. py:attribute:: cap_exogenous_quantities :type: bool :value: True .. py:method:: __attrs_post_init__() .. py:method:: extract_context_params(min_values: bool, level: int | None = None) -> ContextParams .. py:method:: make_predefined_config(agent_types: list[type[scml.oneshot.agent.OneShotAgent]], agent_processes: list[int], agent_params: list[dict[str, Any]], n_agents_per_process: list[int]) -> dict[str, Any] Generates a config for a world .. py:method:: contains_context(context: Context, raise_on_failure: bool = False, warn_on_failure: bool = False, n_tests: int = NTESTS) -> bool Checks that the any world generated from the given `context` could have been generated from this context .. py:method:: _assign_types(n_processes, types, params, levels, n_agents_per_process) .. py:method:: _distribute_agents(n_types) .. py:method:: make_config() -> dict[str, Any] Generates a config for a world .. py:method:: is_valid_world(world: scml.oneshot.world.SCMLBaseWorld, raise_on_failure: bool = False, warn_on_failure: bool = False, types: tuple[str | type[scml.oneshot.agent.OneShotAgent], Ellipsis] | None = None) -> bool Checks that the given world could have been generated from this context .. py:method:: contains_general_context(context: GeneralContext) -> bool Checks that the any world generated from the given `context` could have been generated from this context .. py:class:: ANACContext Bases: :py:obj:`GeneralContext` Generates a oneshot world with no constraints except compatibility with a specific ANAC competition year. .. py:attribute:: year :type: int :value: 2024 .. py:method:: __attrs_post_init__() .. py:class:: LimitedPartnerNumbersContext Bases: :py:obj:`GeneralContext` Generates a world limiting the range of the agent level, production capacity and the number of suppliers, consumers, and optionally same-level competitors. .. py:attribute:: level :type: int :value: 0 .. py:attribute:: n_consumers :type: tuple[int, int] :value: (4, 8) .. py:attribute:: n_suppliers :type: tuple[int, int] :value: (0, 0) .. py:attribute:: n_competitors :type: tuple[int, int] .. py:attribute:: buying_strength :type: Strength | None :value: None .. py:attribute:: selling_strength :type: Strength | None :value: None .. py:method:: __attrs_post_init__() .. py:method:: extract_context_params(min_values: bool, level: int | None = None) -> ContextParams .. py:method:: make_config() -> dict[str, Any] Generates a config .. py:method:: find_test_agents(world: scml.oneshot.world.SCMLBaseWorld, types: tuple[type[scml.oneshot.agent.OneShotAgent], Ellipsis] | None = None) -> list[str] .. py:method:: is_valid_world(world: scml.oneshot.world.SCMLBaseWorld, types: tuple[type[scml.oneshot.agent.OneShotAgent], Ellipsis] | None = None, raise_on_failure: bool = False, warn_on_failure: bool = False) -> bool Checks that the given world could have been generated from this context .. py:method:: contains_limited_partner_context(context: LimitedPartnerNumbersContext, raise_on_failure: bool = False, warn_on_failure: bool = False) -> bool .. py:method:: contains_context(context: Context, raise_on_failure: bool = False, warn_on_failure: bool = False, n_tests: int = NTESTS) -> bool Checks that the any world generated from the given `context` could have been generated from this context .. py:class:: FixedPartnerNumbersContext Bases: :py:obj:`LimitedPartnerNumbersContext` Generates a world limiting the range of the agent level, production capacity and the number of suppliers, consumers, and optionally same-level competitors. .. py:attribute:: level :type: int :value: 0 .. py:attribute:: n_consumers :type: int :value: 4 .. py:attribute:: n_suppliers :type: int :value: 0 .. py:attribute:: n_competitors :type: int :value: 3 .. py:method:: __attrs_post_init__() .. py:method:: extract_context_params(min_values: bool, level: int | None = None) -> ContextParams .. py:class:: ANACOneShotContext Bases: :py:obj:`ANACContext` Generates a oneshot world with no constraints except compatibility with a specific ANAC competition year. .. py:method:: __attrs_post_init__() .. py:class:: LimitedPartnerNumbersOneShotContext Bases: :py:obj:`LimitedPartnerNumbersContext` Generates a oneshot world limiting the range of the agent level, production capacity and the number of suppliers, consumers, and optionally same-level competitors. .. py:attribute:: year :type: int :value: 2024 .. py:method:: __attrs_post_init__() .. py:class:: FixedPartnerNumbersOneShotContext Bases: :py:obj:`FixedPartnerNumbersContext` Generates a world limiting the range of the agent level, production capacity and the number of suppliers, consumers, and optionally same-level competitors. .. py:class:: SupplierContext(*args, **kwargs) Bases: :py:obj:`LimitedPartnerNumbersOneShotContext` A world context that can generate any world compatible with the observation manager .. py:class:: ConsumerContext(*args, **kwargs) Bases: :py:obj:`LimitedPartnerNumbersOneShotContext` A world context that can generate any world compatible with the observation manager .. py:class:: StrongSupplierContext(*args, **kwargs) Bases: :py:obj:`SupplierContext` A supplier with almost many consumers relative to competitors .. py:class:: StrongConsumerContext(*args, **kwargs) Bases: :py:obj:`ConsumerContext` A consumer with almost many suppliers relative to competitors .. py:class:: WeakSupplierContext(*args, **kwargs) Bases: :py:obj:`SupplierContext` A supplier with few consumers relative to competitors .. py:class:: WeakConsumerContext(*args, **kwargs) Bases: :py:obj:`ConsumerContext` A consumer with few suppliers relative to competitors .. py:class:: BalancedSupplierContext(*args, **kwargs) Bases: :py:obj:`SupplierContext` A supplier with almost same number of consumers as competitors .. py:class:: BalancedConsumerContext(*args, **kwargs) Bases: :py:obj:`ConsumerContext` A consumer with almost same number of suppliers as competitors .. py:class:: RepeatingContext Bases: :py:obj:`BaseContext` Encapsulates one or more configs and switches between them when asked to generate or make something. .. py:attribute:: configs :type: tuple[dict[str, Any], Ellipsis] .. py:attribute:: randomize :type: bool :value: True .. py:attribute:: rename :type: bool :value: True .. py:attribute:: _next :type: int .. py:method:: __attrs_post_init__() .. py:method:: extract_context_params(min_values: bool, level: int | None = None) -> ContextParams .. py:method:: make_config(types: tuple[type[scml.oneshot.agent.OneShotAgent], Ellipsis] = DEFAULT_PLACEHOLDER_AGENT_TYPES, params: tuple[dict[str, Any], Ellipsis] | None = None) -> dict[str, Any] Generates a config for a world .. py:method:: from_context(context: BaseContext, n: int = 1, types: tuple[type[scml.oneshot.agent.OneShotAgent]] = DEFAULT_PLACEHOLDER_AGENT_TYPES, rename: bool = False, randomize: bool = False) :classmethod: .. py:method:: contains_repeating_context(context: RepeatingContext, raise_on_failure: bool = False, warn_on_failure: bool = False) .. py:method:: is_valid_world(world: scml.oneshot.world.SCMLBaseWorld, raise_on_failure=RAISE_ON_FAILURE, warn_on_failure=WARN_ON_FAILURE, types: tuple[str | type[scml.oneshot.agent.OneShotAgent], Ellipsis] | None = None) -> bool Checks that the given world could have been generated from this context .. py:method:: contains_context(context: Context, raise_on_failure: bool = False, warn_on_failure: bool = False, n_tests: int = NTESTS) -> bool Checks that the any world generated from the given `context` could have been generated from this context .. py:class:: ContextParams Basic Parameters you can assume about a context. Returned by `extract_context_params` .. py:attribute:: perishable :type: bool .. py:attribute:: nlines :type: int .. py:attribute:: nsuppliers :type: int .. py:attribute:: nconsumers :type: int .. py:class:: MonopolicContext Bases: :py:obj:`LimitedPartnerNumbersContext` An agent that has no competitors in the same level as themselves .. py:attribute:: n_competitors :type: tuple[int, int] :value: (0, 0) .. py:attribute:: n_agents_per_process :type: numpy.ndarray | list[int] | tuple[int, int] | int .. py:method:: __attrs_post_init__() .. py:class:: SingleAgentPerLevelSupplierContext Bases: :py:obj:`MonopolicContext` A world in which every level has exactly one factory and the agent is a supplier .. py:attribute:: level :type: int :value: 0 .. py:attribute:: n_consumers :type: tuple[int, int] :value: (1, 1) .. py:attribute:: n_suppliers :type: tuple[int, int] :value: (0, 0) .. py:attribute:: n_agents_per_process :type: numpy.ndarray | list[int] | tuple[int, int] | int .. py:class:: EutopiaContext Bases: :py:obj:`MonopolicContext` An unrealistic context in which the agent is the only one in its level and all other agents are nice. .. py:attribute:: non_competitors :type: tuple[str | type[scml.oneshot.agent.OneShotAgent], Ellipsis] .. py:class:: EutopiaConsumerContext Bases: :py:obj:`EutopiaContext` An unrealistic context in which the agent is the only consumer and all suppliers are nice. .. py:attribute:: level :type: int .. py:attribute:: n_consumers :type: tuple[int, int] :value: (0, 0) .. py:attribute:: n_suppliers :type: tuple[int, int] :value: (4, 8) .. py:class:: EutopiaSupplierContext Bases: :py:obj:`EutopiaContext` An unrealistic context in which the agent is the only supplier and all consumers are nice. .. py:attribute:: level :type: int .. py:attribute:: n_consumers :type: tuple[int, int] :value: (4, 8) .. py:attribute:: n_suppliers :type: tuple[int, int] :value: (0, 0) .. 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. .. py:data:: __all__ .. py:class:: ActionManager Bases: :py:obj:`abc.ABC` Manges actions of an agent in an RL environment. .. py:attribute:: context :type: scml.oneshot.context.BaseContext .. py:attribute:: continuous :type: bool :value: False .. py:attribute:: n_suppliers :type: int .. py:attribute:: n_consumers :type: int .. py:attribute:: n_partners :type: int .. py:method:: make_space() -> gymnasium.Space :abstractmethod: Creates the action space .. py:method:: decode(awi: scml.oneshot.awi.OneShotAWI, action: numpy.ndarray) -> dict[str, negmas.sao.common.SAOResponse] :abstractmethod: Decodes an action from an array to a `PurchaseOrder` and a `CounterMessage`. .. py:method:: encode(awi: scml.oneshot.awi.OneShotAWI, responses: dict[str, negmas.sao.common.SAOResponse]) -> numpy.ndarray Encodes an action as an array. This is only used for testing so it is optional .. py:class:: FlexibleActionManager Bases: :py:obj:`ActionManager` An action manager that matches any context. :param n_prices: Number of distinct prices allowed in the action. :param max_quantity: Maximum allowed quantity to offer in any negotiation. The number of quantities is one plus that because zero is allowed to model ending negotiation. :param n_partners: Maximum of partners allowed in the action. Remarks: - This action manager will always generate offers that are within the price and quantity limits given in its parameters. Wen decoding them, it will scale them up so that the maximum corresponds to the actual value in the world it finds itself. For example, if `n_prices` is 10 and the world has only two prices currently in the price issue, it will use any value less than 5 as the minimum price and any value above 5 as the maximum price. If on the other hand the current price issue has 20 values, then it will scale by multiplying the number given in the encoded action (ranging from 0 to 9) by 19/9 which makes it range from 0 to 19 which is what is expected by the world. - This action manager will adjust offers for different number of partners as follows: - If the true number of partners is larger than `n_partners` used by this action manager, it will simply use `n_partners` of them and always end negotiations with the rest of them. - If the true number of partners is smaller than `n_partners`, it will use the first `n_partners` values in the encoded action and increase the quantities of any counter offers (i.e. ones in which the response is REJECT_OFFER) by the amount missing from the ignored partners in the encoded action up to the maximum quantities allowed by the current negotiation context. For example, if `n_partneers` is 4 and we have only 2 partners in reality, and the received quantities from partners were [4, 3] while the maximum quantity allowed is 10 and the encoded action was [2, *, 3, *, 2, *, 1, *] (where we ignored prices), then the encoded action will be converted to [(Reject, 5, *), (Accept, 3, *)] where the 3 extra units that were supposed to be offered to the last two partners are moved to the first partner. If the maximum quantity allowed was 4 in that example, the result will be [(Reject, 4, *), (Accept, 3, *)]. .. py:attribute:: capacity_multiplier :type: int :value: 1 .. py:attribute:: n_prices :type: int :value: 2 .. py:attribute:: max_group_size :type: int :value: 2 .. py:attribute:: reduce_space_size :type: bool :value: True .. py:attribute:: extra_checks :type: bool :value: False .. py:attribute:: max_quantity :type: int .. py:method:: __attrs_post_init__() .. py:method:: make_space() -> gymnasium.spaces.MultiDiscrete | gymnasium.spaces.Box Creates the action space .. py:method:: decode(awi: scml.oneshot.awi.OneShotAWI, action: numpy.ndarray) -> 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(awi: scml.oneshot.awi.OneShotAWI, responses: dict[str, negmas.sao.common.SAOResponse]) -> numpy.ndarray Receives offers for all partners and generates the corresponding action. Used mostly for debugging and testing. .. py:data:: DefaultActionManager The default action manager .. py:class:: OneShotRLAgent(*args, models: list[scml.oneshot.rl.common.RLModel] | tuple[scml.oneshot.rl.common.RLModel, Ellipsis] = tuple(), observation_managers: list[scml.oneshot.rl.observation.ObservationManager] | tuple[scml.oneshot.rl.observation.ObservationManager, Ellipsis] = tuple(), action_managers: list[scml.oneshot.rl.action.ActionManager] | tuple[scml.oneshot.rl.action.ActionManager, Ellipsis] | None = None, fallback_type: type[scml.oneshot.agent.OneShotAgent] | None = GreedyOneShotAgent, fallback_params: dict[str, Any] | None = None, dynamic_context_switching: bool = False, randomize_test_order: bool = False, **kwargs) Bases: :py:obj:`scml.oneshot.policy.OneShotPolicy` A oneshot agent that can execute trained RL models in appropriate worlds. It falls back to the given agent type otherwise :param models: List of models to choose from. :param observation_managers: List of observation managers. Must be the same length as `models` :param action_managers: List of action managers of the same length as `models` or `None` to use the default action manager. :param fallback_type: A `OneShotAgent` type to use as a fall-back if the current world is not compatible with any observation/action managers :param fallback_params: Parameters of the `fallback_type` :param dynamic_context_switching: If `True`, the world is tested each step (instead of only at init) to find the appropriate model :param randomize_test_order: If `True`, the order at which the observation/action managers are checked for compatibility with the current world is randomized. :param \*\*kwargs: Any other OneShotPolicy parameters .. py:attribute:: _models :value: () .. py:attribute:: _action_managers :value: None .. py:attribute:: _obs_managers :value: () .. py:attribute:: _fallback_type .. py:attribute:: _dynamic_context_switching :value: False .. py:attribute:: _randomize_test_order :value: False .. py:attribute:: _fallback_params :value: None .. py:attribute:: _valid_context :type: scml.oneshot.context.Context :value: None .. py:attribute:: _valid_action_manager :type: scml.oneshot.rl.action.ActionManager :value: None .. py:attribute:: _valid_obs_manager :type: scml.oneshot.rl.observation.ObservationManager :value: None .. py:attribute:: _valid_index :type: int :value: -1 .. py:attribute:: _fallback_agent :type: scml.oneshot.agent.OneShotAgent :value: None .. py:method:: setup_fallback() .. py:method:: has_no_valid_model() .. py:method:: context_switch() .. py:method:: init() Called once after the AWI is set. Remarks: - Use this for any proactive initialization code. .. py:method:: encode_state(mechanism_states: dict[str, negmas.sao.common.SAOState]) -> scml.oneshot.rl.common.RLState Called to generate a state to be passed to the act() method. The default is all of `awi` of type `OneShotState` .. py:method:: decode_action(action: scml.oneshot.rl.common.RLAction) -> 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:: act(state: scml.oneshot.rl.common.RLState) -> scml.oneshot.rl.common.RLAction The main policy. Generates an action given a state .. py:method:: propose(*args, **kwargs) -> negmas.outcomes.Outcome | None Called when the agent is asking to propose in one negotiation .. py:method:: respond(*args, **kwargs) -> negmas.gb.common.ResponseType Called when the agent is asked to respond to an offer .. py:method:: before_step() Called at at the BEGINNING of every production step (day) .. py:method:: step() Called at at the END of every production step (day) .. py:method:: on_negotiation_failure(*args, **kwargs) -> None Called when a negotiation the agent is a party of ends without agreement .. py:method:: on_negotiation_success(*args, **kwargs) -> None Called when a negotiation the agent is a party of ends with agreement .. py:data:: RLState We assume that RL states are numpy arrays .. py:data:: RLAction We assume that RL actions are numpy arrays .. py:data:: RLModel A policy is a callable that receives a state and returns an action .. py:function:: model_wrapper(model, deterministic: bool = False) -> RLModel Wraps a stable_baselines3 model as an RL model .. py:class:: OneShotEnv(action_manager: scml.oneshot.rl.action.ActionManager, observation_manager: scml.oneshot.rl.observation.ObservationManager, reward_function: scml.oneshot.rl.reward.RewardFunction = DefaultRewardFunction(), context: scml.oneshot.context.BaseContext = FixedPartnerNumbersOneShotContext(), agent_type: type[scml.oneshot.agent.OneShotAgent] = Placeholder, agent_params: dict[str, Any] | None = None, extra_checks: bool = True, skip_after_negotiations: bool = True, render_mode=None, debug=False) Bases: :py:obj:`gymnasium.Env` The main Gymnasium class for implementing Reinforcement Learning Agents environments. The class encapsulates an environment with arbitrary behind-the-scenes dynamics through the :meth:`step` and :meth:`reset` functions. An environment can be partially or fully observed by single agents. For multi-agent environments, see PettingZoo. The main API methods that users of this class need to know are: - :meth:`step` - Updates an environment with actions returning the next agent observation, the reward for taking that actions, if the environment has terminated or truncated due to the latest action and information from the environment about the step, i.e. metrics, debug info. - :meth:`reset` - Resets the environment to an initial state, required before calling step. Returns the first agent observation for an episode and information, i.e. metrics, debug info. - :meth:`render` - Renders the environments to help visualise what the agent see, examples modes are "human", "rgb_array", "ansi" for text. - :meth:`close` - Closes the environment, important when external software is used, i.e. pygame for rendering, databases Environments have additional attributes for users to understand the implementation - :attr:`action_space` - The Space object corresponding to valid actions, all valid actions should be contained within the space. - :attr:`observation_space` - The Space object corresponding to valid observations, all valid observations should be contained within the space. - :attr:`spec` - An environment spec that contains the information used to initialize the environment from :meth:`gymnasium.make` - :attr:`metadata` - The metadata of the environment, e.g. `{"render_modes": ["rgb_array", "human"], "render_fps": 30}`. For Jax or Torch, this can be indicated to users with `"jax"=True` or `"torch"=True`. - :attr:`np_random` - The random number generator for the environment. This is automatically assigned during ``super().reset(seed=seed)`` and when assessing :attr:`np_random`. .. seealso:: For modifying or extending environments use the :class:`gymnasium.Wrapper` class .. note:: To get reproducible sampling of actions, a seed can be set with ``env.action_space.seed(123)``. .. note:: For strict type checking (e.g. mypy or pyright), :class:`Env` is a generic class with two parameterized types: ``ObsType`` and ``ActType``. The ``ObsType`` and ``ActType`` are the expected types of the observations and actions used in :meth:`reset` and :meth:`step`. The environment's :attr:`observation_space` and :attr:`action_space` should have type ``Space[ObsType]`` and ``Space[ActType]``, see a space's implementation to find its parameterized type. .. py:attribute:: _skip_after_negotiations :value: True .. py:attribute:: _extra_checks :value: True .. py:attribute:: _reward_function .. py:attribute:: _world :type: scml.oneshot.world.SCMLBaseWorld :value: None .. py:attribute:: _agent_type .. py:attribute:: _agent_params :value: None .. py:attribute:: _agent_id :type: str :value: '' .. py:attribute:: _agent :type: scml.oneshot.agent.OneShotAgent :value: None .. py:attribute:: _obs_manager .. py:attribute:: _action_manager .. py:attribute:: _context .. py:attribute:: action_space .. py:attribute:: observation_space .. py:attribute:: render_mode :value: None .. py:method:: _get_obs() .. py:method:: calc_info() Calculates info to be returned from `step()`. .. py:method:: _render_frame() Used for rendering. Override with your rendering code .. py:method:: close() After the user has finished using the environment, close contains the code necessary to "clean up" the environment. This is critical for closing rendering windows, database or HTTP connections. Calling ``close`` on an already closed environment has no effect and won't raise an error. .. py:method:: render() Compute the render frames as specified by :attr:`render_mode` during the initialization of the environment. The environment's :attr:`metadata` render modes (`env.metadata["render_modes"]`) should contain the possible ways to implement the render modes. In addition, list versions for most render modes is achieved through `gymnasium.make` which automatically applies a wrapper to collect rendered frames. .. note:: As the :attr:`render_mode` is known during ``__init__``, the objects used to render the environment state should be initialised in ``__init__``. By convention, if the :attr:`render_mode` is: - None (default): no render is computed. - "human": The environment is continuously rendered in the current display or terminal, usually for human consumption. This rendering should occur during :meth:`step` and :meth:`render` doesn't need to be called. Returns ``None``. - "rgb_array": Return a single frame representing the current state of the environment. A frame is a ``np.ndarray`` with shape ``(x, y, 3)`` representing RGB values for an x-by-y pixel image. - "ansi": Return a strings (``str``) or ``StringIO.StringIO`` containing a terminal-style text representation for each time step. The text can include newlines and ANSI escape sequences (e.g. for colors). - "rgb_array_list" and "ansi_list": List based version of render modes are possible (except Human) through the wrapper, :py:class:`gymnasium.wrappers.RenderCollection` that is automatically applied during ``gymnasium.make(..., render_mode="rgb_array_list")``. The frames collected are popped after :meth:`render` is called or :meth:`reset`. .. note:: Make sure that your class's :attr:`metadata` ``"render_modes"`` key includes the list of supported modes. .. versionchanged:: 0.25.0 The render function was changed to no longer accept parameters, rather these parameters should be specified in the environment initialised, i.e., ``gymnasium.make("CartPole-v1", render_mode="human")`` .. py:method:: reset(*, seed: int | None = None, options: dict[str, Any] | None = None) -> tuple[Any, dict[str, Any]] Resets the environment to an initial internal state, returning an initial observation and info. This method generates a new starting state often with some randomness to ensure that the agent explores the state space and learns a generalised policy about the environment. This randomness can be controlled with the ``seed`` parameter otherwise if the environment already has a random number generator and :meth:`reset` is called with ``seed=None``, the RNG is not reset. Therefore, :meth:`reset` should (in the typical use case) be called with a seed right after initialization and then never again. For Custom environments, the first line of :meth:`reset` should be ``super().reset(seed=seed)`` which implements the seeding correctly. .. versionchanged:: v0.25 The ``return_info`` parameter was removed and now info is expected to be returned. :param seed: The seed that is used to initialize the environment's PRNG (`np_random`) and the read-only attribute `np_random_seed`. If the environment does not already have a PRNG and ``seed=None`` (the default option) is passed, a seed will be chosen from some source of entropy (e.g. timestamp or /dev/urandom). However, if the environment already has a PRNG and ``seed=None`` is passed, the PRNG will *not* be reset and the env's :attr:`np_random_seed` will *not* be altered. If you pass an integer, the PRNG will be reset even if it already exists. Usually, you want to pass an integer *right after the environment has been initialized and then never again*. Please refer to the minimal example above to see this paradigm in action. :type seed: optional int :param options: Additional information to specify how the environment is reset (optional, depending on the specific environment) :type options: optional dict :returns: Observation of the initial state. This will be an element of :attr:`observation_space` (typically a numpy array) and is analogous to the observation returned by :meth:`step`. info (dictionary): This dictionary contains auxiliary information complementing ``observation``. It should be analogous to the ``info`` returned by :meth:`step`. :rtype: observation (ObsType) .. py:method:: step(action) Run one timestep of the environment's dynamics using the agent actions. When the end of an episode is reached (``terminated or truncated``), it is necessary to call :meth:`reset` to reset this environment's state for the next episode. .. versionchanged:: 0.26 The Step API was changed removing ``done`` in favor of ``terminated`` and ``truncated`` to make it clearer to users when the environment had terminated or truncated which is critical for reinforcement learning bootstrapping algorithms. :param action: an action provided by the agent to update the environment state. :type action: ActType :returns: An element of the environment's :attr:`observation_space` as the next observation due to the agent actions. An example is a numpy array containing the positions and velocities of the pole in CartPole. reward (SupportsFloat): The reward as a result of taking the action. terminated (bool): Whether the agent reaches the terminal state (as defined under the MDP of the task) which can be positive or negative. An example is reaching the goal state or moving into the lava from the Sutton and Barto Gridworld. If true, the user needs to call :meth:`reset`. truncated (bool): Whether the truncation condition outside the scope of the MDP is satisfied. Typically, this is a timelimit, but could also be used to indicate an agent physically going out of bounds. Can be used to end the episode prematurely before a terminal state is reached. If true, the user needs to call :meth:`reset`. info (dict): Contains auxiliary diagnostic information (helpful for debugging, learning, and logging). This might, for instance, contain: metrics that describe the agent's performance state, variables that are hidden from observations, or individual reward terms that are combined to produce the total reward. In OpenAI Gym gymnasium.spaces.Space Creates the observation space .. py:method:: encode(awi: scml.oneshot.awi.OneShotAWI) -> numpy.ndarray Encodes an observation from the agent's awi .. py:method:: make_first_observation(awi: scml.oneshot.awi.OneShotAWI) -> numpy.ndarray Creates the initial observation (returned from gym's reset()) .. py:method:: get_offers(awi: scml.oneshot.awi.OneShotAWI, encoded: numpy.ndarray) -> dict[str, negmas.outcomes.Outcome | None] Gets the offers from an encoded awi .. py:class:: FlexibleObservationManager Bases: :py:obj:`BaseObservationManager` An observation manager that can be used with any SCML world. :param capacity_multiplier: A factor to multiply by the number of lines to give the maximum quantity allowed in offers :param exogenous_multiplier: A factor to multiply maximum production capacity with when encoding exogenous quantities :param continuous: If given the observation space will be a Box otherwise it will be a MultiDiscrete :param n_prices: The number of prices to use for encoding the unit price (if not `continuous`) :param max_production_cost: The limit for production cost. Anything above that will be mapped to this max :param max_group_size: Maximum size used for grouping observations from multiple partners. This will be used in the number of partners in the simulation is larger than the number used for training. :param n_past_received_offers: Number of past received offers to add to the observation. :param n_bins: N. bins to use for discretization (if not `continuous`) :param n_sigmas: The number of sigmas used for limiting the range of randomly distributed variables :param extra_checks: If given, extra checks are applied to make sure encoding and decoding make sense Remarks: ... .. py:attribute:: capacity_multiplier :type: int :value: 1 .. py:attribute:: n_prices :type: int :value: 2 .. py:attribute:: max_group_size :type: int :value: 2 .. py:attribute:: reduce_space_size :type: bool :value: True .. py:attribute:: n_past_received_offers :type: int :value: 1 .. py:attribute:: extra_checks :type: bool :value: False .. py:attribute:: n_bins :type: int :value: 40 .. py:attribute:: n_sigmas :type: int :value: 2 .. py:attribute:: max_production_cost :type: int :value: 10 .. py:attribute:: exogenous_multiplier :type: int :value: 1 .. py:attribute:: max_quantity :type: int .. py:attribute:: _chosen_partner_indices :type: list[int] | None .. py:attribute:: _previous_offers :type: collections.deque .. py:attribute:: _dims :type: list[int] | None .. py:method:: __attrs_post_init__() .. py:method:: get_dims() -> list[int] Get the sizes of all dimensions in the observation space. Used if not continuous. .. py:method:: make_space() -> gymnasium.spaces.MultiDiscrete | gymnasium.spaces.Box Creates the action space .. py:method:: make_first_observation(awi: scml.oneshot.awi.OneShotAWI) -> numpy.ndarray Creates the initial observation (returned from gym's reset()) .. py:method:: encode(awi: scml.oneshot.awi.OneShotAWI) -> numpy.ndarray Encodes the awi as an array .. py:method:: extra_obs(awi: scml.oneshot.awi.OneShotAWI) -> list[tuple[float, int] | float] The observation values other than offers and previous offers. :returns: A list of tuples. Each is some observation variable as a real number between zero and one and a number of bins to use for discrediting this variable. If a single value, the number of bins will be self.n_bin .. py:method:: get_offers(awi: scml.oneshot.awi.OneShotAWI, encoded: numpy.ndarray) -> dict[str, negmas.outcomes.Outcome | None] Gets offers from an encoded awi. .. py:data:: DefaultObservationManager The default observation manager .. py:function:: random_action(obs: numpy.ndarray, env: scml.oneshot.rl.env.OneShotEnv) -> numpy.ndarray Samples a random action from the action space of the .. py:function:: random_policy(obs: numpy.ndarray, env: scml.oneshot.rl.env.OneShotEnv, pend: float = 0.05, paccept: float = 0.15) -> numpy.ndarray Ends the negotiation or accepts with a predefined probability or samples a random response. .. py:function:: greedy_policy(obs: numpy.ndarray, awi: scml.oneshot.awi.OneShotAWI, obs_manager: scml.oneshot.rl.observation.ObservationManager, action_manager: scml.oneshot.rl.action.ActionManager = FlexibleActionManager(ANACOneShotContext()), debug=False, distributor: Callable[[int, int], list[int]] = all_but_concentrated) -> numpy.ndarray A simple greedy policy. :param obs: The current observation :param awi: The AWI of the agent running the policy :param obs_manager: The observation manager used to encode the observation :param action_manager: The action manager to be used to encode the action :param debug: If True, extra assertions are tested :param distributor: A callable that receives a total quantity to be distributed over n partners and returns a list of n values that sum to this total quantity Remarks: - Accepts the subset of offers with maximum total quantity under current needs. - The remaining quantity is distributed over the remaining partners using the distributor function - Prices are set to the worst for the agent if the price range is small else they are set randomly .. py:class:: RewardFunction Bases: :py:obj:`Protocol` Represents a reward function. Remarks: - `before_action` is called before the action is executed for initialization and should return info to be passed to the call - `__call__` is called with the awi (to get the state), action and info and should return the reward .. py:method:: before_action(awi: scml.oneshot.awi.OneShotAWI) -> Any Called before executing the action from the RL agent to save any required information for calculating the reward in its return Remarks: The returned value will be passed as `info` to `__call__()` when it is time to calculate the reward. .. py:method:: __call__(awi: scml.oneshot.awi.OneShotAWI, action: dict[str, negmas.SAOResponse], info: Any) -> float Called to calculate the reward to be given to the agent at the end of a step. :param awi: `OneShotAWI` to access the agent's state :param action: The action (decoded) as a mapping from partner ID to responses to their last offer. :param info: Information generated from `before_action()`. You an use this to store baselines for calculating the reward :returns: The reward (a number) to be given to the agent at the end of the step. .. py:class:: DefaultRewardFunction Bases: :py:obj:`RewardFunction` The default reward function of SCML Remarks: - The reward is the difference between the balance before the action and after it. .. py:method:: before_action(awi: scml.oneshot.awi.OneShotAWI) -> float Called before executing the action from the RL agent to save any required information for calculating the reward in its return Remarks: The returned value will be passed as `info` to `__call__()` when it is time to calculate the reward. .. py:method:: __call__(awi: scml.oneshot.awi.OneShotAWI, action: dict[str, negmas.SAOResponse], info: float) Called to calculate the reward to be given to the agent at the end of a step. :param awi: `OneShotAWI` to access the agent's state :param action: The action (decoded) as a mapping from partner ID to responses to their last offer. :param info: Information generated from `before_action()`. You an use this to store baselines for calculating the reward :returns: The reward (a number) to be given to the agent at the end of the step. .. py:class:: DefaultOneShotAdapter(*args, **kwargs) Bases: :py:obj:`negmas.Adapter`, :py:obj:`scml.oneshot.mixins.OneShotUFunCreatorMixin` The base class of all agents running in OneShot based on OneShotAgent. Remarks: - It inherits from `Adapter` allowing it to just pass any calls not defined explicity in it to the internal `_obj` object representing the OneShotAgent. .. py:attribute:: _obj :type: scml.oneshot.agent.OneShotAgent .. py:method:: make_ufun(add_exogenous: bool, in_adapter=False) .. py:method:: on_negotiation_failure(partners, annotation, mechanism, state) Called whenever a negotiation ends without agreement .. py:method:: on_negotiation_success(contract: negmas.Contract, mechanism) Called whenever a negotiation ends with agreement .. 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:: 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:: init_() Called to initialize the agent **after** the world is initialized. the AWI is accessible at this point. .. py:method:: init() Override this method to modify initialization logic .. py:method:: reset() .. py:method:: is_clean() -> bool .. py:method:: before_step() .. py:method:: step() Override this method to modify stepping logic .. 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:: 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:: awi :type: scml.oneshot.awi.OneShotAWI Gets the Agent-world interface. .. py:property:: short_type_name Returns a short name of the type of this entity .. py:class:: _StdSystemAgent(*args, role, **kwargs) Bases: :py:obj:`DefaultOneShotAdapter` Implements an agent for handling system operations .. py:attribute:: id The unique ID of this entity .. py:attribute:: name A convenient name of the entity (intended primarily for printing/logging/debugging). .. py:attribute:: profile :value: None .. py:property:: type_name Returns a short name of the type of this entity .. py:property:: short_type_name Returns a short name of the type of this entity .. py:method:: respond_to_negotiation_request(initiator: str, issues: list[negmas.Issue], annotation: dict[str, Any], mechanism: negmas.NegotiatorMechanismInterface) -> Optional[negmas.Negotiator] .. py:method:: before_step() .. py:method:: step() Override this method to modify stepping logic .. py:method:: init() Override this method to modify initialization logic .. 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:: sign_all_contracts(contracts: list[negmas.Contract]) -> list[Optional[str]] Signs all contracts .. py:class:: OneShotUFun(ex_pin: int, ex_qin: int, ex_pout: int, ex_qout: int, input_product: int, input_agent: bool, output_agent: bool, production_cost: float, disposal_cost: float, storage_cost: float, shortfall_penalty: float, input_penalty_scale: float | None, output_penalty_scale: float | None, storage_penalty_scale: float | None, n_input_negs: int, n_output_negs: int, current_step: int, agent_id: str | None, time_range: tuple[int, int], inventory_in: int = 0, inventory_out: int = 0, input_qrange: tuple[int, int] = (0, 0), input_prange: tuple[int, int] = (0, 0), output_qrange: tuple[int, int] = (0, 0), output_prange: tuple[int, int] = (0, 0), force_exogenous: bool = True, n_lines: int = 10, normalized: bool = False, current_balance: int | float = float('inf'), suppliers: set[str] = set(), consumers: set[str] = set(), perishable=True, **kwargs) Bases: :py:obj:`negmas.preferences.StationaryMixin`, :py:obj:`negmas.preferences.UtilityFunction` Calculates the utility function of a list of contracts or offers. :param force_exogenous: Is the agent forced to accept exogenous contracts given through `ex_*` arguments? :param ex_pin: total price of exogenous inputs for this agent :param ex_qin: total quantity of exogenous inputs for this agent :param ex_pout: total price of exogenous outputs for this agent :param ex_qout: total quantity of exogenous outputs for this agent. :param cost: production cost of the agent. :param disposal_cost: disposal cost per unit of input/output. :param shortfall_penalty: penalty for failure to deliver one unit of output. :param input_agent: Is the agent an input agent which means that its input product is the raw material :param output_agent: Is the agent an output agent which means that its output product is the final product :param n_lines: Number of production lines. If None, will be read through the AWI. :param input_product: Index of the input product. If None, will be read through the AWI :param input_qrange: A 2-int tuple giving the range of input quantities negotiated. If not given will be read through the AWI :param input_prange: A 2-int tuple giving the range of input unit prices negotiated. If not given will be read through the AWI :param output_qrange: A 2-int tuple giving the range of output quantities negotiated. If not given will be read through the AWI :param output_prange: A 2-int tuple giving the range of output unit prices negotiated. If not given will be read through the AWI :param n_input_negs: How many input negotiations are allowed. If not given, it will be the number of suppliers as given by the AWI :param n_output_negs: How many output negotiations are allowed. If not given, it will be the number of consumers as given by the AWI :param current_step: Current simulation step. Needed only for `ufun_range` when returning best outcomes :param normalized: If given the values returned by `from_*`, `utility_range` and `__call__` will all be normalized between zero and one. Remarks: - The utility function assumes that the agent will have to pay for all its input products but will receive money only for the output products it could generate and sell. - The utility function respects production capacity (n. lines). The agent cannot produce more than the number of lines it has. - disposal cost is paid for items bought but not produced only. Items consumed in production (i.e. sold) are not counted. .. py:attribute:: agent_id .. py:attribute:: time_range .. py:attribute:: suppliers .. py:attribute:: consumers .. py:attribute:: current_balance .. py:attribute:: normalized :value: False .. py:attribute:: input_penalty_scale .. py:attribute:: storage_penalty_scale .. py:attribute:: output_penalty_scale .. py:attribute:: current_step .. py:attribute:: inventory_in :value: 0 .. py:attribute:: inventory_out :value: 0 .. py:attribute:: n_input_negs .. py:attribute:: perishable :value: True .. py:attribute:: n_output_negs .. py:attribute:: force_exogenous :value: True .. py:attribute:: n_lines :value: 10 .. py:attribute:: input_product .. py:attribute:: reserved_value .. py:attribute:: _signed_agreements :type: list[tuple[int, int, int]] :value: [] .. py:attribute:: _signed_is_output :type: list[bool] :value: [] .. py:attribute:: _registered_sale_failures :type: set[str] .. py:attribute:: _registered_supply_failures :type: set[str] .. py:property:: best_option :type: UFunLimit Best possible options .. py:property:: worst_option :type: UFunLimit Best possible options .. py:method:: register_supply_failure(supplier_id: str) .. py:method:: register_sale_failure(consumer_id: str) .. py:method:: register_sale(q: int, p: int, t: int) Registers a sale to be considered when calculating utilities .. py:method:: register_supply(q: int, p: int, t: int) Registers a supply to be considered when calculating utilities .. py:method:: xml(issues) -> str :abstractmethod: .. py:method:: eval(offer: tuple[int, int, int] | None) -> float Calculates the utility function given a single contract. Remarks: - This method calculates the utility value of a single offer assuming all other negotiations end in failure. - It can only be called for agents that exist in the first or last layer of the production graph. .. py:method:: from_contracts(contracts: Iterable[negmas.Contract], return_info: Literal[False] = False, ignore_exogenous=True) -> float from_contracts(contracts: Iterable[negmas.Contract], return_info: Literal[True], ignore_exogenous=True) -> UtilityInfo Calculates the utility function given a list of contracts :param contracts: A list/tuple of contracts :param ignore_exogenous: If given, any contracts with a system agent will be ignored. Remarks: - This method ignores any unsigned contracts passed to it. - We do not consider time at all so it is implicitly assumed that all contracts have the same delivery time value. - The reason for having the `ignore_exogenous` parameter is to avoid double counting exogenous contracts if their information is passed during construction of the ufun and they also exist in the list of `contracts` passed here. .. py:method:: outcome_as_tuple(offer) :staticmethod: .. py:method:: from_offers(offers: tuple[tuple[int, int, int | float] | None, Ellipsis] | dict[str, tuple[int, int, int] | None], outputs: tuple[bool, Ellipsis] | None = None, return_info: Literal[False] = False, ignore_signed_contracts: bool = True) -> float from_offers(offers: tuple[tuple[int, int, int | float] | None, Ellipsis] | dict[str, tuple[int, int, int] | None], outputs: tuple[bool, Ellipsis] | None, return_info: Literal[True], ignore_signed_contracts: bool = True) -> UtilityInfo Calculates the utility value given a list of offers and whether each offer is for output or not (= input). :param offers: An iterable (e.g. list) of tuples each with three values: (quantity, time, unit price) IN THAT ORDER. Time is ignored and can be set to any value. :param outputs: An iterable of the same length as offers of booleans specifying for each offer whether it is an offer for buying the agent's output product. :param return_info: If true, detailed utility information is returned as Utility Info :param ignore_signed_contracts: If true, ignores the registered signed contracts. This means that only exogenous contracts and offers will be used in evaluating the utility. Remarks: - This method takes into account the exogenous contract information passed when constructing the ufun. - You can pass a dictionary mapping partner ID to an offer and the system will use the correct value for the corresponding outputs array. .. py:method:: from_aggregates(qin: int, qout_signed: int, qout_sold: int, pin: int, pout: int, input_penalty: float, output_penalty: float, storage_penalty: float) -> float Calculates the utility from aggregates of input/output quantity/prices :param qin: Input quantity (total including all exogenous contracts). :param qout_signed: Output quantity (total including all exogenous contracts) that the agent agreed to sell. :param qout_sold: Output quantity (total including all exogenous contracts) that the agent will actually sell. :param pin: Input total price (i.e. unit price * qin). :param pout: Output total price (i.e. unit price * qin). :param input_penalty: total disposal cost :param output_penalty: total shortfall penalty :param storage_penalty: total storage penalty Remarks: - Most likely, you do not need to directly call this method. Consider `from_offers` and `from_contracts` that take current balance and exogenous contract information (passed during ufun construction) into account. - The method respects production capacity (n. lines). The agent cannot produce more than the number of lines it has. - This method does not take exogenous contracts or current balance into account. - The method assumes that the agent CAN pay for all input and production. .. py:method:: breach_level(qin: int = 0, qout: int = 0) Calculates the breach level that would result from a given quantities .. py:method:: is_breach(qin: int = 0, qout: int = 0) Whether the given quantities would lead to a breach. .. py:property:: max_utility The maximum possible utility value .. py:property:: min_utility The minimum possible utility value .. py:method:: minmax(*args, **kwargs) -> tuple[float, float] Finds the range of the given utility function for the given outcomes :param self: The utility function :param issues: List of issues (optional) :param outcomes: A collection of outcomes (optional) :param max_cardinality: the maximum number of outcomes to try sampling (if sampling is used and outcomes are not given) :param above_reserve: If given, the minimum and maximum will be set to reserved value if they were less than it. :returns: (lowest, highest) utilities in that order .. py:method:: extreme_outcomes(outcome_space: negmas.outcomes.OutcomeSpace | None = None, issues: Iterable[negmas.outcomes.Issue] | None = None, outcomes: Iterable[negmas.outcomes.Outcome] | None = None, max_cardinality=1000) -> tuple[negmas.outcomes.Outcome, negmas.outcomes.Outcome] .. py:method:: utility_range(outcome_space: negmas.outcomes.OutcomeSpace | None = None, issues: list[negmas.outcomes.Issue] | None = None, outcomes: list[negmas.outcomes.Outcome] | None = None, return_outcomes=False, max_n_outcomes=1000) -> tuple[float, float] | tuple[float, float, negmas.outcomes.Outcome, negmas.outcomes.Outcome] Finds the utility range and optionally returns the corresponding outcomes from a given issue space or in a single negotiation. :param issues: The set of issues of the negotiation. If not given it will be read from the AWI. Note that you cannot specify these issues except for agent in the first or last layer of the production graph (because otherwise, the agent cannot know whether this negotiation is for buying of selling). :param outcomes: A list of outcomes to consider. Using outcomes is much slower than using issues and you should never pass both. :param infeasible_cutoff: A utility value under which we consider the outcome infeasible. :param return_outcomes: If given the worst and best outcomes (in that order) will be returned. :param max_n_outcomes: Maximum number of outcomes to try. Not used. :returns: A tuple of worst and best utility values if `return_outcomes` is `False`. otherwise, the worst and best outcomes are appended to the returned utilities leading to a 4-items tuple instead of two. Remarks: - You will get a warning if you use a list of outcomes here because it is too slow. - You should only pass `issues` if you know that the agent is either an input agent or an output agent. Agents in the middle of the production graph cannot know whether these issues are for buying of for selling. To find the utility range for these agents, you can use `worst` and `best` that allow specifying input and output issues separately. - It is always assumed that the range required is for a single negotiation not a set of negotiations and under the assumption that all other negotiations if any will end in failure .. py:method:: _is_midlevel() .. py:method:: find_limit(best: bool, n_input_negs=None, n_output_negs=None, secured_input_quantity=0, secured_input_unit_price=0.0, secured_output_quantity=0, secured_output_unit_price=0.0, ignore_signed_contracts: bool = True) -> UFunLimit Finds either the maximum or the minimum of the ufun. :param best: Best(max) or worst (min) ufun value? :param n_input_negs: How many input negs are we to consider? None means all :param n_output_negs: How many output negs are we to consider? None means all :param secured_input_quantity: A quantity that MUST be bought :param secured_input_unit_price: The (average) unit price of the quantity that MUST be bought. :param secured_output_quantity: A quantity that MUST be sold. :param secured_output_unit_price: The (average) unit price of the quantity that MUST be sold. :param ignore_signed_contracts: If True all signed contracts will be ignored. Use secured_* to pass this information if you need to in this case. Remarks: - You can use the `secured_*` arguments and control over the number of negotiations to consider to find the utility limits **given** some already concluded and signed contracts .. py:method:: best() -> negmas.outcomes.Outcome .. py:method:: worst() -> negmas.outcomes.Outcome .. py:method:: find_limit_brute_force(best, n_input_negs=None, n_output_negs=None, secured_input_quantity=0, secured_input_unit_price=0.0, secured_output_quantity=0, secured_output_unit_price=0.0, ignore_signed_contracts=True) -> UFunLimit Finds either the maximum and the minimum of the ufun. :param best: Best(max) or worst (min) ufun value? :param n_input_negs: How many input negs are we to consider? None means all :param n_output_negs: How many output negs are we to consider? None means all :param secured_input_quantity: A quantity that MUST be bought :param secured_input_unit_price: The (average) unit price of the quantity that MUST be bought. :param secured_output_quantity: A quantity that MUST be sold. :param secured_output_unit_price: The (average) unit price of the quantity that MUST be sold. Remarks: - You can use the `secured_*` arguments and control over the number of negotiations to consider to find the utility limits **given** some already concluded and signed contracts - Note that this function CANNOT take into account the sales or supplies already signed (and registered via `register_sale` and/or `register_supply`). You MUST pass the quantities and prices for signed contracts through the secured_* parameters. :returns: worst and best outcome information in the form of `UFunLimit` tuple. .. py:method:: ok_to_buy_at(unit_price: float) -> bool Checks if the unit price can -- even in principle -- be acceptable for buying Remarks: - This method is **very** optimistic. If it returns `False`, an agent should **never** buy at this price. If it returns `True`, it may *still be a bad idea* to buy at this price. - If we **buy** at this price, the **best** case scenario is that we pay it and pay production cost then receive the unit price of one output. - If we do **not** buy at this price, the **worst** case scenario is that we will pay shortfall penalty for one item - We should **NOT** buy if the best case scenario when buying is worse than the worst case scenario when not buying. - If called for agents not at the end of the production chain, it will always return `True` because in these cases we do not know what the the unit price for the output so there is nothing to compare with. .. py:method:: ok_to_sell_at(unit_price: float) -> bool Checks if the unit price can -- even in principle -- be acceptable for selling Remarks: - This method is **very** optimistic. If it returns `False`, an agent should **never** sell at this price. If it returns `True`, it may *still be a bad idea* to sell at this price. - Sales decisions does not affect in any way the amount we pay for input materials. It only affects the amount we produce, the amout we get paid in sales and the amount we pay as disposal cost and shortfall penalty. - If we agree to sell an item at this price, the best case scenario is that we can actually produce this item and sell it. We pay production cost and receive the given unit price. - If we do **not** sell at this price, the worst case scenario is that we really needed that sale. In this case, we will pay disposal cost for one item. - We should **NOT** sell if the best case scenario when selling is worse than the worst case scenario when not selling. - If called for agents not at the beginning of the production chain, it will always return `True` because in these cases we do not know what the the unit price for the input so there is nothing to compare with. .. py:class:: UFunLimit Bases: :py:obj:`tuple` .. py:attribute:: utility .. py:attribute:: input_quantity .. py:attribute:: input_price .. py:attribute:: output_quantity .. py:attribute:: output_price .. py:attribute:: exogenous_input_quantity .. py:attribute:: exogenous_input_price .. py:attribute:: exogenous_output_quantity .. py:attribute:: exogenous_output_price .. py:attribute:: inventory_input .. py:attribute:: inventory_output .. py:attribute:: producible .. py:class:: UtilityInfo .. py:attribute:: producible :type: int .. py:attribute:: total_input :type: int .. py:attribute:: total_output :type: int .. py:attribute:: shortfall_quantity :type: int .. py:attribute:: shortfall_penalty :type: float .. py:attribute:: remaining_quantity :type: int .. py:attribute:: disposal_cost :type: float .. py:attribute:: storage_cost :type: float .. py:attribute:: utility :type: float .. py:class:: SCMLBaseWorld(catalog_prices: numpy.ndarray, profiles: list[scml.oneshot.common.OneShotProfile], agent_types: list[type[scml.oneshot.agent.OneShotAgent]], agent_params: list[dict[str, Any]], catalog_quantities: int | numpy.ndarray = 50, financial_report_period=5, bankruptcy_limit=0.0, penalize_bankrupt_for_future_contracts=True, penalties_scale: Literal['trading', 'catalog', 'unit', 'none'] = 'trading', exogenous_contracts: Collection[scml.oneshot.common.OneShotExogenousContract] = tuple(), exogenous_dynamic: bool = False, exogenous_force_max: bool = False, initial_balance: numpy.ndarray | tuple[int, int] | int = 1000, compact=True, no_logs=True, fast=True, n_steps=1000, time_limit=60 * 15, sync_calls=False, neg_n_steps=20, neg_time_limit=None, neg_hidden_time_limit=60, neg_step_time_limit=20, negotiation_speed=None, shuffle_negotiations=False, one_offer_per_step=False, publish_exogenous_summary=True, publish_trading_prices=True, publish_assets=False, publish_production_capacity=True, price_multiplier=0.0, price_range_fraction=0.0, wide_price_range=False, allow_zero_quantity: bool = False, trading_price_discount=0.9, signing_delay=0, force_signing=False, batch_signing=True, name: str | None = None, agent_name_reveals_position: bool = True, agent_name_reveals_type: bool = True, inventory_valuation_catalog=0, inventory_valuation_trading=0, perishable=True, horizon=0, one_time_per_negotiation=True, quantity_multiplier: float = 1.0, nullify_bankrupt_contracts: bool = False, debug: bool = False, verbose: bool = False, **kwargs) Bases: :py:obj:`negmas.TimeInAgreementMixin`, :py:obj:`negmas.World`\ [\ :py:obj:`scml.oneshot.awi.OneShotAWI`\ , :py:obj:`scml.oneshot.sysagents.DefaultOneShotAdapter`\ ] Implements the a generalized form of SCML-OneShot game which supports both oneshot and standard simulations :param catalog_prices: An n_products vector (i.e. n_processes+1 vector) giving the catalog price of all products :param profiles: An n_agents list of `OneShotFactoryProfile` objects specifying the private profile of the factory associated with each agent. :param agent_types: An n_agents list of strings/ `OneShotAgent` classes specifying the type of each agent :param agent_params: An n_agents dictionaries giving the parameters of each agent :param catalog_quantities: The quantities in the past for which catalog_prices are the average unit prices. This is used when updating the trading prices. If set to zero then the trading price will follow the market price and will not use the catalog_price (except for products that are never sold in the market for which the trading price will take the default value of the catalog price). If set to a large value (e.g. 10000), the price at which a product is sold will not affect the trading price :param financial_report_period: The number of steps between financial reports. If < 1, it is a fraction of n_steps :param exogenous_force_max: If true, exogenous contracts are forced to be signed independent of the setting of `force_signing` :param compact: If True, no logs will be kept and the whole simulation will use a smaller memory footprint :param n_steps: Number of simulation steps (can be considered as days). :param time_limit: Total time allowed for the complete simulation in seconds. :param neg_n_steps: Number of negotiation steps allowed for all negotiations. :param neg_time_limit: Total time allowed for a complete negotiation in seconds. :param neg_step_time_limit: Total time allowed for a single step of a negotiation. in seconds. :param negotiation_speed: The number of negotiation steps that pass in every simulation step. If 0, negotiations will be guaranteed to finish within a single simulation step :param signing_delay: The number of simulation steps to pass between a contract is concluded and signed :param name: The name of the simulations :param \*\*kwargs: Other parameters that are passed directly to `SCML2020World` constructor. .. py:attribute:: _verbose :value: False .. py:attribute:: _debug :value: False .. py:attribute:: agents :type: dict[str, scml.oneshot.sysagents.DefaultOneShotAdapter] .. py:attribute:: publish_assets :value: False .. py:attribute:: publish_production_capacity :value: True .. py:attribute:: perishable :value: True .. py:attribute:: horizon :value: 0 .. py:attribute:: price_range_fraction :value: 0.0 .. py:attribute:: nullify_bankrupt_contracts :value: False .. py:attribute:: inventory_valuation_catalog :value: 0 .. py:attribute:: inventory_valuation_trading :value: 0 .. py:attribute:: allow_zero_quantity :value: False .. py:attribute:: _profits :type: dict[str, list[float]] .. py:attribute:: _breach_levels :type: dict[str, list[float]] .. py:attribute:: _breaches_of :type: dict[str, list[bool]] .. py:attribute:: _inventory_input :type: dict[str, int] .. py:attribute:: _inventory_output :type: dict[str, int] .. py:attribute:: _productivity :type: dict[str, float] .. py:attribute:: _shortfall_quantity :type: dict[str, int] .. py:attribute:: _shortfall_penalty :type: dict[str, float] .. py:attribute:: _storage_cost :type: dict[str, float] .. py:attribute:: _disposal_cost :type: dict[str, float] .. py:attribute:: _penalized_quantity :type: dict[str, int] .. py:attribute:: _n_nullified :type: int :value: 0 .. py:attribute:: _nullified_quantity :type: int :value: 0 .. py:attribute:: _nullified_price :type: float :value: 0 .. py:attribute:: _activity :value: 0 .. py:attribute:: trading_price_discount :value: 0.9 .. py:attribute:: catalog_quantities :value: 50 .. py:attribute:: publish_exogenous_summary :value: True .. py:attribute:: price_multiplier :value: 0.0 .. py:attribute:: wide_price_range :value: False .. py:attribute:: publish_trading_prices :value: True .. py:attribute:: penalize_bankrupt_for_future_contracts :value: True .. py:attribute:: agent_disposal_cost :type: dict[str, list[float]] .. py:attribute:: agent_storage_cost :type: dict[str, list[float]] .. py:attribute:: agent_shortfall_penalty :type: dict[str, list[float]] .. py:attribute:: compact :value: True .. py:attribute:: quantity_multiplier :value: 1.0 .. py:attribute:: one_time_per_negotiation :value: True .. py:attribute:: exogenous_dynamic :value: False .. py:attribute:: penalties_scale :value: 'trading' .. py:attribute:: bankruptcy_limit :value: -0.0 .. py:attribute:: profiles .. py:attribute:: catalog_prices .. py:attribute:: process_inputs .. py:attribute:: process_outputs .. py:attribute:: n_products .. py:attribute:: n_processes .. py:attribute:: exogenous_force_max :value: False .. py:attribute:: financial_reports_period :value: 5 .. py:attribute:: controller_types .. py:attribute:: agent_types .. py:attribute:: agent_params .. py:attribute:: agent_unique_types .. py:attribute:: agent_n_contracts .. py:attribute:: suppliers :type: list[list[str]] .. py:attribute:: consumers :type: list[list[str]] .. py:attribute:: production_capacity :type: list[int] .. py:attribute:: agent_processes :type: dict[str, list[int]] .. py:attribute:: agent_inputs :type: dict[str, list[int]] .. py:attribute:: agent_outputs :type: dict[str, list[int]] .. py:attribute:: agent_consumers :type: dict[str, list[str]] .. py:attribute:: agent_suppliers :type: dict[str, list[str]] .. py:attribute:: agent_profiles :type: dict[str, scml.oneshot.common.OneShotProfile] .. py:attribute:: is_bankrupt :type: dict[str, bool] .. py:attribute:: exogenous_contracts :type: dict[int:list[Contract]] .. py:attribute:: _traded_quantity .. py:attribute:: _real_price .. py:attribute:: _sold_quantity .. py:attribute:: _trading_price .. py:attribute:: _betas .. py:attribute:: _betas_sum .. py:attribute:: _input_quantity .. py:attribute:: _input_price .. py:attribute:: _output_quantity .. py:attribute:: _output_price .. py:attribute:: exogenous_qout .. py:attribute:: exogenous_qin .. py:attribute:: exogenous_pout .. py:attribute:: exogenous_pin .. py:attribute:: exogenous_contracts_summary :value: [] .. py:attribute:: initial_balances .. py:attribute:: _max_n_lines .. py:attribute:: a2i .. py:attribute:: _current_issues :type: list[list[negmas.ContiguousIssue]] :value: [] .. py:attribute:: __contracts :type: dict[str, list[negmas.Contract]] .. py:attribute:: _agent_negotiations :type: dict[str, dict[str, dict[str, scml.oneshot.common.NegotiationDetails]]] .. py:method:: action_info_cols() -> list[tuple[str, type]] .. py:method:: extract_action_info(action: Any) -> list[int] .. py:method:: agreement_info_cols() -> list[tuple[str, type]] .. py:method:: extract_agreement_info(agreement: negmas.Outcome | None) -> list[int] .. py:method:: extra_neg_info(info: negmas.situated.NegotiationInfo) -> dict[str, Any] .. py:method:: replace_agents(config: dict, old_types: tuple[str | type[scml.oneshot.agent.OneShotAgent], Ellipsis] | list[str | type[scml.oneshot.agent.OneShotAgent]], types: tuple[str | type[scml.oneshot.agent.OneShotAgent], Ellipsis] | list[str | type[scml.oneshot.agent.OneShotAgent]], params: list[dict[str, Any]] | tuple[dict[str, Any], Ellipsis] | None = None) :classmethod: Replaces all agents of a given type by agents of a new type .. py:method:: generate(agent_types: tuple[str | type[scml.oneshot.agent.OneShotAgent], Ellipsis] | list[str | type[scml.oneshot.agent.OneShotAgent]] | type[scml.oneshot.agent.OneShotAgent] | str, agent_params: list[dict[str, Any]] | tuple[dict[str, Any], Ellipsis] | None = None, agent_processes: list[int] | None = None, n_steps: tuple[int, int] | int = (50, 200), n_processes: tuple[int, int] | int = 2, n_lines: numpy.ndarray | tuple[int, int] | int = 10, n_agents_per_process: numpy.ndarray | tuple[int, int] | int = (4, 8), process_inputs: numpy.ndarray | tuple[int, int] | int = 1, process_outputs: numpy.ndarray | tuple[int, int] | int = 1, production_costs: numpy.ndarray | tuple[int, int] | int = (1, 4), profit_means: numpy.ndarray | tuple[float, float] | float = (0.1, 0.2), profit_stddevs: numpy.ndarray | tuple[float, float] | float = 0.05, max_productivity: numpy.ndarray | tuple[float, float] | float = (0.8, 1.0), initial_balance: numpy.ndarray | tuple[int, int] | int | None = None, exogenous_supply_predictability: tuple[float, float] | float = (0.6, 0.9), exogenous_sales_predictability: tuple[float, float] | float = (0.6, 0.9), exogenous_control: tuple[float, float] | float = -1, cash_availability: tuple[float, float] | float = (1.5, 2.5), shortfall_penalty: tuple[float, float] | float = (0.2, 1.0), shortfall_penalty_dev: tuple[float, float] | float = (0.0, 0.1), disposal_cost: tuple[float, float] | float = (0.0, 0.2), disposal_cost_dev: tuple[float, float] | float = (0.0, 0.02), storage_cost: tuple[float, float] | float = (0.0, 0.02), storage_cost_dev: tuple[float, float] | float = 0, exogenous_price_dev: tuple[float, float] | float = (0.1, 0.2), price_multiplier: numpy.ndarray | tuple[float, float] | float = (1.5, 2.0), cost_increases_with_level=True, equal_exogenous_supply=False, equal_exogenous_sales=False, force_signing=True, profit_basis=np.max, random_agent_types: bool = False, penalties_scale: str | list[str] = 'trading', cap_exogenous_quantities: bool = True, exogenous_generation_method='profitable', perishable: bool | None = True, max_supply: numpy.ndarray | tuple[float, float] | float = (0.8, 1.0), **kwargs) -> dict[str, Any] :classmethod: Generates the configuration for a world :param agent_types: All agent types :param agent_params: Agent parameters used to initialize them :param n_steps: Number of simulation steps :param n_processes: Number of processes in the production chain :param n_lines: Number of lines per factory :param process_inputs: Number of input units per process :param process_outputs: Number of output units per process :param production_costs: Production cost per factory :param profit_means: Mean profitability per production level (i.e. process). :param profit_stddevs: Std. Dev. of the profitability of every level (i.e. process). :param max_productivity: Maximum possible productivity per level (i.e. process). :param max_supply: Maximum possible supply level to the market, :param initial_balance: The initial balance of all agents :param n_agents_per_process: Number of agents per process :param agent_processes: The process for each agent. If not `None` , it will override `n_agents_per_process` and must be a list/tuple of the same length as `agent_types` . Morevoer, `random_agent_types` must be False in this case :param cost_increases_with_level: If true, production cost will be higher for processes nearer to the final product. :param profit_basis: The statistic used when controlling catalog prices by profit arguments. It can be np.mean, np.median, np.min, np.max or any Callable[[list[float]], float] and is used to summarize production costs at every level. :param equal_exogenous_supply: If true, external supply will be distributed equally among all agents in the first layer :param equal_exogenous_sales: If true, external sales will be distributed equally among all agents in the last layer :param exogenous_supply_predictability: How predictable are exogenous supplies of each agent over time. 1.0 means that every agent will have the same quantity for all of its contracts over time. 0.0 means quantities per agent are completely random :param exogenous_sales_predictability: How predictable are exogenous supplies of each agent over time. 1.0 means that every agent will have the same quantity for all of its contracts over time. 0.0 means quantities per agent are completely random :param force_signing: Whether to force contract signatures (exogenous contracts are treated in the same way). :param exogenous_control: How much control does the agent have over exogenous contract signing. Only effective if force_signing is False and use_exogenous_contracts is True :param cap_exogenous_quantities: If True, all exogenous quantities in all contracts are capped to be no more than the number of lines :param cash_availability: The fraction of the total money needs of the agent to work at maximum capacity that is available as `initial_balance` . This is only effective if `initial_balance` is set to `None` . :param exogenous_control: How much control does the agent have over exogenous contract signing. Only effective if force_signing is False and use_exogenous_contracts is True :param disposal_cost: A range to sample mean-disposal costs for all factories from (only used if perishable is True) :param shortfall_penalty: A range to sample mean-shortfall penalty for all factories from :param storage_cost: A range to sample mean-storage costs fro all factories from (only used if perishable is False) :param disposal_cost_dev: A range to sample std. dev of disposal costs for all factories from :param shortfall_penalty_dev: A range to sample std. dev of shortfall penalty for all factories from :param storage_cost_dev: The standard deviation of storage cost relative to the mean price :param exogenous_price_dev: The standard deviation of exogenous contract prices relative to the mean price :param price_multiplier: A value to multiply with trading/catalog price to get the upper limit on prices for all negotiations :param random_agent_types: If True, the final agent types used by the generator will always be sampled from the given types. If False, this random sampling will only happen if len(agent_types) != n_agents. :param penalties_scale: What are `disposal_cost` and `shortfall_penalty` relative to. There are four options: `trading`, `catalog` mean trading and catalog prices of the product. `unit` means the unit price in the contract and `none` means the `storage-cost` and `shortfall_penalty` are absolute values (in money unit). If not given will be read through the AWI :param exogenous_generation_method: the generation method. This is only for compatibility with SCML2020World and is not used. :param perishable: If True, storage_cost is set to zero as there is no storage and if False, disposal_cost is set to zero as there is no disposal. If None, neither is overridden. :param \*\*kwargs: :returns: world configuration as a Dict[str, Any]. A world can be generated from this dict by calling OneShotWorld(**d) Remarks: - There are two general ways to use this generator: 1. Pass `random_agent_types = False`, and pass `agent_types`, `agent_processes` to control placement of each agent in each level of the production graph. 2. Pass `random_agent_types = True` and pass `agent_types`, `n_agents_per_process` to make the system randomly place the specified number of agents in each production level - Most parameters (i.e. `process_inputs` , `process_outputs` , `n_agents_per_process` , `costs` ) can take a single value, a tuple of two values, or a list of values. If it has a single value, it is repeated for all processes/factories as appropriate. If it is a tuple of two numbers $(i, j)$, each process will take a number sampled from a uniform distribution supported on $[i, j]$ inclusive. If it is a list of values, of the length `n_processes` , it is used as it is otherwise, it is used to sample values for each process. .. py:method:: type_name_for_logs(agent: scml.oneshot.agent.OneShotAgent | None) -> str | None .. py:property:: negotiated_contract_records :type: list[dict[str, Any]] .. py:property:: exogenous_contract_records :type: list[dict[str, Any]] .. py:method:: current_balance(agent_id: str) .. py:method:: add_financial_report(agent: scml.oneshot.sysagents.DefaultOneShotAdapter, reports_agent, reports_time) -> None Records a financial report for the given agent in the agent indexed reports and time indexed reports :param agent: The agent :param reports_agent: A dictionary of financial reports indexed by agent id :param reports_time: A dictionary of financial reports indexed by time Returns: .. py:property:: agent_contracts .. py:method:: _update_exogenous(s) .. py:method:: step_with(actions: dict[str, dict[str, negmas.SAOResponse]], init=False) -> bool Runs a simulation step for the agents given in keys passing the corresponding values as counter offers. :returns: False if this is the last negotiation. Remarks: - You must call this with `init=True` once at the beginning of every simulation to make sure that `init()` and other initialization code is called correctly. - Every step advances all negotiations one step. - Negotiators belonging to the given agents are never called as long as a corresponding action (response) is given in the agents dict. - The world MUST be created with `one_offer_per_step` passed as `True` (default is `False`). .. py:method:: simulation_step(stage=0) A single step of the simulation. :param stage: How many times so far was this method called within the current simulation step Remarks: - Using the stage parameter, it is possible to have `Operations` . `SimulationStep` several times with the list of operations while differentiating between these calls. .. py:method:: _breach_record(perpetrator, level, type_) -> dict[str, Any] .. py:method:: _adjust_contract_types(contract) .. py:method:: on_contract_signed(contract: negmas.Contract) -> bool Called to add a contract to the existing set of contract after it is signed :param contract: The contract to add :returns: True if everything went OK and False otherwise Remarks: - By default this function just adds the contract to the set of contracts maintaned by the world. - You should ALWAYS call this function when overriding it. .. py:method:: contract_record(contract: negmas.Contract) -> dict[str, Any] Converts a contract to a record suitable for permanent storage .. py:method:: breach_record(breach: negmas.Breach) -> dict[str, Any] Converts a breach to a record suitable for storage during the simulation .. py:method:: execute_action(action, agent, callback: Callable | None = None) -> bool Executes the given action by the given agent .. py:method:: contract_size(contract: negmas.Contract) -> float Returns an estimation of the **activity level** associated with this contract. Higher is better :param contract: Returns: .. py:method:: post_step_stats() Called at the end of the simulation step to update all stats Kept for backward compatibility and will be dropped. Override `update_stats` ins .. py:method:: pre_step_stats() Called at the beginning of the simulation step to prepare stats or update them Kept for backward compatibility and will be dropped. Override `update_stats` instead .. py:method:: welfare(include_bankrupt: bool = False) -> float Total welfare of all agents .. py:method:: relative_welfare(include_bankrupt: bool = False) -> float | None Total welfare relative to expected value. Returns None if no expectation is found in self.info .. py:method:: is_valid_contact(contract: negmas.Contract) -> bool Checks whether a signed contract is valid .. py:method:: scores(assets_multiplier: float = 0.0) -> dict[str, float] Scores of all agents given the asset multiplier. :param assets_multiplier: A multiplier to multiply the assets with. .. py:property:: winners The winners of this world (factory managers with maximum wallet balance .. py:method:: trading_prices_for(discount: float = 1.0, condition='executed') -> numpy.ndarray Calculates the prices at which all products traded using an optional discount factor :param discount: A discount factor to treat older prices less importantly (exponential discounting). :param condition: The condition for contracts to consider. Possible values are executed, signed, concluded, nullified :returns: an n_products vector of trading prices .. py:property:: trading_prices .. py:property:: stats_df :type: pandas.DataFrame Returns a pandas data frame with the stats .. py:property:: contracts_df :type: pandas.DataFrame Returns a pandas data frame with the contracts .. py:property:: system_agents :type: list[scml.oneshot.sysagents._StdSystemAgent] Returns the two system agents .. py:property:: system_agent_names :type: list[str] Returns the names two system agents .. py:property:: non_system_agents :type: list[scml.oneshot.sysagents.DefaultOneShotAdapter] Returns all agents except system agents .. py:property:: non_system_agent_names :type: list[str] Returns names of all agents except system agents .. py:property:: agreement_fraction :type: float Fraction of negotiations ending in agreement and leading to signed contracts .. py:attribute:: system_agent_ids .. py:attribute:: non_system_agent_ids .. py:method:: draw(steps: tuple[int, int] | int | None = None, what: Collection[str] = DEFAULT_EDGE_TYPES, who: Callable[[negmas.Agent], bool] | None = None, where: Callable[[negmas.Agent], int | tuple[float, float]] | None = None, together: bool = True, axs: Collection[matplotlib.axis.Axis] | None = None, ncols: int = 4, figsize: tuple[int, int] = (15, 15), **kwargs) -> tuple[matplotlib.axis.Axis, networkx.Graph] | tuple[list[matplotlib.axis.Axis], list[networkx.Graph]] .. py:method:: _request_negotiations(agent_id: str, controller: negmas.sao.SAOController | None = None, negotiators: list[negmas.sao.SAONegotiator] | None = None, extra: dict[str, Any] | None = None) -> bool Requests negotiations (used internally) :param agent_id: the agent requesting :param product: The product to negotiate about :param quantity: The minimum and maximum quantities. Passing a single value q is equivalent to passing (q,q) :param unit_price: The minimum and maximum unit prices. Passing a single value u is equivalent to passing (u,u) :param time: The minimum and maximum delivery step. Passing a single value t is equivalent to passing (t,t) :param controller: The controller to manage the complete set of negotiations :param negotiators: An optional list of negotiators to use for negotiating with the given partners (in the same order). :param extra: Extra information accessible through the negotiation annotation to the caller :param # consumer_starts: Whether the consumer or supplier sends the first offer in the negotiation :returns: `True` if the partner accepted and the negotiation is ready to start .. py:method:: _request_negotiation(agent_id: str, product: int, partner: str, negotiator: negmas.sao.SAONegotiator, extra: dict[str, Any] | None = None, is_buy: bool = True) -> negmas.situated.NegotiationInfo | None Requests a negotiation :param product: The product to negotiate about :param quantity: The minimum and maximum quantities. Passing a single value q is equivalent to passing (q,q) :param unit_price: The minimum and maximum unit prices. Passing a single value u is equivalent to passing (u,u) :param time: The minimum and maximum delivery step. Passing a single value t is equivalent to passing (t,t) :param partner: ID of the partner to negotiate with. :param negotiator: The negotiator to use for this negotiation (if the partner accepted to negotiate) :param extra: Extra information accessible through the negotiation annotation to the caller :param is_buy: whether the consumer starts the negotiation :returns: `True` if the partner accepted and the negotiation is ready to start .. py:method:: _make_issues(product) -> tuple[tuple[int, int], tuple[int, int], tuple[int, int]] Creates the negotiation agendas :param product: The product to be negotiated about :type product: int :returns: A tuple of minimum and maximum values for unit-price, time, and quantity in that order .. py:method:: _make_negotiations() .. py:method:: order_contracts_for_execution(contracts: Collection[negmas.Contract]) -> Collection[negmas.Contract] Orders the contracts in a specific time-step that are about to be executed .. py:method:: get_private_state(agent: negmas.Agent) -> dict Reads the private state of the given agent .. py:method:: _contract_record(contract) Converts a contract to a record suitable for permanent storage .. py:method:: start_contract_execution(contract: negmas.Contract) -> set[negmas.Breach] | None Tries to execute the contract :param contract: :returns: The set of breaches committed if any. If there are no breaches return an empty set :rtype: Set[Breach] Remarks: - You must call super() implementation of this method before doing anything - It is possible to return None which indicates that the contract was nullified (i.e. not executed due to a reason other than an execution exeception). .. py:method:: complete_contract_execution(contract: negmas.Contract, breaches: list[negmas.Breach], resolution: negmas.Contract) -> None Called after breach resolution is completed for contracts for which some potential breaches occurred. :param contract: The contract considered. :param breaches: The list of potential breaches that was generated by `_execute_contract`. :param resolution: The agreed upon resolution Returns: .. py:method:: plot_combined_stats(worlds: tuple[SCMLBaseWorld, Ellipsis] | SCMLBaseWorld, stats: str | tuple[str, Ellipsis] | None = None, pertype=False, makefig=False, title=True, ylabel=False, xlabel=False, legend=True, figsize=None, perishable: bool = False, **kwargs) :classmethod: Plots combined statistics of multiple worlds in a single plot :param stats: The statistics to plot. If `None`, some selected stats will be displayed :param pertype: combine agent-statistics per type :param use_sum: plot sum for type statistics instead of mean :param title: If given a title will be added to each subplot :param ylabel: If given, the ylabel will be added to each subplot :param xlabel: If given The xlabel will be added (Simulation Step) :param legend: If given, a legend will be displayed :param makefig: If given a new figure will be started :param figsize: Size of the figure to host the plot :param ylegend: y-axis of legend for cases with large number of labels :param legend_n_cols: number of columns in the legend .. py:method:: plot_stats(stats: str | tuple[str, Ellipsis] | None = None, pertype=False, use_sum=False, makefig=False, title=True, ylabel=False, xlabel=False, legend=True, figsize=None, ylegend=2.0, legend_ncols=8) Plots statistics of the world in a single plot :param stats: The statistics to plot. If `None`, some selected stats will be displayed :param pertype: combine agent-statistics per type :param use_sum: plot sum for type statistics instead of mean :param title: If given a title will be added to each subplot :param ylabel: If given, the ylabel will be added to each subplot :param xlabel: If given The xlabel will be added (Simulation Step) :param legend: If given, a legend will be displayed :param makefig: If given a new figure will be started :param figsize: Size of the figure to host the plot :param ylegend: y-axis of legend for cases with large number of labels .. py:class:: OneShotWorld(catalog_prices: numpy.ndarray, profiles: list[scml.oneshot.common.OneShotProfile], agent_types: list[type[scml.oneshot.agent.OneShotAgent]], agent_params: list[dict[str, Any]], catalog_quantities: int | numpy.ndarray = 50, financial_report_period=5, bankruptcy_limit=0.0, penalize_bankrupt_for_future_contracts=True, penalties_scale: Literal['trading', 'catalog', 'unit', 'none'] = 'trading', exogenous_contracts: Collection[scml.oneshot.common.OneShotExogenousContract] = tuple(), exogenous_dynamic: bool = False, exogenous_force_max: bool = False, initial_balance: numpy.ndarray | tuple[int, int] | int = 1000, compact=True, no_logs=True, fast=True, n_steps=1000, time_limit=60 * 15, sync_calls=False, neg_n_steps=20, neg_time_limit=None, neg_hidden_time_limit=60, neg_step_time_limit=20, negotiation_speed=None, shuffle_negotiations=False, one_offer_per_step=False, publish_exogenous_summary=True, publish_trading_prices=True, publish_assets=False, publish_production_capacity=True, price_multiplier=0.0, price_range_fraction=0.0, wide_price_range=False, allow_zero_quantity: bool = False, trading_price_discount=0.9, signing_delay=0, force_signing=False, batch_signing=True, name: str | None = None, agent_name_reveals_position: bool = True, agent_name_reveals_type: bool = True, inventory_valuation_catalog=0, inventory_valuation_trading=0, perishable=True, horizon=0, one_time_per_negotiation=True, quantity_multiplier: float = 1.0, nullify_bankrupt_contracts: bool = False, debug: bool = False, verbose: bool = False, **kwargs) Bases: :py:obj:`SCMLBaseWorld` Basic oneshot simulation .. py:class:: SCML2020OneShotWorld(catalog_prices: numpy.ndarray, profiles: list[scml.oneshot.common.OneShotProfile], agent_types: list[type[scml.oneshot.agent.OneShotAgent]], agent_params: list[dict[str, Any]], catalog_quantities: int | numpy.ndarray = 50, financial_report_period=5, bankruptcy_limit=0.0, penalize_bankrupt_for_future_contracts=True, penalties_scale: Literal['trading', 'catalog', 'unit', 'none'] = 'trading', exogenous_contracts: Collection[scml.oneshot.common.OneShotExogenousContract] = tuple(), exogenous_dynamic: bool = False, exogenous_force_max: bool = False, initial_balance: numpy.ndarray | tuple[int, int] | int = 1000, compact=True, no_logs=True, fast=True, n_steps=1000, time_limit=60 * 15, sync_calls=False, neg_n_steps=20, neg_time_limit=None, neg_hidden_time_limit=60, neg_step_time_limit=20, negotiation_speed=None, shuffle_negotiations=False, one_offer_per_step=False, publish_exogenous_summary=True, publish_trading_prices=True, publish_assets=False, publish_production_capacity=True, price_multiplier=0.0, price_range_fraction=0.0, wide_price_range=False, allow_zero_quantity: bool = False, trading_price_discount=0.9, signing_delay=0, force_signing=False, batch_signing=True, name: str | None = None, agent_name_reveals_position: bool = True, agent_name_reveals_type: bool = True, inventory_valuation_catalog=0, inventory_valuation_trading=0, perishable=True, horizon=0, one_time_per_negotiation=True, quantity_multiplier: float = 1.0, nullify_bankrupt_contracts: bool = False, debug: bool = False, verbose: bool = False, **kwargs) Bases: :py:obj:`OneShotWorld` Oneshot simulation as used in SCML 2020 competition .. py:class:: SCML2021OneShotWorld(*args, **kwargs) Bases: :py:obj:`SCML2020OneShotWorld` Oneshot simulation as used in SCML 2021 competition .. py:class:: SCML2022OneShotWorld(*args, **kwargs) Bases: :py:obj:`SCML2021OneShotWorld` Oneshot simulation as used in SCML 2022 competition .. py:class:: SCML2023OneShotWorld(*args, **kwargs) Bases: :py:obj:`SCML2020OneShotWorld` Oneshot simulation as used in SCML 2023 competition .. py:class:: SCML2024OneShotWorld(*args, **kwargs) Bases: :py:obj:`SCML2023OneShotWorld` Oneshot simulation as used in SCML 2024 competition .. py:data:: PLACEHOLDER_AGENT_PREFIX :value: 'PlaceHolder__' .. py:function:: builtin_agent_types(as_str=False) Returns all built-in agents. :param as_str: If true, the full type name will be returned otherwise the type object itself. .. py:data:: __all__