Ejemplo n.º 1
0
        private void ProcessPartialSolutions()
        {
            SolutionsMessage solution = null;

            lock (partialSolutionsMessageQueue)
            {
                if (partialSolutionsMessageQueue.Count > 0)
                {
                    solution = partialSolutionsMessageQueue.Dequeue();
                }
            }

            if (solution == null)
            {
                return;
            }

            _logger.Debug("Merging solution");

            TaskSolverDVRP taskSolver = CreateTaskSolver(solution.ProblemType, solution.CommonData);

            taskSolver.MergeSolution(solution.Solutions.Select(x => x.Data).ToArray());

            _logger.Debug("Finished merging solution: " + solution.Id);
            _logger.Debug("Finished merging solution: " + solution.Id);
            _logger.Debug("Finished merging solution: " + solution.Id);

            SolutionsMessage solutionsMessage = new SolutionsMessage()
            {
                Id          = solution.Id,
                CommonData  = null,
                ProblemType = "DVRP",
                Solutions   = new Solution[1]
            };

            solutionsMessage.Solutions[0] = new Solution()
            {
                Type = SolutionType.Final,
                Data = taskSolver.Solution
            };

            var socket = communicationModule.SetupClient();

            communicationModule.Connect(socket);
            var message = SerializeMessage(solutionsMessage);

            communicationModule.SendData(message, socket);

            communicationModule.CloseSocket(socket);
        }
        public void SolveProblemTest17D()
        {
            string testData = System.IO.File.ReadAllText(@"DVRPTestData\okul17D.vrp");

            byte[]         problemData = CommunicationModule.ConvertStringToData(testData);
            TaskSolverDVRP taskSolver  = new TaskSolverDVRP(problemData);

            byte[][] division  = taskSolver.DivideProblem(6);
            byte[][] solutions = new byte[6][];
            for (int i = 0; i <= 6; i++)
            {
                int[][] partialData = DVRPHelper.ParsePartialProblemData(division[i]);
                solutions[i] = taskSolver.Solve(division[i], new TimeSpan());
            }
            taskSolver.MergeSolution(solutions);
            DVRPPartialSolution finalSol = DVRPPartialSolution.Parse2FinalSol(CommunicationModule.ConvertDataToString(taskSolver.Solution, taskSolver.Solution.Length), taskSolver.Dvrp);

            Assert.IsTrue(Math.Abs(finalSol.pathLen - 1089) < 1);
        }