scml.scml2019.agent

The base class agent needed for all SCML agents.

Module Contents

Classes

SCML2019Agent

The base for all SCM Agents

class scml.scml2019.agent.SCML2019Agent(name: str | None = None, ufun: negmas.UtilityFunction | None = None)[source]

Bases: negmas.situated.Agent

The base for all SCM Agents

property awi: scml.scml2019.awi.SCMLAWI[source]

Returns the Agent-SCML2020World-Interface through which the agent does all of its actions in the world.

A single excption is request_negotiation for which it is recommended to actually call the helper method on the agent itself instead of directly calling the AWI version.

line_profiles: Dict[int, scml.scml2019.common.ManufacturingProfileCompiled][source]

A mapping specifying for each Line index, all the profiles used to run it in the factory

process_profiles: Dict[int, scml.scml2019.common.ManufacturingProfileCompiled][source]

A mapping specifying for each Process index, all the profiles used to run it in the factory

producing: Dict[int, List[scml.scml2019.common.ProductManufacturingInfo]][source]

Mapping from a product to all manufacturing processes that can generate it

consuming: Dict[int, List[scml.scml2019.common.ProductManufacturingInfo]][source]

Mapping from a product to all manufacturing processes that can consume it

compiled_profiles: List[scml.scml2019.common.ManufacturingProfileCompiled] = [][source]

All the profiles to be used by the factory belonging to this agent compiled to use indices

immediate_negotiations = False[source]

Whether or not negotiations start immediately upon registration (default is to start on the next production step)

negotiation_speed_multiple: int = 1[source]

The number of negotiation rounds (steps) conducted in a single production step

transportation_delay: int = 0[source]

Transportation delay in the system. Default is zero

products: List[scml.scml2019.common.Product] = [][source]

List of products in the system

processes: List[scml.scml2019.common.Process] = [][source]

List of processes in the system

reset()[source]
is_clean() bool[source]
init_()[source]

The initialization function called by the world directly.

It does the following actions by default:

  1. copies some of the static world settings to the agent to make them available without calling the AWI.

  2. prepares production related properties like producing, consuming, line_profiles, compiled_profiles, etc.

  3. registers interest in all products that the agent can produce or consume in its factory.

  4. finally it calls any custom initialization logic implemented in `init`()

See also

init, step

can_expect_agreement(cfp: scml.scml2019.common.CFP, margin: int)[source]

Checks if it is possible in principle to get an agreement on this CFP by the time it becomes executable

Parameters:
  • margin

  • cfp

Returns:

_create_annotation(cfp: scml.scml2019.common.CFP, partner: str = None)[source]

Creates full annotation based on a cfp that the agent is receiving

Parameters:
  • cfp – The call for proposal to create annotation about

  • partner – The partner who requested the negotiation

Remarks:

  • If the annotation is to be created for a CFP that was published by self, partner must be passed

_respond_to_negotiation_request(initiator: str, partners: List[str], issues: List[negmas.outcomes.Issue], annotation: Dict[str, Any], mechanism: negmas.common.NegotiatorMechanismInterface, role: str | None, req_id: str | None) negmas.negotiators.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

request_negotiation(cfp: scml.scml2019.common.CFP, negotiator: negmas.negotiators.Negotiator = None, ufun: negmas.UtilityFunction = None) bool[source]

Requests a negotiation from the AWI while keeping track of available negotiation requests

Parameters:
  • cfp

  • negotiator

  • ufun

Returns:

Whether the negotiation request was successful indicating that the partner accepted the negotiation

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

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

abstract on_contract_breached(contract: negmas.situated.Contract, breaches: List[negmas.situated.Breach], resolution: negmas.situated.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.

abstract confirm_loan(loan: scml.scml2019.common.Loan, bankrupt_if_rejected: bool) bool[source]

called by the world manager to confirm a loan if needed by the buyer of a contract that is about to be breached

abstract on_contract_nullified(contract: negmas.situated.Contract, bankrupt_partner: str, compensation: float) None[source]

Will be called whenever a contract the agent is involved in is nullified because another partner went bankrupt

abstract on_agent_bankrupt(agent_id: str) None[source]

Will be called whenever any agent goes bankrupt

Parameters:

agent_id – The ID of the agent that went bankrupt

Remarks:

  • Agents can go bankrupt in two cases:

    1. Failing to pay one installments of a loan they bought and refusing (or being unable to) get another loan to pay it.

    2. Failing to pay a penalty on a sell contract they failed to honor (and refusing or being unable to get a loan to pay for it).

  • All built-in agents ignore this call and they use the bankruptcy list ONLY to decide whether or not to negotiate in their on_new_cfp and respond_to_negotiation_request callbacks by pulling the bulletin-board using the helper function is_bankrupt of their AWI.

abstract confirm_partial_execution(contract: negmas.situated.Contract, breaches: List[negmas.situated.Breach]) bool[source]

Will be called whenever a contract cannot be fully executed due to breaches by the other partner.

Parameters:
  • contract – The contract that was breached

  • breaches – A list of all the breaches committed.

Remarks:

  • Will not be called if both partners committed breaches.

abstract confirm_contract_execution(contract: negmas.situated.Contract) bool[source]

Called before executing any agreement

abstract respond_to_negotiation_request(cfp: scml.scml2019.common.CFP, partner: str) negmas.negotiators.Negotiator | None[source]

Called when a prospective partner requests a negotiation to start

abstract on_new_cfp(cfp: scml.scml2019.common.CFP)[source]

Called when a new CFP for a product for which the agent registered interest is published

abstract on_remove_cfp(cfp: scml.scml2019.common.CFP)[source]

Called when a new CFP for a product for which the agent registered interest is removed

abstract on_new_report(report: scml.scml2019.common.FinancialReport)[source]

Called whenever a financial report is published.

Parameters:

report – The financial report giving details of the standing of an agent at some time (see FinancialReport)

Remarks:

abstract on_inventory_change(product: int, quantity: int, cause: str) None[source]

Received whenever something moves in or out of the factory’s storage

Parameters:
  • product – Product index.

  • quantity – Negative value for products moving out and positive value for products moving in

  • cause

    The cause of the change. Possibilities include:

    • contract: Contract execution

    • insurance: Received from insurance company

    • bankruptcy: Liquidated due to bankruptcy

    • transport: Arrival of goods (when transportation delay in the system is > 0).

abstract on_cash_transfer(amount: float, cause: str) None[source]

Received whenever money is transferred to the factory or from it.

Parameters:
  • amount – Amount of money (negative for transfers out of the factory, positive for transfers to it).

  • cause

    The cause of the change. Possibilities include:

    • contract: Contract execution

    • insurance: Received from insurance company

    • bankruptcy: Liquidated due to bankruptcy

    • transfer: Arrival of transferred money (when transfer delay in the system is > 0).