コード例 #1
0
        // runs all search algorithms for start and goal state
        private static void RunSingleSearch(PuzzleState initState, PuzzleState goalState)
        {
            var searcher = new Searcher(initState, goalState);

            // for 15-puzzle, cost from one state to next is always 1
            CostFunc cost = (fromState, toState) => 1;

            // do each search on a separate thread to speed things up
            var searchThreads = new List <Thread>
            {
                new Thread(() => Console.WriteLine(searcher.DepthFirstSearch(6).ToString())),
                new Thread(() => Console.WriteLine(searcher.DepthFirstSearch(12).ToString())),
                new Thread(() => Console.WriteLine(searcher.DepthFirstSearch(18).ToString())),
                new Thread(() => Console.WriteLine(searcher.IterativeDeepeningDfs().ToString())),
                new Thread(() => Console.WriteLine(searcher.BreadthFirstSearch().ToString())),
                new Thread(() => Console.WriteLine(searcher.UniformCostSearch(cost).ToString())),
                new Thread(() => Console.WriteLine(searcher.AStarSearch(cost, new MyHeuristic()).ToString())),
                new Thread(() => Console.WriteLine(searcher.GreedySearch(cost, new MyHeuristic()).ToString())),
                new Thread(() => Console.WriteLine(searcher.GreedySearch(cost, new ManhattanDistanceHeuristic()).ToString())),
                new Thread(() => Console.WriteLine(searcher.AStarSearch(cost, new ManhattanDistanceHeuristic()).ToString())),
            };

            // start all searches
            searchThreads.ForEach(x => x.Start());

            // wait for all searches to complete
            searchThreads.ForEach(x => x.Join());
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: sidroopdaska/FifteenPuzzle
        private static void RunSingleSearch(PuzzleState initState, PuzzleState goalState)
        {
            Searcher searcher = new Searcher(initState, goalState);
            CostFunc cost     = (state1, state2) => 1;

            List <Thread> searchThreads = new List <Thread>()
            {
                new Thread(() => Console.WriteLine(searcher.BFS().ToString())),
                new Thread(() => Console.WriteLine(searcher.DFS(6).ToString())),
                new Thread(() => Console.WriteLine(searcher.DFS(12).ToString())),
                new Thread(() => Console.WriteLine(searcher.DFS(18).ToString())),
                new Thread(() => Console.WriteLine(searcher.UCS().ToString())),
                new Thread(() => Console.WriteLine(searcher.GreedyBestFirstSearch(new ManhattanDistanceHeuristic()).ToString())),
                new Thread(() => Console.WriteLine(searcher.AStarSearch(new ManhattanDistanceHeuristic()).ToString())),
                new Thread(() =>
                           Console.WriteLine(searcher.GreedyBestFirstSearch(new ManhanttanDistanceWithLinearConflictHeuristic()).ToString())),
                new Thread(() =>
                           Console.WriteLine(searcher.AStarSearch(new ManhanttanDistanceWithLinearConflictHeuristic()).ToString()))
            };

            searchThreads.ForEach(x => x.Start());

            searchThreads.ForEach(x => x.Join());
        }