Hierarchical SD Modeling

Alike other SD tools, AnyLogic supports laying out complex SD models using sectors

However, AnyLogic also naturally offers all benefits of object-oriented approach to system dynamics modelers. You can define complex models in a hierarchical manner where logically separate parts of the stock and flow diagram are encapsulated into different agent types and expose only their interface variables (as inputs or outputs). 

System dynamics components can be packaged into AnyLogic agent types, parameterized, organized in various structures, and reused. 

Sample model: Population


Take a look into the given sample model to understand how you can lay out your SD model in an hierarchical way.

This model has two logical parts, each focusing on a particular aspect, housing sector and population sector. The stock-and-flow diagram for each part is drawn apart from others, in the separate agent type: HousingSector and PopulationSector.

HousingSector diagram


PopulationSector diagram

In AnyLogic you can partition the model into components in object-oriented way by using agents exposing the "input" and "output" dynamic variables as a part of their interface.

The "interface" between the sectors includes two variables:

For each such variable there is one "original" instance in one of the sectors and "shadow" copies in the other sectors. 

Let us explain how the interface variables were created.

Creation of the "output" interface variable for Houses

  1. Add the  Dynamic Variable element from the  System Dynamics palette onto the HousingSector diagram.
  2. Name this variable HousesOut.
  3. For this variable, select the Visible on upper level check box. This way we declare this variable as an interface variable that will be visible in the agent that will link two parts together (in Main).
  4. In the HousesOut= field, set the variable's value to Houses. This is how we tell the variable to take the value of the Houses stock (and expose it to the agent's interface).

Creation of the shadow variable for another interface variable, HouseholdsToHousesRatio

  1. Drag the Shadow  element from the System Dynamics  palette onto the HousingSector canvas.
  2. Select the "original" variable HouseholdsToHousesRatio from the list.

Create the housing sector's interface

  1. Draw the icon for this agent type with presentation shapes
  2. For all icon shapes, select the Icon check box in their properties.
  1. Place the HousesOut variable on the icon border.
  2. Draw the link going from Houses to HousesOut.
  3. Move the "original" variable HouseholdsToHousesRatio onto the icon border.
  4. In the properties of this variable, select the option Visible on upper level to expose this variable on the agent's interface. 
  5. Select the Dependent check box. This way we tell this variable that it will get its value "from outside", in our case - from the external interface variable of the population sector that will be connected to it on the Main diagram.
  6. Reconnect the link from this variable to its shadow, <HouseholdsToHousesRatio> to make the stock-and-flow diagram look neat.

Do similar things in the PopulationSector diagram.

Then drag both HousingSector and PopulationSector agents from the Projects tree on the Main diagram and connect their interface variables together with connectors as shown below.

This figure gives you the idea how values are passed from one sector to another via the interface variables we've created.