简体   繁体   English

网络中最大的连接组件

[英]Biggest connected component in network

I have a big text file (20 GB) file that contains source-target nodes and threshold.If threshold > 0 is connected otherwise not connected.I want to add the connected nodes in array or array list(which one is suitable for large amount of data?) and to find the giant connected component.I think BFS algorithm is a solution for the shortest path.我有一个包含源目标节点和阈值的大文本文件 (20 GB) 文件。如果阈值 > 0 已连接,否则未连接。我想在数组或数组列表中添加连接的节点(哪个适合大量数据?)并找到巨大的连通分量。我认为BFS算法是最短路径的解决方案。

Txt file文本文件

100 101 -0.3434
100 102  1.0023
100 103  1.100
103 104  0.210
...

My code:我的代码:

String line = null;
HashMap<Integer,ArrayList<Node>> arr = new HashMap<Integer,ArrayList<Node>>();
BufferedReader reader = new BufferedReader(new FileReader("C:/Users/UserPC/Desktop/output.txt"));
        while((line = reader.readLine()) != null){
            String[] spl = line.split("\\s+");
            //System.out.println(spl[0]+","+spl[1]);
            int source = Integer.parseInt(spl[0]);
            int target = Integer.parseInt(spl[1]);


            arr.computeIfAbsent( source, k -> new ArrayList<>()).add(new Node(target));

        } 

        reader.close();

20 GB will take too much time if you don't implement them correctly btw you can consider a graph data structure and later you apply minimum spanningtree algorithm by adjusting weight so it only find nodes who have weight less or greater than a certain value.如果您没有正确实现它们,20 GB 将花费太多时间顺便说一句,您可以考虑使用图形数据结构,然后通过调整权重来应用最小生成树算法,因此它只能找到权重小于或大于某个值的节点。

Steps: Step 1: Make one dimensional array of bags which contains a source node, destination and weight/threshold.步骤: 步骤 1:制作一维袋子数组,其中包含源节点、目的地和重量/阈值。

    step 1:
    private Bag<Integer>[] array = (Bag<Integer>[]) new Bag[V];
    for all indexes:
    array[i] = new Bag<Integer>();

Create one class which says that your components are connected and what is their threshold: call is connected.创建一个类,说明您的组件已连接以及它们的阈值是多少:调用已连接。

int firstNode = readIn via scanner.
int secondNode = readIn.
Int thresHold = read;
Connected connected = new Conncted(firstNode,secondNode,threshold);



    add all these connected component into array of bag so you have a graph then use minimumspanning tree or anyother algorithm, there are many.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM