[英]Biggest connected component in network
我有一個包含源目標節點和閾值的大文本文件 (20 GB) 文件。如果閾值 > 0 已連接,否則未連接。我想在數組或數組列表中添加連接的節點(哪個適合大量數據?)並找到巨大的連通分量。我認為BFS算法是最短路徑的解決方案。
文本文件
100 101 -0.3434
100 102 1.0023
100 103 1.100
103 104 0.210
...
我的代碼:
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 將花費太多時間順便說一句,您可以考慮使用圖形數據結構,然后通過調整權重來應用最小生成樹算法,因此它只能找到權重小於或大於某個值的節點。
步驟: 步驟 1:制作一維袋子數組,其中包含源節點、目的地和重量/閾值。
step 1:
private Bag<Integer>[] array = (Bag<Integer>[]) new Bag[V];
for all indexes:
array[i] = new Bag<Integer>();
創建一個類,說明您的組件已連接以及它們的閾值是多少:調用已連接。
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.