SlowFactorySimulator¶
- class scml.scml2019.SlowFactorySimulator(initial_wallet, initial_storage, n_steps, n_products, profiles, max_storage)[source]¶
Bases:
scml.scml2019.simulators.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 given everything scheduled so-far
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
goto
(t)Steps the factory to the end of step t :type t:
int
:param t: timeReturns 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
reset_to
(t)- rtype
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 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
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¶
- initial_storage¶
Initial inventory
- Return type
array
- n_lines¶
Methods Documentation
- 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)¶
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-stept
.
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)¶
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)¶
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)¶
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
- bookmark()[source]¶
Sets a bookmark to the current location
- Return type
- 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 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
- delete_bookmark(bookmark_id)[source]¶
Commits everything since the bookmark so it cannot be rolled back
- Parameters
bookmark (bookmark_id The bookmark ID returned from) –
- 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).
- fix_before(t)[source]¶
Fix the history before this point
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 beforet
.This function is useful for fixing any difference between the simulator and the real state (in conjunction with
set_state
).
See also
- goto(t)[source]¶
Steps the factory to the end of step t :type t:
int
:param t: timeReturns:
- Return type
- line_schedules_at(t)¶
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
- 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
- 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.
- 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)¶
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-stept
.
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)¶
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.
- rollback(bookmark_id)[source]¶
Rolls back to the given bookmark ID
- Parameters
bookmark (bookmark_id The bookmark ID returned from) –
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
- 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 time-step
- Return type
- 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 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
- 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 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)¶
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-stept
.
See also
- 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)¶
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)¶
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
- 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