I am trying to come up with an algorithm for a tree traversal, but I am getting stuck.
This is a fairly hard question (compared to others I have asked) so I may need to keep figuring on my own. But I thought I would throw it out here.
I have the following class structure:
public class Transition
{
// The state we are moving from.
public String From { get; set; }
// All the To states for this from
public List<String>To { get; set; }
}
List<Transition> currentTransistions;
When currentTransistions is fully filled out it looks like this (for me):
<?xml version="1.0" encoding="utf-8"?>
<ArrayOfTransition xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Transition>
<From />
<To>
<string>Not Done</string>
</To>
</Transition>
<Transition>
<From>Not Done</From>
<To>
<string>In Progress</string>
<string>Deleted</string>
</To>
</Transition>
<Transition>
<From>Deleted</From>
<To>
<string>Not Done</string>
</To>
</Transition>
<Transition>
<From>In Progress</From>
<To>
<string>Done</string>
<string>Ready For Test</string>
<string>Deleted</string>
</To>
</Transition>
<Transition>
<From>Done</From>
<To>
<string>In Progress</string>
</To>
</Transition>
<Transition>
<From>Ready For Test</From>
<To>
<string>In Progress</string>
<string>Done</string>
<string>Deleted</string>
</To>
</Transition>
</ArrayOfTransition>
The idea here is that I have mapped the state transitions for TFS Work items. What I need now is a way to say "Given a current state, how do I get to another state".
Ideally it would look like this:
foreach (string state in GetToFinalState(finalState, currentState, currentTransistions)
{
// Save the workitem at the state so we can get to the final state.
}
GetToFinalState, would have to have a way to caclulate the shortest path and use the yield feature of C# to offer them up one at a time for the foreach statement.
I have used yield one before, so I think I can figure that out. But I am not sure how to do that at the same time as finding the shortest path (with out recalculating on each time in the func)?
If you have read this far, thanks. If you offer an answer then double thanks.