You are on page 1of 41

Bass diffusion model

Complexity: grade grade grade grade grade

Modeling approach: system dynamics

Features: optimization stock-and-flow


diagram stock flow parameter feedback loop link table function event time plot

AnyLogic supports different modeling techniques. This document covers System Dynamics modeling
approach. There are many spheres where system dynamics simulation can be successfully
applied — the range of SD applications includes business, urban, social, ecological types of systems.
AnyLogic allows you to create complex dynamic models using standard SD graphical notation.

This tutorial will briefly take you through the process of constructing a simulation model using
AnyLogic. It is intended to introduce you to AnyLogic interface and many of its main features. We will
create a simple illustrative example—the product life cycle model, used for forecasting sales of new
products.

The first 10 steps will take you through the process of construction of the classic Bass
diffusion model. The model describes a product diffusion process. Potential adopters of a product
are influenced into buying the product by advertising and by word of mouth from adopters — those
who have already purchased the new product. Adoption of a new product driven by word of mouth is
likewise an epidemic. Potential adopters come into contact with adopters through social interactions.
A fraction of these contacts results in the purchase of the new product. The advertising causes a
constant fraction of the potential adopter population to adopt each time period.

Then we will expand our model by considering some details and introducing you to some advanced
features of AnyLogic useful in creating system dynamics models. The expanded model may help you
to better plan the entry strategy, target the right consumer and anticipate demand so as to have an
efficient and effective promotion strategy.
There are several reference files available for this model representing the milestones of the editing.
You can use reference files if you experience any difficulties creating a model and you would like to
compare your model with the reference file. You can use Welcome Page to open those
examples. Welcome Page appears automatically when you open AnyLogic. It can be also opened
whenever you like from AnyLogic menu: Help > Welcome.
Phase 0. Analyzing the model

Phase 1. Creating a new model


First, we will create a new model.

Create a new model

1. Click the New toolbar button. The New Model dialog box is displayed.
2. Specify the name of the model. In the Model name edit box, type Bass Diffusion

3. Specify the location where you want to store your model file. Browse for the existing folder
using the Browse button, or type the name of the folder you want to create in the Location edit
box.
4. Select years as the Model time units.
5. Click Finish to complete the process.
New model is created. In the center you can see the graphical editor where you add model elements.
To the left of the graphical editor you can see the Projects view and the Palette view sharing the
same area, and to the right is the Properties view.

When working with a project, do not forget to save it by clicking Save model toolbar button.

Phase 2. Adding stocks


Now we will add two stocks to model adopter and potential adopter populations.

Add a stock to model potential adopter population

1. Drag the Stock element from the System Dynamics palette onto the graphical diagram of
the agent.

To open a stencil of the Palette view, click the corresponding tab of the view.
2. A new variable appears on the diagram, displayed as a little blue rectangle.

3. Once you have placed the element onto the diagram, it becomes selected and its properties
are displayed in the Properties view. You can adjust element properties here as your model
requires.

The Properties view is a context-sensitive view and it displays the properties of the currently
selected element of the model. To adjust properties at a later time, first select the element
(e.g. by clicking on the element in the graphical editor or in the Projects view) and then
modify the required properties.

Properties view. At the moment


view displays the properties of the currently selected stock.
4. Change the name of the stock. In the stock’s Properties, type PotentialAdopters

in the Name edit box.

5. Increase the stock icon a little bit. To resize the stock icon, first select it by clicking and then
drag the handle shown in its right lower corner.

Add a stock to model adopter population

1. Add another stock (the simplest way to get the stock of the same size is to clone the existing
stock by Ctrl + dragging (Mac OS: Cmd + dragging) its icon aside). Place it to the right of
the PotentialAdopters stock as shown in the figure below.
2. Name this stock Adopters

At this point, the stocks are not defined properly. We have not defined integral functions and initial
values for our stocks yet. But we will create the adoption flow first.
Phase 3. Adding adoption flow
We have successfully created two stocks representing population pools. It is time to create flows of
our model now. Our model has just one flow — a flow of adoption, which increases the adopter
population, while decreasing the potential adopter population.

Add a flow from PotentialAdopters to Adopters

1. Double-click the Flow.


2. Right after that, go to the graphical editor, click the stock where the flow flows out
( PotentialAdopters) and then click the stock where the flow flows in ( Adopters).
3. AnyLogic creates new flow and makes it an outflow for PotentialAdopters and an inflow
for Adopters. The direction of the flow arrow indicates the flow influence on population
pools.

