Пример #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;
        }
Пример #2
0
        public void OnNext(ToSolution solution)
        {
            Task taskToAwait = Solver.AlgorithmTasks[solution.Id];

            try
            {
                taskToAwait.Wait();
            }
            catch (AggregateException ae)
            {
                OnError(ae);
            }

            string message    = string.Empty;
            string errMessage = string.Empty;

            if (solution.IsValid)
            {
                message = MessagesRepository.GetMessage(MessageCode.EXREPSolutionReceived, solution.Id, solution.Cost);
            }
            else
            {
                message    = MessagesRepository.GetMessage(MessageCode.EXREPSolutionReceivedWithPenalty, solution.Id, solution.Cost, Math.Abs(solution.Penalty));
                errMessage = solution.ViolatedConstraintsToString();
            }

            Console.WriteLine(message);
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine(errMessage);
            Console.ForegroundColor = ConsoleColor.Gray;
        }
Пример #3
0
        public void OnCompleted()
        {
            //string algorithmDescription = Solver.CurrentStage.Flow.CurrentAlgorithm.ToString();
            //TimeSpan elapsedTime = _timer.Elapsed;
            TimeSpan elapsedTime    = Solver.CurrentStageExecutionTime;
            string   elapsedTimeMsg = MessagesRepository.GetMessage(MessageCode.EXREPTimeFormat, elapsedTime.Hours, elapsedTime.Minutes, elapsedTime.Seconds);

            Console.WriteLine(MessagesRepository.GetMessage(MessageCode.EXREPAlgorithmPerformance, Solver.CurrentAlgorithm.ToString(), elapsedTimeMsg));
        }
Пример #4
0
        /// <summary>
        /// Launch a Configuration, running all its stages.
        /// </summary>
        /// <param name="executionFunc">Method to invoke.</param>
        /// <returns></returns>
        private async Task ExecuteConfiguration(Func <Algorithm, Task> executionFunc)
        {
            // Run all Stages.
            foreach (Stage stage in WorkingConfiguration.Stages)
            {
                CurrentStage = stage;
                Console.WriteLine(MessagesRepository.GetMessage(MessageCode.SolverStageStart, CurrentStage.Description));
                Algorithm algorithm = GetAlgorithm(stage.Flow.CurrentAlgorithm);
                if (algorithm is null)
                {
                    throw new NullReferenceException(nameof(algorithm));
                }
                CurrentAlgorithm     = algorithm.Type;
                algorithm.Parameters = stage.Flow.AlgorithmParameters;
                await executionFunc.Invoke(algorithm);

                CurrentStageExecutionTime = default;
                Console.WriteLine(MessagesRepository.GetMessage(MessageCode.SolverStageEnd, CurrentStage.Description));
            }

            Console.WriteLine(MessagesRepository.GetMessage(
                                  MessageCode.SolverEndConfiguration, BestSolution.Id, BestSolution.Cost,
                                  BestSolution.Tour.GetTotalDistance() * 0.001));
        }
Пример #5
0
        internal void SendMessage(MessageCode messageCode, params object[] paramsList)
        {
            string message = MessagesRepository.GetMessage(messageCode, paramsList);

            SendMessage(message);
        }
Пример #6
0
 public void OnError(Exception error)
 {
     Console.WriteLine(MessagesRepository.GetMessage(MessageCode.EXREPExceptionOccurred, error.Message, error.StackTrace));
     throw error;
 }