生成软件堆栈图的算法

发布于 2024-07-18 17:24:46 字数 370 浏览 5 评论 0原文

我正在寻找一种算法的想法,该算法在给定一组非循环依赖关系的情况下生成类似于下图的图表(我使用此图像来表明依赖关系可能很复杂)

alt text
(来源:interactivetvweb.org

I'm looking for ideas for an algorithm that generates a diagram similar to the following, given a set of acyclic dependencies (I'm using this image to show that the dependencies can be complex)

alt text
(source: interactivetvweb.org)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

寒冷纷飞旳雪 2024-07-25 17:24:46

并不总是能够制作这样的图表。 (非循环)依赖关系:

A 取决于 X、Y、Z

B 取决于 X、Y、Z

C 取决于 X、Y、Z

描述了六个顶点上的完全二部图,即 非平面。 对于您显示的图表类型来说,这样做的结果是,图表中的至少一个区域必须分为两个单独的部分,和/或至少其中一个区域不得直接连接到其依赖项。

基于图形的可视化(例如 graphvis)可以避免此问题,其中边可以相互交叉。

用于生成您正在寻找的图表的启发式算法的概要如下:

  1. 解析依赖关系树以计算每个项目的“级别”。 在上面给出的示例中,X、Y 和 Z 将在该图中在第 1 级分别出现 3 次,作为 A、B 和 C 的子级(在第 0 级)
  2. 以明显的方式绘制树,项目位于每个“级别”位于同一水平级别,其祖先/子代分别位于其下方/上方。 可以选择每个级别的项目放置顺序。
  3. 根据单个项目被分成图表上多个区域的次数,计算图表的好坏程度。 如果项目的顺序良好,并且代表同一项目的两个或多个区域相互接触,则可以将它们融合在一起。
  4. 使用此指标来优化同一级别的项目排列,使用组合优化算法,例如 Metropolis 算法

这不会每次都产生最好的图表(如果这样的概念是明确定义的......),但应该对像你的例子这样的问题做一个合理的工作。

It's not always going to be possible to make such a diagram. The (acyclic) dependency relationship:

A depends on X, Y, Z

B depends on X, Y, Z

C depends on X, Y, Z

describes the complete bipartite graph on six vertices, which is non-planar. The consequence of this for the type of diagram you show is that at least one of the areas in your graph must be either split into two separate pieces, and/or at least one of the areas must not connect directly to its dependent.

This problem is avoided by graph-based visualisation (such as graphvis), where edges can cross each other.

The outline of a heuristic algorithm to produce the sort of diagrams you're looking for is as follows:

  1. Parse the tree of dependencies to calculate a 'level' for each item. In the example I give above, X, Y and Z will each appear three times in this graph at level 1, as children of each of A, B and C (at level 0)
  2. Draw the tree in the obvious way, with items at each 'level' at the same horizontal level, and their ancestors/children below/above them respectively. There is a choice as to what order the items are placed at each level.
  3. Calculate some metric of how good the diagram is, based on how many times a single item is split into multiple areas on the graph. If the ordering of the items is good, and two or more areas representing the same item touch each other, you can fuse them together.
  4. Use this metric to optimise the permutations of items at the same level, using a combinatorial optimisation algorithm such as the Metropolis algorithm.

This won't produce the best graph every time (if such a concept is even well-defined...) but should do a reasonable job for problems like your example.

不必你懂 2024-07-25 17:24:46

虽然不是一种算法(这就是您所要求的),但您可能想看看 NDepend,它执行类似的分析并生成与您所追求的类似的图表:

http://ndepend.com/

(我与 NDepend 没有任何关系)

While not an algorithm (which is what you asked for) you might want to check out NDepend which performs similar analysis and generates similar diagrams to the one you're after:

http://ndepend.com/

(I have no affiliation with NDepend)

如日中天 2024-07-25 17:24:46

STAN4J 从 java 代码生成这种图表。

STAN4J generates this kind of diagrams from java-code.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文