2

我已經嘗試在c#中實現深度優先搜索,但我不完全確定如何執行此分佈式計算方式。如果你們能幫助我在這,我將非常感激:)你可以在下面找到以分佈式方式深度優先搜索

public class DFS 
{ 
static List<string> traversedList = new List<string>(); 
static List<string> parentList = new List<string>(); 

public static void Main(string[] args) 
{ 

    int N = 100; 
    int M = N * 4; 
    int P = N * 16; 

    Stack newstack = new Stack(); 

    List<string> global_list=new List<string>(); 

    StreamReader file = new StreamReader("my input file"); 

    string text = file.ReadToEnd(); 

    string[] lines = text.Split('\n'); 

    string[][] array1 = new string[lines.Length][]; 

    for (int i = 0; i < lines.Length; i++) 
    { 
     lines[i] = lines[i].Trim(); 
     string[] words = lines[i].Split(' '); 

     array1[i] = new string[words.Length]; 

     for (int j = 0; j < words.Length; j++) 
     { 
      array1[i][j] = words[j]; 
     } 
    } 

    StreamWriter sr = new StreamWriter(args[0]); 

    for (int i = 0; i < array1.Length; i++) 
    { 
     for (int j = 0; j < array1[i].Length; j++) 
     { 
      if (j != 0) 
      { 
       sr.Write(array1[i][0] + ":" + array1[i][j]); 
       Console.WriteLine(array1[i][0] + ":" + array1[i][j]); 
       sr.Write(sr.NewLine); 
      } 
     } 

    } 

    int start_no = Convert.ToInt32(args[args.Length-1]); 

    traversedList.Add(start_no.ToString()); 
    parentList.Add("root"); 
    dfs(array1, start_no); 

    for (int z = 0; z < traversedList.Count; z++) 
    { 
      Console.WriteLine(traversedList.ElementAt(z) + " "+parentList.ElementAt(z)+" "+(z+1)); 
    } 
    Console.ReadLine(); 
} 

private static void dfs(string[][] array, int point) 
{ 
    for (int z = 1; z < array[point].Length; z++) 
     { 
      if ((!traversedList.Contains(array[point][z]))) 
      { 
       traversedList.Add(array[point][z]); 
       parentList.Add(point.ToString()); 
       dfs(array, int.Parse(array[point][z])); 
      } 
     } 
     return; 
} 

我的DFS代碼}

+0

請問您能澄清一下你的意思是?「分佈式計算」通常意味着將計算分佈在幾臺不同的計算機上。你是不是指「並行計算」?還有,你試過了什麼?失敗了怎麼辦? – svick

+0

That right !!實現DFS的並行方式..我不知道該去哪裏開始......你能給我提一些關於這個問題的提示嗎? –

回答

1

你應該讀計算機國際象棋文獻(現在演變成世界 - 冠軍電腦遊戲玩家)的世界。他們已經做了大約30年的深度優先搜索,並且有很多想法。正確的做法很棘手,因爲您必須均勻分配工作而不知道特定分支可能包含多少工作。

退房Monty Newborn或麥吉爾大學,這似乎是十年前的一個相當溫牀。

當然,GIYF:「分佈深度優先搜索」對本文產生了參考:Distributed Algorithms for Depth-First Search。我猜想它包含了很多來自計算機象棋世界的想法。

*共享內存的問題「DFS有點困難;你不必發送消息給你的分佈式幫助器,你可以簡單地傳遞一個指針: - }它有助於提供一種語言爲你提供並行並管理可能發生的爆炸性並行性增長,如果您的程序在每個分支上都會發生這種情況,我會提供一個以我設計的並行編程語言構建的example 4x4 N-puzzle solver(這個例子是我最早的SO帖子之一)