AWI

class scml.scml2020.AWI(world, agent)[source]

Bases: negmas.situated.AgentWorldInterface

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

Attributes Summary

all_consumers

Returns a list of agent IDs for all consumers for every product

all_suppliers

Returns a list of agent IDs for all suppliers for every product

catalog_prices

Returns the catalog prices of all products

current_step

Current simulation step

default_signing_delay

rtype

int

inputs

Returns the number of inputs to every production process

my_consumers

Returns a list of IDs for all the agent’s consumers (agents that can consume at least one product it may produce).

my_input_product

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

my_input_products

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

my_output_product

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

my_output_products

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

my_suppliers

Returns a list of IDs for all of the agent’s suppliers (agents that can supply at least one product it may need).

n_lines

The number of lines in the corresponding factory.

n_processes

Number of processes in the world

n_products

Number of products in the world

n_steps

Number of steps in a simulation

outputs

Returns the number of outputs to every production process

profile

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

relative_time

Relative time of the simulation going from 0 to 1

state

Receives the factory state

Methods Summary

available_for_production(repeats[, step, …])

Finds available times and lines for scheduling production.

bb_query(section, query[, query_keys])

Returns all records in the given section/sections of the bulletin-board that satisfy the query

bb_read(section, key)

Reads the value associated with given key from the bulletin board

bb_record(section, value[, key])

Records data in the given section of the bulletin board

bb_remove(section, *[, query, key, …])

Removes a value or a set of values from the bulletin Board

cancel_production(step, line)

Cancels any production commands on that line at this step

execute(action[, callback])

Executes an action in the world simulation

logdebug(msg)

Logs a WARNING message

logerror(msg)

Logs a WARNING message

loginfo(msg)

Logs an INFO message

logwarning(msg)

Logs a WARNING message

order_production(process, steps, lines)

Orders production of the given process

request_negotiation(is_buy, product, …[, …])

Requests a negotiation

request_negotiation_about(issues, partners, …)

Requests to start a negotiation with some other agents

request_negotiations(is_buy, product, …[, …])

Requests a negotiation

run_negotiation(issues, partners, negotiator)

Runs a negotiation until completion

run_negotiations(issues, partners, negotiators)

Requests to run a set of negotiations simultaneously.

schedule_production(process, repeats[, …])

Orders the factory to run the given process at the given line at the given step

Attributes Documentation

all_consumers

Returns a list of agent IDs for all consumers for every product

Return type

List[List[str]]

all_suppliers

Returns a list of agent IDs for all suppliers for every product

Return type

List[List[str]]

catalog_prices

Returns the catalog prices of all products

Return type

ndarray

current_step

Current simulation step

Return type

int

default_signing_delay
Return type

int

inputs

Returns the number of inputs to every production process

Return type

ndarray

my_consumers

Returns a list of IDs for all the agent’s consumers (agents that can consume at least one product it may produce).

Remarks:

  • If the agent have multiple output products, consumers of a specific product $p$ can be found using: self.all_consumers[p].

Return type

List[str]

my_input_product

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

Return type

int

my_input_products

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

Return type

ndarray

my_output_product

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

Return type

int

my_output_products

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

Return type

ndarray

my_suppliers

Returns a list of IDs for all of the agent’s suppliers (agents that can supply at least one product it may need).

Remarks:

  • If the agent have multiple input products, suppliers of a specific product $p$ can be found using: self.all_suppliers[p].

Return type

List[str]

n_lines

The number of lines in the corresponding factory. You can read state to get this among other information

Return type

int

n_processes

Number of processes in the world

Return type

int

n_products

Number of products in the world

Return type

int

n_steps

Number of steps in a simulation

Return type

int

outputs

Returns the number of outputs to every production process

Return type

ndarray

profile

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

Return type

FactoryProfile

relative_time

Relative time of the simulation going from 0 to 1

Return type

float

state

Receives the factory state

Return type

FactoryState

