Error Messages/41148

Error Text

A dynamic-loop dependency has been encountered at X[Time=1] during the evaluation of Y[Time-«k»]. In a dynamic-loop cyclic dependency, a slice along the Time index depends on itself. To avoid this, you should ensure that this X depends on itself only at earlier Time points.

Cause

The Dynamic function allows you to create models where a variable ultimately depends on itself. However, it must still be the case that no variable value at a particular time point depends on itself at that same time point. For example, if X[Time=1] directly or indirectly depends on X[Time=1], then a cyclic dependency exists, and this error will result.

Consider this example:

Constant TN := 4
SysVar Time := 1..TN
Variable X := Dynamic(Y[Time=TN], Y[Time-1]+1)
Variable Y := Dynamic(1,X[Time-1]*2)

Let's trace through the dependencies, starting with X[Time=1] which clearly dependends on Y[Time=4]:

X[Time=1] ← Y[Time=4] ← X[Time=3] ← Y[Time=2] ← X[Time=1]

As an exercise, trace through the dependencies when TN:=5 (or any odd number ≥3) and show that in that case no such dynamic-cyclic dependency exists in the above example.

In the above example, we've jumped forward in time with the offset in the expression for X[Time=1]. A more common mistake is to have a zero offset as you traverse through the loop, e.g.:

Variable A := Dynamic(A0,F(B))
Variable B := Dynamic(B0,F(A))

Remedy

It is unusual to have forward and backward offsets in the same dynamic loop. Unless you are intentionally doing something unusual in that regard, make sure you have only backward offsets, or only forward offsets, in the dynamic loop. (If you have only forward offsets, to future time points, as may occur in dynamic programming, you're dynamic calls should also have the optional «reverse» parameter set to true for better efficiency). Then make sure you have at least one non-zero offset in any loop.

Comments


You are not allowed to post comments.