/// <summary> /// Convert a tree into an MTG of NbScales. /// </summary> /// <param name="tree"></param> /// <param name="nbScales"></param> /// <returns></returns> public mtg RandomMtg(mtg tree, int nbScales) { int n = tree.NbVertices(); Random r = new Random(); Dictionary <int, List <int> > colors = new Dictionary <int, List <int> >() { }; colors.Add(nbScales - 1, tree.Vertices()); for (int s = nbScales - 2; s > 0; s--) { n = r.Next(1, n); var sample = (IEnumerable <int>)colors[s + 1]; sample = sample.OrderBy(x => r.Next()).Take(n); List <int> l = sample.ToList(); l.Sort(); if (!l.Contains(tree.root)) { l.Insert(0, tree.root); } colors.Add(s, l); } return(ColoredTree(tree, colors)[0]); }