I am using a terminal client to interact with a mainframe computer. The entire interface is based on the concept of screens. An example workflow might look like:
- Login Screen: enter login credentials, press enter
- Menu Screen: enter the number of the menu item you want (lets say “6” for memos), press enter
- Memo Screen: enter account number, press enter
- Add Memo Screen: enter memo details, etc, press enter to save, F3 to go back
I have written a python application to automate the processing of records through this terminal interface. One of the difficulties I am having is that there are a lot of different screens and my application right now is pretty dumb about how to get from one screen to another. It can go from the login screen, to adding memos. But, if it finds itself on the memo screen and needs to de-activate an account, it has to logout and login again because it only knows how to get to the deactivation screen from the login screen, not from the add memos screen.
So, I would like to create a “map” in my application that links each screen to the screens that are “next” to it. Then, I need an algorithm that could tell how to get from any screen A to any screen B in the shortest manner possible.
I already have some screen objects setup and have “related” them to the screens next to them. So, I am looking for some kind of algorithm that I can implement or python library that I can use that will do the work of calculating the route from one screen to another.
Edit: I realize that I am looking for some kind of shortest-path graph algorithm. What is currently throwing me is that I don’t really have a “distance”, I just have nodes. So, I really don’t want shortest-distance, I want least-nodes.
Since I am using an unweighted graph, it looks like the simplest approach is going to be Breadth-first search:
http://en.wikipedia.org/wiki/Breadth-first_search
Edit: I found a library which does everything I need:
http://networkx.lanl.gov/reference/generated/networkx.algorithms.shortest_paths.generic.shortest_path.html