Methods Documentation

available_for_production(repeats, step=-1, line=-1, override=True, method='latest')[source]

Finds available times and lines for scheduling production.

Parameters
  • repeats (int) – How many times to repeat the process

  • step (Union[int, Tuple[int, int]]) – The simulation step or a range of steps. The special value ANY_STEP gives the factory the freedom to schedule production at any step in the present or future.

  • line (int) – The production line. The special value ANY_LINE gives the factory the freedom to use any line

  • override (bool) – Whether to override any existing commands at that line at that time.

  • method (str) – When to schedule the command if step was set to a range. Options are latest, earliest, all

Return type

Tuple[ndarray, ndarray]

Returns

Tuple[np.ndarray, np.ndarray] The steps and lines at which production is scheduled.

Remarks:

  • You cannot order production in the past or in the current step

  • Ordering production, will automatically update inventory and balance for all simulation steps assuming that this production will be carried out. At the indicated step if production was not possible (due to insufficient funds or insufficient inventory of the input product), the predictions for the future will be corrected.

bb_query(section, query, query_keys=False)

Returns all records in the given section/sections of the bulletin-board that satisfy the query

Parameters
  • section (Union[str, List[str], None]) – Either a section name, a list of sections or None specifying ALL public sections (see remarks)

  • query (Any) – The query which is USUALLY a dict with conditions on it when querying values and a RegExp when

  • keys (querying) –

  • query_keys – Whether the query is to be applied to the keys or values.

Returns

value pairs giving all records that satisfied the given requirements.

Return type

  • A dictionary with key

Remarks:

  • A public section is a section with a name that does not start with an underscore

  • If a set of sections is given, and two records in different sections had the same key, only one of them will be returned

  • Key queries use regular expressions and match from the beginning using the standard re.match function

bb_read(section, key)

Reads the value associated with given key from the bulletin board

Parameters
  • section (str) – section name

  • key (str) – key

Return type

Optional[Any]

Returns

Content of that key in the bulletin-board

bb_record(section, value, key=None)

Records data in the given section of the bulletin board

Parameters
  • section (str) – section name (can contain subsections separated by ‘/’)

  • key (Optional[str]) – The key

  • value (Any) – The value

Return type

None

bb_remove(section, *, query=None, key=None, query_keys=False, value=None)

Removes a value or a set of values from the bulletin Board

Parameters
  • section (Union[str, List[str], None]) – The section

  • query (Optional[Any]) – the query to use to select what to remove

  • key (Optional[str]) – the key to remove (no need to give a full query)

  • query_keys (bool) – Whether to apply the query (if given) to keys or values

  • value (Optional[Any]) – Value to be removed

Returns

Success of failure

Return type

bool

cancel_production(step, line)[source]

Cancels any production commands on that line at this step

Parameters
  • step (int) – The step to cancel production at (must be in the future).

  • line (int) – The production line

Return type

bool

Returns

success/failure

Remarks:

  • The step cannot be in the past or the current step. Cancellation can only be ordered for future steps

execute(action, callback=None)

Executes an action in the world simulation

Return type

bool

logdebug(msg)

Logs a WARNING message

Parameters

msg (str) – The message to log

Returns:

Return type

None

logerror(msg)

Logs a WARNING message

Parameters

msg (str) – The message to log

Returns:

Return type

None

loginfo(msg)

Logs an INFO message

Parameters

msg (str) – The message to log

Returns:

Return type

None

logwarning(msg)

Logs a WARNING message

Parameters

msg (str) – The message to log

Returns:

Return type

None

order_production(process, steps, lines)[source]

Orders production of the given process

Parameters
  • process (int) – The process to run

  • steps (ndarray) – The time steps to run the process at as an np.ndarray

  • lines (ndarray) – The corresponding lines to run the process at

Remarks:

  • len(steps) must equal len(lines)

  • No checks are done in this function. It is expected to be used after calling available_for_production

