java - JgraphT 导出到点文件

标签 java interface export dot jgrapht

我正在构建一个关于图论算法的项目,为此我使用 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/

相关文章:

r - 使用 cbind 将 R lm 回归导出到文本

java - 查找特定 LocalDate 是否属于 YearMonth 的最简单方法是什么?

language-agnostic - "program to an interface"是什么意思?

Delphi:从什么时候开始,接口(interface)引用不再在 with block 末尾释放?

Java:难以理解接口(interface)的用途?

azure - azure 中的自动化 bacpac 导出

java - 正确使用 JRSwapFileVirtualizer?

java - 在 Linux 64 位上用 Java 监视文件

java - 为什么查询谷歌云文件返回一个空列表?

java - Struts2 datetimepicker 不显示