DecentralizingAgent

class scml.scml2020.DecentralizingAgent(*args, negotiator_type=<class 'negmas.sao.AspirationNegotiator'>, negotiator_params=None, **kwargs)[source]

Bases: scml.scml2020.agents.decentralizing._NegotiationCallbacks, scml.StepNegotiationManager, scml.PredictionBasedTradingStrategy, scml.SupplyDrivenProductionStrategy, scml.SCML2020Agent

Attributes Summary

accepted_negotiation_requests

A list of negotiation requests sent to this agent that are already accepted by it.

awi

Gets the Agent-world interface.

id

The unique ID of this entity

initialized

Was the agent initialized (i.e.

internal_state

name

A convenient name of the entity (intended primarily for printing/logging/debugging).

negotiation_requests

A list of the negotiation requests sent by this agent that are not yet accepted or rejected.

requested_negotiations

The negotiations currently requested by the agent.

running_negotiations

The negotiations currently requested by the agent.

short_type_name

Returns a short name of the type of this entity

type_name

Returns the name of the type of this entity

unsigned_contracts

All contracts that are not yet signed.

uuid

The unique ID of this entity

Methods Summary

acceptable_unit_price(step, sell)

rtype

int

add_controller(is_seller, target, urange, …)

rtype

StepController

all_negotiations_concluded(controller_index, …)

Called by the StepController to affirm that it is done negotiating for some time-step

can_be_produced(contract_id)

Returns True if the SELL contract given can be honored in principle given the production capacity of the agent (n.

checkpoint(path[, file_name, info, …])

Saves a checkpoint of the current object at the given path.

checkpoint_info(file_name)

Returns the information associated with a dump of the object saved in the given file

confirm_production(commands, balance, inventory)

Called just before production starts at every time-step allowing the agent to change what is to be produced in its factory

create(*args, **kwargs)

Creates an object and returns a proxy to it.

create_negotiation_request(issues, partners, …)

Creates a new NegotiationRequestInfo record and returns its ID

from_checkpoint(file_name[, return_info])

Creates an object from a saved checkpoint

from_config(config[, section, …])

Creates an object of this class given the configuration info

init()

init_()

Called to initialize the agent after the world is initialized.

notify(notifiable, notification)

on_agent_bankrupt(agent, contracts, …)

rtype

None

on_contract_breached(contract, breaches, …)

rtype

None

on_contract_cancelled(contract, rejectors)

Called whenever at least a partner did not sign the contract

on_contract_cancelled_(contract, rejectors)

Called whenever at least a partner did not sign the contract

on_contract_executed(contract)

rtype

None

on_contract_signed(contract)

Called whenever a contract is signed by all partners

on_contract_signed_(contract)

Called whenever a contract is signed by all partners

on_contracts_finalized(signed, cancelled, …)

rtype

None

on_event(event, sender)

on_failures(failures)

Called whenever there are failures either in production or in execution of guaranteed transactions

on_neg_request_accepted(req_id, mechanism)

Called when a requested negotiation is accepted

on_neg_request_accepted_(req_id, mechanism)

Called when a requested negotiation is accepted

on_neg_request_rejected(req_id, by)

Called when a requested negotiation is rejected

on_neg_request_rejected_(req_id, by)

Called when a requested negotiation is rejected

on_negotiation_failure(partners, annotation, …)

Called whenever a negotiation ends without agreement

on_negotiation_failure_(partners, …)

Called whenever a negotiation ends without agreement

on_negotiation_success(contract, mechanism)

Called whenever a negotiation ends with agreement

on_negotiation_success_(contract, mechanism)

Called whenever a negotiation ends with agreement

on_simulation_step_ended()

Will be called at the end of the simulation step after everything else

on_simulation_step_started()

Will be called at the beginning of the simulation step before everything else (except init)

predict_quantity(contract)

read_config(config[, section])

Reads the configuration from a file or a dict and prepares it for parsing

respond_to_negotiation_request(initiator, …)

rtype

Optional[Negotiator]

respond_to_negotiation_request_(initiator, …)

Called when a negotiation request is received

respond_to_renegotiation_request(contract, …)

Called to respond to a renegotiation request

set_renegotiation_agenda(contract, breaches)

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

sign_all_contracts(contracts)

rtype

List[Optional[str]]

sign_contract(contract)

Called after the signing delay from contract conclusion to sign the contract.

start_negotiations(product, quantity, …[, …])

Starts a set of negotiations to by/sell the product with the given limits

step()

step_()

Called at every time-step.

target_quantities(steps, sell)

Implemented for speed but not really required

target_quantity(step, sell)

rtype

int

Attributes Documentation

accepted_negotiation_requests

A list of negotiation requests sent to this agent that are already accepted by it.

Remarks:
  • These negotiations did not start yet as they are still not accepted by all partners. Once that happens, they will be moved to running_negotiations

Return type

List[NegotiationInfo]

awi

Gets the Agent-world interface.

Return type

AgentWorldInterface

id

The unique ID of this entity

initialized

Was the agent initialized (i.e. was init_() called)

Return type

bool

internal_state
name

A convenient name of the entity (intended primarily for printing/logging/debugging).

negotiation_requests

A list of the negotiation requests sent by this agent that are not yet accepted or rejected.

Remarks:
  • These negotiations did not start yet as they are still not accepted by all partners. Once that happens, they will be moved to running_negotiations

Return type

List[NegotiationInfo]

requested_negotiations

The negotiations currently requested by the agent.

Return type

List[NegotiationRequestInfo]

Returns

A list of negotiation request information objects (NegotiationRequestInfo)

running_negotiations

The negotiations currently requested by the agent.

Return type

List[RunningNegotiationInfo]

Returns

A list of negotiation information objects (RunningNegotiationInfo)

short_type_name

Returns a short name of the type of this entity

type_name

Returns the name of the type of this entity

unsigned_contracts

All contracts that are not yet signed.

Return type

List[Contract]

uuid

The unique ID of this entity

Methods Documentation

acceptable_unit_price(step, sell)
Return type

int

add_controller(is_seller, target, urange, expected_quantity, step)
Return type

StepController

all_negotiations_concluded(controller_index, is_seller)

Called by the StepController to affirm that it is done negotiating for some time-step

Return type

None

can_be_produced(contract_id)

Returns True if the SELL contract given can be honored in principle given the production capacity of the agent (n. lines). It does not check for the availability of inputs or enough money to run the production process.

Remarks:

  • Cannot be called before calling on_contracts_finalized

checkpoint(path, file_name=None, info=None, exist_ok=False, single_checkpoint=True, step_attribs=('current_step', '_current_step', '_Entity__current_step', '_step'))

Saves a checkpoint of the current object at the given path.

Parameters
  • path (Union[Path, str]) – Full path to a directory to store the checkpoint

  • file_name (Optional[str]) – Name of the file to dump into. If not given, a unique name is created

  • info (Optional[Dict[str, Any]]) – Information to save with the checkpoint (must be json serializable)

  • exist_ok (bool) – If true, override existing dump

  • single_checkpoint (bool) – If true, keep a single checkpoint for the last step

  • step_attribs (Tuple[str]) – Attributes to represent the time-step of the object. Any of the given attributes will be used in the file name generated if single_checkpoint is False. If single_checkpoint is True, the filename will not contain time-step information

Return type

Path

Returns

full path to the file used to save the checkpoint

classmethod checkpoint_info(file_name)

Returns the information associated with a dump of the object saved in the given file

Parameters

file_name (Union[str, Path]) – Name of the object

Returns:

Return type

Dict[str, Any]

confirm_production(commands, balance, inventory)

Called just before production starts at every time-step allowing the agent to change what is to be produced in its factory

Parameters
  • commands (ndarray) – an n_lines vector giving the process to be run at every line (NO_COMMAND indicates nothing to be processed

  • balance (int) – The current balance of the factory

  • inventory – an n_products vector giving the number of items available in the inventory of every product type.

Return type

ndarray

Returns

an n_lines vector giving the process to be run at every line (NO_COMMAND indicates nothing to be processed

Remarks:

  • Not called in SCML2020 competition.

  • The inventory will contain zero items of all products that the factory does not buy or sell

  • The default behavior is to just retrun commands confirming production of everything.

classmethod create(*args, **kwargs)

Creates an object and returns a proxy to it.

create_negotiation_request(issues, partners, annotation, negotiator, extra)

Creates a new NegotiationRequestInfo record and returns its ID

Parameters
Return type

str

Returns

A unique identifier for this negotiation info structure

classmethod from_checkpoint(file_name, return_info=False)

Creates an object from a saved checkpoint

Parameters
  • file_name (Union[str, Path]) –

  • return_info – If True, tbe information saved when the file was dumped are returned

Return type

Union[NamedObject, Tuple[NamedObject, Dict[str, Any]]]

Returns

Either the object or the object and dump-info as a dict (if return_info was true)

Remarks:

  • If info is returned, it is guaranteed to have the following members:
    • time: Dump time

    • type: Type of the dumped object

    • id: ID

    • name: name

classmethod from_config(config, section=None, ignore_children=True, try_parsing_children=True, scope=None)

Creates an object of this class given the configuration info

Parameters
  • config (Union[str, dict]) – Either a file name or a dictionary

  • section (Optional[str]) – A section in the file or a key in the dictionary to use for loading params

  • ignore_children (bool) – If true then children will be ignored and there will be a single return

  • try_parsing_children (bool) – If true the children will first be parsed as ConfigReader classes if they are not

  • types (e.g. int, str, float, Iterable[int|str|float] (simple) –

  • scope – The scope at which to evaluate any child classes. This MUST be passed as scope=globals() if you are

  • any children that are to be parsed. (having) –

Returns

An object of cls if ignore_children is True or a tuple with an object of cls and a dictionary with children that were not parsed.

Remarks:

  • This function will return an object of its class after passing the key-value pairs found in the config to the init function.

  • Requiring passing scope=globals() to this function is to get around the fact that in python eval() will be called with a globals dictionary based on the module in which the function is defined not called. This means that in general when eval() is called to create the children, it will not have access to the class definitions of these children (except if they happen to be imported in this file). To avoid this problem causing an undefined_name exception, the caller must pass her globals() as the scope.

init()
init_()

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

notify(notifiable, notification)
on_agent_bankrupt(agent, contracts, quantities, compensation_money)
Return type

None

on_contract_breached(contract, breaches, resolution)
Return type

None

on_contract_cancelled(contract, rejectors)

Called whenever at least a partner did not sign the contract

Return type

None

on_contract_cancelled_(contract, rejectors)

Called whenever at least a partner did not sign the contract

Return type

None

on_contract_executed(contract)
Return type

None

on_contract_signed(contract)

Called whenever a contract is signed by all partners

Return type

None

on_contract_signed_(contract)

Called whenever a contract is signed by all partners

Return type

None

on_contracts_finalized(signed, cancelled, rejectors)
Return type

None

on_event(event, sender)
on_failures(failures)

Called whenever there are failures either in production or in execution of guaranteed transactions

Parameters

failures (List[Failure]) – A list of Failure s.

Return type

None

on_neg_request_accepted(req_id, mechanism)

Called when a requested negotiation is accepted

on_neg_request_accepted_(req_id, mechanism)

Called when a requested negotiation is accepted

on_neg_request_rejected(req_id, by)

Called when a requested negotiation is rejected

Parameters
  • req_id (str) – The request ID passed to _request_negotiation

  • by (Optional[List[str]]) – A list of agents that refused to participate or None if the failure was for another reason

on_neg_request_rejected_(req_id, by)

Called when a requested negotiation is rejected

Parameters
  • req_id (str) – The request ID passed to _request_negotiation

  • by (Optional[List[str]]) – A list of agents that refused to participate or None if the failure was for another reason

on_negotiation_failure(partners, annotation, mechanism, state)

Called whenever a negotiation ends without agreement

Return type

None

on_negotiation_failure_(partners, annotation, mechanism, state)

Called whenever a negotiation ends without agreement

Return type

None

on_negotiation_success(contract, mechanism)

Called whenever a negotiation ends with agreement

Return type

None

on_negotiation_success_(contract, mechanism)

Called whenever a negotiation ends with agreement

Return type

None

on_simulation_step_ended()

Will be called at the end of the simulation step after everything else

on_simulation_step_started()

Will be called at the beginning of the simulation step before everything else (except init)

predict_quantity(contract)
classmethod read_config(config, section=None)

Reads the configuration from a file or a dict and prepares it for parsing

Parameters
  • config (Union[str, dict]) – Either a file name or a dictionary

  • section (Optional[str]) – A section in the file or a key in the dictionary to use for loading params

Return type

Dict[str, Any]

Returns

A dict ready to be parsed by from_config

Remarks:

respond_to_negotiation_request(initiator, issues, annotation, mechanism)
Return type

Optional[Negotiator]

respond_to_negotiation_request_(initiator, partners, issues, annotation, mechanism, role, req_id)

Called when a negotiation request is received

Return type

Optional[Negotiator]

respond_to_renegotiation_request(contract, breaches, agenda)

Called to respond to a renegotiation request

Parameters
  • agenda (RenegotiationRequest) –

  • contract (Contract) –

  • breaches (List[Breach]) –

Returns:

Return type

Optional[Negotiator]

set_renegotiation_agenda(contract, breaches)

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

Parameters
  • contract (Contract) – The contract being breached

  • breaches (List[Breach]) – All breaches on contract

Return type

Optional[RenegotiationRequest]

Returns

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

sign_all_contracts(contracts)
Return type

List[Optional[str]]

sign_contract(contract)

Called after the signing delay from contract conclusion to sign the contract. Contracts become binding only after they are signed.

Return type

Optional[str]

start_negotiations(product, quantity, unit_price, step, partners=None)

Starts a set of negotiations to by/sell the product with the given limits

Parameters
  • product (int) – product type. If it is an input product, negotiations to buy it will be started otherweise to sell.

  • quantity (int) – The maximum quantity to negotiate about

  • unit_price (int) – The maximum/minimum unit price for buy/sell

  • step (int) – The maximum/minimum time for buy/sell

  • partners (Optional[List[str]]) – A list of partners to negotiate with

Remarks:

  • This method assumes that product is either my_input_product or my_output_product

Return type

None

step()
step_()

Called at every time-step. This function is called directly by the world.

target_quantities(steps, sell)

Implemented for speed but not really required

Return type

ndarray

target_quantity(step, sell)
Return type

int