AnyLogic 6 System Dynamics Modeling Tutorial

Embed Size (px)

Citation preview

  • 7/27/2019 AnyLogic 6 System Dynamics Modeling Tutorial

    1/25

    System Dynamics Modeling Tutorial

  • 7/27/2019 AnyLogic 6 System Dynamics Modeling Tutorial

    2/25

    AnyLogic 6 System Dynamics Modeling Tutorial

    Copyright 1992-2007 XJ Technologies. All rights reserved.

    XJ Technologies Company [email protected]://www.xjtek.com/anylogic

    2 1992-2007 XJ Technologies http://www.xjtek.com

    http://www.xjtek.com/anylogichttp://www.xjtek.com/anylogic
  • 7/27/2019 AnyLogic 6 System Dynamics Modeling Tutorial

    3/25

    AnyLogic 6 System Dynamics Modeling Tutorial

    Contents

    CONTENTS............................................................................................................................... 3BASS DIFFUSION MODEL ...................................................................................................... 4STEP 0. ANALYZING THE MODEL ......................................................................................... 5STEP 1. CREATING A NEW MODEL ...................................................................................... 6STEP 2. ADDING STOCKS ...................................................................................................... 8STEP 3. ADDING ADOPTION FLOW .................................................................................... 10STEP 4. ADDING CONSTANTS............................................................................................. 12STEP 5. DEFINING INITIAL VALUES OF STOCKS.............................................................. 14STEP 6. ADDING AUXILIARIES ............................................................................................ 15STEP 7. CONFIGURING SIMULATION ................................................................................. 18STEP 8. RUNNING THE MODEL ........................................................................................... 20STEP 9. ADDING CHARTS .................................................................................................... 24

    1992-2007 XJ Technologies http://www.xjtek.com 3

  • 7/27/2019 AnyLogic 6 System Dynamics Modeling Tutorial

    4/25

    AnyLogic 6 System Dynamics Modeling Tutorial

    Bass Diffusion ModelAnyLogic supports different modeling techniques. This document covers System Dynamicsmodeling approach. There are many spheres where system dynamics simulation can besuccessfully appliedthe 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 usingAnyLogic. It is intended to introduce you to AnyLogic interface and many of its main features.We will create a simple illustrative examplethe product life cycle model, used for forecastingsales of new products.

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

    Then we will expand our model by considering some details and introducing you to someadvanced features of AnyLogic useful in creating system dynamics models. The expandedmodel may help you to better plan the entry strategy, target the right consumer and anticipatedemand so as to have an efficient and effective promotion strategy.

    Note that there are several reference files available for this model representing the milestonesof the editing. You can use reference files if you experience any difficulties creating a modeland you would like to compare your model with the reference file. You can use WelcomePage 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.

    4 1992-2007 XJ Technologies http://www.xjtek.com

  • 7/27/2019 AnyLogic 6 System Dynamics Modeling Tutorial

    5/25

    AnyLogic 6 System Dynamics Modeling Tutorial

    Step 0. Analyzing the ModelFirst of all, we need to analyze the model to decide how it can be described in the systemdynamics terms. We should distinguish the key variables of the model and their patterns ofinfluence and then create stock and flow diagram of the model. When constructing stock andflow diagram, we should consider what variables should be modeled with stocks, flows or

    auxiliaries.

    Stocks (also known as levels, accumulations, or state variables) change their valuecontinuously over time. Flows, also known as rates, change the value of stocks. In turn,stocks in a system determine the values of flows. Intermediate concepts are known asauxiliaries and can change instantaneously.

    When constructing a stock and flow diagram, consider what variables accumulate over aperiod of time. In our model, adopter and potential adopter populations are stocks and theadoption rate a flow.

    The system dynamics presentation of the model is shown in the following figure. Stocks aredenoted with squares, flow with a valve, and auxiliaries with circles. Arrows denote causaldependencies in the model.

    1992-2007 XJ Technologies http://www.xjtek.com 5

  • 7/27/2019 AnyLogic 6 System Dynamics Modeling Tutorial

    6/25

    AnyLogic 6 System Dynamics Modeling Tutorial

    Step 1. Creating a New ModelFirst, we will create a new model.

    Create a new model

    1. Click the New Model toolbar button. The New Model dialog box is displayed.

    2. Specify the name of the model. In the Model Name edit box, type Bass Di f f usi on.

    3. Specify the location where you want to store your model file. Browse for the existingfolder using the Browse buton, or type the name of the folder you want to create inthe Location edit box.

    4. Click Finish.

    New model is created. The diagram you see in the center of the workspace is the graphicaleditor. To the left of the graphical editor you can see the Project view, to the right - thePalette view, and at the bottom - the Properties view.

    6 1992-2007 XJ Technologies http://www.xjtek.com

  • 7/27/2019 AnyLogic 6 System Dynamics Modeling Tutorial

    7/25

    AnyLogic 6 System Dynamics Modeling Tutorial

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

    1992-2007 XJ Technologies http://www.xjtek.com 7

  • 7/27/2019 AnyLogic 6 System Dynamics Modeling Tutorial

    8/25

    AnyLogic 6 System Dynamics Modeling Tutorial

    Step 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. Select the Stock element in the Model stencil of the Palette.

    2. Click in the graphical editor where you want to place the stock variable. A newvariable appears on the diagram, displayed as a little blue rectangle.

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

    Please note that the Properties view is a context-sensitive view and it displays theproperties of the currently selected element of the model. To adjust properties at alater time, first select the element (e.g. by clicking on the element in the graphicaleditor) and then modify the required properties.

    Properties view . At the moment view displays the properties of the currently selected stockvariable.

    4. Change the name of the stock. On the General page of the Properties view, type

    Pot ent i al Adopters in the Name edit box.

    8 1992-2007 XJ Technologies http://www.xjtek.com

  • 7/27/2019 AnyLogic 6 System Dynamics Modeling Tutorial

    9/25

    AnyLogic 6 System Dynamics Modeling Tutorial

    Add a stock to model adopter population

    1. Add another stock in the same way. Place it to the right of the Pot ent i al Adoptersstock as shown in the figure below.

    2. Name this stock Adopters.

    3. Move text labels of the stocks above stocks' icons. Do it in the following way: firstselect a variable by clicking on it (if selected, it is drawn in a blue outline and its labelis underlined) and then drag the label wherever you like. Place labels as on the figurebelow:

    We need this since otherwise later these labels will be painted over with arrows pointing fromone stock to other.At this point, the stocks are not defined properly. We have not defined integral functions andinitial values for our stocks yet. But we will create the adoption flow first.

    1992-2007 XJ Technologies http://www.xjtek.com 9

  • 7/27/2019 AnyLogic 6 System Dynamics Modeling Tutorial

    10/25

    AnyLogic 6 System Dynamics Modeling Tutorial

    Step 3. Adding Adoption Flow

    We have successfully created two stocks representing population pools. It is time tocreate flows of our model now. Our model has just one flow - a flow of adoption, whichincreases the adopter population, while decreasing the potential adopter population.

    Add a f low from PotentialAdopters to Adopters

    1. We will add a flow using AnyLogic flow tool. Flow tool creates flow variable and setsup stocks so their values are changed with the specified flow value automatically.

    2. To create flow, double-click Pot ent i al Adopters variable and then click Adoptersvariable.

    3. AnyLogic creates new flow variable and makes it an outflow

    forPot ent i al Adopters and an inflow forAdopter s. Arrows appeared on thestock and flow diagram denote flow influence on population pools.

    4. Select the flow in the graphical editor and change its name from default f l owAuxVar

    to Adopt i onRat e. When finished, please press Ct r l +Ent er to rename flow

    names mentioned in formulas of stocks also.

    4. You can have a look at stock properties now. AnyLogic automatically adjustsformulas for stocks. The value of inflows i.e. flows that increase stock value, areadded and the value of outflows, i.e. flows that decrease stock are subtracted fromthe current value of the stock. In our case we should have the following formulasdefined:

    10 1992-2007 XJ Technologies http://www.xjtek.com

  • 7/27/2019 AnyLogic 6 System Dynamics Modeling Tutorial

    11/25

    AnyLogic 6 System Dynamics Modeling Tutorial

    We will define the formula calculating the value of the flow a little bit later.

    1992-2007 XJ Technologies http://www.xjtek.com 11

  • 7/27/2019 AnyLogic 6 System Dynamics Modeling Tutorial

    12/25

    AnyLogic 6 System Dynamics Modeling Tutorial

    Step 4. Adding Constants

    Now we will define constants of our model. In AnyLogic you define a constant by creating aparameter.

    Define a constant representing to tal population

    1. Click the Parameter element from the Model page of the Palette view.

    2. Click in the graphical editor to place the parameter.

    3. On the General page of the Properties view, set up the parameter properties.

    4. Change the name of the constant. TypeTot al Popul at i on in the Name edit box.

    5. In the Default Value edit box, type 100000. This will be the total population in ourmodel.

    The rate, with which potential adopters come into contact with adopters, is assumed to beconstant. 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: Cont actRate.

    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 adoptas the result of exposure to a given amount of advertising are assumed to be constant eachperiod. So, we will add a constant to model the advertising effectivenessthe fractionaladoption rate from advertising.

    12 1992-2007 XJ Technologies http://www.xjtek.com

  • 7/27/2019 AnyLogic 6 System Dynamics Modeling Tutorial

    13/25

    AnyLogic 6 System Dynamics Modeling Tutorial

    Define a constant representing advertising effectiveness

    1. Define a constant in the similar way. Name it AdEf f ect i veness.

    2. Set the value to 0. 011.

    Define one more constant to specify the adoption fractionthe proportion of contacts that aresufficiently persuasive to induce the potential adopter to purchase the product.

    Define the AdoptionFraction constant

    1. Name the constant Adopt i onFr act i on.

    2. Set the value to 0. 015.

    1992-2007 XJ Technologies http://www.xjtek.com 13

  • 7/27/2019 AnyLogic 6 System Dynamics Modeling Tutorial

    14/25

    AnyLogic 6 System Dynamics Modeling Tutorial

    Step 5. Defining Initial Values of Stocks

    Now we are ready to specify the initial values of stocks.

    Define the init ial number of potential adopters

    1. Click the Pot ent i al Adopters variable in the graphical editor.

    2. On the General page of the Properties view, typeTotal Popul at i on in the InitialValue edit box. Use intelli-sense mechanism to avoid typing the whole names ofvariables and functions. To open the intelli-sense wizard, click at the desired position

    in the edit box, and then press Ct r l +space.

    The wizard listing model variables and functions appears. Scroll to the name you want to add,or type the first letters of the name until it becomes visible in the list. Finally, press Enter toinsert the name.

    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.

    14 1992-2007 XJ Technologies http://www.xjtek.com

  • 7/27/2019 AnyLogic 6 System Dynamics Modeling Tutorial

    15/25

    AnyLogic 6 System Dynamics Modeling Tutorial

    Step 6. Adding Auxi liaries

    We need to add two auxiliaries representing adoptions resulting from word of mouth and fromadvertising.

    Create the AdoptionFromAdauxiliary

    1. Choose the Flow Aux Variable element from the Model page of the Palette view.

    2. Click in the graphical editor where you want to place the variable.

    3. In the Properties view, change the Name to Adopt i onFr omAd.

    4. Define the formula expression. In theAdoptionFromAd = edit box, type:AdEf f ect i veness*Potent i al Adopters

    Create the AdoptionFromWOMauxiliary

    1. Do it in the same way except name the auxiliary Adopt i onFr omWOMand specify the

    following formula:Cont act Rate*Adopt i onFract i on*Pot ent i al Adopters*Adopters/ Tot al Popul at i on

    Now we can formulate the adoption flow using just defined auxiliares. The two sources ofadoption are assumed to be independent. Thus, the total adoption rate is the sum ofadoptions resulting from word of mouth driven by the population of adopters and adoptionsresulting from advertising.

    Define the formula for the adoption rate

    1. Click the just created flow variable on the diagram.

    1992-2007 XJ Technologies http://www.xjtek.com 15

  • 7/27/2019 AnyLogic 6 System Dynamics Modeling Tutorial

    16/25

    AnyLogic 6 System Dynamics Modeling Tutorial

    2. Go to the General page of the Properties view.

    3. Change the variable name to Adopt i onRat e.

    4. Specify the formula expression in theAdoptionRate= field:Adopt i onFr omAd+Adopt i onFr omWOM

    Now we have completely defined our model. The stock and flow diagram of the model shouldlook like as on the figure below.

    You may examine the causal dependencies between stocks, flows and auxiliaries in yourmodel. They are denoted with arrows as in standard SD notation.

    A thick arrow going from flow to stock means that this flow acts as inflow for thisstock.

    A thick arrow going from stock to flow means that this flow acts as outflow.

    A thin arrow going from A variable to B means that A causes to change B.

    You can see that our model has one balancing and one reinforcing feedback loop.

    16 1992-2007 XJ Technologies http://www.xjtek.com

  • 7/27/2019 AnyLogic 6 System Dynamics Modeling Tutorial

    17/25

    AnyLogic 6 System Dynamics Modeling Tutorial

    A balancing feedback loop affects the adoption rate due to advertising. The adoptionrate reduces the pool of the potential adopters, which in turn decreases the adoptionrate.

    A reinforcing loop affects the adoption rate due to word of mouth. The adoption rateincreases the adopter population, resulting in an increase of word of mouth, and thus theincrease of the adoption rate.

    1992-2007 XJ Technologies http://www.xjtek.com 17

  • 7/27/2019 AnyLogic 6 System Dynamics Modeling Tutorial

    18/25

    AnyLogic 6 System Dynamics Modeling Tutorial

    Step 7. Configuring Simulation

    Model simulation has a set of specific settings. A group of model settings is called anexperiment, and experiments are displayed at the bottom of the model branch in theworkspace tree. You can create several experiments for the same model with alternative

    model settings. One experiment is created by default and named Si mul at i on.

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

    There are also other types of experiments (optimization, risk assessment, parametervariations experiment), used when the model parameters play a significant role and you needto 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 100 time units and then will stop. Since we want to observeonly how the model behaves when the adoption process takes place, we need to stop themodel when the system comes to equilibrium. The adoption process in this model lastssomething over 10 years.

    Set the model to stop at time 10

    1. In the Project view, click the Si mul at i on: Mai n experiment item.

    2. On the Model Time tab of the Properties window, select the Stop model at

    specified time check box. In the edit box on the right, type 10. The model will stopafter 10 model time units elapse.

    Before running the model, we will set the real time mode to control the execution speed and,consequently, animation speed. In real time mode, the model is executed regarding thephysical time.

    Set the real time execution mode

    18 1992-2007 XJ Technologies http://www.xjtek.com

  • 7/27/2019 AnyLogic 6 System Dynamics Modeling Tutorial

    19/25

    AnyLogic 6 System Dynamics Modeling Tutorial

    1. In the Project view, click the Si mul at i on experiment.

    2. On the Presentation page of the Properties view, go to the Simulation Speedsection and choose the Real time with scale option.

    3. Specify the model execution speed, i.e., how many model time units will be executed

    in one second. In the edit box to the right, type 2.

    1992-2007 XJ Technologies http://www.xjtek.com 19

  • 7/27/2019 AnyLogic 6 System Dynamics Modeling Tutorial

    20/25

    AnyLogic 6 System Dynamics Modeling Tutorial

    Step 8. Running the Model

    Build your project by clicking the Build Model toolbar button. If there are some errors inyour model, the building fails and the Problems view appears listing all the errors found inyour model. ClickAl l button in the upper right corner of the view to show all errors in the

    model and then 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, youautomatically bring the current model up to date.

    Start the model

    1. Click the Run toolbar button and choose the experiment you want to run from the

    drop-down list. Your simulation experiment is called Bass

    Di f f usi on/ Si mul at i on.

    In the case this model is the only one opened in the workspace at the moment you willbe prompted to run this particular experiment. Later on this button will start thepreviously run experiment. To run any other experiment, right-click the experiment inthe Project view and choose Run from the context menu.

    Having started the model, you will see the presentation window. It displays the presentationdesigned for your simulation experiment. AnyLogic automatically places the show-bench titleand the button enabling running your model and switching to the presentation designed for

    the Mai n class.

    20 1992-2007 XJ Technologies http://www.xjtek.com

  • 7/27/2019 AnyLogic 6 System Dynamics Modeling Tutorial

    21/25

    AnyLogic 6 System Dynamics Modeling Tutorial

    You can see animated stock-and-flow diagram. 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 toolbarbuttons.

    1992-2007 XJ Technologies http://www.xjtek.com 21

  • 7/27/2019 AnyLogic 6 System Dynamics Modeling Tutorial

    22/25

    AnyLogic 6 System Dynamics Modeling Tutorial

    AnyLogic supports various tools for collecting, displaying, and analyzing data during model

    execution. The simpliest way to examine current state and history of a parameter or a variableduring model simulation is to use inspect window. We want to inspect our variables

    Adopt i onFr omAd and Adopt i onFr omWOMto view the contribution of different adoptionsources.

    Inspect adoption sources

    1. Click the Adopt i onFr omAd variable in the presentation. The yellow popup box willbe shown. If needed, move it by dragging the toolbar of the window and resize it tothe 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 by clicking the "rectangle" button in the upper right

    corner of the window. Now it shows the time plot showing the trendforAdopt i onFr omAd variable.

    3. In the same way, open inspect window forAdopt i onFr omWOMand switch it to theplot mode.

    22 1992-2007 XJ Technologies http://www.xjtek.com

  • 7/27/2019 AnyLogic 6 System Dynamics Modeling Tutorial

    23/25

    AnyLogic 6 System Dynamics Modeling Tutorial

    "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 aninnovation is introduced and the adopter population is zero, the only source of adoption will beadvertising. The advertising effect is largest at the start of the diffusion process and steadilydiminishes as the pool of potential adopters is depleted.

    1992-2007 XJ Technologies http://www.xjtek.com 23

  • 7/27/2019 AnyLogic 6 System Dynamics Modeling Tutorial

    24/25

    AnyLogic 6 System Dynamics Modeling Tutorial

    Step 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. Wewill also use the same chart to show how the adoption rate changes in our model.

    Create a data set for the PotentialAdopters variable

    1. In the graphical editor, right-click the Pot ent i al Adopters variable and choose

    Create Data Set from the popup menu. The data set Pot ent i al AdoptersDS willbe created. It will store the history of the variable that can be displayed on the chart.Move the data set icon aside like shown on the figure below.

    2. Go to the General page of the Properties view.

    3. Specify the data set title in the Title edit box: # of pot ent i al adopt ers. It will

    be displayed in the legend displayed for this data item in the chart.

    4. Clear the Show at Runtime check box to prevent showing the data set icon in thepresentation window at model runtime.

    Create one more data set forAdopters

    1. Create data set for the Adopters variable in the same way and set up its title: # of

    adopt ers.

    Draw a time plot displaying adopter and potential adopter population pools

    1. Choose the Time Plot element from theAnalysis page of the Palette view.

    2. Click the place in the graphical editor where you want to place the chart and resize asshown on the figure.

    24 1992-2007 XJ Technologies http://www.xjtek.com

  • 7/27/2019 AnyLogic 6 System Dynamics Modeling Tutorial

    25/25

    AnyLogic 6 System Dynamics Modeling Tutorial

    3. Go to the General page of the Properties view.

    4. Set up the charts time diapason. In the Time Window edit box, type: 8 (so the chartwill display all the simulation run).

    5. Specify data sets to be displayed on the time plot.

    6. Add Pot ent i al AdoptersDS data set to be visualized on this plot by clicking theAdd Data Set button and defining settings for the data set in the property

    section above. Choose Pot ent i al AdoptersDS data set from the Data Set drop-down list. Choose the first option from the Point Style drop-down list to turn offindicating data set values with a marker.

    7. Add AdoptersDS data set in the same way.

    8. Define how the plot will be updated with new data set values. At the botom of theproperties page, choose Update automatically option and specify the update rate in

    the Recurrence (in time uni ts) edit box to the right: 0. 1.

    Now you can run the model and examine the trend of potential adopter and adopterpopulations over time. You will see classic S-shaped diffusion curves.