博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
gephi生成图(java版)
阅读量:6095 次
发布时间:2019-06-20

本文共 5804 字,大约阅读时间需要 19 分钟。

hot3.png

 
不说啥了,直接代码 ,对于图的生成,推荐使用组合算法,yifan hu 算法点生成图是百万级的
/* Copyright 2008-2010 Gephi Authors : Mathieu Bastian <mathieu.bastian@gephi.org> Website : http://www.gephi.org This file is part of Gephi. Gephi is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. Gephi is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with Gephi. If not, see <http://www.gnu.org/licenses/>. */ package org.gephi.toolkit.demos; import java.io.File; import java.io.IOException; import java.util.concurrent.TimeUnit; import org.gephi.graph.api.DirectedGraph; import org.gephi.graph.api.GraphController; import org.gephi.graph.api.GraphModel; import org.gephi.io.exporter.api.ExportController; import org.gephi.io.importer.api.Container; import org.gephi.io.importer.api.EdgeDefault; import org.gephi.io.importer.api.ImportController; import org.gephi.io.processor.plugin.DefaultProcessor; import org.gephi.layout.plugin.AutoLayout; import org.gephi.layout.plugin.force.StepDisplacement; import org.gephi.layout.plugin.force.yifanHu.YifanHuLayout; import org.gephi.layout.plugin.forceAtlas.ForceAtlasLayout; import org.gephi.project.api.ProjectController; import org.gephi.project.api.Workspace; import org.openide.util.Lookup; /** * This demo shows how to use the <code>AutoLayout</code> class to run layout * programmatically. * <p> * You can set a layout duration, and an execution ratio for several layout. For * instance you set 0.8 for a Yifan Hu algorithm and 0.2 for Label Adjust. If * execution time is 100 seconds, the first algorithm run for 80 seconds and the * second for 20 seconds. It also allows to change property values dynamically * (at a certain ratio or interpolated if values are numerical). * * @author Mathieu Bastian */ public class WithAutoLayout { public void script() { //Init a project - and therefore a workspace //��ʼ��һ����Ŀ - ��һ�������� ProjectController pc = Lookup.getDefault().lookup(ProjectController.class); pc.newProject(); Workspace workspace = pc.getCurrentWorkspace(); //Append container to graph structure //��������ͼ�νṹ ImportController importController = Lookup.getDefault().lookup(ImportController.class); //Import file //�����ļ� Container container; try { File file = new File(getClass().getResource("/org/gephi/toolkit/demos/resources/lesmiserables3582908092477373.gml").toURI()); container = importController.importFile(file); container.getLoader().setEdgeDefault(EdgeDefault.DIRECTED); //Force DIRECTED container.setAllowAutoNode(false); //Don't create missing nodes } catch (Exception ex) { ex.printStackTrace(); return; } importController.process(container, new DefaultProcessor(), workspace); //See if graph is well imported //���ͼ��� GraphModel graphModel = Lookup.getDefault().lookup(GraphController.class).getModel(); DirectedGraph graph = graphModel.getDirectedGraph(); for (int i = 1;i <= graph.getNodeCount();i++) { // System.out.println("Nodes: " + graph.getNode(i).getNodeData()); } System.out.println("Edges: " + graph.getEdgeCount()); //Layout for 1 minute //����1���� //^^ long time = 0; if (graph.getEdgeCount() > 20000) { time = (long) (((double) graph.getEdgeCount() / 80)); // System.out.println("log:huangzheng:"+DateUtil.time2str((int)System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss")+"当前生成图像所花费的时间:"+time); }else if (graph.getEdgeCount() > 12000) { time = (long) (((double) graph.getEdgeCount() / 85)); // System.out.println("log:huangzheng:"+DateUtil.time2str((int)System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss")+"当前生成图像所花费的时间:"+time); } else if (graph.getEdgeCount() > 8000) { time = (long) (((double) graph.getEdgeCount() / 90)); // System.out.println("log:huangzheng:"+DateUtil.time2str((int)System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss")+"当前生成图像所花费的时间:"+time); } else if (graph.getEdgeCount() > 5000) { time = (long) (((double) graph.getEdgeCount() / 95)); // System.out.println("log:huangzheng:"+DateUtil.time2str((int)System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss")+"当前生成图像所花费的时间:"+time); } else if (graph.getEdgeCount() > 100) { time = (long) (((double) graph.getEdgeCount() / 100)); // System.out.println("log:huangzheng:"+DateUtil.time2str((int)System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss")+"当前生成图像所花费的时间:"+time); } else { time = 1; } AutoLayout autoLayout = new AutoLayout(time, TimeUnit.SECONDS); autoLayout.setGraphModel(graphModel); YifanHuLayout secondLayout = new YifanHuLayout(null, new StepDisplacement(1f)); ForceAtlasLayout firstLayout = new ForceAtlasLayout(null); AutoLayout.DynamicProperty adjustBySizeProperty = AutoLayout.createDynamicProperty("forceAtlas.adjustSizes.name", Boolean.TRUE, 0.1f);//True after 10% of layout time AutoLayout.DynamicProperty repulsionProperty = AutoLayout.createDynamicProperty("forceAtlas.repulsionStrength.name", new Double(500.), 0f);//500 for the complete period autoLayout.addLayout(firstLayout , 0.5f, new AutoLayout.DynamicProperty[]{adjustBySizeProperty, repulsionProperty}); autoLayout.addLayout(secondLayout, 0.5f); autoLayout.execute(); //^^ //Export ExportController ec = Lookup.getDefault().lookup(ExportController.class); try { ec.exportFile(new File("WebRoot/WEB-INF/weiboGexf/io_gexf2.gexf")); } catch (IOException ex) { ex.printStackTrace(); } } public static void main(String[] args) { WithAutoLayout autoLayout = new WithAutoLayout(); autoLayout.script(); // System.out.println(); } }

转载于:https://my.oschina.net/ouyanghuangzheng/blog/136546

你可能感兴趣的文章
Jenkins持续集成环境部署
查看>>
emoji等表情符号存mysql的方法
查看>>
Excel到R中的日期转换
查看>>
检查磁盘利用率并且定期发送告警邮件
查看>>
MWeb 1.4 新功能介绍二:静态博客功能增强
查看>>
linux文本模式和文本替换功能
查看>>
Windows SFTP 的安装
查看>>
摄像机与绕任意轴旋转
查看>>
rsync 服务器配置过程
查看>>
预处理、const与sizeof相关面试题
查看>>
爬虫豆瓣top250项目-开发文档
查看>>
Elasticsearch增删改查
查看>>
oracle归档日志增长过快处理方法
查看>>
有趣的数学书籍
查看>>
teamviewer 卸载干净
查看>>
多线程设计模式
查看>>
解读自定义UICollectionViewLayout--感动了我自己
查看>>
SqlServer作业指定目标服务器
查看>>
UnrealEngine4.5 BluePrint初始化中遇到编译警告的解决办法
查看>>
User implements HttpSessionBindingListener
查看>>