AnyLogic
Expand
Font size

Variables connection

You can establish interaction between two objects by connecting their variables. 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. This provides for continuous and/or discrete time object interaction.

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.

You can connect:

  • Two public variables of two embedded objects;
  • A variable of a container object with a public variable of an embedded object.

The figure below is the screenshot from the Population model. It illustrates the case when two embedded objects interact via connected variables.

Connection on variables of embedded objects

When connecting variables, please mind these rules:
  • Only the variables of compatible types can be connected.
  • You cannot connect two variables of the same object.
  • 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?