scml.oneshot.adapter

Classes

AWIHelper

The Agent SCML2020World Interface for SCML2020 world allowing a single process per agent

DefaultOneShotAdapter

The base class of all agents running in OneShot based on OneShotAgent.

OneShotSCML2020Adapter

Base class for adapters allowing SCML std agents to run as Oneshot agents in SCML2020Oneshot worlds

Module Contents

class scml.oneshot.adapter.AWIHelper(owner: scml.oneshot.adapter.OneShotSCML2020Adapter)[source]

The Agent SCML2020World Interface for SCML2020 world allowing a single process per agent

request_negotiations(is_buy: bool, product: int, quantity: int | tuple[int, int], unit_price: int | tuple[int, int], time: int | tuple[int, int], controller: negmas.sao.SAOController | None = None, negotiators: list[negmas.sao.SAONegotiator] | None = None, partners: list[str] | None = None, extra: dict[str, Any] | None = None, copy_partner_id=True) bool[source]
request_negotiation(is_buy: bool, product: int, quantity: int | tuple[int, int], unit_price: int | tuple[int, int], time: int | tuple[int, int], partner: str, negotiator: negmas.sao.SAONegotiator, extra: dict[str, Any] | None = None) bool[source]
schedule_production(process: int, repeats: int, step: int | tuple[int, int] = ANY_STEP, line: int = ANY_LINE, override: bool = True, method: str = 'latest', partial_ok: bool = False) tuple[numpy.ndarray, numpy.ndarray][source]
order_production(process: int, steps: numpy.ndarray, lines: numpy.ndarray) None[source]
available_for_production(repeats: int, step: int | tuple[int, int] = ANY_STEP, line: int = ANY_LINE, override: bool = True, method: str = 'latest') tuple[numpy.ndarray, numpy.ndarray][source]
set_commands(commands: numpy.ndarray, step: int = -1) None[source]
cancel_production(step: int, line: int) bool[source]
property trading_prices: numpy.ndarray | None

Returns the current trading prices of all products

property current_balance: float
property exogenous_contract_summary
__getattr__(attr)[source]
property inputs: numpy.ndarray

Returns the number of inputs to every production process

property outputs: numpy.ndarray

Returns the number of outputs to every production process

property my_input_products: numpy.ndarray

Returns a list of products that are inputs to at least one process the agent can run

property my_output_products: numpy.ndarray

Returns a list of products that are outputs to at least one process the agent can run

is_system(aid: str) bool[source]

Checks whether an agent is a system agent or not

Parameters:

aid – Agent ID

property state: scml.scml2020.common.FactoryState

Receives the factory state

property profile: scml.scml2020.common.FactoryProfile

Gets the profile (static private information) associated with the agent

property allow_zero_quantity: bool

Does negotiations allow zero quantity?

class scml.oneshot.adapter.DefaultOneShotAdapter(*args, **kwargs)[source]

Bases: negmas.Adapter, 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.

make_ufun(add_exogenous: bool, in_adapter=False)[source]
on_negotiation_failure(partners, annotation, mechanism, state)[source]

Called whenever a negotiation ends without agreement

on_negotiation_success(contract: negmas.Contract, mechanism)[source]

Called whenever a negotiation ends with agreement

on_contract_executed(contract: negmas.Contract) None[source]

Called after successful contract execution for which the agent is one of the partners.

on_contract_breached(contract: negmas.Contract, breaches: list[negmas.Breach], resolution: negmas.Contract | None) None[source]

Called after complete processing of a contract that involved a breach.

Parameters:
  • contract – The contract

  • breaches – All breaches committed (even if they were resolved)

  • resolution – The resolution contract if re-negotiation was successful. None if not.

init_()[source]

Called to initialize the agent after the world is initialized. the AWI is accessible at this point.

init()[source]

Override this method to modify initialization logic

reset()[source]
is_clean() bool[source]
before_step()[source]
step()[source]

Override this method to modify stepping logic

to_dict()[source]
_respond_to_negotiation_request(initiator: str, partners: list[str], issues: list[negmas.Issue], annotation: dict[str, Any], mechanism: negmas.NegotiatorMechanismInterface, role: str | None, req_id: str | None) negmas.Negotiator | None[source]

