Java 中的有向图处理 [英] Directed Graph Processing in Java
问题描述
我希望实现一个 Java 应用程序,该应用程序将计算一组要执行的任务.这些任务将相互依赖,形成一个有向图.是否有现有的 SDK 或算法(最好是 Java)可以帮助我:
I am looking to implement a Java application that will compute a set of tasks to execute. The tasks will have dependencies on each other, forming a directed graph. Is there an existing SDK or algorithm (preferably in Java) out there that will help me:
- 定义任务图
- 确保图中没有循环依赖
- 使用线程池执行图中的任务
第 3 步是最重要的部分.我需要以并行方式执行任务以获得最佳性能,同时确保任务不会在其依赖项之前执行.
Step 3 is the most important part. I need to execute the tasks in a parallel fashion for maximum performance yet ensure that a task isn't executed before its dependencies.
推荐答案
看看以前的question,本质上建议使用 JGraphT.
Have a look at this previous question, which essentially suggests using JGraphT.
它显然会使 1) 变得容易,并且第 3 部分具有循环检测器).不要认为它会为您完成第 3 部分,但您需要做的就是让所有顶点的出度(或度数取决于您的表示)为 0 并开始这些任务.任务完成后,从图中删除顶点并重新开始.
It will obviously make 1) easy and has cycle detectors for part 3). Don't think it will do part 3 for you but all you need to do is get all vertexes with an out degree (or in degree depending on your representation) of 0 and start those tasks. When a task finishes then delete the vertex from the graph and start again.
这篇关于Java 中的有向图处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!