FactorySimulator

class scml.scml2019.FactorySimulator(initial_wallet, initial_storage, n_steps, n_products, profiles, max_storage=None)[source]

Bases: abc.ABC

Simulates a factory allowing for prediction of storage/balance in the future.

Parameters
  • initial_wallet (float) – The initial amount of cash in the wallet

  • initial_storage (Dict[int, int]) – initial inventory

  • n_steps (int) – number of simulation steps

  • n_products (int) – number of products in the world

  • profiles (List[ManufacturingProfile]) – all profiles that the factory being simulated can run

  • max_storage (Optional[int]) – maximum available storage space.

Attributes Summary

final_balance

Final balance given everything scheduled so-far

fixed_before

Gives the time before which the schedule is fixed.

initial_storage

Initial inventory

initial_wallet

Initial cash in wallet

max_storage

Maximum storage available

n_lines

Number of lines

n_steps

Number of steps to predict ahead.

Methods Summary

add_loan(total, t)

Adds a loan at the given time

available_storage_at(t)

Returns the available storage of all products at time t

available_storage_to(t)

Returns the available storage of all products up to time t.

balance_at(t)

Returns the balance fo the factory at time t.

balance_to(t)

Returns the balance fo the factory up to time t.

bookmark()

Sets a bookmark to the current location

buy(product, quantity, price, t[, …])

Buy a given quantity of a product for a given price at some time t

delete_bookmark(bookmark_id)

Commits everything since the bookmark so it cannot be rolled back

fix_before(t)

Fix the history before this point

line_schedules_at(t)

Returns the schedule of each line at a given timestep

line_schedules_to(t)

Returns the schedule of each line up to a given timestep

loans_at(t)

Returns loans at time t

loans_to(t)

Returns loans up to time t

pay(payment, t[, ignore_money_shortage])

Simulate payment at time t

receive(payment, t)

Simulates receiving payment at time t

reserve(product, quantity, t)

Simulates reserving the given quantity of the given product at times >= t.

reserved_storage_at(t)

Returns the reserved storage of all products at time t

reserved_storage_to(t)

Returns the reserved storage of all products up to time t

rollback(bookmark_id)

Rolls back to the given bookmark ID

schedule(job[, ignore_inventory_shortage, …])

Simulates scheduling the given job at its time and line optionally overriding whatever was already scheduled

sell(product, quantity, price, t[, …])

sell a given quantity of a product for a given price at some time t

set_state(t, storage, wallet, loans, …)

Sets the current state at the given time-step.

storage_at(t)

Returns the storage of all products at time t

storage_to(t)

Returns the storage of all products up to time t

total_storage_at(t)

The total storage at a given time

total_storage_to(t)

The total storage up to a given time

transport_to(product, quantity, t[, …])

Simulates transporting products to/from storage at time t

wallet_at(t)

Returns the cash in wallet at a given timestep (given all simulated actions)

wallet_to(t)

Returns the cash in wallet up to and including time t.

Attributes Documentation

final_balance

Final balance given everything scheduled so-far

Return type

float

fixed_before

Gives the time before which the schedule is fixed.

See also

fix_before

initial_storage

Initial inventory

Return type

array

initial_wallet

Initial cash in wallet

Return type

float

max_storage

Maximum storage available

Return type

Optional[int]

n_lines

Number of lines

n_steps

Number of steps to predict ahead.

Return type

int

Methods Documentation

abstract add_loan(total, t)[source]

Adds a loan at the given time

Parameters
  • total (float) – Total amount of the loan

  • t (int) – time step to take the loan

Return type

bool

Returns

Success or failure

Remarks:

  • Taking a loan is simulated as reception of money. Payment back of the loan is not simulated in this call. To simulate paying back the loan, use pay at the times of installment payments.

available_storage_at(t)[source]

Returns the available storage of all products at time t

Parameters

t (int) – Time

Return type

array

Returns

An array of size n_products giving the quantity of each product available at time-step t.

Remarks:

  • Available storage is defined as the difference between storage and reserved storage.

  • Reserved storage is counted in calls to storage_at , total_storage_at , storage_to , total_storage_to

  • Reserving quantities of products is a tool that can be used to avoid double counting availability of given products in the inventory for multiple contracts.

available_storage_to(t)[source]

Returns the available storage of all products up to time t.

Parameters

t (int) – Time

