资源简介

这是一个基于遗传算法的社区发现算法代码
论文:Community detection based on modularity and an improved genetic algorithm
###使用方法:
1.在CommityData.java文件里面,更改path变量.
###代码结构:
1.CommityData.java:定义了全部变量,以及数据的初始化工作
2.SpeciesIndividual.java:染色体个体
3.SpeciesPopulation.java:物种群,用链表的形式来存储每一个SpeciesIndividual个体 4.GeneticAlgorithm.java:遗传算法步骤,包括选择交叉变异等操作
5.MainRun.java:主函数

资源截图

代码片段和文件信息

package com.shoulaxiao;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

/**
 * @USER: shoulaxiao
 * @DATE: 19-12-3
 * @TIME: 上午11:39
 **/
public class CommityData {


    public static int NODE_NUM;
    public static int EDGE_NUM;
    static int COMMITY_NUM;
    static final int SPECIES_NUM=450;//种群数
    static final int DEVELOP_NUM=50;//进化代数

    static final float pcl=0.2fpch=0.8f;//交叉概率
    static final float pm=0.2f;//变异概率

    static int T=800000;//初始温度
    static final int l=10;//每个温度循环次数l
    static final float k=0.99f;//常数k


    public static List> neigbor_List;//邻接表
    public static int[][] adjacentMatrix;//邻接矩阵

    static String path=“/home/shoulaxiao/文档/dataCluster/football.txt“;

    static {
        String encoding=“utf-8“;
        try {
            File file=new File(path);
            if (file.isFile()&&file.exists()){
                InputStreamReader reader=new InputStreamReader(new FileInputStream(file)encoding);
                BufferedReader br=new BufferedReader(reader);
                String lineTxt=null;
                lineTxt=br.readLine();


                //读取结点的边数与结点数(数据的第一行)
                String[] cur2=lineTxt.split(“ “);
                NODE_NUM=Integer.parseInt(cur2[0]);
                EDGE_NUM=Integer.parseInt(cur2[1]);
                neigbor_List=new ArrayList>(NODE_NUM);
                adjacentMatrix=new int[NODE_NUM][NODE_NUM];

                //初始化邻接表
                for (int i=0;i                    neigbor_List.add(new ArrayList());
                }

                //初始化邻接矩阵
                for (int i=0;i                    for (int j=0;j                        adjacentMatrix[i][j]=0;
                    }
                }

                //正式读取数据
                while ((lineTxt=br.readLine())!=null){
                    String cur[] = lineTxt.split(“ “);
                    int u = Integer.parseInt(cur[0]);
                    int v = Integer.parseInt(cur[1]);
                    addEdges(uv);
                    addEdges(vu);
                }
                reader.close();
                System.out.println(“数据读取成功!“);
            }
            else {
                System.out.println(“指定文件不存在请重新输入文件“);
            }
        }catch (Exception e){
            System.out.println(“读取文件内容出错请稍后再试“);
            e.printStackTrace();
        }

    }

    /**
     * 添加节点
     * @param i
     * @param j
     */
    private static void addEdges(int i int j) {
        neigbor_List.get(i).add((j));// 给编号为i的顶点一条添加指向编号为j的边
        adjacentMatrix[i][j]=1;
    }


    /**
     * 输出矩阵
     */
    public static void printData(){
        for (int i=0;i            for (int j=0;j                System.out.

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2019-12-03 08:25  MIGA-master\
     目录           0  2019-12-03 08:25  MIGA-master\.idea\
     目录           0  2019-12-03 08:25  MIGA-master\.idea\artifacts\
     文件         270  2019-12-03 08:25  MIGA-master\.idea\artifacts\MIGA_jar.xml
     文件         135  2019-12-03 08:25  MIGA-master\.idea\encodings.xml
     文件         273  2019-12-03 08:25  MIGA-master\.idea\misc.xml
     文件         248  2019-12-03 08:25  MIGA-master\.idea\modules.xml
     文件        8792  2019-12-03 08:25  MIGA-master\.idea\uiDesigner.xml
     文件         180  2019-12-03 08:25  MIGA-master\.idea\vcs.xml
     文件       31795  2019-12-03 08:25  MIGA-master\.idea\workspace.xml
     文件         577  2019-12-03 08:25  MIGA-master\MIGA.iml
     文件         700  2019-12-03 08:25  MIGA-master\README.md
     目录           0  2019-12-03 08:25  MIGA-master\out\
     目录           0  2019-12-03 08:25  MIGA-master\out\artifacts\
     目录           0  2019-12-03 08:25  MIGA-master\out\artifacts\MIGA_jar\
     文件       11664  2019-12-03 08:25  MIGA-master\out\artifacts\MIGA_jar\MIGA.jar
     目录           0  2019-12-03 08:25  MIGA-master\out\production\
     目录           0  2019-12-03 08:25  MIGA-master\out\production\MIGA\
     目录           0  2019-12-03 08:25  MIGA-master\out\production\MIGA\meta-INF\
     文件          58  2019-12-03 08:25  MIGA-master\out\production\MIGA\meta-INF\MANIFEST.MF
     文件          16  2019-12-03 08:25  MIGA-master\out\production\MIGA\meta-INF\MIGA.kotlin_module
     目录           0  2019-12-03 08:25  MIGA-master\out\production\MIGA\com\
     目录           0  2019-12-03 08:25  MIGA-master\out\production\MIGA\com\shoulaxiao\
     文件        3796  2019-12-03 08:25  MIGA-master\out\production\MIGA\com\shoulaxiao\CommityData.class
     文件        6158  2019-12-03 08:25  MIGA-master\out\production\MIGA\com\shoulaxiao\GeneticAlgorithm.class
     文件        1800  2019-12-03 08:25  MIGA-master\out\production\MIGA\com\shoulaxiao\MainRun.class
     文件        3739  2019-12-03 08:25  MIGA-master\out\production\MIGA\com\shoulaxiao\SpeciesIndividual.class
     文件        1684  2019-12-03 08:25  MIGA-master\out\production\MIGA\com\shoulaxiao\SpeciesPopulation.class
     目录           0  2019-12-03 08:25  MIGA-master\out\production\MIGA\data\
     文件         910  2019-12-03 08:25  MIGA-master\out\production\MIGA\data\dolphin.txt
     文件        4954  2019-12-03 08:25  MIGA-master\out\production\MIGA\data\football.txt
............此处省略27个文件信息

评论

共有 条评论