public void ShouldCutoff()
        {
            _states["A"].NextStatesList = new[] { _states["B"], _states["C"] };
            _states["B"].NextStatesList = new[] { _states["D"] };
            _states["C"].NextStatesList = new[] { _states["E"] };
            _states["E"].NextStatesList = new[] { _states["F"] };
            _states["F"].NextStatesList = new[] { _goalState };

            var problem = new DummyProblem(_states["A"]);

            var dls = new DepthLimitedSearch <DummyProblemState>(3);

            var result = dls.Search(problem).ToList();

            Assert.Empty(result);
            Assert.Equal(true, dls.IsCutoff);
        }
Пример #2
0
 static void nQueensWithRecursiveDLS()
 {
     System.Console.WriteLine("\nNQueensDemo recursive DLS -->");
     try
     {
         IProblem<NQueensBoard, QueenAction> problem =
                 NQueensFunctions.createIncrementalFormulationProblem(boardSize);
         ISearchForActions<NQueensBoard, QueenAction> 
             search = new DepthLimitedSearch<NQueensBoard, QueenAction>(boardSize);
         SearchAgent<NQueensBoard, QueenAction> 
             agent = new SearchAgent<NQueensBoard, QueenAction>(problem, search);
         printActions(agent.getActions());
         printInstrumentation(agent.getInstrumentation());
     }
     catch (Exception e)
     {
         throw e;
     } 
 }
Пример #3
0
        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);
        }
Пример #4
0
        public static void UninformedAlgorithms()
        {
            Console.WriteLine("Welcome\nARTIFICIAL INTELLIGENCE SEARCH ALGORITHMS");
            ShowOptions();

            var input = Console.ReadLine();
            int res   = 1;

            while (int.TryParse(input, out res) == false)
            {
                ShowOptions();
                input = Console.ReadLine();
            }
            Node <string> startNode = null;
            Node <string> goalNode  = null;

            switch (Convert.ToInt32(input))
            {
            case 1:
            {
                startNode = GetRootNode();
                goalNode  = GetGoalNode();
                Console.WriteLine("BREADTH FIRST SEARCH IMPLEMENTATION------------");
                var bfs = new BreadthFirstSearch <string>(goalNode, startNode);
                bfs.Search();
            }
            break;

            case 2:
            {
                startNode = GetRootNode();
                goalNode  = GetGoalNode();
                Console.WriteLine("DEPTH FIRST SEARCH IMPLEMENTATION------------");
                var dfs = new DepthFirstSearch <string>(goalNode, startNode);
                dfs.Search();
            }
            break;

            case 3:
            {
                startNode = GetRootNode();
                goalNode  = GetGoalNode();
                Console.WriteLine("\nEnd\n");
                Console.WriteLine("ITERATIVE DEEPENING SEARCH IMPLEMENTATION------------");
                var ids = new IterativeDeepingSearch <string>(goalNode, startNode);
                ids.Search();
            }
            break;

            case 4:
            {
                startNode = GetRootNode();
                goalNode  = GetGoalNode();
                Console.WriteLine("DEPTH LIMITED SEARCH IMPLEMENTATION------------");
                Console.Write("Enter limit to search: ");
                var limit = int.Parse(Console.ReadLine());
                var dls   = new DepthLimitedSearch <string>(goalNode, startNode, limit);
                dls.Search();
            }
            break;

            case 5:
            {
                startNode = GetRootNode();
                goalNode  = GetGoalNode();

                Console.WriteLine("Enter the cost for the nodes");
                foreach (var node in Nodes)
                {
                    Console.Write($"Enter cost for node: {node.NodeName}: ");
                    node.Cost = double.Parse(Console.ReadLine());
                }
                Console.WriteLine("UNIFORM COST SEARCH IMPLEMENTATION------------");

                var ucs = new UniformCostSearch <string>(goalNode, startNode);
                ucs.Search();
            }
            break;

            case 6:
            {
                startNode = GetRootNode();
                goalNode  = GetGoalNode();
                Console.WriteLine("BIDIRECTIONAL SEARCH IMPLEMENTATION------------");
                var bidi = new BidirectionalSearch <string>(goalNode, startNode);
                bidi.Search();
            }
            break;

            default:
                ShowOptions();
                break;
            }
        }