title: How to calculate the relation strength between 2 nodes?
body: <p>So I'm trying to make an application that resembles the six degrees of Kevin Bacon game. First I read from a text file the contains the actors and the movies they starred in. The format of it is something like that :<a href="https://i.stack.imgur.com/VnVH2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VnVH2.png" alt="enter image description here"></a></p>
  
  <p>So I stored my graph as an adjacency list that takes actors as nodes and their neighbors and which movies they starred (i.e Dictionary &lt; string, HashSet &lt; Dictionary &lt; string, HashSet &lt; string >>>>) (i.e Actor A: Actor B movie 0, movie 1, movie 7, Actor C movie 8 Actor Z movie 9... etc ) I know the data structure is weird but I was asked to do it like that. This is my graph class.</p>
  
  <pre><code>class Graph
  {
      public Dictionary&lt;string, HashSet&lt;Dictionary&lt;string, HashSet&lt;string&gt;&gt;&gt;&gt; dic;
      public Dictionary&lt;string, HashSet&lt;string&gt;&gt; dic1;
  
      int count = 0;
  
  
      public Graph()
      {
          dic = new Dictionary&lt;string, HashSet&lt;Dictionary&lt;string, HashSet&lt;string&gt;&gt;&gt;&gt;();
          //dic2 = new Dictionary&lt;string, Dictionary&lt;string, int&gt;&gt;();
      }
      public Graph(string filename, string delimeter)
      {
          dic = new Dictionary&lt;string, HashSet&lt;Dictionary&lt;string, HashSet&lt;string&gt;&gt;&gt;&gt;();
          //dic2 = new Dictionary&lt;string, Dictionary&lt;string, int&gt;&gt;();
  
          FileStream fs = new FileStream(filename, FileMode.Open);
  
          StreamReader sr = new StreamReader(fs);
  
  
          while (sr.Peek() != -1)
          {
              string line = sr.ReadLine();
              char r;
              r = Convert.ToChar(delimeter);
              int j;
              int i=0;
  
              string[] names = line.Split(r);
              for (j=1; j &lt; names.Length; j++)
              {
                  for (i = j; i &lt; names.Length; i++)
                  {
                      if (!dic.ContainsKey(names[i])) //without this line code throws  exception key is not found
                          addVertex(names[i]);
                      if (!(dic[names[i]].Equals(dic[names[j]])))
  
                          addEdge(names[i], names[j], names[0]);
  
  
                  }
  
              }
  
  
  
  
          }
  
          sr.Close();
      }
  
      public void addEdge(string a, string b, string c)
      {
          if (!dic.ContainsKey(a))
          {
              addVertex(a);
          }
  
          if (!dic.ContainsKey(b))
          {
              addVertex(b);
          }
  
  
          dic1 = new Dictionary&lt;string, HashSet&lt;string&gt;&gt;();
  
          dic1.Add(a, new HashSet&lt;string&gt;());
  
          dic1.Add(b, new HashSet&lt;string&gt;());
  
          dic1[b].Add(c);
          dic1[a].Add(c);
  
          dic[a].Add(dic1);
          dic[b].Add(dic1);
  
  
  
      }
  
      public void addVertex(string v)
      {
          if (!dic.ContainsKey(v))
              dic.Add(v, new HashSet&lt;Dictionary&lt;string, HashSet&lt;string&gt;&gt;&gt;());
      }
  
  
      public IEnumerable&lt;Dictionary&lt;string, HashSet&lt;string&gt;&gt;&gt; adjacentto(string v)
      {
          return dic[v];
      }
  }
  </code></pre>
  
  <p>And then I'm supposed to calculate the degree of separation between each 2 nodes for which I applied the BFS algorithm. This is my BFS class: </p>
  
  <pre><code>     class BFS
  {
      private Dictionary&lt;string, int&gt; dist = new Dictionary&lt;string, int&gt;();
      //private Dictionary&lt;string, HashSet&lt;int&gt;&gt; prev = new Dictionary&lt;string, HashSet&lt;int&gt;&gt;();
  
  
      public void BFSDegree(Graph g, string s, string p)
      {
          Queue&lt;string&gt; q = new Queue&lt;string&gt;();
  
          dist.Add(s, 0);
          q.Enqueue(s);
          //int count;
  
          //int v = 0;
          while (q.Count() != 0)
          {
              string j = q.Dequeue();
              //count = 0;
              foreach (Dictionary&lt;string, HashSet&lt;string&gt;&gt; h in g.adjacentto(j))
              {
                  foreach (string m in h.Keys)
                  {
  
                      if (!dist.ContainsKey(m))
                      {
                          q.Enqueue(m);
                          dist.Add(m, 1 + dist[j]);
  
  
  
                      }
                      if (j == p)
                      {
                          Console.WriteLine("             " + dist[j]);
                          //count++;
                          return;
                      }
  
                  }
  
  
              }
  
  
          }
  
  
      }
  
  
  
  
  
  
      public void BfsOnFile(string filename, string delimeter, Graph G)
      {
          FileStream fs = new FileStream(filename, FileMode.Open);
          StreamReader sr = new StreamReader(fs);
          string actor1 = "";
          string actor2 = "";
          while (sr.Peek() != -1)
          {
              string line = sr.ReadLine();
  
              char r;
              r = Convert.ToChar(delimeter);
              string[] names = line.Split(r);
              for (int i = 0; i &lt; names.Length; i++)
              {
  
                  actor1 = names[0];
                  actor2 = names[1];
  
  
              }
              Console.Write(" " + line);
              BFSDegree(G, actor1, actor2);
  
              dist.Clear();
  
  
          }
  
  
      }
  
  }
  </code></pre>
  
  <p>And through these 2 classes I was able to calculate the degree of separation between them. Now my problem is to calculate something called the relation strength between 2 nodes. for example Actor A and actor B are directly linked with a degree of separation equal 1. The relation strength between them is three movies since they directly appeared together in the three movies.
  Actor C and actor E are linked with a degree of separation equal 2 through either actor A, actor B or actor D. The relation strength should equal the max of the three options. So from what I understand if I should calculate the relation strength between actor A and actor B, and since they starred in 3 movies together I should go the dictionary of key A that contains the dictionary of key B and count the number of movies in its hashset. But I don't know how? like the data structure is too complex to deal with but unfortunately I was asked to do it like that!</p>