scml¶
-
class
scml.
RandomAgent
(*args, negotiator_type=<class 'negmas.sao.AspirationNegotiator'>, negotiator_params=None, horizon=5, **kwargs)[source]¶ An agent that negotiates randomly.
-
class
scml.
DoNothingAgent
(**kwargs)[source]¶ An agent that does nothing for the whole length of the simulation
-
confirm_external_sales
(quantities, unit_prices)[source]¶ Called to confirm the amount of guaranteed sales the agent is willing to accept
- Parameters
- Return type
- Returns
An n_products vector specifying the quantities to be sold (up to the given
quantities
limit).
-
confirm_external_supplies
(quantities, unit_prices)[source]¶ Called to confirm the amount of guaranteed supplies the agent is willing to accept
- Parameters
- Return type
- Returns
An n_products vector specifying the quantities to be bought (up to the given
quantities
limit).
-
init
()[source]¶ Called to initialize the agent after the world is initialized. the AWI is accessible at this point.
-
on_contract_breached
(contract, breaches, resolution)[source]¶ Called after complete processing of a contract that involved a breach.
-
on_contract_cancelled
(contract, rejectors)[source]¶ Called whenever at least a partner did not sign the contract
- Return type
None
-
on_contract_executed
(contract)[source]¶ Called after successful contract execution for which the agent is one of the partners.
- Return type
None
-
on_contract_nullified
(contract, compensation_money, compensation_fraction)[source]¶ Called whenever a contract is nullified (because the partner is bankrupt)
-
on_contract_signed
(contract)[source]¶ Called whenever a contract is signed by all partners
- Return type
None
-
on_failures
(failures)[source]¶ Called whenever there are failures either in production or in execution of guaranteed transactions
- Parameters
failures (
List
[Failure
]) – A list ofFailure
s.- Return type
None
-
on_negotiation_failure
(partners, annotation, mechanism, state)[source]¶ Called whenever a negotiation ends without agreement
- Return type
None
-
on_negotiation_success
(contract, mechanism)[source]¶ Called whenever a negotiation ends with agreement
- Return type
None
-
respond_to_negotiation_request
(initiator, issues, annotation, mechanism)[source]¶ Called whenever another agent requests a negotiation with this agent.
- Parameters
initiator (
str
) – The ID of the agent that requested this negotiationissues (
List
[Issue
]) – Negotiation issuesannotation (
Dict
[str
,Any
]) – Annotation attached with this negotiationmechanism (
AgentMechanismInterface
) – TheAgentMechanismInterface
interface to the mechanism to be used for this negotiation.
- Return type
Optional
[Negotiator
]- Returns
None to reject the negotiation, otherwise a negotiator
-
-
class
scml.
IndependentNegotiationsAgent
(*args, negotiator_type=<class 'negmas.sao.AspirationNegotiator'>, negotiator_params=None, horizon=5, **kwargs)[source]¶ Implements the base class for agents that negotiate independently with different partners.
These agents do not take production capacity, availability of materials or any other aspects of the simulation into account. They are to serve only as baselines.
- Parameters
negotiator_type (
Union
[SAONegotiator
,str
]) – The type of the negotiator to use. The default isAspirationNegotiator
negotiator_params (
Optional
[Dict
[str
,Any
]]) – key-value pairs to pass to the constructor of negotiatorshorizon – The number of production step to handle together using a single set of negotiations. See
step
for details
Remarks:
IndependentNegotiationsAgent
agents assume that each production process has one input type with the sameindex as itself and one output type with one added to the index (i.e. process $i$ takes product $i$ as input and creates product $i+1$ as output.
It does not assume that all lines have the same production cost (it uses the average cost though).
It does not assume that the agent has a single production process.
-
confirm_external_sales
(quantities, unit_prices)[source]¶ Called to confirm the amount of guaranteed sales the agent is willing to accept
- Parameters
- Return type
- Returns
An n_products vector specifying the quantities to be sold (up to the given
quantities
limit).
-
confirm_external_supplies
(quantities, unit_prices)[source]¶ Called to confirm the amount of guaranteed supplies the agent is willing to accept
- Parameters
- Return type
- Returns
An n_products vector specifying the quantities to be bought (up to the given
quantities
limit).
-
negotiator
(is_seller, issues=None, outcomes=None)[source]¶ Creates a negotiator
- Return type
SAONegotiator
-
on_contract_signed
(contract)[source]¶ Called whenever a contract is signed by all partners
- Return type
None
-
respond_to_negotiation_request
(initiator, issues, annotation, mechanism)[source]¶ Called whenever another agent requests a negotiation with this agent.
- Parameters
initiator (
str
) – The ID of the agent that requested this negotiationissues (
List
[Issue
]) – Negotiation issuesannotation (
Dict
[str
,Any
]) – Annotation attached with this negotiationmechanism (
AgentMechanismInterface
) – TheAgentMechanismInterface
interface to the mechanism to be used for this negotiation.
- Return type
Optional
[Negotiator
]- Returns
None to reject the negotiation, otherwise a negotiator
-
sign_contract
(contract)[source]¶ Called after the signing delay from contract conclusion to sign the contract. Contracts become binding only after they are signed.
-
start_negotiations
(product, quantity, unit_price, time, to_buy)[source]¶ 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 aboutunit_price (
int
) – The maximum/minimum unit price for buy/selltime (
int
) – The maximum/minimum time for buy/sellto_buy (
bool
) – Is the negotiation to buy or to sell
Remarks:
This method assumes that products cannot be in my_input_products and my_output_products
- Return type
None
-
class
scml.
BuyCheapSellExpensiveAgent
(*args, negotiator_type=<class 'negmas.sao.AspirationNegotiator'>, negotiator_params=None, horizon=5, **kwargs)[source]¶ An agent that tries to buy cheap and sell expensive but does not care about production scheduling.
-
class
scml.
DecentralizingAgent
(*args, negotiator_type=<class 'negmas.sao.AspirationNegotiator'>, negotiator_params=None, horizon=5, predicted_demand=None, predicted_supply=None, agreement_fraction=0.5, **kwargs)[source]¶ An agent that keeps schedules of what it needs to buy and sell and tries to satisfy them.
It assumes that the agent can run a single process
-
all_negotiations_concluded
(controller_index, is_seller)[source]¶ Called by the
StepController
to affirm that it is done negotiating for some time-step- Return type
None
-
confirm_external_sales
(quantities, unit_prices)[source]¶ Called to confirm the amount of guaranteed sales the agent is willing to accept
- Parameters
- Return type
- Returns
An n_products vector specifying the quantities to be sold (up to the given
quantities
limit).
-
confirm_external_supplies
(quantities, unit_prices)[source]¶ Called to confirm the amount of guaranteed supplies the agent is willing to accept
- Parameters
- Return type
- Returns
An n_products vector specifying the quantities to be bought (up to the given
quantities
limit).
-
generate_buy_negotiations
(step)[source]¶ Creates the controller and starts negotiations to acquire all required inputs (supplies) at the given step
-
generate_sell_negotiations
(step)[source]¶ Creates the controller and starts negotiations to sell all required outputs (sales) at the given step
-
init
()[source]¶ Called to initialize the agent after the world is initialized. the AWI is accessible at this point.
-
max_consumption_till
(step)[source]¶ Returns the maximum number of units that can be consumed until the given step given current production schedule
- Return type
-
max_production_till
(step)[source]¶ Returns the maximum number of units that can be produced until the given step given current production schedule
- Return type
-
on_contract_signed
(contract)[source]¶ Called whenever a contract is signed by all partners
- Return type
None
-
on_negotiation_failure
(partners, annotation, mechanism, state)[source]¶ Called whenever a negotiation ends without agreement
- Return type
None
-
on_negotiation_success
(contract, mechanism)[source]¶ Called whenever a negotiation ends with agreement
- Return type
None
-
respond_to_negotiation_request
(initiator, issues, annotation, mechanism)[source]¶ Called whenever another agent requests a negotiation with this agent.
- Parameters
initiator (
str
) – The ID of the agent that requested this negotiationissues (
List
[Issue
]) – Negotiation issuesannotation (
Dict
[str
,Any
]) – Annotation attached with this negotiationmechanism (
AgentMechanismInterface
) – TheAgentMechanismInterface
interface to the mechanism to be used for this negotiation.
- Return type
Optional
[Negotiator
]- Returns
None to reject the negotiation, otherwise a negotiator
-
-
class
scml.
FactoryState
(inventory, balance, commands, inventory_changes, balance_change, contracts)[source]¶ -
balance
= None¶ Current balance in the wallet
-
balance_change
= None¶ Change in the balance in the last step
-
commands
= None¶ n_steps * n_lines array giving the process scheduled on each line at every step for the whole simulation
-
contracts
= None¶ The An n_steps list of lists containing the contracts of this agent by time-step
-
inventory
= None¶ An n_products vector giving current quantity of every product in storage
-
inventory_changes
= None¶ Changes in the inventory in the last step
-
-
class
scml.
SCML2020Agent
(**kwargs)[source]¶ Base class for all SCML2020 agents (factory managers)
-
abstract
confirm_external_sales
(quantities, unit_prices)[source]¶ Called to confirm the amount of guaranteed sales the agent is willing to accept
- Parameters
- Return type
- Returns
An n_products vector specifying the quantities to be sold (up to the given
quantities
limit).
-
abstract
confirm_external_supplies
(quantities, unit_prices)[source]¶ Called to confirm the amount of guaranteed supplies the agent is willing to accept
- Parameters
- Return type
- Returns
An n_products vector specifying the quantities to be bought (up to the given
quantities
limit).
-
abstract
on_contract_nullified
(contract, compensation_money, compensation_fraction)[source]¶ Called whenever a contract is nullified (because the partner is bankrupt)
-
abstract
on_failures
(failures)[source]¶ Called whenever there are failures either in production or in execution of guaranteed transactions
- Parameters
failures (
List
[Failure
]) – A list ofFailure
s.- Return type
None
-
abstract
respond_to_negotiation_request
(initiator, issues, annotation, mechanism)[source]¶ Called whenever another agent requests a negotiation with this agent.
- Parameters
initiator (
str
) – The ID of the agent that requested this negotiationissues (
List
[Issue
]) – Negotiation issuesannotation (
Dict
[str
,Any
]) – Annotation attached with this negotiationmechanism (
AgentMechanismInterface
) – TheAgentMechanismInterface
interface to the mechanism to be used for this negotiation.
- Return type
Optional
[Negotiator
]- Returns
None to reject the negotiation, otherwise a negotiator
-
respond_to_renegotiation_request
(contract, breaches, agenda)[source]¶ Called to respond to a renegotiation request
- Parameters
agenda (
RenegotiationRequest
) –contract (
Contract
) –breaches (
List
[Breach
]) –
Returns:
- Return type
Optional
[Negotiator
]
-
abstract
-
class
scml.
AWI
(world, agent)[source]¶ The Agent SCML2020World Interface for SCML2020 world allowing a single process per agent
-
property
all_consumers
¶ Returns a list of agent IDs for all consumers for every product
-
property
all_suppliers
¶ Returns a list of agent IDs for all suppliers for every product
-
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.
-
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
-
property
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].
-
property
my_input_product
¶ Returns a list of products that are inputs to at least one process the agent can run
- Return type
-
property
my_input_products
¶ Returns a list of products that are inputs to at least one process the agent can run
- Return type
-
property
my_output_product
¶ Returns a list of products that are outputs to at least one process the agent can run
- Return type
-
property
my_output_products
¶ Returns a list of products that are outputs to at least one process the agent can run
- Return type
-
property
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].
-
property
n_lines
¶ The number of lines in the corresponding factory. You can read
state
to get this among other information- 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
None
-
property
profile
¶ Gets the profile (static private information) associated with the 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 (
Optional
[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):
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_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 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 (
SAOController
) – The controller to manage the complete set of negotiationspartners (
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
- 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
-
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 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, earliest
- 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
-
property
state
¶ Receives the factory state
- Return type
-
property
-
class
scml.
SCML2020World
(process_inputs, process_outputs, catalog_prices, profiles, agent_types, agent_params=None, initial_balance=1000, buy_missing_products=True, borrow_on_breach=True, bankruptcy_limit=0.2, breach_penalty=0.15, financial_report_period=5, interest_rate=0.05, compensation_fraction=1.0, compensate_immediately=False, compensate_before_past_debt=False, external_force_max=True, external_no_borrow=False, external_no_bankruptcy=False, external_penalty=0.15, external_supply_limit=None, external_sales_limit=None, production_no_borrow=False, production_no_bankruptcy=False, production_penalty=0.15, compact=False, no_logs=False, n_steps=1000, time_limit=5400, neg_n_steps=20, neg_time_limit=120, neg_step_time_limit=60, negotiation_speed=21, signing_delay=1, name=None, **kwargs)[source]¶ A Supply Chain SCML2020World Simulation as described for the SCML league of ANAC @ IJCAI 2020.
- Parameters
process_inputs (
ndarray
) – An n_processes vector specifying the number of inputs from each product needed to execute each process.process_outputs (
ndarray
) – An n_processes vector specifying the number of inputs from each product generated by executing each process.catalog_prices (
ndarray
) – An n_products vector (i.e. n_processes+1 vector) giving the catalog price of all productsprofiles (
List
[FactoryProfile
]) – An n_agents list ofFactoryProfile
objects specifying the private profile of the factory associated with each agent.agent_types (
List
[Type
[SCML2020Agent
]]) – An n_agents list of strings/SCML2020Agent
classes specifying the type of each agentagent_params (
Optional
[List
[Dict
[str
,Any
]]]) – An n_agents dictionaries giving the parameters of each agentinitial_balance (
Union
[ndarray
,Tuple
[int
,int
],int
]) – The initial balance in each agent’s wallet. All agents will start with this same value.breach_penalty – The total penalty paid upon a breach will be calculated as (breach_level * breach_penalty * contract_quantity * contract_unit_price).
external_supply_limit (
Optional
[ndarray
]) – An n_steps * n_products array giving the total supply available of each product over time. Only affects guaranteed supply.external_sales_limit (
Optional
[ndarray
]) – An n_steps * n_products array giving the total sales to happen for each product over time. Only affects guaranteed sales.financial_report_period – The number of steps between financial reports. If < 1, it is a fraction of n_steps
borrow_on_breach – If true, agents will be forced to borrow money on breach as much as possible to honor the contract
interest_rate – The interest at which loans grow over time (it only affect a factory when its balance is negative)
bankruptcy_limit – The maximum amount that be be borrowed (including interest). The balance of any factory cannot go lower than - borrow_limit or the agent will go bankrupt immediately
compensation_fraction – Fraction of a contract to be compensated (at most) if a partner goes bankrupt. Notice that this fraction is not guaranteed because the bankrupt agent may not have enough assets to pay all of its standing contracts to this level of compensation. In such cases, a smaller fraction will be used.
compensate_immediately – If true, compensation will happen immediately when an agent goes bankrupt and in in money. This means that agents with contracts involving the bankrupt agent will just have these contracts be nullified and receive monetary compensation immediately . If false, compensation will not happen immediately but at the contract execution time. In this case, agents with contracts involving the bankrupt agent will be informed of the compensation fraction (instead of the compensation money) at the time of bankruptcy and will receive the compensation in kind (money if they are sellers and products if they are buyers) at the normal execution time of the contract. In the special case of no-compensation (i.e.
compensation_fraction
is zero or the bankrupt agent has no assets), the two options will behave similarity.compensate_before_past_debt – If true, then compensations will be paid before past debt is considered, otherwise, the money from liquidating bankrupt agents will first be used to pay past debt then whatever remains will be used for compensation. Notice that in all cases, the trigger of bankruptcy will be paid before compensation and past debts.
external_force_max – If true, agents are not asked to confirm guaranteed transactions and they are carried out up to bankruptcy
external_no_borrow – If true, agents will not borrow if they fail to satisfy an external transaction. The transaction will just fail silently
external_no_bankruptcy – If true, agents will not go bankrupt because of an external transaction. The transaction will just fail silently
external_penalty – The penalty paid for failure to honor external contracts
production_no_borrow – If true, agents will not borrow if they fail to satisfy its production need to execute a scheduled production command
production_no_bankruptcy – If true, agents will not go bankrupt because of an production related transaction.
production_penalty – The penalty paid when buying from spotmarket to satisfy production needs
compact – If True, no logs will be kept and the whole simulation will use a smaller memory footprint
n_steps – Number of simulation steps (can be considered as days).
time_limit – Total time allowed for the complete simulation in seconds.
neg_n_steps – Number of negotiation steps allowed for all negotiations.
neg_time_limit – Total time allowed for a complete negotiation in seconds.
neg_step_time_limit – Total time allowed for a single step of a negotiation. in seconds.
negotiation_speed – The number of negotiation steps that pass in every simulation step. If 0, negotiations will be guaranteed to finish within a single simulation step
signing_delay – The number of simulation steps to pass between a contract is concluded and signed
**kwargs – Other parameters that are passed directly to
SCML2020World
constructor.
-
add_financial_report
(agent, factory, reports_agent, reports_time)[source]¶ Records a financial report for the given agent in the agent indexed reports and time indexed reports
- Parameters
agent (
SCML2020Agent
) – The agentfactory (
Factory
) – Its factoryreports_agent – A dictionary of financial reports indexed by agent id
reports_time – A dictionary of financial reports indexed by time
Returns:
- Return type
None
-
property
agreement_rate
¶ Fraction of negotiations ending in agreement and leading to signed contracts
- Return type
-
breach_record
(breach)[source]¶ Converts a breach to a record suitable for storage during the simulation
-
property
business_size
¶ The total business size defined as the total money transferred within the system
- Return type
-
property
cancellation_rate
¶ Fraction of negotiations ending in agreement and leading to signed contracts
- Return type
-
compensate
(available, factory)[source]¶ Called by a factory when it is going bankrupt after liquidation
- Parameters
Returns:
- Return type
None
-
complete_contract_execution
(contract, breaches, resolution)[source]¶ Called after breach resolution is completed for contracts for which some potential breaches occurred.
- Parameters
contract (
Contract
) – The contract considered.breaches (
List
[Breach
]) – The list of potential breaches that was generated by_execute_contract
.resolution (
Contract
) – The agreed upon resolution
Returns:
- Return type
None
-
property
contract_execution_fraction
¶ Fraction of signed contracts successfully executed
- Return type
-
contract_size
(contract)[source]¶ Returns an estimation of the activity level associated with this contract. Higher is better :type contract:
Contract
:param contract:Returns:
- Return type
-
execute_action
(action, agent, callback=None)[source]¶ Executes the given action by the given agent
- Return type
-
classmethod
generate
(agent_types, agent_params=None, n_steps=100, n_processes=4, n_lines=10, n_agents_per_process=3, process_inputs=1, process_outputs=1, production_costs=(1, 10), profit_means=0.15, profit_stddevs=0.05, max_productivity=(0.8, 1.0), initial_balance=10000, cost_increases_with_level=False, equal_external_supply=False, equal_external_sales=False, cash_availability=1.0, profit_basis=<function mean>, **kwargs)[source]¶ Generates the configuration for a world
- Parameters
agent_types (
List
[Type
[SCML2020Agent
]]) – All agent typesagent_params (
Optional
[List
[Dict
[str
,Any
]]]) – Agent parameters used to initialize themn_steps – Number of simulation steps
n_processes – Number of processes in the production chain
n_lines (
Union
[ndarray
,Tuple
[int
,int
],int
]) – Number of lines per factoryprocess_inputs (
Union
[ndarray
,Tuple
[int
,int
],int
]) – Number of input units per processprocess_outputs (
Union
[ndarray
,Tuple
[int
,int
],int
]) – Number of output units per processproduction_costs (
Union
[ndarray
,Tuple
[int
,int
],int
]) – Production cost per factoryprofit_means (
Union
[ndarray
,Tuple
[float
,float
],float
]) – Mean profitability per production level (i.e. process).profit_stddevs (
Union
[ndarray
,Tuple
[float
,float
],float
]) – Std. Dev. of the profitability of every level (i.e. process).max_productivity (
Union
[ndarray
,Tuple
[float
,float
],float
]) – Maximum possible productivity per level (i.e. process).initial_balance (
Union
[ndarray
,Tuple
[int
,int
],int
,None
]) – The initial balance of all agentsn_agents_per_process (
Union
[ndarray
,Tuple
[int
,int
],int
]) – Number of agents per processcost_increases_with_level – If true, production cost will be higher for processes nearer to the final product.
profit_basis – The statistic used when controlling catalog prices by profit arguments. It can be np.mean, np.median, np.min, np.max or any Callable[[list[float]], float] and is used to summarize production costs at every level.
equal_external_supply – If true, external supply will be distributed equally among all agents in the first layer
equal_external_sales – If true, external sales will be distributed equally among all agents in the last layer
cash_availability – The fraction of the total money needs of the agent to work at maximum capacity that is available as
initial_balance
. This is only effective ifinitial_balance
is set toNone
.**kwargs –
- Return type
- Returns
world configuration as a Dict[str, Any]. A world can be generated from this dict by calling SCML2020World(**d)
Remarks:
Most parameters (i.e.
process_inputs
,process_outputs
,n_agents_per_process
,costs
) can take a single value, a tuple of two values, or a list of values. If it has a single value, it is repeated for all processes/factories as appropriate. If it is a tuple of two numbers $(i, j)$, each process will take a number sampled from a uniform distribution supported on $[i, j]$ inclusive. If it is a list of values, of the lengthn_processes
, it is used as it is otherwise, it is used to sample values for each process.
-
property
n_negotiation_rounds_failed
¶ Average number of rounds in a successful negotiation
- Return type
-
property
n_negotiation_rounds_successful
¶ Average number of rounds in a successful negotiation
- Return type
-
on_contract_concluded
(contract, to_be_signed_at)[source]¶ Called to add a contract to the existing set of contract after it is signed
- Parameters
contract (
Contract
) – The contract to addto_be_signed_at (
int
) – The timestep at which the contract is to be signed
Remarks:
By default this function just adds the contract to the set of contracts maintaned by the world.
You should ALWAYS call this function when overriding it.
- Return type
None
-
on_contract_signed
(contract)[source]¶ Called to add a contract to the existing set of contract after it is signed
- Parameters
contract (
Contract
) – The contract to add
Remarks:
By default this function just adds the contract to the set of contracts maintaned by the world.
You should ALWAYS call this function when overriding it.
-
order_contracts_for_execution
(contracts)[source]¶ Orders the contracts in a specific time-step that are about to be executed
- Return type
Collection
[Contract
]
-
pre_step_stats
()[source]¶ Called at the beginning of the simulation step to prepare stats or update them
-
start_contract_execution
(contract)[source]¶ Tries to execute the contract
- Parameters
contract (
Contract
) –- Returns
The set of breaches committed if any. If there are no breaches return an empty set
- Return type
Set[Breach]
Remarks:
You must call super() implementation of this method before doing anything
-
property
winners
¶ The winners of this world (factory managers with maximum wallet balance
-
class
scml.
FinancialReport
(agent_id, step, cash, assets, breach_prob, breach_level, is_bankrupt, agent_name)[source]¶ A report published periodically by the system showing the financial standing of an agent
-
agent_id
¶ Agent ID
-
agent_name
¶ Agent name for printing purposes
-
assets
¶ Value of the products in the agent’s inventory @ catalog prices.
-
breach_level
¶ Sum of the agent’s breach levels so far divided by the number of contracts it signed.
-
breach_prob
¶ Number of times the agent breached a contract over the total number of contracts it signed.
-
cash
¶ Cash in the agent’s wallet. Negative numbers indicate liabilities.
-
is_bankrupt
¶ Whether the agent is already bankrupt (i.e. incapable of doing any more transactions).
-
step
¶ Simulation step at the beginning of which the report was published.
-
-
class
scml.
FactoryProfile
(costs, external_sales, external_supplies, external_sale_prices, external_supply_prices)[source]¶ Defines all private information of a factory
-
costs
¶ An n_lines * n_processes array giving the cost of executing any process (INVALID_COST indicates infinity)
-
external_sale_prices
¶ A n_steps * n_products array giving guaranteed unit prices for the
external_quantities
. It will be zero for times and products for which there are no guaranteed quantities (i.e. (external_quantities[…] == 0) =>(external_prices[…] == 0) )
-
external_sales
¶ A n_steps * n_products array giving guaranteed sales of different products for the whole simulation time
-
external_supplies
¶ A n_steps * n_products array giving guaranteed sales of different products for the whole simulation time
-
external_supply_prices
¶ A n_steps * n_products array giving guaranteed unit prices for the
external_quantities
. It will be zero for times and products for which there are no guaranteed quantities (i.e. (external_quantities[…] == 0) =>(external_prices[…] == 0) )
-
-
class
scml.
Factory
(profile, initial_balance, inputs, outputs, catalog_prices, world, compensate_before_past_debt, buy_missing_products, external_penalty, external_no_bankruptcy, external_no_borrow, production_penalty, production_no_bankruptcy, production_no_borrow, agent_id, agent_name=None)[source]¶ A simulated factory
-
agent_id
= None¶ A unique ID for the agent owning the factory
-
agent_name
= None¶ SCML2020Agent names used for logging purposes
-
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.
-
balance_change
= None¶ Change in the balance in the last step
-
buy
(product, quantity, unit_price, buy_missing, penalty, no_bankruptcy=False, no_borrowing=False)[source]¶ Executes a transaction to buy/sell involving adding quantity and paying price (both are signed)
- Parameters
product (
int
) – The product transacted onquantity (
int
) – The quantity (added)unit_price (
int
) – The unit price (paid)buy_missing (
bool
) – If true, attempt buying missing products from the spot marketpenalty (
float
) – The penalty as a fraction to be paid for breachesno_bankruptcy (
bool
) – If true, this transaction can never lead to bankruptcyno_borrowing (
bool
) – If true, this transaction can never lead to borrowing
- Return type
- Returns
Tuple[int, int] The actual quantities bought and the total cost
-
cancel_production
(step, line)[source]¶ Cancels pre-ordered production given that it did not start yet.
- Parameters
- Return type
- Returns
True if step >= self.current_step
Remarks:
Cannot cancel a process in the past or present.
-
commands
= None¶ An n_steps * n_lines array giving the process scheduled for each line at every step. -1 indicates an empty line.
-
contracts
= None¶ A list of lists of contracts per time-step (len == n_steps)
-
inputs
= None¶ An n_process array giving the number of inputs needed for each process (of the product with the same index)
-
inventory_changes
= None¶ Changes in the inventory in the last step
-
is_bankrupt
= None¶ Will be true when the factory is bankrupt
-
min_balance
= None¶ The minimum balance possible
-
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
None
-
outputs
= None¶ An n_process array giving the number of outputs produced by each process (of the product with the next index)
-
profile
= None¶ The readonly factory profile (See
FactoryProfile
)
-
schedule_production
(process, repeats, step=-1, line=-1, override=True, method='latest')[source]¶ Orders production of the given process on the given step and line.
- Parameters
process (
int
) – The process indexrepeats (
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.
-
step
(accepted_sales, accepted_supplies)[source]¶ Override this method to modify stepping logic.
- Parameters
Returns:
- Return type
List
[Failure
]
-
store
(product, quantity, unit_price, buy_missing, penalty, no_bankruptcy=False, no_borrowing=False)[source]¶ Stores the given amount of product (signed) to the factory.
- Parameters
product (
int
) – Productquantity (
int
) – quantity to store/take out (-ve means take out)unit_price (
int
) – Unit pricebuy_missing (
bool
) – If the quantity is negative and not enough product exists in the market, it buys the product from the spot-market at an increased price of penaltypenalty (
float
) – The fraction of unit_price added because we are buying from the spot market. Only effectivec if quantity is negative and not enough of the product exists in the inventoryno_bankruptcy (
bool
) – Never bankrupt the agent on this transactionno_borrowing (
bool
) – Never borrow for this transaction
- Return type
- Returns
The quantity actually stored or taken out (always positive)
-