Return type

None

request_negotiation(is_buy, product, quantity, unit_price, time, partner, negotiator, extra=None)[source]

Requests a negotiation

Parameters
  • is_buy (bool) – If True the negotiation is about buying otherwise selling.

  • product (int) – The product to negotiate about

  • quantity (Union[int, Tuple[int, int]]) – The minimum and maximum quantities. Passing a single value q is equivalent to passing (q,q)

  • unit_price (Union[int, Tuple[int, int]]) – The minimum and maximum unit prices. Passing a single value u is equivalent to passing (u,u)

  • time (Union[int, Tuple[int, int]]) – The minimum and maximum delivery step. Passing a single value t is equivalent to passing (t,t)

  • partner (str) – ID of the partner to negotiate with.

  • negotiator (SAONegotiator) – The negotiator to use for this negotiation (if the partner accepted to negotiate)

  • extra (Optional[Dict[str, Any]]) – Extra information accessible through the negotiation annotation to the caller

Return type

bool

Returns

True if the partner accepted and the negotiation is ready to start

Remarks:

  • All negotiations will use the following issues in order: quantity, time, unit_price

  • Negotiations with bankrupt agents or on invalid products (see next point) will be automatically rejected

  • Valid products for a factory are the following (any other products are not valid):

    1. Buying an input product (i.e. product $in$ my_input_products 1. Seeling an output product (i.e. product $in$ my_output_products

request_negotiation_about(issues, partners, req_id, roles=None, annotation=None, mechanism_name=None, mechanism_params=None)

Requests to start a negotiation with some other agents

Parameters
  • req_id (str) –

  • issues (List[Issue]) – Negotiation issues

  • annotation (Optional[Dict[str, Any]]) – Extra information to be passed to the partners when asking them to join the negotiation

  • partners (List[str]) – A list of partners to participate in the negotiation

  • roles (Optional[List[str]]) – The roles of different partners. If None then each role for each partner will be None

  • mechanism_name (Optional[str]) – Name of the mechanism to use. It must be one of the mechanism_names that are supported by the

  • or None which means that the World should select the mechanism. If None, then roles and my_role (World) –

  • also be None (must) –

  • mechanism_params (Optional[Dict[str, Any]]) – A dict of parameters used to initialize the mechanism object

Return type

bool

Returns

List[“Agent”] the list of partners who rejected the negotiation if any. If None then the negotiation was accepted. If empty then the negotiation was not started from the world manager

Remarks:

on_neg_request_rejected

request_negotiations(is_buy, product, quantity, unit_price, time, controller, partners=None, extra=None)[source]

Requests a negotiation

Parameters
  • is_buy (bool) – If True the negotiation is about buying otherwise selling.

  • product (int) – The product to negotiate about

  • quantity (Union[int, Tuple[int, int]]) – The minimum and maximum quantities. Passing a single value q is equivalent to passing (q,q)

  • unit_price (Union[int, Tuple[int, int]]) – The minimum and maximum unit prices. Passing a single value u is equivalent to passing (u,u)

  • time (Union[int, Tuple[int, int]]) – The minimum and maximum delivery step. Passing a single value t is equivalent to passing (t,t)

  • controller (SAOController) – The controller to manage the complete set of negotiations

  • partners (Optional[List[str]]) – ID of all the partners to negotiate with.

  • extra (Optional[Dict[str, Any]]) – Extra information accessible through the negotiation annotation to the caller

Return type

bool

Returns

True if the partner accepted and the negotiation is ready to start

Remarks:

  • All negotiations will use the following issues in order: quantity, time, unit_price

  • Negotiations with bankrupt agents or on invalid products (see next point) will be automatically rejected

  • Valid products for a factory are the following (any other products are not valid):

    1. Buying an input product (i.e. product $in$ my_input_products 1. Seeling an output product (i.e. product $in$ my_output_products

run_negotiation(issues, partners, negotiator, ufun=None, caller_role=None, roles=None, annotation=None, mechanism_name=None, mechanism_params=None)

Runs a negotiation until completion

Parameters
  • partners (Collection[Agent]) – The list of partners that the agent wants to negotiate with. Roles will be determined by these agents.

  • negotiator (Negotiator) – The negotiator to be used in the negotiation

  • ufun (Optional[UtilityFunction]) – The utility function. Only needed if the negotiator does not already know it

  • caller_role (Optional[str]) – The role of the caller in the negotiation

  • issues (Collection[Issue]) – Negotiation issues

  • annotation (Optional[Dict[str, Any]]) – Extra information to be passed to the partners when asking them to join the negotiation

  • partners – A list of partners to participate in the negotiation

  • roles (Optional[Collection[str]]) – The roles of different partners. If None then each role for each partner will be None

  • mechanism_name (Optional[str]) – Name of the mechanism to use. It must be one of the mechanism_names that are supported by the

  • or None which means that the World should select the mechanism. If None, then roles and my_role (World) –

  • also be None (must) –

  • mechanism_params (Optional[Dict[str, Any]]) – A dict of parameters used to initialize the mechanism object

Return type

Optional[Tuple[Contract, AgentMechanismInterface]]

Returns

A Tuple of a contract and the ami of the mechanism used to get it in case of success. None otherwise

run_negotiations(issues, partners, negotiators, ufuns=None, caller_roles=None, roles=None, annotations=None, mechanism_names=None, mechanism_params=None, all_or_none=False)

Requests to run a set of negotiations simultaneously. Returns after all negotiations are run to completion

Parameters
  • partners (List[List[Agent]]) – The list of partners that the agent wants to negotiate with. Roles will be determined by these agents.

  • issues (Union[List[Issue], List[List[Issue]]]) – Negotiation issues

  • negotiators (List[Negotiator]) – The negotiator to be used in the negotiation

  • ufuns (Optional[List[UtilityFunction]]) – The utility function. Only needed if the negotiator does not already know it

  • caller_roles (Optional[List[str]]) – The role of the caller in the negotiation

  • annotations (Optional[List[Optional[Dict[str, Any]]]]) – Extra information to be passed to the partners when asking them to join the negotiation

  • partners – A list of partners to participate in the negotiation

  • roles (Optional[List[Optional[List[str]]]]) – The roles of different partners. If None then each role for each partner will be None

  • mechanism_names (Union[str, List[str], None]) – Name of the mechanism to use. It must be one of the mechanism_names that are supported by the

  • or None which means that the World should select the mechanism. If None, then roles and my_role (World) –

  • also be None (must) –

  • mechanism_params (Union[Dict[str, Any], List[Dict[str, Any]], None]) – A dict of parameters used to initialize the mechanism object

  • all_or_none (bool) – If true, either no negotiations will be started execpt if all partners accepted

Returns

contract (None for failure) and ami (The mechanism info [None if the corresponding partner refused to negotiation])

Return type

A list of tuples each with two values

schedule_production(process, repeats, step=-1, line=-1, override=True, method='latest')[source]

Orders the factory to run the given process at the given line at the given step

Parameters
  • process (int) – The process to run

  • repeats (int) – How many times to repeat the process

  • step (Union[int, Tuple[int, int]]) – The simulation step or a range of steps. The special value ANY_STEP gives the factory the freedom to schedule production at any step in the present or future.

  • line (int) – The production line. The special value ANY_LINE gives the factory the freedom to use any line

  • override (bool) – Whether to override existing production commands or not

  • method (str) – When to schedule the command if step was set to a range. Options are latest, earliest

Return type

Tuple[ndarray, ndarray]

Returns

Tuple[int, int] giving the steps and lines at which production is scheduled.

Remarks:

  • The step cannot be in the past. Production can only be ordered for current and future steps

  • ordering production of process -1 is equivalent of cancel_production only if both step and line are given