Using feedback in iteration

In ModelBuilder, the output of a process can be used as an input to a previous process. This is known as feedback, since an output is fed back to a previous process as input.

There are two ways to set the feedback loop:

  1. From the variable properties
  2. Using the connect tool

In the example model below, the output of Buffer is fed back as the input to Buffer in each iteration of the model.

Setting feedback loop

From the variable properties

Steps:
  1. Select and right-click the input variable.
  2. On the General tab, select the variable that you want to use as feedback from the Feedback Variable drop-down list.

    This will create a dotted blue feedback connector line from the output variable to the input variable. Every time the tool iterates, the output variable will be used as input for the next iteration.

Using the connect tool

Steps:
  1. In ModelBuilder, click the Connect tool Add Connection.
  2. Click the output you want to use as feedback and click the input.

    The model knows the output is being connected to the input and automatically creates a dotted blue feedback connector line. Every time the tool iterates, the output variable will be used as input for the next iteration.

  3. Since the model produces one output dataset for each iteration, it is important to have a unique output name for each iteration so the previous iteration output is not overwritten. Assigning a unique name for each iteration output can be accomplished by appending the output path with the inline variable substitution as shown in the example below.

Limiting model iteration count

The model must have an iteration count set; otherwise the model will enter a never-ending feedback loop. See the example below.

Steps:
  1. To limit the model's iterations, use the For iterator.
  2. To run the feedback loop for a number of times, enter an appropriate From Value, To Value, and By Value. For example, to iterate the model four times, set a starting From Value of 1, an ending To Value of 4, and an interval By Value of 1.
  3. Make the output of the For tool a precondition to the next tool. This ensures that the iteration number is available before the next tool executes. Learn more about setting up a precondition
  4. When setting the output of For as a precondition to any other tool, the From Value should start with a value greater than zero. If the default zero value is used, the output of For is set to zero after the first iteration, and the downstream tool fails with the error message: The process did not execute because the precondition is false. This is because a zero value is interpreted as a false precondition in models.
  5. To avoid overwriting the output of each iteration, append the output name with the %Value% inline variable. When the model runs, %Value% will be replaced by number 1, 2, 3, 4 coming from the output parameter Value of the For iterator.
  6. Connect the output of the tool as a feedback to the input, as in the example below where the output of Buffer is connected to the Input variable as feedback.
  7. Also, connect the output of the tool (Output in the example) to the Collect Values tool.
  8. If you run a model with feedback loop and inline variable substitution from its tool dialog box, connect the final output of the model to the Collect Values Model Only tool and make the output of the Collect Values tool a model parameter. The Collect Values tool does not create any new output. Instead, it passes the inputs as outputs; therefore, the output does not show on the tool dialog box when exposed as a model parameter. Making it a model parameter ensures that the results are added to display in ArcMap if the Add results of geoprocessing operations to display option is checked from the drop-down menu in ArcMap Geoprocessing > Geoprocessing Options.
  9. Run the model.
Using feedback loop

9/13/2011