寻找算法来帮助确定从一个终端屏幕到另一个终端屏幕的最短路径
我正在使用终端客户端与大型计算机交互。整个界面基于屏幕的概念。示例工作流程可能如下所示:
- 登录屏幕:输入登录凭据,按 Enter 键
- 菜单屏幕:输入所需菜单项的编号(比如“6”表示备忘录),按 Enter 键
- 备忘录屏幕:输入帐号,按 Enter
- 添加备忘录屏幕:输入备忘录详细信息等,按 Enter 保存,F3 返回
我编写了一个 python 应用程序,通过此终端界面自动处理记录。我遇到的困难之一是有很多不同的屏幕,而我的应用程序现在对于如何从一个屏幕转到另一个屏幕非常愚蠢。它可以从登录屏幕到添加备忘录。但是,如果它发现自己位于备忘录屏幕上并且需要停用帐户,则必须注销并再次登录,因为它只知道如何从登录屏幕进入停用屏幕,而不知道如何从添加备忘录屏幕进入停用屏幕。
因此,我想在我的应用程序中创建一个“地图”,将每个屏幕链接到其“旁边”的屏幕。然后,我需要一种算法来告诉如何以最短的方式从任何屏幕 A 到达任何屏幕 B。
我已经设置了一些屏幕对象,并将它们“关联”到它们旁边的屏幕。因此,我正在寻找某种可以实现的算法或可以使用的 python 库来完成计算从一个屏幕到另一个屏幕的路线的工作。
编辑:我意识到我正在寻找某种最短路径图算法。目前让我困惑的是,我实际上没有“距离”,我只有节点。所以,我真的不想要最短距离,我想要最少节点。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您已经创建了屏幕拓扑,A* 算法应该可以正常工作。
If you have created a topology of the screens, the A* algorithm should work fine.
由于我使用的是未加权图,看起来最简单的方法是广度优先搜索:
http://en.wikipedia.org/wiki/Breadth-first_search
编辑:我找到了一个可以完成我需要的一切的库:
http://networkx.lanl.gov/reference/ generated/networkx .algorithms.shortest_paths.generic.shortest_path.html
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