Async In-Place Value Iteration Sweep
Problem Statement
Perform one in-place (asynchronous) value-iteration sweep: states are updated left to right, and each update immediately uses the freshest values of earlier states. For each state you are given a list of actions, each {"reward": r, "probs": [...], "next": [...]} where next are next-state indices aligned with probs.
Mutate and return the values list. Implement vi_sweep_inplace(states, gamma, V).
Example
vi_sweep_inplace([[{"reward":0.0,"probs":[1.0],"next":[1]}],[{"reward":1.0,"probs":[1.0],"next":[1]}]], 0.9, [0.0, 0.0])[0.0, 1.0]
- Initialize State 0: The sweep begins with state . It has one action with reward , probability , and next state . Since the update is in-place, it uses the current value of state 1, which is initially .
- Compute Value for State 0: Calculate the Q-value for the single action: . This becomes the new value for state 0, so is updated to .
- Process State 1: Move to state . It has one action with reward , probability , and next state (a self-loop). The calculation uses the current value of state 1, which is still because state 1 has not been updated yet in this sweep.
- Compute Value for State 1: Calculate the Q-value: . This becomes the new value for state 1, so is updated to .
- The final output is [0.0, 1.0]
Constraints
len(states) == len(V); update states 0..n-1 in order, in place.- Later states in the same sweep see earlier states' new values.
- Return the same (mutated) list.