Ejemplo n.º 1
0
        /// <summary>
        /// Initialize the graph of the city using CityScoverRepository.
        /// </summary>
        private void InitializeTour()
        {
            CityScoverRepository.LoadPoints(WorkingConfiguration.PointsFilename);

            Points = (WorkingConfiguration.TourCategory == TourCategoryType.None) ?
                     CityScoverRepository.Points :
                     GetPointsByCategory(WorkingConfiguration.TourCategory);

            RoutesGenerator.GenerateRoutes(Points, Points.Count());
            CityScoverRepository.LoadRoutes(Points);

            // Creation of the Graph.
            CityMapGraph cityGraph = new CityMapGraph();

            foreach (var point in Points)
            {
                cityGraph.AddNode(point.Id, new InterestPointWorker(point));
            }

            var routes = CityScoverRepository.Routes;

            foreach (var route in routes)
            {
                cityGraph.AddEdge(route.PointFrom.Id, route.PointTo.Id, new RouteWorker(route));
            }

            if (cityGraph.NodeCount == 0)
            {
                string message = MessagesRepository.GetMessage(
                    MessageCode.SolverGraphCreationError, nameof(InitializeTour));
                throw new Exception(message);
            }

            CityMapGraph = cityGraph;
        }