/// <summary>
 /// Constructor, creates graph of a given dictionary.
 /// </summary>
 /// <param name="dictionary">List of words, generated from input file</param>
 /// <param name="wordLength">Length of words in graph</param>
 /// <param name="graphSearch">Type of search used to get shortest path</param>
 public DictionaryGraph(List <string> dictionary, int wordLength, IGraphSearch graphSearch)
 {
     _dictionary  = dictionary;
     _wordLength  = wordLength;
     _graphSearch = graphSearch;
     Graph        = CreateGraph();
 }
        /// <summary>
        /// Существует ли путь из вершины <paramref name="from"/> в <paramref name="to"/>
        /// </summary>
        /// <param name="graphSearch">Граф поиска</param>
        /// <param name="from">Вершина из</param>
        /// <param name="to">Вершина в</param>
        /// <returns>Путь есть или нет</returns>
        public static bool PathExists(this IGraphSearch graphSearch, Vertex from, Vertex to)
        {
            foreach (var item in graphSearch.BreadthFirstSearch(from))
            {
                if (item.Id == to.Id)
                {
                    return(true);
                }
            }

            return(false);
        }
Esempio n. 3
0
        private static void GraphSearchTest(IGraphSearch search)
        {
            Console.WriteLine(search.Name);

            // 打印所有与目标顶点连通的顶点
            for (int i = 0; i < vertexCount; i++)
            {
                if (search.IsConnectedTo(i))
                {
                    Console.Write(i + " ");
                }
            }

            Console.WriteLine();
            Console.WriteLine(search.Count());
        }
Esempio n. 4
0
        private static void SolveProblem <TState, TAction>(
            ActionFunction <TState, TAction> actionFunction,
            ResultFunction <TState, TAction> resultFunction,
            GoalTest <TState> goalTest,
            StepCost <TState, TAction> stepCost,
            TState initialState,
            IGraphSearch <TState, TAction> searchAlgorithm)
        {
            var problem = new Problem <TState, TAction>(
                initialState, actionFunction, resultFunction, goalTest, stepCost);

            var solution = searchAlgorithm.Search(problem);

            Console.WriteLine("Solution:");
            Console.WriteLine("=========");
            foreach (var node in solution)
            {
                Console.WriteLine(node.State);
            }

            Console.ReadKey();
        }
Esempio n. 5
0
 public QueryController(IGraphSearch service)
 {
     Service = service;
 }