AnyLogic
Expand
Font size

Connecting system dynamics variables

You can expose system dynamics variable to the agent interface and connect it to a dependent variable of other agent. Connected variables will have the same value at any moment of time; i.e., changes of one variable will be immediately propagated to another variable declared as dependent one. You can use this technique to create hierarchical SD models.

You can connect only system dynamics variables:  dynamic variables or  flows. The approach described in this article cannot be applied to  variables.

You can connect:

  • Two public variables of two embedded agents;
  • A variable of a container agent with a public variable of an embedded agent.
The value of the dependent variable always depends on the value of the connected variable but not vice versa: if you modify the dependent variable, this does not affect others.

The figure below is the screenshot from the Population model. It illustrates the case when two embedded agents interact via connected variables. You can examine this model to see when the described technique may be useful.

Demo model: Population Open the model page in AnyLogic Cloud. There you can run the model or download it (by clicking Model source files).

Connection on variables of embedded agents

When connecting variables, please mind these rules:
  • Only the variables of compatible types can be connected (you can connect flows or dynamic variables, but you cannot connect a flow to a dynamic variable).
  • You cannot connect two variables of the same agent.
  • AnyLogic allows connection of several dependent variables to one variable. But to prevent collisions, only one variable can be connected to a dependent variable.

Connecting variables

When connecting two variables, one variable should be necessarily defined as dependent one. The dependent variable always gets value of another variable.

To make a variable dependent

  1. Select the variable in the graphical editor or in the Projects view.
  2. In the Properties view, select the Dependent check box.

When finished, connect variables graphically with connectors.

To connect two variables

  1. Double-click the  Connector element in the  Agent palette to activate its drawing mode.
  2. In the graphical editor, subsequently click both variables that you want to connect.

When drawing connectors, you can notice that connector’s point put correctly inside variable icon is indicated with a small green circle. In the case you do not see the green circle, it probably means that you are trying to connect variables that cannot be connected, or you have put connector’s point close by a variable and you need to move it onto it.

How can we improve this article?