static void nQueensHillClimbingSearch() { System.Console.WriteLine("\nNQueensDemo HillClimbing -->"); try { IProblem <NQueensBoard, QueenAction> problem = NQueensFunctions.createCompleteStateFormulationProblem( boardSize, NQueensBoard.Config.QUEENS_IN_FIRST_ROW); HillClimbingSearch <NQueensBoard, QueenAction> search = new HillClimbingSearch <NQueensBoard, QueenAction>( NQueensFunctions.createAttackingPairsHeuristicFunction()); SearchAgent <NQueensBoard, QueenAction> agent = new SearchAgent <NQueensBoard, QueenAction>(problem, search); System.Console.WriteLine(); printActions(agent.getActions()); System.Console.WriteLine("Search Outcome=" + search.getOutcome()); System.Console.WriteLine("Final State=\n" + search.getLastSearchState()); printInstrumentation(agent.getInstrumentation()); } catch (Exception e) { throw e; } }
private void btnHillClimbing_Click(object sender, System.EventArgs e) { this.textBox1.Text = "NQueensDemo HillClimbing -->" + System.Environment.NewLine; Problem problem = new Problem(new NQueensBoard(8), new NQueensSuccessorFunction(), new NQueensGoalTest(), new QueensToBePlacedHeuristic()); Search search = new HillClimbingSearch(); SearchAgent agent = new SearchAgent(problem, search); printActions(agent.getActions()); printInstrumentation(agent.getInstrumentation()); }
public aima.core.search.framework.Search GetSearch(Object owner, IContextLookup globalVars, HeuristicFunction objHeuristicFunction) { aima.core.search.framework.Search toReturn; QueueSearch objQueueSearch; switch (QueueSearchType) { case QueueSearchType.TreeSearch: objQueueSearch = new TreeSearch(); break; default: objQueueSearch = new GraphSearch(); break; } switch (AlgorithmType) { case SearchAlgorithmType.KnownInformed: switch (KnownInformedAlgorithm) { case KnownInformedSearch.GreedyBestFirst: toReturn = new GreedyBestFirstSearch(objQueueSearch, objHeuristicFunction); break; case KnownInformedSearch.RecursiveGreedyBestFirst: toReturn = new RecursiveBestFirstSearch(new GreedyBestFirstEvaluationFunction(objHeuristicFunction)); break; case KnownInformedSearch.RecursiveAStar: toReturn = new RecursiveBestFirstSearch(new AStarEvaluationFunction(objHeuristicFunction)); break; case KnownInformedSearch.HillClimbing: toReturn = new HillClimbingSearch(objHeuristicFunction); break; case KnownInformedSearch.SimulatedAnnealing: toReturn = new SimulatedAnnealingSearch(objHeuristicFunction); break; default: toReturn = new AStarSearch(objQueueSearch, objHeuristicFunction); break; } break; case SearchAlgorithmType.KnownUninformed: switch (KnownUninformedAlgorithm) { case KnownUninformedSearch.DepthFirst: toReturn = new DepthFirstSearch(objQueueSearch); break; case KnownUninformedSearch.DepthLimited: toReturn = new DepthLimitedSearch(DepthLimit); break; case KnownUninformedSearch.IterativeDeepening: toReturn = new IterativeDeepeningSearch(); break; case KnownUninformedSearch.UniformCost: toReturn = new UniformCostSearch(objQueueSearch); break; case KnownUninformedSearch.Bidirectional: toReturn = new BidirectionalSearch(); break; default: toReturn = new BreadthFirstSearch(objQueueSearch); break; } break; default: toReturn = CustomSearchAlgorithm.EvaluateTyped(owner, globalVars); break; } return(toReturn); }
/** * Creates a search instance. * * @param strategy * search strategy. See static constants. * @param qSearchImpl * queue search implementation: e.g. {@link #TREE_SEARCH}, {@link #GRAPH_SEARCH} * */ public ISearchForActions <S, A> createSearch <S, A>(int strategy, int qSearchImpl, IToDoubleFunction <Node <S, A> > h) { QueueSearch <S, A> qs = null; ISearchForActions <S, A> result = null; switch (qSearchImpl) { case TREE_SEARCH: qs = new TreeSearch <S, A>(); break; case GRAPH_SEARCH: qs = new GraphSearch <S, A>(); break; case GRAPH_SEARCH_RED_FRONTIER: qs = new GraphSearchReducedFrontier <S, A>(); break; case GRAPH_SEARCH_BFS: qs = new GraphSearchBFS <S, A>(); break; case BIDIRECTIONAL_SEARCH: qs = new BidirectionalSearch <S, A>(); break; } switch (strategy) { case DF_SEARCH: result = new DepthFirstSearch <S, A>(qs); break; case BF_SEARCH: result = new BreadthFirstSearch <S, A>(qs); break; case ID_SEARCH: result = new IterativeDeepeningSearch <S, A>(); break; case UC_SEARCH: result = new UniformCostSearch <S, A>(qs); break; case GBF_SEARCH: result = new GreedyBestFirstSearch <S, A>(qs, h); break; case ASTAR_SEARCH: result = new AStarSearch <S, A>(qs, h); break; case RBF_SEARCH: result = new RecursiveBestFirstSearch <S, A>(new AStarSearch <S, A> .EvalFunction(h)); break; case RBF_AL_SEARCH: result = new RecursiveBestFirstSearch <S, A>(new AStarSearch <S, A> .EvalFunction(h), true); break; case HILL_SEARCH: result = new HillClimbingSearch <S, A>(h); break; } return(result); }
public void TC_HillClimbingSearch() { // The search path is basically random, no point to test the solution here var sasProblem = new Planner.SAS.Problem(new SASInputData(GetFilePath("TC_Gripper.sas"))); var sasSearch = new HillClimbingSearch(sasProblem, new BlindHeuristic(), false, new TimeSpan(0, 0, 1), 50000); sasSearch.Start(); var sasSolution = sasSearch.GetSearchResults(); Assert.AreEqual("Hill-Climbing Search", sasSolution.Algorithm); Assert.AreEqual("TC_Gripper", sasSolution.ProblemName); Assert.AreEqual("Blind Heuristic", sasSolution.Heuristic); Assert.IsTrue(sasSolution.SearchTime.TotalMilliseconds >= 0); var sasSearch2 = new HillClimbingSearch(sasProblem, new BlindHeuristic(), false, new TimeSpan(0, 0, 1), 50000); sasSearch2.Start(SearchType.BackwardWithConditions); var sasSolution2 = sasSearch2.GetSearchResults(); Assert.AreEqual("Hill-Climbing Search (Backward)", sasSolution2.Algorithm); Assert.AreEqual("TC_Gripper", sasSolution2.ProblemName); Assert.AreEqual("Blind Heuristic", sasSolution2.Heuristic); Assert.IsTrue(sasSolution2.SearchTime.TotalMilliseconds >= 0); var sasSearch3 = new HillClimbingSearch(sasProblem, new BlindHeuristic(), false, new TimeSpan(0, 0, 1), 50000); sasSearch3.Start(SearchType.BackwardWithStates); var sasSolution3 = sasSearch3.GetSearchResults(); Assert.AreEqual("Hill-Climbing Search (Backward)", sasSolution3.Algorithm); Assert.AreEqual("TC_Gripper", sasSolution3.ProblemName); Assert.AreEqual("Blind Heuristic", sasSolution3.Heuristic); Assert.IsTrue(sasSolution3.SearchTime.TotalMilliseconds >= 0); var pddlProblem = new Planner.PDDL.Problem(new PDDLInputData(GetFilePath("TC_Gripper_D.pddl"), GetFilePath("TC_Gripper_P.pddl"))); var pddlSearch = new HillClimbingSearch(pddlProblem, new BlindHeuristic(), false, new TimeSpan(0, 0, 1), 50000); pddlSearch.Start(); var pddlSolution = pddlSearch.GetSearchResults(); Assert.AreEqual("Hill-Climbing Search", pddlSolution.Algorithm); Assert.AreEqual("gripper", pddlSolution.DomainName); Assert.AreEqual("problem-1", pddlSolution.ProblemName); Assert.AreEqual("Blind Heuristic", pddlSolution.Heuristic); Assert.IsTrue(pddlSolution.SearchTime.TotalMilliseconds >= 0); var pddlSearch2 = new HillClimbingSearch(pddlProblem, new BlindHeuristic(), false, new TimeSpan(0, 0, 1), 50000); pddlSearch2.Start(SearchType.BackwardWithConditions); var pddlSolution2 = pddlSearch2.GetSearchResults(); Assert.AreEqual("Hill-Climbing Search (Backward)", pddlSolution2.Algorithm); Assert.AreEqual("gripper", pddlSolution2.DomainName); Assert.AreEqual("problem-1", pddlSolution2.ProblemName); Assert.AreEqual("Blind Heuristic", pddlSolution2.Heuristic); Assert.IsTrue(pddlSolution2.SearchTime.TotalMilliseconds >= 0); var pddlSearch3 = new HillClimbingSearch(pddlProblem, new BlindHeuristic(), false, new TimeSpan(0, 0, 1), 50000); pddlSearch3.Start(SearchType.BackwardWithStates); var pddlSolution3 = pddlSearch3.GetSearchResults(); Assert.AreEqual("Hill-Climbing Search (Backward)", pddlSolution3.Algorithm); Assert.AreEqual("gripper", pddlSolution3.DomainName); Assert.AreEqual("problem-1", pddlSolution3.ProblemName); Assert.AreEqual("Blind Heuristic", pddlSolution3.Heuristic); Assert.IsTrue(pddlSolution3.SearchTime.TotalMilliseconds >= 0); }