If the flow is drawn correctly, when you select it with a click, its end points should be indicated
with little green circles. Otherwise, if there is a white circle on some its end, it means that this
particular end point was not connected correctly. To establish the valid connection, please
drag this end point onto the stock you want to connect.

4. Go to the properties of the flow and rename it to AdoptionRate

5. You can have a look at properties of the stocks now. AnyLogic automatically adjusts formulas
for stocks. The value of inflows i.e. flows that increase stock value, are added and the value of
outflows, i.e. flows that decrease stock are subtracted from the current value of the stock. In
our case we should have the following formulas defined:

We will define the formula calculating the value of the flow a little bit later.
Phase 4. Adding constants
Now we will define constants of our model. In AnyLogic you define a constant by creating a
parameter.

Define a constant representing total population

1. Drag the Parameter element from the System Dynamics palette onto the graphical
diagram of agent.
2. In the parameter’s Properties, set up the parameter properties.
3. Change the name of the constant. Type TotalPopulation

in the Name edit box.

4. In the Default value edit box, type 100000. This will be the total population in our model.

The rate, with which potential adopters come into contact with adopters, is assumed to be constant.
So, we will define a constant to represent contact rate.

Define the ContactRate constant


1. Define the constant in the same way. Enter the Name: ContactRate
2. Assume a contact rate of 100 per person per year. In the Default value, type 100.

In this model the volume of advertising and the probability that a potential adopter will adopt as the
result of exposure to a given amount of advertising are assumed to be constant each period. So, we
will add a constant to model the advertising effectiveness — the fractional adoption rate from
advertising.

Define a constant representing advertising effectiveness


1. Define a constant in the similar way. Name it AdEffectiveness
2. Set the value to 0.011.

Define one more constant to specify the adoption fraction — the proportion of contacts that are
sufficiently persuasive to induce the potential adopter to purchase the product.

Define the AdoptionFraction constant

1. Name the constant AdoptionFraction


2. Set the value to 0.015.
Phase 5. Initial values of stocks
Now we are ready to specify initial values of stocks.

We want to set total population (our TotalPopulation parameter) as the initial value
of PotentialAdopters stock.

When you mention some element in initial value of a stock, you should first connect it to this stock
with a link. Link is used to define a dependency between elements of a stock and flow diagram.

To create a link

1. Double-click the Link.


2. Right after that, go to the graphical editor and click the element that is mentioned in initial
value (TotalPopulation).
3. Finally, click the PotentialAdopters stock.

It is important to draw the link in the right direction — from the independent variable to
dependent.

4. You will see the link in the graphical editor.

Analogous to the flow, when it is selected, its end points should be indicated with little green
circles. Otherwise, if there is a white circle on some its end, it means that this particular end
point was not connected correctly. To establish the valid connection, please drag this end
point onto the variable you want to connect.

Now, when you created the link, you can specify the initial value mentioning the connected
parameter.

Define the initial number of potential adopters

1. Select the PotentialAdopters stock.


2. In the stock’s Properties, type TotalPopulation
in the Initial value edit box. Use code completion master to avoid typing the whole names of
variables and functions. To open the master, click at the desired position in the edit box, and
then press Ctrl + Space (Alt + Space on Mac).

The list of model variables and functions available in the current context appears. Scroll to the name
you want to add, or type the first letters of the name until it becomes visible in the list. Press Enter to
insert the name.

Finally you should get TotalPopulation specified as the stock’s initial value:

We do not need to set up the initial value for the Adopters stock explicitly since there are no
adopters initially and the stock is already initialized with zero by default.
Phase 6. Adding variables
We need to add two dynamic variables representing adoptions resulting from word of mouth and
from advertising.

Create AdoptionFromAd dynamic variable

1. Drag the Dynamic Variable element from the System Dynamics palette onto the
graphical diagram of agent.
2. In the Properties view, change the Name to AdoptionFromAd

Now we want to specify a formula for this dynamic variable. The formula for the adoption from
advertising is AdEffectiveness*PotentialAdopters.

Again, as with mentioning some variable in stock’s initial value, when you mention some variable in
equation of dynamic variable, flow, or some other system dynamics element, you need to connect
those variables with a link prior to specifying the formula.

Add links from two variables to AdoptionFromAd

1. Add a link from PotentialAdopters to AdoptionFromAd.


