SlowFactorySimulator

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

Bases: scml.scml2019.FactorySimulator

A slow factory simulator that runs an internal factory to find-out what will happen in the future

Remarks:

  • It is much faster to always access the properties/methods of this class in ascending time. If that is not the case, each time reversal will cause a complete reset.

  • It is recommended to call fix_before () to fix the past once a production step is completed. That will speed up operations

Attributes Summary

final_balance

Final balance given everything scheduled so-far

fixed_before

Gives the time before which the schedule is fixed.

n_lines

Number of lines

Methods Summary

add_loan(total, t)

Adds a loan at the given time

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

goto(t)

Steps the factory to the end of step t :type t: int :param t: time

line_schedules_to(t)

Returns the schedule of each line up to a given timestep

loans_to(t)

Returns loans up to time t

pay(payment, t[, ignore_money_shortage])

Simulate payment at time t

reset_to(t)

rtype

None

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_to(t)

Returns the storage of all products up to time t

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

Simulates transporting products to/from storage at time t

wallet_to(t)

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

Attributes Documentation

final_balance
Return type

float

fixed_before
n_lines

Methods Documentation

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.

bookmark()[source]

Sets a bookmark to the current location

Return type

int

Returns

bookmark ID

Remarks:

  • Bookmarks can be used to implement transactions.

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

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).

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).

goto(t)[source]

Steps the factory to the end of step t :type t: int :param t: time

Returns:

Return type

None

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_to(t)[source]

Returns loans up to time t

Parameters

t (int) – time

Return type

float

Returns

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

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

reset_to(t)[source]
Return type

None

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

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

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

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_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.

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_to(t)[source]

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

Parameters

t (int) – Time

Returns:

Return type

array