The adoption fraction in our model is constant each period. Actually it changes in a complex way since the demand on our product follows the cycle of the seasons. The peak of the demand is in summer while in winter the product is in little demand. There is also a little peak in adopter activity before the New Year holiday. We want to model the demand cycle and its affect on the adoption fraction in our model.
Assume that we have experimental data how the average demand on the product changes during the year. We will use a table function to add this data to our model. Table function is a function defined in the table form. It returns tabulated values for defined argument values. If the function argument does not correspond to any of the tabulated values, table function computes a value based on the chosen interpolation.
Define the demand curve with a table function
- Drag the Table Function element from the System Dynamics palette onto the Main diagram.
- Go to the table function’s Properties and set up the function properties.
- Name the function demand.
Define data for a table function in the Table Data table. Each “argument-value” pair is specified in an individual row of the table. To define pair of values, click the empty Argument cell and enter a new argument of the function. Then click the adjacent Value cell to the right and enter the function value for this argument. Define the function values as in the following figure:
- Define how the table function is interpolated. From the Interpolation drop-down list, choose Linear. The function will take a straight line between data points.
- Define how the function behaves when the provided arguments are out-of-range. From the Out Of Range drop-down list, choose Nearest option. In the case of out-of-range arguments the function will raise an error. The function will use the nearest valid argument for out-of-range arguments.
Finally you will see how the demand curve looks in the function’s preview chart on the function’s properties page:
Now we want to model how the adoption fraction depends on the current demand on the product. Therefore we will define a custom function and replace the AdoptionFraction parameter with the dynamic variable, which value is calculated according to this function.
Define a function evaluating the adoption fraction
- Drag the Function element from the Agent palette onto the Main diagram.
- Go to the function’s Properties and name the function adoptFraction.
- Specify that the function returns the double value. Choose the Returns value option and leave double as the return Type.
- Our function should have one argument to pass the current time value to the function. In the Arguments section of the properties, add argument with Name: time and Type: double.
- Open the Function body section of the Properties and enter the function expression. Type here the following string instead of existing one:
return demand( getMonth() 1 )/200.0;
This expression calculates the demand for the current month. Finally, to obtain the adoption fraction value, the demand value is divided on the conversion factor.
getMonth() is AnyLogic predefined function. You can use frequently used functions (sin(), time(), getDay(), etc.) in your expressions. Entering expressions, you can use code completion, where predefined functions are listed as well as variables.
Finally, we will replace the adoption fraction constant with the dynamic variable evaluating its value with the created function.
Replace AdoptionFraction parameter with a dynamic variable
- Delete AdoptionFraction parameter.
Create the AdoptionFraction dynamic variable. Set the variable’s formula to adoptFraction(time()). Thus, the dynamic variable’s value will be computed by our function. The function takes one argument, time().
time() function returns the current model time.
Set DiscardRate to be displayed by the lower time plot
- Just add DiscardRate as one more data item to be displayed by this plot.
- Specify Discard rate as the title of this data item.
Set model to stop at time 20 and run the model. You can see that now the behavior of a model deviates above and below an equilibrium point since the adoption rate and the discard rate oscillate.
Reference model: Bass Diffusion — Phase 4
How can we improve this article?