2. You can adjust the link appearance (change its arc) by dragging the marker in the middle of
the link. Adjust the appearance to make the link look like in the following figure:

You may have noticed that this link looks different from the one drawn
from TotalPopulation to PotentialAdopters. Links to variables mentioned in stock initial
values are drawn with dotted lines, while other links — with solid lines.

3. Add one more link, going from AdEffectiveness to AdoptionFromAd.

4. Now you can specify the formula in the properties of AdoptionFromAd (in
the AdoptionFromAd = edit box): AdEffectiveness*PotentialAdopters
Create AdoptionFromWOM dynamic variable

1. Add one more Dynamic Variable. Name it AdoptionFromWOM

and specify the following formula:


ContactRate*AdoptionFraction*PotentialAdopters*Adopters/TotalPopulation

You may find it boring to add numerous links for all the variables mentioned in this formula.
For this case AnyLogic provides a quick fix mechanism that automatically creates missing
links to the variables mentioned in an equation.

2. After specifying the given formula, click inside the formula field. You will see error indicators.

3. Click the error indicator (right where the arrow points in the figure above). You will see the
context menu with items Create missing link for: ContactRate, etc. Choose this item and the
corresponding link from the ContactRate parameter to AdoptionFromWOM will be created.
Do the same things for all other missing links one by one.

4. You can also fix dependency links using the context menu.

Finally you will get the following stock and flow diagram:
Now we can formulate the adoption flow using just defined dynamic variables. The two sources of
adoption are assumed to be independent. Thus, the total adoption rate is the sum of adoptions
resulting from word of mouth driven by the population of adopters and adoptions resulting from
advertising.

Define the formula for the adoption rate

1. We want to define the formula AdoptionFromAd+AdoptionFromWOM for the flow. First, add two
links pointing from these variables to the flow.
2. Now select the flow on the diagram and go to the flow properties. Specify the formula
expression in the AdoptionRate= field: AdoptionFromAd+AdoptionFromWOM

Now we have completely defined our model. The stock and flow diagram of the model should look
like as on the figure below.
The relationships between variables, represented by links, can be labeled as positive or negative.

 Positive causal link means that the two variables change in the same direction, i.e. if the
variable in which the link starts decreases, the other variable also decreases. Similarly, if the
variable in which the link starts increases, the other variable increases.
 Negative causal link means that the two variables change in opposite directions, i.e. if the
variable in which the link starts increases, then the other variable decreases, and vice versa.

Polarity is usually indicated with a /- sign at the link arrowhead. You can add polarity labels for the
links present in your stock and flow diagram.

Actually all of them are positive except for the one going
from TotalPopulation to AdoptionFromWOM.

Add polarity labels for links

1. To add a polarity sign, select the link in the graphical editor and choose + or - option from
the Polarity group of options in the link’s Properties.
2. You can change here the color of the link either (in the Color control).

Our model has one balancing and one reinforcing feedback loop.

 A balancing feedback loop affects the adoption rate due to advertising. The adoption rate
reduces the pool of the potential adopters, which in turn decreases the adoption rate.
 A reinforcing loop affects the adoption rate due to word of mouth. The adoption rate increases
the adopter population, resulting in an increase of word of mouth, and thus the increase of the
adoption rate.

Add an identifier for Market Saturation loop

1. Drag the Loop element from the System Dynamics palette onto the graphical diagram, as
shown in the figure below:

2. Go to the Properties view to set up properties of the loop.


3. Set the Direction of this loop — this loop is Counterclockwise.
4. Type the brief text explaining the meaning of this loop in the Text property: Market Saturation.
This text will be shown on the presentation.
5. Choose the symbol that will be shown for this element from the Type group of buttons.
Choose B here (stands for Balancing) since this loop is balancing.

To determine if a causal loop is reinforcing or balancing, one can start with an assumption, e.g.
"VariableN increases" and follow the loop around. The loop is:

 reinforcing if, after going around the loop, one ends up with the same result as the initial
assumption.
 balancing if the result contradicts the initial assumption.
Add an identifier for Word of Mouth loop

1. Add one more loop identifier as shown in the figure below:

2. This loop stands for word of mouth effect. It is reinforcing, so choose R as a symbol denoting
its type.
3. Specify Word of Mouth as its Text.
4. Set the Direction of this loop — this loop is Clockwise.

Finally the diagram should look like in the figure below:


