/// <summary> /// Populate states reachable from initial state within the current number of iterations /// </summary> private void ExtendStateSpace(IDeterministicPolicy <TState> policy) { var previousLayer = StateSpace[_iteration - 1]; if (StateSpace.ContainsKey(_iteration)) { return; } var layer = new HashSet <TState>(); if (_iteration > 2) { layer = StateSpace[_iteration - 2]; layer.Clear(); } var distinctLayer = new List <TState>(); var nextStates = new HashSet <TState>(); foreach (var state in previousLayer) { var action = policy[state]; if (action == null) { continue; } nextStates.UnionWith(action[state]); } foreach (var nextState in nextStates) { if (AllStateSpace.Add(nextState)) { distinctLayer.Add(nextState); } layer.Add(nextState); } StateSpace[_iteration] = layer; DistinctStateSpace[_iteration] = distinctLayer; }