public void Test_Solution_Trees_Consolidate() { SudokuOptions.Current.ShowAllSolutions = false; ProgressIndicator pi = new ProgressIndicator(System.Reflection.MethodBase.GetCurrentMethod().Name); FileInfo[] files = new DirectoryInfo(Directories.SolutionTrees).GetFiles(FileExtensions.XmlZipMask); string dir = Directories.SolutionTrees + Path.DirectorySeparatorChar + "Consolidate"; new DirectoryInfo(dir).CreateOrEmpty(); int index = 0; ConcurrentCounter counter = new ConcurrentCounter(); Parallel.ForEach(files, (file) => { counter.Increment(); pi.AddLine((counter.Value * 100 / files.Length).ToString()); SudokuSolutionNode root = SudokuSolutionNode.LoadFromFile(file.FullName); foreach (SudokuSolutionNode node in root.GetAllNodesEnumerator()) { if (node.State != SudokuSolutionNodeState.State) { continue; } var filtered_sols = SudokuSolutionNode.FilterByOptions(node.Nodes.Select(n => n.Solution).ToList()); var filtered_nodes = (from n in node.Nodes where filtered_sols.Contains(n.Solution) select n).ToList(); var new_includes = (from n1 in filtered_nodes from n2 in filtered_nodes where SudokuSolutionNode.IsInclude(n1.Solution, n2.Solution, false) select new { n1, n2 }).ToList(); var ignore_pairs = new[] { new [] { SudokuSolutionType.NakedPair, SudokuSolutionType.BoxLineReduction }, new [] { SudokuSolutionType.NakedPair, SudokuSolutionType.PointingPair }, new [] { SudokuSolutionType.NakedPair, SudokuSolutionType.NakedTriple }, new [] { SudokuSolutionType.NakedPair, SudokuSolutionType.NakedQuad }, new [] { SudokuSolutionType.NakedTriple, SudokuSolutionType.BoxLineReduction }, new [] { SudokuSolutionType.NakedTriple, SudokuSolutionType.NakedQuad }, new [] { SudokuSolutionType.NakedTriple, SudokuSolutionType.PointingPair }, new [] { SudokuSolutionType.NakedTriple, SudokuSolutionType.PointingTriple }, new [] { SudokuSolutionType.NakedQuad, SudokuSolutionType.PointingPair }, new [] { SudokuSolutionType.HiddenPair, SudokuSolutionType.HiddenTriple }, new [] { SudokuSolutionType.HiddenPair, SudokuSolutionType.HiddenQuad }, new [] { SudokuSolutionType.HiddenTriple, SudokuSolutionType.HiddenQuad }, }; var ignore = from pair in new_includes from ignore_pair in ignore_pairs where (((pair.n1.Solution.Type == ignore_pair.First()) && (pair.n2.Solution.Type == ignore_pair.Last())) || ((pair.n1.Solution.Type == ignore_pair.Last()) && (pair.n2.Solution.Type == ignore_pair.First()))) select pair; new_includes = new_includes.Except(ignore).ToList(); var doubles = from p1 in new_includes from p2 in new_includes where (p1.n1 == p2.n2) && (p1.n2 == p2.n1) select p1; new_includes = new_includes.Except(doubles).ToList(); foreach (var pair in new_includes) { SudokuIntermediateSolution intermediate_solution_1 = new SudokuIntermediateSolution(pair.n1.Board, pair.n1.NextBoard, pair.n1.Solution); intermediate_solution_1.SaveToFile(dir + Path.DirectorySeparatorChar + index + "_" + Path.GetFileNameWithoutExtension(Path.GetFileNameWithoutExtension(file.FullName)) + "_" + pair.n1.Solution.Type + FileExtensions.XmlZipExt); SudokuIntermediateSolution intermediate_solution_2 = new SudokuIntermediateSolution(pair.n2.Board, pair.n2.NextBoard, pair.n2.Solution); intermediate_solution_2.SaveToFile(dir + Path.DirectorySeparatorChar + index + "_" + Path.GetFileNameWithoutExtension(Path.GetFileNameWithoutExtension(file.FullName)) + "_" + pair.n2.Solution.Type + FileExtensions.XmlZipExt); index++; } } }); Assert.IsTrue(index == 0); }