Phase 7. Configuring simulation
Model simulation has a set of specific settings. A group of model settings is called an experiment,
and experiments are displayed at the bottom of the model branch in the workspace tree. You can
create several experiments for the same model with alternative model settings. One experiment is
created by default and named Simulation.

It is a simulation experiment, enabling model simulation with customized parameter values.

There are also other types of experiments (optimization, risk assessment, parameter variations
experiment), used when the model parameters play a significant role and you need to analyze how
they affect the model behavior, or when you want to find optimal parameters of your model.

If we start the model, it will work infinitely until we stop it. Since we want to observe only how the
model behaves when the adoption process takes place, we need to stop the model when the system
comes to equilibrium. The adoption process in this model lasts something over 8 years.

Set the model to stop at time 8

1. Open the Projects view (click the view tab close to the Palette view tab).
2. In the Projects view, click the Simulation: Main experiment item.
3. In the Model Time section of the experiment’s Properties, choose Stop at specified time from
the Stop drop-down list. Type 8 in the Stop time field below. The model will stop after 8 model
time units elapse.
Now we want to change one model setting.

As you remember, the model time units of our model are years.

While running the model, we will be examining how our variables change their values over time. We
will not add any charts for that since AnyLogic automatically collects data history for dynamic
variables and provides a simple tool for examining their values at model runtime — inspect windows.
The only thing that we want to change is the update rate of these automatically collected datasets.
By default new data samples of dynamic variables are added to these datasets every time unit, and
we want to increase this update rate to 0.1 to get more detailed information on our variables.

Increase update rate of auto-created datasets collecting history of dynamic variables

1. Double click Main in the Projects view.


2. Go to the Advanced section of the agent type properties and scroll it down. Type 0.1 in
the Recurrence time edit box. Now AnyLogic will update datasets collected for dynamic
variables not every 1 model time unit, but ten times per time unit. And this will make charts
displayed for dynamic variables in inspect windows more smooth.
Phase 8. Running the model
Build your project by clicking the Build model toolbar button. If there are some errors in your
model, the building fails and the Problems view appears listing all the errors found in your model.
Double-click an error in the list to open the location of the error and fix it.

Problems
view

After the model is successfully built, you can start it. Running the simulation, you automatically bring
the current model up to date.

Start the model

1. Choose the experiment you want to run from the drop-down list of the Run toolbar button.
Your simulation experiment is called Bass Diffusion/Simulation.

Later on you can use the Run toolbar button to start the previously run experiment.

You will see the model window where animated stock-and-flow diagram is displayed. Elements of the
diagram match the system dynamics notation. The actual values of variables are displayed as well.

You can adjust the execution speed to your needs using Slow down and Speed up toolbar
buttons.
AnyLogic supports various tools for collecting, displaying, and analyzing data during model
execution. The simplest way to examine current state and history of a parameter or a variable during
model simulation is to use inspect window. We want to inspect our
variables AdoptionFromAd and AdoptionFromWOM to view the contribution of different adoption
sources.

Inspect adoption sources

1. Click the AdoptionFromAd variable in the presentation. The light brown popup box will be
shown. If needed, move it by dragging the toolbar of the window and resize it to the desired
size by dragging the lower right corner of the window.
2. By default the window is in inspect mode — it displays the current value of the variable. You
can switch it to the plot mode. Hover the mouse over the inspect window title and click
the button in the upper right corner of the window. Now it shows the time plot showing the
trend for AdoptionFromAd variable.
3. In the same way, open inspect window for AdoptionFromWOM and switch it to the plot mode.
“Inspect” charts change scales automatically to embrace the plots, displaying the variables changing
from the beginning to the end of simulation. We can easily see that when an innovation is introduced
and the adopter population is zero, the only source of adoption will be advertising. The advertising
effect is largest at the start of the diffusion process and steadily diminishes as the pool of potential
adopters is depleted.

Phase 9. Adding charts


You can also observe how the values of variables change during the simulation using charts. Namely,
we want to examine the adopter and potential adopters populations dynamics. We will also add a
chart to show how the adoption rate changes in our model.

Draw a time plot displaying adopter and potential adopter population pools

1. Drag the Time Plot element from the Analysis palette onto the graphical editor.
2. Resize it as shown on the figure.
3. Go to the Properties view.
4. Open the Data section of the Properties and specify two data items to be displayed on the
time plot.

