我正在构建一个关于图论算法的项目,为此我使用 JGraphT .我已经完全构建了我的图表,并且在过去的几个月里我一直在研究它。现在我想导出它,以便在 Gephi 中可视化它。 我不想使用 JGraph 和 Java 可视化,因为我已经有足够的代码并且我想保持简单。我想使用 DOTExporter class from JgraphT .我已经达到了导出精细顶点和边,但不导出边权重的程度。
所以这是我的导出功能。我不知道如何实现 ComponentAttributeProvider
接口(interface),也找不到摆脱这种困惑的方法。
有什么想法我应该放什么而不是 null,null?
static public void exportGraph(){
StringNameProvider<CustomVertex> p1=new StringNameProvider<CustomVertex>();
IntegerNameProvider<CustomVertex> p2=new IntegerNameProvider<CustomVertex>();
StringEdgeNameProvider<CustomWeightedEdge> p3 = new StringEdgeNameProvider<CustomWeightedEdge>();
DOTExporter export=new DOTExporter(p2, p1, p3, null, null);
try {
export.export(new FileWriter("graph.dot"), g);
}catch (IOException e){}
}
我做过类似的事情
ComponentAttributeProvider<CustomWeightedEdge> edgeAttributeProvider =
new ComponentAttributeProvider<CustomWeightedEdge>() {
public Map<String, String> getComponentAttributes(CustomWeightedEdge e) {
Map<String, String> map =new LinkedHashMap<String, String>();
map.put("weight", Double.toString(g.getEdgeWeight(e)));
return map;
}
};
最佳答案
好的。 对于其他希望如何使用点文件将加权图从 jgrapht 导出到 gephi 的人
static public void exportGraph(){
IntegerNameProvider<CustomVertex> p1=new IntegerNameProvider<CustomVertex>();
StringNameProvider<CustomVertex> p2=new StringNameProvider<CustomVertex>();
ComponentAttributeProvider<DefaultWeightedEdge> p4 =
new ComponentAttributeProvider<DefaultWeightedEdge>() {
public Map<String, String> getComponentAttributes(DefaultWeightedEdge e) {
Map<String, String> map =new LinkedHashMap<String, String>();
map.put("weight", Double.toString(g.getEdgeWeight(e)));
return map;
}
};
DOTExporter export=new DOTExporter(p1, p2, null, null, p4);
try {
export.export(new FileWriter("graph.dot"), g);
}catch (IOException e){}
}
关于java - JgraphT 导出到点文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16998608/