scml.scml2020.factory

Implements the world class for the SCML2020 world

Module Contents

Classes

Factory

A simulated factory

class scml.scml2020.factory.Factory(profile: scml.scml2020.common.FactoryProfile, initial_balance: int, inputs: numpy.ndarray, outputs: numpy.ndarray, catalog_prices: numpy.ndarray, world: scml.scml2020.world.SCML2020World, compensate_before_past_debt: bool, buy_missing_products: bool, production_buy_missing: bool, production_penalty: float, production_no_bankruptcy: bool, production_no_borrow: bool, agent_id: str, agent_name: str | None = None, confirm_production: bool = True, initial_inventory: numpy.ndarray | None = None, disallow_concurrent_negs_with_same_partners=False)[source]

A simulated factory

property state: scml.scml2020.common.FactoryState[source]
property current_inventory: numpy.ndarray[source]

Current inventory contents

property current_balance: int[source]

Current wallet balance

_disallow_concurrent_negs_with_same_partners[source]

The readonly factory profile (See FactoryProfile )

commands[source]

An n_steps * n_lines array giving the process scheduled for each line at every step. -1 indicates an empty line.

_balance[source]

Current balance

_inventory[source]

Current inventory

agent_id[source]

A unique ID for the agent owning the factory

inputs[source]

An n_process array giving the number of inputs needed for each process (of the product with the same index)

outputs[source]

An n_process array giving the number of outputs produced by each process (of the product with the next index)

inventory_changes[source]

Changes in the inventory in the last step

balance_change = 0[source]

Change in the balance in the last step

min_balance[source]

The minimum balance possible

is_bankrupt = False[source]

Will be true when the factory is bankrupt

agent_name[source]

SCML2020Agent names used for logging purposes

contracts: List[List[scml.scml2020.common.ContractInfo]][source]

A list of lists of contracts per time-step (len == n_steps)

schedule_production(process: int, repeats: int, step: int | Tuple[int, int] = ANY_STEP, line: int = ANY_LINE, override: bool = True, method: str = 'latest', partial_ok: bool = False) Tuple[numpy.ndarray, numpy.ndarray][source]

Orders production of the given process on the given step and line.

Parameters:
  • process – The process index

  • repeats – How many times to repeat the process

  • step – 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 – The production line. The special value ANY_LINE gives the factory the freedom to use any line

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

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

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

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.

order_production(process: int, steps: numpy.ndarray, lines: numpy.ndarray) None[source]

Orders production of the given process

Parameters:
  • process – The process to run

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

  • lines – 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

available_for_production(repeats: int, step: int | Tuple[int, int] = ANY_STEP, line: int = ANY_LINE, override: bool = True, method: str = 'latest') Tuple[numpy.ndarray, numpy.ndarray][source]

Finds available times and lines for scheduling production.

Parameters:
  • repeats – How many times to repeat the process

  • step – 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 – The production line. The special value ANY_LINE gives the factory the freedom to use any line

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

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

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: int, line: int) bool[source]

Cancels pre-ordered production given that it did not start yet.

Parameters:
  • step – Step to cancel at

  • line – Line to cancel at

Returns:

True if step >= self.current_step

Remarks:

  • Cannot cancel a process in the past or present.

step() List[scml.scml2020.common.Failure][source]

Override this method to modify stepping logic.

spot_price(product: int, spot_loss: float) int[source]

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

Parameters:
  • product – Product

  • spot_loss – Spot loss specific to that agent

Returns:

The unit price

store(product: int, quantity: int, buy_missing: bool, spot_price: float, no_bankruptcy: bool = False, no_borrowing: bool = False) int[source]

Stores the given amount of product (signed) to the factory.

Parameters:
  • product – Product

  • quantity – quantity to store/take out (-ve means take out)

  • buy_missing – 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 – 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 – Never bankrupt the agent on this transaction

  • no_borrowing – Never borrow for this transaction

Returns:

The quantity actually stored or taken out (always positive)

buy(product: int, quantity: int, unit_price: int, buy_missing: bool, penalty: float, no_bankruptcy: bool = False, no_borrowing: bool = False) Tuple[int, int][source]

Executes a transaction to buy/sell involving adding quantity and paying price (both are signed)

Parameters:
  • product – The product transacted on

  • quantity – The quantity (added)

  • unit_price – The unit price (paid)

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

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

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

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

Returns:

Tuple[int, int] The actual quantities bought and the total cost

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

Pays money

Parameters:
  • money – amount to pay

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

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

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

Returns:

The amount actually paid

bankrupt(required: int) int[source]

Bankruptcy processing for the given agent

Parameters:

required – The money required after the bankruptcy is processed

Returns:

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