public void TC_SearchResults() { var problem = new Planner.SAS.Problem(new SASInputData(GetFilePath("TC_SearchResults.sas"))); var heuristic = new PDBHeuristic(problem); var problem2 = new Planner.SAS.Problem(new SASInputData(GetFilePath("TC_SearchResults2.sas"))); var heuristic2 = new PDBHeuristic(problem2); var heap = new RegularBinaryHeap(); var search1 = new AStarSearch(problem, heuristic, heap); var solution1 = search1.Start(); Assert.AreEqual(ResultStatus.SolutionFound, solution1); Assert.IsNotNull(search1.GetSolutionPlan()); var search2 = new AStarSearch(problem2, heuristic2, heap); var solution2 = search2.Start(); Assert.AreEqual(ResultStatus.NoSolutionFound, solution2); Assert.IsNull(search2.GetSolutionPlan()); var search3 = new AStarSearch(problem, heuristic, heap, false, new TimeSpan(0), 5000); var solution3 = search3.Start(); Assert.AreEqual(ResultStatus.TimeLimitExceeded, solution3); Assert.IsNull(search3.GetSolutionPlan()); var search4 = new AStarSearch(problem, heuristic, heap, false, new TimeSpan(0, 1, 0), 0); var solution4 = search4.Start(); Assert.AreEqual(ResultStatus.MemoryLimitExceeded, solution4); Assert.IsNull(search4.GetSolutionPlan()); }
static void testPatterns(bool[] isSelected, int selectedCount, int position, int limit, Problem d, System.IO.StreamWriter writer) { if (selectedCount == limit) { if (TestResult.currentID < TestResult.IDStart) { TestResult.currentID++; return; } HashSet <int> pattern = new HashSet <int>(); bool intersectsWithGoal = false; for (int i = 0; i < isSelected.Length; i++) { if (isSelected[i]) { pattern.Add(i); if (d.GoalConditions.IsVariableConstrained(i)) { intersectsWithGoal = true; } } } if (!intersectsWithGoal) { TestResult.currentID++; return; } DateTime buildingStarted = DateTime.Now; PDBHeuristic h = new PDBHeuristic(d, true, new List <HashSet <int> > { pattern }); DateTime buildingEnded = DateTime.Now; AStarSearch ast = new AStarSearch(d, h); DateTime searchStarted = DateTime.Now; ast.Start(); DateTime searchEnded = DateTime.Now; writer.WriteLine(TestResult.currentID + "\t" + pattern.Count + "\t" + String.Format("{0:0.##}", (buildingEnded - buildingStarted).TotalSeconds) + "\t" + String.Format("{0:0.##}", (searchEnded - searchStarted).TotalSeconds) + "\t" + h.Statistics.HeuristicCallsCount); //res.Add(new TestResult(d, pattern, (buildingEnded - buildingStarted).TotalSeconds, (searchEnded - searchStarted).TotalSeconds, nodes)); TestResult.currentID++; return; } if (selectedCount < limit - (isSelected.Length - position)) { return; } if (position >= isSelected.Length) { return; } isSelected[position] = true; testPatterns(isSelected, selectedCount + 1, position + 1, limit, d, writer); isSelected[position] = false; testPatterns(isSelected, selectedCount, position + 1, limit, d, writer); }
public static void BuildPDBs15() { PDBHeuristic pdbHeuristic; pdbHeuristic = new PDBHeuristic(new int[] { 1, 2, 3, 4 }); pdbHeuristic.Save(); pdbHeuristic = new PDBHeuristic(new int[] { 5, 6, 7, 8 }); pdbHeuristic.Save(); pdbHeuristic = new PDBHeuristic(new int[] { 9, 10, 11, 12 }); pdbHeuristic.Save(); pdbHeuristic = new PDBHeuristic(new int[] { 12, 13, 14, 15 }); pdbHeuristic.Save(); pdbHeuristic = new PDBHeuristic(new int[] { 3, 4, 5, 6 }); pdbHeuristic.Save(); pdbHeuristic = new PDBHeuristic(new int[] { 7, 8, 9, 10 }); pdbHeuristic.Save(); pdbHeuristic = new PDBHeuristic(new int[] { 11, 12, 13, 14 }); pdbHeuristic.Save(); pdbHeuristic = new PDBHeuristic(new int[] { 1, 2, 14, 15 }); pdbHeuristic.Save(); pdbHeuristic = new PDBHeuristic(new int[] { 2, 3, 4, 5 }); pdbHeuristic.Save(); pdbHeuristic = new PDBHeuristic(new int[] { 6, 7, 8, 9 }); pdbHeuristic.Save(); pdbHeuristic = new PDBHeuristic(new int[] { 10, 11, 12, 13 }); pdbHeuristic.Save(); pdbHeuristic = new PDBHeuristic(new int[] { 1, 13, 14, 15 }); pdbHeuristic.Save(); }
public void TC_PDBHeuristic() { var sasProblem = new Planner.SAS.Problem(new SASInputData(GetFilePath("TC_Gripper.sas"))); var heuristic = new PDBHeuristic(sasProblem); Assert.AreEqual(8, heuristic.GetValue(sasProblem.GetInitialState())); Assert.AreEqual("PDB Heuristic", heuristic.GetName()); Assert.AreEqual(1, heuristic.GetCallsCount()); }
public static void BuildPDBs24() { PDBHeuristic pdbHeuristic; pdbHeuristic = new PDBHeuristic(new int[] { 1, 2, 5, 6, 7 }); pdbHeuristic.Save(); pdbHeuristic = new PDBHeuristic(new int[] { 3, 4, 8, 9, 14 }); pdbHeuristic.Save(); pdbHeuristic = new PDBHeuristic(new int[] { 10, 15, 16, 20, 21 }); pdbHeuristic.Save(); pdbHeuristic = new PDBHeuristic(new int[] { 13, 18, 19, 23, 24 }); pdbHeuristic.Save(); pdbHeuristic = new PDBHeuristic(new int[] { 11, 12, 17, 22 }); pdbHeuristic.Save(); pdbHeuristic = new PDBHeuristic(new int[] { 1, 2, 3, 7, 8 }); pdbHeuristic.Save(); pdbHeuristic = new PDBHeuristic(new int[] { 5, 6, 10, 11, 12 }); pdbHeuristic.Save(); pdbHeuristic = new PDBHeuristic(new int[] { 15, 16, 17, 20, 21 }); pdbHeuristic.Save(); pdbHeuristic = new PDBHeuristic(new int[] { 18, 19, 22, 23, 24 }); pdbHeuristic.Save(); pdbHeuristic = new PDBHeuristic(new int[] { 4, 9, 13, 14 }); pdbHeuristic.Save(); }
static void runPatternsTest(string domainFile) { Problem d = new Problem(domainFile, false); //AStarSearch ast; PDBHeuristic h = new PDBHeuristic(d); bool[] isSeleceted = new bool[d.Variables.Count]; //List<TestResult> res = new List<TestResult>(); if (System.IO.File.Exists("idStart.txt")) { using (var reader = new System.IO.StreamReader("idStart.txt")) { TestResult.IDStart = int.Parse(reader.ReadLine()); } } else { using (var writer = new System.IO.StreamWriter("results.txt", true)) { writer.WriteLine("ID\tSize\tCreate\tSearch\tNodes"); } } using (var writer = new System.IO.StreamWriter("results.txt", true)) { writer.AutoFlush = true; for (int i = 0; i <= d.Variables.Count; i++) { testPatterns(isSeleceted, 0, 0, i, d, writer); } /* * //Writing the results * * logger.Log("<---- \tResults\t ---->"); * logger.Log(); * logger.Log("ID\tSize\tCreation\tSearch\tNodes"); * for (int i = 0; i < res.Count; i++) * { * logger.Log(i + "\t" + res[i].pattern.Count + "\t" + res[i].creation + "\t" + res[i].search + "\t" + res[i].nodes); * } */ } }