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_balance

Current wallet balance

current_inventory

Current inventory contents

state

rtype:

FactoryState

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

current_balance

Current wallet balance

Return type:

int

current_inventory

Current inventory contents

Return type:

ndarray

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.

bankrupt(required)[source]

Bankruptcy processing for the given agent

Parameters:

required (int) – The money required after the bankruptcy is processed

Return type:

int

Returns:

The amount of money to pay back to the entity that should have been paid money

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 on

  • quantity (int) – The quantity (added)

  • unit_price (int) – The unit price (paid)

  • buy_missing (bool) – If true, attempt buying missing products from the spot market

  • penalty (float) – The penalty as a fraction to be paid for breaches

  • no_bankruptcy (bool) – If true, this transaction can never lead to bankruptcy

  • no_borrowing (bool) – If true, this transaction can never lead to borrowing

Return type:

Tuple[int, int]

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:
  • step (int) – Step to cancel at

  • line (int) – Line to cancel at

Return type:

bool

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:
  • 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

pay(money, no_bankruptcy=False, no_borrowing=False, unit=0)[source]

Pays money

Parameters:
  • money (int) – amount to pay

  • no_bankruptcy (bool) – If true, this transaction can never lead to bankruptcy

  • no_borrowing (bool) – If true, this transaction can never lead to borrowing

  • unit (int) – If nonzero then an integer multiple of unit will be paid

Return type:

int

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 index

  • 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

  • partial_ok (bool) – If true, it is OK to produce only a subset of repeats

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.

spot_price(product, spot_loss)[source]

Get the current spot price for buying the given product on the spot market

Parameters:
  • product (int) – Product

  • spot_loss (float) – Spot loss specific to that agent

Return type:

int

Returns:

The unit price

step()[source]

Override this method to modify stepping logic.

Return type:

List[Failure]

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) – Product

  • quantity (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 penalty

  • spot_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 inventory

  • no_bankruptcy (bool) – Never bankrupt the agent on this transaction

  • no_borrowing (bool) – Never borrow for this transaction

Return type:

int

Returns:

The quantity actually stored or taken out (always positive)