In some dynamic programming algorithms, you start with a known final value, then compute the value at each time point as a function of future values. This dynamic-in-reverse can be accomplished using Dynamic by specifying the recurrence as the first parameter to dynamic, followed by the final value(s), and then specifying
The example model
“Optimal Path Dynamic Programming.ana” computes an optimal path over a finite horizon. There is a final payout in the last time period, as a function of the final state, and an action cost (a function of action and state) at each intermediate step. Dynamic programming is used to find the optimal policy and the utility at each
Decision Best_Action := ArgMax(Sxa_utility, Action) Objective Sxa_utility := Dynamic( Sxa_utility[Time + 1][Action = Best_action[Time + 1]] [State = Transition] - Action_cost, Final_payout, reverse: true)
Notice the use of
[Time + 1] rather than the
[Time - 1] that is commonly used in forward Dynamic loops.