Reference 〉 Class
funcStore

Shocks(modelHelipad)

The Shocks class is an interface for registering automatic shocks to a model parameter. A shock takes a timer function, which determines when to shock the parameter; a value function, which determines how to shock the parameter; and – of course – which parameter to shock. Shocks can be turned on and off from the control panel.

The shocks object is subscriptable: shocks[key] returns the shock registered with name=key. See shocks.add(). It should not be instantiated by user code; the model’s shocks object is initialized during setup and stored in model.shocks. The shock itself is represented with the Shock object, stored in the dict keys of Shocks.

Initialization Parameters

  • model Helipad, required

    The model object.

Methods

Click a method name for more detailed documentation.

  • add( name, param, valFunc, … )

    Registers a shock to a parameter value. Associated with a value function, which shocks the variable, and a timer function, which determines when and how often to execute the value function.

  • atperiod( n )

    Generates a timer function that returns True at one or several specified periods.

  • clear( )

    Clears all added data from the container.

  • everyn( n, offset )

    Generates a timer function that returns True periodically every so many periods.

  • randn( n )

    Generates a timer function that returns True with some probability each period.

  • remove( name, fname, removeall )

    Removes data stored at a certain key.

  • step( )

    Runs through the timer functions of the registered shocks and executes the shock function for any timer function that returns True.

    This function is called from model.step(). It should not be called from user code.

Object Properties

  • buttons dict{str:Shock}

    The subset of Shocks.shocks where shock.timerFunc=='button' and therefore render as buttons in the control panel.

  • shocksExceptButtons dict{str:Shock}

    The subset of Shocks.shocks where shock.timerFunc is a function and therefore render as checkboxes in the control panel.

  • Shock class

    A class to structure the shock data stored in Shocks.shocks, instantiated as the Shock object.

Static Properties

  • multi bool

    Whether the dict values should store a function, or a list of functions. This is a static property and should be changed only by subclassing funcStore.

    Initial value: False

Notes and Examples

  1. Contribute a Note

    Your email address will not be published. Required fields are marked *

    You may use limited HTML for formatting. Please embed blocks of code in <pre><code> </code></pre> tags.

History