本文介绍了GraphViz:给定一个.dot文件,如何计算节点统计信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给定一个图的.dot表示形式,我希望能够编译有关每个节点的一些统计信息.统计信息可以是:边缘数,级别数,节点数.

Given a .dot representation of a graph, I'd like to be able to compile some statistics about each node. Statistics could be: # of edges, # of levels, # of nodes.

有没有可以让我做到这一点的软件包?

Is there a package available that lets me do this?

推荐答案

是的,这与graphviz一起提供.

Yes, this comes with graphviz out of the box.

有关图形的一般统计信息可以通过将图形输入 -计算图形分量:

General statistics about a graph can be obtained by feeding your graph into gc - count graph components:

如果您想生成有关图形的更具体的统计信息,可以使用工具 gvpr -图形模式扫描和处理语言.

If you would like to generate more specific stats about your graph, you can use the tool gvpr - graph pattern scanning and processing language.

gvpr允许对您的图形执行自定义脚本.该脚本可以像您这样简单地收集自定义统计信息,甚至可以修改输入图.

gvpr allows executing a custom script against your graph. The script may simply gather custom statistics like in your case, or it may even modify the input graph.

以上链接的文档非常完整,说明了所有可用的属性和功能,这些都比我在这里能做的更好.下面只是一个简单的示例,可以帮助您入门.

The above linked documentation is very complete and explains all the available properties and features better than I can do here. Below just a simple example to get you started.

如果我们有以下图形graph.gv:

digraph graphinfotest {
    a -> {b; c; d} -> e;
    b -> c;
}

以下gvpr脚本(在文件graphinfo.gvpr中):

The following gvpr script (in file graphinfo.gvpr):

BEG_G {
    int n = nNodes($G);
    int e = nEdges($G);
    printf("There are %d nodes and %d edges in %s\n", n, e, $G.name);
}
N {
    printf("Node %s - indegree %d, outdegree %d\n", $.name, $.indegree, $.outdegree);
}

致电

gvpr -f graphinfo.gvpr graph.gv

将产生以下输出:

There are 5 nodes and 7 edges in graphinfotest
Node a - indegree 0, outdegree 3
Node b - indegree 1, outdegree 2
Node c - indegree 2, outdegree 1
Node d - indegree 1, outdegree 1
Node e - indegree 3, outdegree 0

这篇关于GraphViz:给定一个.dot文件,如何计算节点统计信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 04:21