[英]Creating graph with clusters using jgrapht
Is there any way to create a graph with clusters using jgrapht? 有什么方法可以使用jgrapht创建带有聚类的图? Example graph with two clusters "process #1" and "process #2":
具有两个集群“进程1”和“进程2”的示例图:
Expected dot file content : 预期的点文件内容:
digraph G {
subgraph cluster_0 {
style=filled;
color=lightgrey;
node [style=filled,color=white];
a0 -> a1 -> a2 -> a3;
label = "process #1";
}
subgraph cluster_1 {
node [style=filled];
b0 -> b1 -> b2 -> b3;
label = "process #2";
color=blue
}
start -> a0;
start -> b0;
a1 -> b3;
b2 -> a3;
a3 -> a0;
a3 -> end;
b3 -> end;
start [shape=Mdiamond];
end [shape=Msquare];
}
Your graph design is a bit peculiar. 您的图形设计有些特殊。 When I visually look at your graph, I see a base graph, and 2 clustered groups of nodes .
当我目视观察您的图时,会看到一个基础图和2个群集的节点组 。 When I look at your DOT file, I see 2 subgraphs, and an 'outer' graph that refers to specific nodes in your subgraph.
当我查看您的DOT文件时,我看到2个子图,以及一个“外部”图,它引用了您的子图中的特定节点。 Note that a subgraph is not a cluster.
请注意,子图不是聚类。
Your question seems to have 2 parts: (1) can you create a graph with clusters using jgrapht and (2) can you create the DOT file in your example. 您的问题似乎包括两部分:(1)您可以使用jgrapht创建带有聚类的图吗?(2)您可以在示例中创建DOT文件。 The answers are: (1) yes, (2) no, at least not out of the box, since
DOTExporter
does not support 'subgraphs'. 答案是:(1)是,(2)否,至少不是开箱即用,因为
DOTExporter
不支持“子图”。
There are a few different ways you can create clustered graphs. 您可以通过几种不同的方法来创建聚类图。
List<Set<V>>
to store your clusters. List<Set<V>>
以存储您的聚类。 You could visualize the subgraph induced by a particular cluster using the AsSubgraph
class. AsSubgraph
类可视化由特定群集诱导的子图。 BlockCutpointGraph
implementation. BlockCutpointGraph
实现中做了类似的BlockCutpointGraph
。 If you want to export your graph in a similar fashion as your example DOT file, you'll have to do some work. 如果要以与示例DOT文件类似的方式导出图形,则必须做一些工作。 You could implement your own custom DOTExporter, or modify the existing one.
您可以实现自己的自定义DOTExporter,或修改现有的DOTExporter。 Perhaps an easy alternative (not the cleanest) is to do something along the following lines:
也许一个简单的替代方法(不是最干净的方法)是按照以下方式进行操作:
AsSubgraph
class AsSubgraph
类 MaskSubgraph
class. MaskSubgraph
类。 DOTExporter
class. DOTExporter
类导出在步骤(2)和(3)中创建的DOTExporter
。 subgraph
keywork. subgraph
键盘插入其他图。 Using your example: 使用您的示例:
digraph G {
start -> a0;
start -> b0;
a1 -> b3;
b2 -> a3;
a3 -> a0;
a3 -> end;
b3 -> end;
start [shape=Mdiamond];
end [shape=Msquare];
}
digraph cluster_0 {
style=filled;
color=lightgrey;
node [style=filled,color=white];
a0 -> a1 -> a2 -> a3;
label = "process #1";
}
Here you have to substitute digraph
by subgraph
and insert this graph into the base graph to obtain: 在这里,您必须用
subgraph
替换digraph
subgraph
然后将此图插入基础图以获得:
digraph G {
subgraph cluster_0 {
style=filled;
color=lightgrey;
node [style=filled,color=white];
a0 -> a1 -> a2 -> a3;
label = "process #1";
}
start -> a0;
start -> b0;
a1 -> b3;
b2 -> a3;
a3 -> a0;
a3 -> end;
b3 -> end;
start [shape=Mdiamond];
end [shape=Msquare];
}
Obviously you must repeat this for the remaining clusters. 显然,您必须对其余群集重复此操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.