Factory¶
- class scml.scml2020.Factory(profile, initial_balance, inputs, outputs, catalog_prices, world, compensate_before_past_debt, buy_missing_products, production_buy_missing, production_penalty, production_no_bankruptcy, production_no_borrow, agent_id, agent_name=None, confirm_production=True, initial_inventory=None, disallow_concurrent_negs_with_same_partners=False)[source]¶
Bases:
object
A simulated factory
Attributes Summary
Current wallet balance
Current inventory contents
- rtype:
Methods Summary
available_for_production
(repeats[, step, ...])Finds available times and lines for scheduling production.
bankrupt
(required)Bankruptcy processing for the given agent
buy
(product, quantity, unit_price, ...[, ...])Executes a transaction to buy/sell involving adding quantity and paying price (both are signed)
cancel_production
(step, line)Cancels pre-ordered production given that it did not start yet.
order_production
(process, steps, lines)Orders production of the given process
pay
(money[, no_bankruptcy, no_borrowing, unit])Pays money
schedule_production
(process, repeats[, ...])Orders production of the given process on the given step and line.
spot_price
(product, spot_loss)Get the current spot price for buying the given product on the spot market
step
()Override this method to modify stepping logic.
store
(product, quantity, buy_missing, spot_price)Stores the given amount of product (signed) to the factory.
Attributes Documentation
- 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.
- 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.
- 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:
- pay(money, no_bankruptcy=False, no_borrowing=False, unit=0)[source]¶
Pays money
- Parameters:
- Return type:
- Returns:
The amount actually paid
- schedule_production(process, repeats, step=-1, line=-1, override=True, method='latest', partial_ok=False)[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, allpartial_ok (
bool
) – If true, it is OK to produce only a subset of repeats
- 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.
- spot_price(product, spot_loss)[source]¶
Get the current spot price for buying the given product on the spot market
- store(product, quantity, buy_missing, spot_price, 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)buy_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 penaltyspot_price (
float
) – The fraction of unit_price added because we are buying from the spot market. Only effective 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)