5. To add data item, click the Add data item button and define settings for this data item in
the property section above. Type PotentialAdopters in the Value field. Specify the item’s title
in the Title edit box: Potential adopters
. It will be displayed in the legend displayed for this data item.

6. Add another data item with Value: Adopters in the same way.
7. Set up the chart’s time diapason. Open the Scale section of the properties and type 8 in
the Time window edit box (so the chart will display all the simulation run).
8. Define how the plot will be updated with new data set values. Open the Data update section of
the properties, choose Update automatically option and specify the update rate in
the Recurrence time edit box to the right: 0.1.

Now you can run the model and examine the trend of potential adopter and adopter populations over
time. You will see classic S-shaped diffusion curves.
Now we will create a chart to show how the adoption rate changes in our model.

Draw a time plot displaying adoption rate

1. Create another Time Plot in the same way:

2. Configure this plot to display AdoptionRate:


Run the model. You will see classic bell-shaped curve.
Phase 10. Replacement purchases
The model we have created does not capture situations where the product is consumed, discarded,
or upgraded, all of which lead to repeat purchases. We will model repeat purchase behavior by
assuming that adopters move back into the population of potential adopters when their first unit is
discarded or consumed.

First, we will define a constant representing the average life time of product.

Create the ProductLifeTime constant

1. Assume that the average duration of active use of our product is 2 years. Type 2 as the Default
value.

People move back from the adopter population to the pool of potential adopters when the product
they have purchased is discarded or consumed. So, the discard flow is nothing else but the adoption
flow delayed on the average life time of the product.

Create the discard flow from Adopters to PotentialAdopters

1. Now we want to add a flow going from Adopters to PotentialAdopters. But if we will
draw it with a straight arrow, it will overlap AdoptionRate flow on the diagram. That’s why
we need to create a flow of a custom shape, like shown in the figure given below.
2. To draw a flow of a custom shape, double-click the element in the System
Dynamics palette so that its icon turns into .
3. Right after that, go to the graphical editor and click the stock where the flow flows out
( Adopters).
4. Then click in the intermediate salient points.
5. Finally, click the PotentialAdopters stock. New flow
from Adopters to PotentialAdopters is added.
6. Change the name of the flow to DiscardRate

.
7. You can see that stock formulas have changed as well:

8. Set the following formula for the flow variable: delay(AdoptionRate, ProductLifeTime)

The delay() function implements the time delay and has the following notation:
delay(<variable>, <delay value>, <initial value>)
In our case, the function reproduces AdoptionRate delayed on
the ProductLifeTime value. The discard rate is null until the time of use of the first
purchased products elapses.

Set DiscardRate to be displayed by the lower time plot

1. Just add DiscardRate as one more data item to be displayed by this plot (adding items onto
plots is described in the previous phase).
2. Specify Discard rate

as the title of this data item.

Now we have finished modeling the product replacement purchases. You may check how
the delay() function works. Run the model and view plots for AdoptionRate and DiscardRate.
You can see that rate curves look exactly how we expected — the discard rate is actually the adoption
rate delayed by 2 years — the life time of the product.

Observe the population dynamics using the chart. Now, instead of falling to zero, the potential
adopter population is constantly replenished as adopters discard the product and re-enter the
market. The adoption rate rises, peaks, and falls to a rate that depends on the average life of the
product and the parameters determining the adoption rate. Discards mean there is always some
fraction of the population in the potential adopter pool.

If you like, you may add control group varying product life time, say from 0.5 to 10.

Phase 11. Demand cycle


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.
Adding experimental data to the 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

1. Drag the Table Function element from the System Dynamics palette onto the Main diagram.
2. Go to the table function’s Properties and set up the function properties.
3. Name the function demand

4. 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:

5. 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.
6. 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:

Formulating the adoption fraction

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

1. Drag the Function element from the Agent palette onto the Main diagram.
2. Go to the function’s Properties and name the function adoptFraction

3. Specify that the function returns the double value. Choose the Returns value option and
leave double as the return Type.
4. 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() )/200.0;

This expression calculates the demand for the current month. Finally, to obtain the adoption fraction
value, the demand value is divided by 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


1. Delete AdoptionFraction parameter.
2. Create the AdoptionFraction dynamic variable. Set the variable’s formula to adoptFraction()

. Thus, the dynamic variable’s value will be computed by our function.

Set model to stop at time 20 (setting the stop time is described in the Phase 7) 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.

Phase 12. Promotion strategy


