gpt4 book ai didi

dependencies - 是否有自动删除点图中 "redundant"边的选项?

转载 作者:行者123 更新时间:2023-12-02 14:48:58 25 4
gpt4 key购买 nike

我为我的 Debian 项目创建了一个依赖点图(见图)。依赖关系包括冗余边。我想要一个没有那些冗余边的更简单的图形。我可以自己计算这些,但这并不容易,因为我在 CMakeLists.txt 和 .cmake 扩展名中生成了 .dot 文件。

所以我想知道 dot 或 Graphviz 中是否有一个选项可以删除不需要的边。因此,例如,顶级 snapwebsites 项目依赖于 cssppadvgetopt。由于 cspp 包已经依赖于 advgetopt,因此不需要 snapwebsitesadvgetopt 之间的边缘。

在有向图中,这意味着:

"snapwebsites" -> "advgetopt";     <-- "auto-remove" this one
"snapwebsites" -> "csspp";

"csspp" -> "advgetopt";

那么,有这样的选择吗?

enter image description here

最佳答案

根据@marapet 的回答,我创建了一个脚本,我想也许其他人会从副本中受益。它也在 Snap 中! C++ 作为 clean-dependencies.gvpr .

# Run with:
#
# /usr/bin/gvpr -o clean-dependencies.dot -f clean-dependencies.gvpr dependencies.dot
#
# Clean up the dependencies.svg from double dependencies
# In other words if A depends on B and C, and B also depends on C, we
# can remove the link between A amd C, it's not necessary in our file.

BEG_G {
edge_t direct_edges[int];
node_t children[int];

node_t n = fstnode($G);
while(n != NULL) {

// 1. extract the current node direct children
//
int direct_pos = 0;
edge_t e = fstout_sg($G, n);
while(e != NULL) {
direct_edges[direct_pos] = e;
children[direct_pos] = opp(e, n);
direct_pos = direct_pos + 1;
e = nxtout_sg($G, e);
}

// 2. find all of the grand children
// and see whether some are duplicates, if so delete the
// original (direct) edge
//
int child_pos = direct_pos;
int c = 0;
for(c = 0; c < child_pos; ++c) {
e = fstout_sg($G, children[c]);
while(e != NULL) {
node_t o = opp(e, children[c]);
int idx;
for(idx = 0; idx < direct_pos; ++idx) {
if(children[idx] == o) {
if(direct_edges[idx] != NULL) {
delete($G, direct_edges[idx]);
direct_edges[idx] = NULL;
}
break;
}
}
e = nxtout_sg($G, e);
}
}

n = nxtnode_sg($G, n);
}
}

END_G {
$O = $G;
}

有几件事我想提一下:gvpr 函数似乎不接受数组作为输入。此外,我首先尝试使用递归方法,并且局部变量被进一步调用粉碎(即在递归调用返回时,变量的值是来自子调用的值......所以变量是“本地”到函数,但仍然只有一个实例,没有堆栈!)

希望以后的版本能解决这些问题。

$ gvpr -V
gvpr version 2.38.0 (20140413.2041)

与尝试在 CMake 中执行相同的操作相比,修复我的图表已经是一种更简单的方法。

enter image description here


更新

实际上我最后写了 a Python script做这项工作。很容易删除定义为 makefile 的树中的重复项。读取 .dot 数据并修复它要困难得多。但是,就我而言,我可以访问您可能没有的数据。

关于dependencies - 是否有自动删除点图中 "redundant"边的选项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56948561/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com