AWI¶
- class scml.scml2020.AWI(world, agent)[source]¶
Bases:
AgentWorldInterface
The Agent SCML2020World Interface for SCML2020 world.
This class contains all the methods needed to access the simulation to extract information which are divided into 5 groups:
- Static World Information:
Information about the world and the agent that does not change over time. These include:
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.
catalog_prices: A list of the catalog prices (by product).
inputs: Inputs to every manufacturing process.
outputs: Outputs to every 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)?
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
).settings: The system settings (inherited from
negmas.situated.AgentWorldInterface
).
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.
my_input_products: All input products of a factory controlled by the agent. Currently, it is always a list of one item. For future compatibility.
my_output_products: All output products of a factory controlled by the agent. Currently, it is always a list of one item. For future compatibility.
available_for_production: Returns the line-step slots available for production.
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.
state: The full state of the agent (
FactoryState
).current_balance: The current balance of the agent
current_inventory: The current inventory of the agent (quantity per product)
- Dynamic World Information:
Information about the world and the agent that changes over time.
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.
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.
Current Negotiations Information:
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.
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.
Agent Information:
- spot_market_quantity: The quantity the agent bought from the spot market at
a given step
spot_market_loss: The spot market loss for the agent.
- Actions:
Negotiation Control:
request_negotiations: Requests a set of negotiations controlled by a single controller.
request_negotiation: Requests a negotiation controlled by a single negotiator.
Production Control:
schedule_production: Schedules production using one of the predefined scheduling strategies.
order_production: Orders production directly for the current step.
set_commands: Sets production commands directly on the factory.
cancel_production: Cancels a scheduled production command.
- 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.
Attributes Summary
A list of negotiation requests sent to this agent that are already accepted by it.
Returns a list of agent IDs for all consumers for every product
Returns a list of agent IDs for all suppliers for every product
Returns the catalog prices of all products
Current balance of the agent
Current inventory of the agent
Current simulation step
- rtype:
The exogenous contracts in the current step for all products
Was the agent initialized (i.e.
Returns the number of inputs to every production process
Whether this agent is in the first production level
Whether this agent is in the last production level
Whether this agent is in neither in the first nor in the last level
The production level which is the index of the process for this factory (or the index of its input product)
Returns a list of IDs for all the agent's consumers (agents that can consume at least one product it may produce).
Returns a list of products that are inputs to at least one process the agent can run
Returns a list of products that are inputs to at least one process the agent can run
Returns a list of products that are outputs to at least one process the agent can run
Returns a list of products that are outputs to at least one process the agent can run
Returns a list of IDs for all of the agent's suppliers (agents that can supply at least one product it may need).
Returns the number of factories/agents in the same production level
The number of lines in the corresponding factory.
Number of processes in the world
Number of products in the world
Number of steps in a simulation
A list of the negotiation requests sent by this agent that are not yet accepted or rejected.
Returns the number of outputs to every production process
Returns the basic parameters of the world
Gets the profile (static private information) associated with the agent
Relative time of the simulation going from 0 to 1
The negotiations currently requested by the agent.
The negotiations currently requested by the agent as a mapping from mechanism ID to
RunningNegotiationInfo
The negotiations currently requested by the agent.
Receives the factory state
Returns the current trading prices of all products
All contracts that are not yet signed.
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
is_bankrupt
([aid])Checks whether the agent is bankrupt
is_system
(aid)Checks whether an agent is a system agent or not
logdebug
(msg)Logs a WARNING message
logdebug_agent
(msg)Logs a WARNING message to the agent's log
logerror
(msg)Logs a WARNING message
logerror_agent
(msg)Logs a WARNING message to the agent's log
loginfo
(msg)Logs an INFO message
loginfo_agent
(msg)Logs an INFO message to the agent's log
logwarning
(msg)Logs a WARNING message
logwarning_agent
(msg)Logs a WARNING message to the agent's log
order_production
(process, steps, lines)Orders production of the given process
reports_at_step
(step)Returns a dictionary mapping agent ID to its financial report for the given time-step
reports_of_agent
(aid)Returns a dictionary mapping time-steps to financial reports of the given agent
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
set_commands
(commands[, step])Sets the production commands for all lines in the given step
spot_market_loss
(step)The spot market loss of the agent at the given step.
spot_market_quantity
(step)The quantity bought by the agent from the spot market at the given step.
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
[NegotiationRequestInfo
]
- 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
- current_balance¶
Current balance of the agent
- current_inventory¶
Current inventory of the agent
- exogenous_contract_summary¶
The exogenous contracts in the current step for all products
- is_first_level¶
Whether this agent is in the first production level
- is_last_level¶
Whether this agent is in the last production level
- is_middle_level¶
Whether this agent is in neither in the first nor in the last level
- level¶
The production level which is the index of the process for this factory (or the index of its input product)
- 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].
- my_input_product¶
Returns a list of products that are inputs to at least one process the agent can run
- Return type:
- my_input_products¶
Returns a list of products that are inputs to at least one process the agent can run
- Return type:
- my_output_product¶
Returns a list of products that are outputs to at least one process the agent can run
- Return type:
- my_output_products¶
Returns a list of products that are outputs to at least one process the agent can run
- Return type:
- 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].
- n_lines¶
The number of lines in the corresponding factory. You can read
state
to get this among other information- Return type:
- 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
[NegotiationRequestInfo
]
- profile¶
Gets the profile (static private information) associated with the agent
- Return type:
- requested_negotiations¶
The negotiations currently requested by the agent.
- Return type:
list
[NegotiationRequestInfo
]- Returns:
A list of negotiation request information objects (
NegotiationRequestInfo
)
- running_mechanism_dicts¶
The negotiations currently requested by the agent as a mapping from mechanism ID to
RunningNegotiationInfo
- running_negotiations¶
The negotiations currently requested by the agent.
- Return type:
list
[RunningNegotiationInfo
]- Returns:
A list of negotiation information objects (
RunningNegotiationInfo
)
- settings¶
- state¶
Receives the factory state
- Return type:
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 processstep (
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 lineoverride (
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:
- 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 (
UnionType
[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 whenkeys (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
- bb_record(section, value, key=None)¶
Records data in the given section of the bulletin board
- bb_remove(section, *, query=None, key=None, query_keys=False, value=None)¶
Removes a value or a set of values from the bulletin Board
- cancel_production(step, line)[source]¶
Cancels any production commands on that line at this step
- Parameters:
- Return type:
- Returns:
success/failure
Remarks:
The step cannot be in the past or the current step. Cancellation can only be ordered for future steps
- logdebug(msg)¶
Logs a WARNING message
- Parameters:
msg (
str
) – The message to log
Returns:
- Return type:
- logdebug_agent(msg)¶
Logs a WARNING message to the agent’s log
- Parameters:
msg (
str
) – The message to log
Returns:
- Return type:
- logerror(msg)¶
Logs a WARNING message
- Parameters:
msg (
str
) – The message to log
Returns:
- Return type:
- logerror_agent(msg)¶
Logs a WARNING message to the agent’s log
- Parameters:
msg (
str
) – The message to log
Returns:
- Return type:
- loginfo_agent(msg)¶
Logs an INFO message to the agent’s log
- Parameters:
msg (
str
) – The message to log
Returns:
- Return type:
- logwarning(msg)¶
Logs a WARNING message
- Parameters:
msg (
str
) – The message to log
Returns:
- Return type:
- logwarning_agent(msg)¶
Logs a WARNING message to the agent’s log
- Parameters:
msg (
str
) – The message to log
Returns:
- Return type:
- order_production(process, steps, lines)[source]¶
Orders production of the given process
- Parameters:
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:
- reports_at_step(step)[source]¶
Returns a dictionary mapping agent ID to its financial report for the given time-step
- Return type:
- reports_of_agent(aid)[source]¶
Returns a dictionary mapping time-steps to financial reports of the given agent
- Return type:
- 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 aboutquantity (
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 (
Dict
[str
,Any
]) – Extra information accessible through the negotiation annotation to the caller
- Return type:
- 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):
Buying an input product (i.e. product $in$
my_input_products
) and an output product if the world settings allows it (seeallow_buying_output
)
Selling an output product (i.e. product $in$
my_output_products
) and an input product if the world settings allows it (seeallow_selling_input
)
- request_negotiation_about(issues, partners, req_id, roles=None, annotation=None, mechanism_name=None, mechanism_params=None, group=None)¶
Requests to start a negotiation with some other agents
- Parameters:
req_id (
str
) –issues (
list
[Issue
]) – Negotiation issuesannotation (
Optional
[dict
[str
,Any
]]) – Extra information to be passed to thepartners
when asking them to join the negotiationpartners (
list
[str
]) – A list of partners to participate in the negotiation. Note that the caller itself may not be in this list which makes it possible for an agent to request a negotaition that it does not participate in. If that is not to be allowed in some world, override this method and explicitly check for these kinds of negotiations and return False. If partners is passed as a single string/Agent
or as a list containing a single string/Agent
, then he caller will be added at the beginning of the list. This will only be done ifroles
was passed as None.roles (
Optional
[list
[str
]]) – The roles of different partners. If None then each role for each partner will be Nonemechanism_name (
Optional
[str
]) – Name of the mechanism to use. It must be one of the mechanism_names that are supported by theNone (must also be) –
my_role (then roles and) –
None –
mechanism_params (
Optional
[dict
[str
,Any
]]) – A dict of parameters used to initialize the mechanism objectgroup (
Optional
[str
]) – An opational identifier for the group to which this negotiation belongs. It is not used by the system but is logged for debugging purposes. Moreover, the agent have access to it through itsnegotiations
property.
- Return type:
- 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:
The function will create a request ID that will be used in callbacks
on_neg_request_accepted
and
- request_negotiations(is_buy, product, quantity, unit_price, time, controller=None, negotiators=None, partners=None, extra=None, copy_partner_id=True)[source]¶
Requests a negotiation
- Parameters:
is_buy (
bool
) – If True the negotiation is about buying otherwise selling.product (
int
) – The product to negotiate aboutquantity (
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 (
Optional
[SAOController
]) – The controller to manage the complete set of negotiationsnegotiators (
List
[Negotiator
]) – An optional list of negotiators to use for negotiating with the given partners (in the same order).partners (
List
[str
]) – ID of all the partners to negotiate with.extra (
Dict
[str
,Any
]) – Extra information accessible through the negotiation annotation to the callercopy_partner_id – If true, the partner ID will be copied to the negotiator ID
- Return type:
- Returns:
True
if the partner accepted and the negotiation is ready to start
Remarks:
You can either use controller or negotiators. One of them must be None.
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):
Buying an input product (i.e. product $in$
my_input_products
) and an output product if the world settings allows it (seeallow_buying_output
)
Selling an output product (i.e. product $in$
my_output_products
) and an input product if the world settings allows it (seeallow_selling_input
)
- run_negotiation(issues, partners, negotiator, preferences=None, caller_role=None, roles=None, annotation=None, mechanism_name=None, mechanism_params=None)¶
Runs a negotiation until completion
- Parameters:
partners (
list
[str
|Agent
]) – A list of partners to participate in the negotiation. Note that the caller itself may not be in this list which makes it possible for an agent to request a negotaition that it does not participate in. If that is not to be allowed in some world, override this method and explicitly check for these kinds of negotiations and return False. If partners is passed as a single string/Agent
or as a list containing a single string/Agent
, then he caller will be added at the beginning of the list. This will only be done ifroles
was passed as None.negotiator (
Negotiator
) – The negotiator to be used in the negotiationpreferences (
Optional
[Preferences
]) – The preferences. Only needed if the negotiator does not already know itcaller_role (
Optional
[str
]) – The role of the caller in the negotiationissues (
list
[Issue
]) – Negotiation issuesannotation (
Optional
[dict
[str
,Any
]]) – Extra information to be passed to thepartners
when asking them to join the negotiationpartners – 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 Nonemechanism_name (
Optional
[str
]) – Name of the mechanism to use. It must be one of the mechanism_names that are supported by theNone (must also be) –
my_role (then roles and) –
None –
mechanism_params (
Optional
[dict
[str
,Any
]]) – A dict of parameters used to initialize the mechanism object
- Return type:
Optional
[tuple
[Contract
,NegotiatorMechanismInterface
]]- Returns:
A Tuple of a contract and the nmi of the mechanism used to get it in case of success. None otherwise
- run_negotiations(issues, partners, negotiators, preferences=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
[str
|Agent
]]) – A list of partners to participate in the negotiation. Note that the caller itself may not be in this list which makes it possible for an agent to request a negotaition that it does not participate in. If that is not to be allowed in some world, override this method and explicitly check for these kinds of negotiations and return False. If partners is passed as a single string/Agent
or as a list containing a single string/Agent
, then he caller will be added at the beginning of the list. This will only be done ifroles
was passed as None.issues (
list
[Issue
] |list
[list
[Issue
]]) – Negotiation issuesnegotiators (
list
[Negotiator
]) – The negotiator to be used in the negotiationufuns – 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 negotiationannotations (
Optional
[list
[Optional
[dict
[str
,Any
]]]]) – Extra information to be passed to thepartners
when asking them to join the negotiationpartners – 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 Nonemechanism_names (
UnionType
[str
,list
[str
],None
]) – Name of the mechanism to use. It must be one of the mechanism_names that are supported by theNone (must also be) –
my_role (then roles and) –
None –
mechanism_params (
UnionType
[dict
[str
,Any
],list
[dict
[str
,Any
]],None
]) – A dict of parameters used to initialize the mechanism objectall_or_none (
bool
) – If true, either no negotiations will be started execpt if all partners accepted
- Returns:
contract (None for failure) and nmi (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', partial_ok=False)[source]¶
Orders the factory to run the given process at the given line at the given step
- Parameters:
process (
int
) – The process to runrepeats (
int
) – How many times to repeat the processstep (
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 lineoverride (
bool
) – Whether to override existing production commands or notmethod (
str
) – When to schedule the command if step was set to a range. Options are latest, earliestpartial_ok (
bool
) – If true, allows partial scheduling
- Return type:
- 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
- set_commands(commands, step=-1)[source]¶
Sets the production commands for all lines in the given step