At this point, advertising effectiveness in our model is assumed to be constant each period. Actually,
it depends on the current advertising expenditures. We want to improve our model to be able to
manage the promotion expenditures. Changing the monthly promotion expenditures we will affect
the advertising effectiveness.
Modeling advertising expenditures

Add a constant for the monthly expenditures

1. Add another Parameter and name it MonthlyExpenditures

2. Specify the parameter’s Default value: 1100.

Replace AdEffectiveness parameter with a dynamic variable

1. Delete AdEffectiveness parameter (by selecting it in the graphical editor and pressing Del).
2. Create AdEffectiveness dynamic variable with formula: MonthlyExpenditures/10000.0

. We assume this is how the advertising effectiveness depends on the current promotion expenditures.

3. Draw a dependency link from MonthlyExpenditures to AdEffectiveness.

We want to collect statistics on the total expenditures of our company. We will implement this by
defining a parameter, keeping data about how much money was appropriated for the product
promotion. Every month we will update TotalExpenditures value, adding the value of expenditures for
the upcoming month. We will implement this by creating an event that occurs monthly.

Add a variable to store the total expenditures

1. Drag the Variable element from the Agent palette to the graphical diagram.
2. Name the variable TotalExpenditures

Create an event to update TotalExpenditures

1. Drag the Eventelement from the Agent palette to the graphical diagram.
2. Set monthlyEvent

as the Name of the event.

3. Set up event to occur monthly. Choose Cyclic from the Mode drop-down list.
4. Since we want the event to occur each month, leave 1 as the value of the Recurrence time field, and
choose months from the drop-down list to the right.
5. Specify the Action of the event:
TotalExpenditures += MonthlyExpenditures;

This code will be executed each time the event’ timeout is elapsed. It collects statistics on the total
expenditures, namely it adds the value of advertising expenditures planned on the upcoming month to
the TotalExpenditures.

Modeling a promotion plan

Since advertising plays significant role only at the start of the diffusion process, we want to stop
advertising at some moment of time, say, after 3 years. Thus we will save money aimlessly spent on
advertising, since only adoption from word of mouth determines the market saturation by that time.

Add a parameter for the switch time

1. Add another Parameter and name it SwitchTime

2. Specify the parameter’s Default value: 3.

Now we will define model behavior visually with a statechart. Statechart is used to show the state
space of a given algorithm, the events that cause a transition from one state to another, and the
actions that result from state change.

Create a statechart to model promotion strategy


1. Start defining a statechart with adding a statechart entry point. Therefore drag the Statechart Entry
Point element from the Statechart palette into the graphical editor of Main agent type.

2. Add a state to the statechart. Drag the State element from the Statechart palette onto the
graphical diagram so that it gets connected to the statechart entry point added earlier. Change the
name of just added state to with_advertising

3. Add another State below the created one. Name it without_advertising

4. We need to stop the promotion, when statechart comes to this state. Therefore, in the Entry
action property, type MonthlyExpenditures=0.0;

.
5. Add a transition going from with_advertising state to without_advertising state. Double-click
the Transition element in the Statechart palette. Then draw the transition going
from with_advertising to without_advertising state by clicking the starting point of the transition
(the border of with_advertising state) and then click the ending point of the transition (the border
of without_advertising state).

6. Set up this transition to be taken after SwitchTime timeout. Therefore, leave Timeout in the Triggered
by drop-down list of this transition and type SwitchTime

in the Timeout property (you can use code completion master here).

Now when the statechart is in the initial with_advertising state, company’s advertising
expenditures are defined by the MonthlyExpenditures value. Once the statechart exits this state at
the SwitchTime moment, company stops advertising.

Run the model and see that now the promotion company lasts 3 years only.

Phase 13. Optimizing the strategy


The marketing strategy in the current model is very simple: at the specified moment of time company
stops advertising the product.

Now we want to find an optimal marketing plan to reach the required number of adopters to the
specified moment of time with minimal advertising expenditures. Let’s assume we need the market
to be saturated to 80 percent at the end of the first 1.5 years.

We can solve this problem by using AnyLogic optimization, where selected model parameters are
systematically adjusted to minimize or maximize the objective function.

1. In the Projects view, right-click (Mac OS: Ctrl + click) the model item and
choose New > Experiment from the popup menu. The New Experiment dialog box is displayed.
2. Choose Optimization experiment from the Experiment Type list and click Finish.

You will see that one more experiment is created and its presentation opened in the graphical editor.

