Stock
system dynamics, bptk, bptk-py, python, business prototyping
Stock
Stock in an SD DSL model.
A stock is what a system remembers. Its value at any instant cannot be read off the rest of the system: it is the accumulation of everything that has flowed in and out since the start, which is why it needs both an initial value and an equation.
Create one through the model rather than directly: model.stock("population").
Stock Constructor
Stock(model, name)
Create the stock.
Stock.equation
property equation
The net change per timestep, not the value — usually the inflows minus the outflows. Read, it returns the equation as originally set - an SD DSL Element or Operator.
population.equation = births - deathsWriting the equation replaces the flow lists below. A non-negative stock refuses it: its equation comes from its lists.
Stock.inflows
property inflows
The flows into the stock, as a list. Setting it, or outflows, writes the equation as the inflows minus the outflows - see Inflows and Outflows as Lists.
population.inflows = [births, immigration]
population.outflows = [deaths]A flow leaves one stock only, so naming a flow among the outflows of a second stock raises ElementError.
Stock.initial_value
property initial_value
The value the stock holds at starttime, before any flow has acted on it. Set it to a number, to a Constant — which is what lets a scenario override it — or to any expression:
population = model.stock("population")
population.initial_value = 80000000.0
# or computed, from constants, converters or a user-defined function
births = model.constant("births")
births.equation = 800000.0
population.initial_value = births * 100The expression is evaluated once, before the run, with t at the start time. A boolean is refused, and so is anything that is not a number or a model expression; the error names the stock.
A scenario cannot set the stock itself as a constant - that would replace its equation and the stock would not move. It raises ValueError naming the stock; set the constant its initial value refers to instead.
Stock.non_negative
property non_negative
True keeps the stock from falling below zero, as Stella does, by cutting back its outflows in the order of the list. How they are cut back, the rules that come with it and what happens to a biflow: Non-Negative Stocks.
store.inflows = [delivery]
store.outflows = [sales, scrap]
store.non_negative = TrueStock.outflows
property outflows
The flows out of the stock, as a list. For a non-negative stock the order is the priority in which they are served.
Inherited from Element
Everything else — equation, function_string, plot() and the arrayed-element API — comes from Element, where it is documented once for all element types.