Return type

array

Returns

An array of size n_products * t giving the quantity of each product available at every step up to t.

Remarks:

  • Available storage is defined as the difference between storage and reserved storage.

  • Reserved storage is counted in calls to storage_at , total_storage_at , storage_to , total_storage_to

  • Reserving quantities of products is a tool that can be used to avoid double counting availability of given products in the inventory for multiple contracts.

balance_at(t)[source]

Returns the balance fo the factory at time t.

Parameters

t (int) – time

Remarks:

  • The balance is defined as the cash in wallet minus loans

See also

loans_at wallet_at

Return type

float

balance_to(t)[source]

Returns the balance fo the factory up to time t.

Parameters

t (int) – time

Remarks:

  • The balance is defined as the cash in wallet minus loans

See also

loans_to wallet_to

Return type

array

abstract bookmark()[source]

Sets a bookmark to the current location

Return type

int

Returns

bookmark ID

Remarks:

  • Bookmarks can be used to implement transactions.

abstract buy(product, quantity, price, t, ignore_money_shortage=True, ignore_space_shortage=True)[source]

Buy a given quantity of a product for a given price at some time t

Parameters
  • product (int) – Product to buy (ID/index)

  • quantity (int) – quantity to buy

  • price (int) – unit price

  • t (int) – time

  • ignore_money_shortage (bool) – If True, shortage in money will be ignored and the wallet can go negative

  • ignore_space_shortage (bool) – Ignore the limit on total storage which may lead to total_storage > max_storage

Return type

bool

Returns

Success or failure

Remarks:

  • buy cannot ever have inventory shortage

See also

sell

abstract delete_bookmark(bookmark_id)[source]

Commits everything since the bookmark so it cannot be rolled back

Parameters

The bookmark ID returned from bookmark (bookmark_id) –

Return type

bool

Returns

Success/failure

Remarks:

  • You can delete bookmarks in the reverse order of their creation only. If the bookmark ID given here is not the one at the top of the bookmarks stack, the deletion will fail (return False).

abstract fix_before(t)[source]

Fix the history before this point

Parameters

t (int) – time

Return type

bool

Returns

Success/failure

Remarks:

  • After this function is called at any time-step t, there is no way to change any component of the factory state at any timestep before t.

  • This function is useful for fixing any difference between the simulator and the real state (in conjunction with set_state).

line_schedules_at(t)[source]

Returns the schedule of each line at a given timestep

Parameters

t (int) – time

Return type

array

Returns

An array of n_lines values giving the schedule up at t.

Remarks:

  • A NO_PRODUCTION value means no production, otherwise the index of the process being run

abstract line_schedules_to(t)[source]

Returns the schedule of each line up to a given timestep

Parameters

t (int) – time

Return type

array

Returns

An array of n_lines * t values giving the schedule up to t.

Remarks:

  • A NO_PRODUCTION value means no production, otherwise the index of the process being run

loans_at(t)[source]

Returns loans at time t

Parameters

t (int) – time

Return type

float

abstract loans_to(t)[source]

Returns loans up to time t

Parameters

t (int) – time

Return type

array

Returns

An array of t real numbers giving the loans registered at time-steps up to t

abstract pay(payment, t, ignore_money_shortage=True)[source]

Simulate payment at time t

Parameters
  • payment (float) – Amount payed

  • t (int) – time

  • ignore_money_shortage (bool) – If True, shortage in money will be ignored and the wallet can go negative

Return type

bool

Returns

Success or failure

receive(payment, t)[source]

Simulates receiving payment at time t

Parameters
  • payment (float) – Amount received

  • t (int) – time

Return type

bool

Returns

Success or failure

reserve(product, quantity, t)[source]

Simulates reserving the given quantity of the given product at times >= t.

Parameters
  • product (int) – Index/ID of the product being reserved

  • quantity (int) – quantity being reserved

  • t (int) – time

Return type

bool

Returns

Success/failure

Remarks:

  • Reserved products show in calls to storage_at , total_storage_at etc.

  • Reserving a product does nothing more than mark some quantity as reserved for calls to reserved_storage_at and available_storage_at.

  • This feature can be used to simulate inventory hiding commands in the real factory and to avoid double counting of inventory when calculating needs for future contracts.

reserved_storage_at(t)[source]

Returns the reserved storage of all products at time t

Parameters