Called by the mechanism to ask for joining a negotiation. The agent can refuse by returning a None

Parameters:
  • initiator – The ID of the agent that initiated the negotiation request

  • partners – The partner list (will include this agent)

  • issues – The list of issues

  • annotation – Any annotation specific to this negotiation.

  • mechanism – The mechanism that started the negotiation

  • role – The role of this agent in the negotiation

  • 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

set_renegotiation_agenda(contract: negmas.Contract, breaches: list[negmas.Breach]) negmas.RenegotiationRequest | None[source]

Received by partners in ascending order of their total breach levels in order to set the renegotiation agenda when contract execution fails

Parameters:
  • contract – The contract being breached

  • breaches – All breaches on contract

Returns:

Renegotiation agenda (issues to negotiate about to avoid reporting the breaches).

respond_to_renegotiation_request(contract: negmas.Contract, breaches: list[negmas.Breach], agenda: negmas.RenegotiationRequest) negmas.Negotiator | None[source]

Called to respond to a renegotiation request

Parameters:
  • agenda

  • contract

  • breaches

Returns:

on_neg_request_rejected(req_id: str, by: list[str] | None)[source]

Called when a requested negotiation is rejected

Parameters:
  • req_id – The request ID passed to _request_negotiation

  • by – A list of agents that refused to participate or None if the failure was for another reason

on_neg_request_accepted(req_id: str, mechanism: negmas.NegotiatorMechanismInterface)[source]

Called when a requested negotiation is accepted

property awi: scml.oneshot.awi.OneShotAWI

Gets the Agent-world interface.

property short_type_name
Returns a short name of the type of this entity
class scml.oneshot.adapter.OneShotSCML2020Adapter(*args, **kwargs)[source]

Bases: scml.oneshot.sysagents.DefaultOneShotAdapter

Base class for adapters allowing SCML std agents to run as Oneshot agents in SCML2020Oneshot worlds

reset()[source]
is_clean() bool[source]
on_negotiation_failure(partners, annotation, mechanism, state)[source]

Called whenever a negotiation ends without agreement

on_negotiation_success(contract, mechanism)[source]

Called whenever a negotiation ends with agreement

on_contract_executed(contract: negmas.Contract) None[source]

Called after successful contract execution for which the agent is one of the partners.

on_contract_breached(contract: negmas.Contract, breaches: List[negmas.Breach], resolution: negmas.Contract | None) None[source]

Called after complete processing of a contract that involved a breach.

Parameters:
  • contract – The contract

  • breaches – All breaches committed (even if they were resolved)

  • resolution – The resolution contract if re-negotiation was successful. None if not.

init()[source]

Override this method to modify initialization logic

before_step()[source]
to_dict()[source]
_respond_to_negotiation_request(initiator, partners, issues, annotation, mechanism, role, req_id)[source]

Called by the mechanism to ask for joining a negotiation. The agent can refuse by returning a None

Parameters:
  • initiator – The ID of the agent that initiated the negotiation request

  • partners – The partner list (will include this agent)

  • issues – The list of issues

  • annotation – Any annotation specific to this negotiation.

  • mechanism – The mechanism that started the negotiation

  • role – The role of this agent in the negotiation

  • 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

set_renegotiation_agenda(contract, breaches)[source]

Received by partners in ascending order of their total breach levels in order to set the renegotiation agenda when contract execution fails

Parameters:
  • contract – The contract being breached

  • breaches – All breaches on contract

Returns:

Renegotiation agenda (issues to negotiate about to avoid reporting the breaches).

respond_to_renegotiation_request(contract, breaches, agenda)[source]

Called to respond to a renegotiation request

Parameters:
  • agenda

  • contract

  • breaches

Returns:

on_neg_request_rejected(req_id, by)[source]

Called when a requested negotiation is rejected

Parameters:
  • req_id – The request ID passed to _request_negotiation

  • by – A list of agents that refused to participate or None if the failure was for another reason

on_neg_request_accepted(req_id, mechanism)[source]

Called when a requested negotiation is accepted