Exemple #1
0
        /// <summary>
        /// Common code to search algorithms
        /// </summary>
        /// <typeparam name="T">Type of objects in the graph vertices</typeparam>
        /// <param name="graph">Graph structure to operate on</param>
        /// <param name="collection">Abstraction of the collection the search algorithm uses (e.g. for DFS collection will be a stack)</param>
        /// <param name="searchItem">Item to find</param>
        /// <returns>True if search item is in the graph, false otherwise</returns>
        private static bool SearchHelper <T>(Graph <T> graph, ISearchCollection <T> collection, T searchItem)
        {
            var visited = new HashSet <T>();

            while (collection.Count != 0)
            {
                var currentNode = collection.Remove();
                Console.WriteLine("currentNode: {0}. Neighbors:  ", currentNode);

                if (currentNode.Equals(searchItem))
                {
                    return(true);
                }

                var neighbors = graph.GetAllNeighborsOf(currentNode)?.ToList();
                if (neighbors == null)
                {
                    continue;
                }

                foreach (var node in neighbors)
                {
                    if (!visited.Contains(node))
                    {
                        Console.WriteLine(node);
                        collection.Add(node);
                        visited.Add(node);
                    }
                }
            }
            return(false);
        }
Exemple #2
0
 public WideTree(ISearchCollection <NodeModel> searchMode, INodeProcessor <NodeModel> nodeProcessor, IPrune prune, IThreadPool threadPool)
 {
     this.searchCollection = searchMode;
     this.visitors         = new List <IVisitor>();
     this.prune            = prune;
     this.nodeProcessor    = nodeProcessor;
     this.threadPool       = threadPool;
 }
Exemple #3
0
        private ISearchCollection <NodeModel> GetSearchCollection()
        {
            var auxSearchCollection = this.searchCollection;

            this.searchCollection = new ExtendedPrioritySearch <NodeModel>(new SumNodeComparer <NodeModel>());

            return(auxSearchCollection);
        }
Exemple #4
0
        public TreeFactory(Dictionary <int, Point> coordinates)
        {
            this.visitors    = new List <IVisitor>();
            this.coordinates = coordinates;

            var space = new Space(coordinates);

            this.sumCalculator    = new SumOfSquareCalculator(space);
            this.prune            = new Prune(space.PointMapping.Count);
            this.nodeProcessor    = new NodeProcessor(coordinates.Keys, sumCalculator);
            this.threadCount      = new ThreadCount();
            this.searchCollection = new DfsSearch <NodeModel>();
        }