导演图形处理Java中图形处理、导演、Java

2023-09-11 04:06:46 作者:世界再好也不及你

我期待实现一个Java应用程序,将计算一组任务来执行的。任务会对彼此的依赖性,形成有向图。是否有一个现有的SDK或算法(在Java中preferably)在那里,这将有助于我:

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.

推荐答案

有一个在这个previous的问题,基本上建议使用 JGraphT 。

Have a look at this previous question, which essentially suggests using JGraphT.

这显然使1)容易并且有周期探测器第3部分)。不要以为它会做第3部分为你,但你需要做的就是用out度所有顶点(或学位取决于您重新presentation)为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.