Define the objective function

1. We want to minimize money spent on the product promotion. In the Properties view,
type root.TotalExpenditures

in the Objective field. Here we access the top level agent of the experiment as root.
2. Leave the minimize option selected.

Configure the optimization

1. In the Properties of the experiment, ensure that each simulation ends. By default, simulation never
ends; therefore the optimization engine gets no samples of the objective function. To ensure that each
simulation ends, you must specify a simulation stop condition. Go to the Model time section of the
experiment’s Properties and select Stop at specified time in the Stop drop-down list. In the Stop
time edit box, type 1.5. The model will stop after 1.5 model time units (i.e. years) elapse.

We will optimize the parameters MonthlyExpenditures and SwitchTime. During optimization, these
parameters will be systematically adjusted to find the smallest total expenditures leading to the
required market saturation.

Define optimization parameters

1. In the Parameters section of the optimization experiment’s Properties you can see all parameters of
the experiment’s top level agent. By default, all of them are fixed, i.e. they are not varied by optimization
process. To enable optimizing a parameter, you should choose another option instead of fixed in
the Type cells of the corresponding rows of the table.
2. First, let’s setup the first parameter we want to vary during the optimization: MonthlyExpenditures.
Choose continuous in the Type cell of the MonthlyExpenditures row. Set Max value for this parameter
to 10000 and Suggested value to 1000. Thus we tell the optimizer that this parameter may accept any
real values from 0 to 10000, and optimizer will start the optimization with the suggested value: 1000.
3. Second, setup the parameter SwitchTime. Choose discrete in its Type cell since we want this
parameter to have values only corresponding to particular timestamps: one month, two months, etc.
Specify 0.0833 in the Step cell. This value corresponds to one month in our model, since 1 stands for
one year and therefore one month is 1.0/12.0 = 0.0833. Finally set Max value for this parameter
to 1.5 and Suggested value to 1.
Create the experiment’s UI

1. Click the Create default UI button in the properties view of the experiment.

2. This creates default UI for the optimization experiment as shown in the figure below. The default UI
consists of a number of controls that will display all necessary information regarding the current status
and the results of the optimization at the runtime.

Creating the default UI deletes anything on the diagram of the optimization experiment, so we
recommend you to create the UI first and then adjust it anyhow.

Defining the additional requirement (market saturation check)

Now it is time to define the requirement for the successful simulation. We want 80000 people to
adopt the product after first 1.5 years.

Define the requirement for the optimization experiment


1. Open the Requirements section of the optimization experiment’s Properties and define a requirement
in the uppermost row of the Requirements (are tested after a simulation run to determine whether the
solution is feasible) table.
2. Type root.Adopters

in the Expression cell. Here we access the top level agent of the experiment as root.

3. Choose >= in the Type cell.


4. Type 80000 in the Bound cell.
5. Finally select the checkbox in the leftmost column of this row of the table to enable this requirement.

We have finished defining the requirement. It will be checked at the end of simulation. If this
requirement is not met, the solution is considered as infeasible.

Running optimization

The model is now ready to optimize.

Run the optimization

1. Right-click (Mac OS: Ctrl + click) the optimization experiment in the Projects view and choose Run from
the context menu. You will see the model window opened, showing the UI you have created for this
experiment.

2. Click the Run control in the model window to start the optimization process.
3. AnyLogic will run the model 500 times, adjusting the values of MonthlyExpenditures and SwitchTime. A
summary of the optimization statistics will be displayed in the controls on the canvas of the model
window.
When the optimization process finishes, you will see the Best objective found. In the Best column of
the Parameters table you can find the values of SwitchTime and MonthlyExpenditures parameters
that correspond to this best objective value.

Now we can update the model with the optimized values of SwitchTime and MonthlyExpenditures.
Save the obtained parameter values in the Simulation experiment to adopt the found solution in the
model.

Adopt optimization results

1. Right after finishing the optimization, click the Copy best button on the canvas of the model window.
Thus you copy the optimal parameter values to the Clipboard.
2. Close the model window and select the Simulation experiment in the Projects view.
3. Paste the values from the Clipboard by clicking the Paste from clipboard button in the experiment’s
properties view.

Run the Simulation experiment experiment. Now the model will be launched with optimal
parameters resulting in the best found solution. You can check that the required number of adopters
is reached by the required time (1.5 years).

Now you have planned your entry strategy so as to have an efficient and effective product promotion.

You might also like