t (int) – Time

Return type

array

Returns

An array of size n_products giving the quantity of each product reserved at time-step t.

Remarks:

  • Reserved storage is counted in calls to storage_at , total_storage_at , storage_to , total_storage_to

  • Reserving quantities of products is a tool that can be used to avoid double counting availability of given products in the inventory for multiple contracts.

reserved_storage_to(t)[source]

Returns the reserved storage of all products up to time t

Parameters

t (int) – Time

Return type

array

Returns

An array of size n_products * t giving the quantity of each product reserved at every step up to t.

Remarks:

  • Reserved storage is counted in calls to storage_at , total_storage_at , storage_to , total_storage_to

  • Reserving quantities of products is a tool that can be used to avoid double counting availability of given products in the inventory for multiple contracts.

abstract rollback(bookmark_id)[source]

Rolls back to the given bookmark ID

Parameters

The bookmark ID returned from bookmark (bookmark_id) –

Remarks:

  • You can only rollback in the reverse order of bookmarks. If the bookmark ID given here is not the one at the top of the bookmarks stack, the rollback will fail (return False)

Return type

bool

abstract schedule(job, ignore_inventory_shortage=True, ignore_money_shortage=True, ignore_space_shortage=True, override=True)[source]

Simulates scheduling the given job at its time and line optionally overriding whatever was already scheduled

Parameters
  • job (Job) – Production job

  • ignore_inventory_shortage – If true shortages in inputs will be ignored

  • ignore_money_shortage – If true, shortage in money will be ignored

  • ignore_space_shortage – If true, shortage in space will be ignored

  • override – Whether the job should override any already registered job at its time-step

Return type

bool

Returns

Success/failure

abstract sell(product, quantity, price, t, ignore_money_shortage=True, ignore_inventory_shortage=True)[source]

sell a given quantity of a product for a given price at some time t

Parameters
  • product (int) – Index/ID of the product to be sold

  • quantity (int) – quantity to be sold

  • price (int) – unit price

  • t (int) – time

  • ignore_money_shortage (bool) – If True, shortage in money will be ignored and the wallet can go negative

  • ignore_inventory_shortage (bool) – Ignore shortage in the product which may lead to negative storage[product]

Return type

bool

Returns

Success or failure

Remarks:

  • sell cannot ever have space shortage

See also

buy

abstract set_state(t, storage, wallet, loans, line_schedules)[source]

Sets the current state at the given time-step. It implicitly causes a fix_before(t + 1)

Parameters
  • t (int) – Time step to set the state at

  • storage (array) – quantity of every product (array of integers of size n_products)

  • wallet (float) – Cash in wallet

  • loans (float) – Loans

  • line_schedules (array) – Line schedules (array of process numbers/NO_PRODUCTION of size n_lines)

Return type

None

storage_at(t)[source]

Returns the storage of all products at time t

Parameters

t (int) – Time

Return type

array

Returns

An array of size n_products giving the quantity of each product in storage at time-step t.

abstract storage_to(t)[source]

Returns the storage of all products up to time t

Parameters

t (int) – Time

Return type

array

Returns

An array of size n_products * t giving the quantity of each product in storage at every step up to t.

total_storage_at(t)[source]

The total storage at a given time

Parameters

t (int) – time

Return type

int

Returns

an integer giving the total quantity of stored products in the inventory at timestep t

total_storage_to(t)[source]

The total storage up to a given time

Parameters

t (int) – time

Return type

array

Returns

an array of size t giving the total quantity of stored products in the inventory up to timestep t

abstract transport_to(product, quantity, t, ignore_inventory_shortage=True, ignore_space_shortage=True)[source]

Simulates transporting products to/from storage at time t

Parameters
  • product (int) – product ID (index)

  • quantity (int) – quantity to transport

  • t (int) – time

  • ignore_inventory_shortage (bool) – Ignore shortage in the product which may lead to negative storage[product]

  • ignore_space_shortage (bool) – Ignore the limit on total storage which may lead to total_storage > max_storage

Return type

bool

Returns

Success or failure

wallet_at(t)[source]

Returns the cash in wallet at a given timestep (given all simulated actions)

Parameters

t (int) –

Returns:

Return type

float

abstract wallet_to(t)[source]

Returns the cash in wallet up to and including time t.

Parameters

t (int) – Time

Returns:

Return type

array