I have a state diagram that I want to navigate through:
It got 6 steady states (states that only have 1 possible next states), and the rest of the states are used to move from state to state (2 possible next states). I want to write a function that takes in the current state and endstate, and returns a byte[] with the 0's and 1's that are used to move from start to end state. I want the method to find the fastest way to the destination as possible.
I've had some thoughts regarding how to solve this problem, but I haven't thought of a good (and preferably elegant) solution.
- A state can have either 1 or 2 next states - a state could be saved as a string array, where the next states are listed in the array (there might be a much better way to hold information of state/next state combinations, please enlighten me!)
- I might be able to find the end state through recursive functions, but I'm unsure how.
- Through Google searches on how to solve this problem, I've encountered Dijkstra's algorithm. It seems to me that this algorithm might not be useful in my scenario - or what?
I've thought about hardcoding it, but this makes the function awfully long. Surely there must be a smarter way to do this?
Any help will be much appreciated!
EDIT:
private STATE TapStateNext(STATE state, bool tms)
{
switch (tapState)
{
case STATE.TEST_LOGIC_RESET:
return tms ? STATE.TEST_LOGIC_RESET_B : STATE.RUN_TEST_IDLE;
case STATE.TEST_LOGIC_RESET_B:
return tms ? STATE.TEST_LOGIC_RESET_A : STATE.RUN_TEST_IDLE;
case STATE.RUN_TEST_IDLE:
return tms ? STATE.SELECT_DR_SCAN : state;
case STATE.SELECT_DR_SCAN:
return tms ? STATE.SELECT_IR_SCAN : STATE.CAPTURE_DR;
case STATE.SELECT_IR_SCAN:
return tms ? STATE.TEST_LOGIC_RESET_A : STATE.CAPTURE_IR;
case STATE.CAPTURE_DR:
return tms ? STATE.EXIT1_DR : STATE.SHIFT_DR;
case STATE.SHIFT_DR:
return tms ? STATE.EXIT1_DR : state;
case STATE.EXIT1_DR:
return tms ? STATE.UPDATE_DR : STATE.PAUSE_DR;
case STATE.PAUSE_DR:
return tms ? STATE.EXIT2_DR : state;
case STATE.EXIT2_DR:
return tms ? STATE.UPDATE_DR : STATE.SHIFT_DR;
case STATE.UPDATE_DR:
return tms ? STATE.SELECT_DR_SCAN : STATE.RUN_TEST_IDLE;
case STATE.CAPTURE_IR:
return tms ? STATE.EXIT1_IR : STATE.SHIFT_IR;
case STATE.SHIFT_IR:
return tms ? STATE.EXIT1_IR : state;
case STATE.EXIT1_IR:
return tms ? STATE.UPDATE_IR : STATE.PAUSE_IR;
case STATE.PAUSE_IR:
return tms ? STATE.EXIT2_IR : state;
case STATE.EXIT2_IR:
return tms ? STATE.UPDATE_IR : STATE.SHIFT_IR;
case STATE.UPDATE_IR:
return tms ? STATE.SELECT_DR_SCAN : STATE.RUN_TEST_IDLE;
default:
throw new Exception("Illegal TAP controller state detected");
}
}