/// <summary>
/// Converts the experience pair into their equivalent math forms.
/// </summary>
/// <param name="state">IMDPState instance.</param>
/// <param name="nodes">List of nodes added to the result set.</param>
/// <param name="states">Matrix to store contained successor state vectors.</param>
/// <param name="actions">Vector to store the contained action values.</param>
/// <param name="statesP">Matrix to store all contained successor transition state vectors.</param>
/// <param name="rewards">Vector to store all contained reward values.</param>
/// <returns>HashSet<string></returns>
private static void Convert(this IMDPState state, ref List<string> nodes, ref Matrix states, ref Vector actions, ref Matrix statesP, ref Vector rewards)
{
if (state != null)
{
foreach (IMDPSuccessor successor in state.GetSuccessors())
{
if (state.Features.Length != states.Cols)
states = Matrix.Reshape(states, states.Rows, state.Features.Length);
if (state.Features.Length != statesP.Cols)
statesP = Matrix.Reshape(statesP, statesP.Rows, ((IMDPState) successor.State).Features.Length);
string id = $"{state.Id}:{successor.State.Id}";
if (!nodes.Contains(id))
{
states = states.Insert(state.ToVector(), states.Rows - 1, VectorType.Row);
actions = actions.Insert(actions.Length - 1, successor.Action.Id);
statesP = statesP.Insert(((IMDPState) successor.State).ToVector(), statesP.Rows - 1, VectorType.Row);
rewards = rewards.Insert(rewards.Length - 1, successor.Reward);
nodes.Add(id);
}
if (!successor.State.IsTerminal)
{
var successorState = ((IMDPState) successor.State);
if (successorState.Id != state.Id)
successorState.Convert(ref nodes, ref states, ref actions, ref statesP, ref rewards);
}
}
}
}