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 walletn_steps (
int
) – number of simulation stepsn_products (
int
) – number of products in the worldprofiles (
List
[ManufacturingProfile
]) – all profiles that the factory being simulated can runmax_storage (
Optional
[int
]) – maximum available storage space.
Attributes Summary
Final balance given everything scheduled sofar
Gives the time before which the schedule is fixed.
Initial inventory
Initial cash in wallet
Maximum storage available
Number of lines
Number of steps to predict ahead.
Methods Summary
add_loan
(total, t)Adds a loan at the given time
Returns the available storage of all products at time 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
Returns the schedule of each line at a given timestep
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.
Returns the reserved storage of all products at time 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
andline
optionally overriding whatever was already scheduledsell
(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 timestep.
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
The total storage at a given time
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

fixed_before
¶ Gives the time before which the schedule is fixed.
See also

initial_storage
¶ Initial inventory
 Return type
array

n_lines
¶ Number of lines
Methods Documentation

abstract
add_loan
(total, t)[source]¶ Adds a loan at the given time
 Parameters
 Return type
 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 timestept
.
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 tot
.
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
 Return type

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
 Return type
array

abstract
bookmark
()[source]¶ Sets a bookmark to the current location
 Return type
 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 buyprice (
int
) – unit pricet (
int
) – timeignore_money_shortage (
bool
) – If True, shortage in money will be ignored and the wallet can go negativeignore_space_shortage (
bool
) – Ignore the limit on total storage which may lead to total_storage > max_storage
 Return type
 Returns
Success or failure
Remarks:
buy cannot ever have inventory shortage
See also

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
 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
Remarks:
After this function is called at any timestep
t
, there is no way to change any component of the factory state at any timestep beforet
.This function is useful for fixing any difference between the simulator and the real state (in conjunction with
set_state
).
See also

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 att
.
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 tot
.
Remarks:
A
NO_PRODUCTION
value means no production, otherwise the index of the process being run

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 timesteps up tot

reserve
(product, quantity, t)[source]¶ Simulates reserving the given quantity of the given product at times >= t.
 Parameters
 Return type
 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
andavailable_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 timestept
.
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 tot
.
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

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
andline
optionally overriding whatever was already scheduled Parameters
job (
Job
) – Production jobignore_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 timestep
 Return type
 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 soldquantity (
int
) – quantity to be soldprice (
int
) – unit pricet (
int
) – timeignore_money_shortage (
bool
) – If True, shortage in money will be ignored and the wallet can go negativeignore_inventory_shortage (
bool
) – Ignore shortage in theproduct
which may lead to negative storage[product]
 Return type
 Returns
Success or failure
Remarks:
sell cannot ever have space shortage
See also

abstract
set_state
(t, storage, wallet, loans, line_schedules)[source]¶ Sets the current state at the given timestep. It implicitly causes a fix_before(t + 1)
 Parameters
t (
int
) – Time step to set the state atstorage (
array
) – quantity of every product (array of integers of sizen_products
)wallet (
float
) – Cash in walletloans (
float
) – Loansline_schedules (
array
) – Line schedules (array of process numbers/NO_PRODUCTION of sizen_lines
)
 Return type

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 timestept
.
See also

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

total_storage_at
(t)[source]¶ The total storage at a given time
 Parameters
t (
int
) – time Return type
 Returns
an integer giving the total quantity of stored products in the inventory at timestep
t
See also

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 timestept
See also

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 transportt (
int
) – timeignore_inventory_shortage (
bool
) – Ignore shortage in theproduct
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
 Returns
Success or failure