Beispiel #1
0
        private void MergeProblem(ProblemSolvingHelper problemHelper)
        {
            var taskSolver = problemHelper.TaskSolver;
            var solutions  = problemHelper.PartialSolutions.Select(s => s.Data).ToArray();

            taskSolver.MergeSolution(solutions);
            var finalSolution = new Solution(false, ESolutionType.Final, problemHelper.ComputationsTime, taskSolver.Solution);
            var message       = new SolutionsMessage(problemHelper.ProblemType, problemHelper.ProblemId, problemHelper.CommonData, new List <Solution>()
            {
                finalSolution
            });

            SendMessage(message.Serialize());
        }
Beispiel #2
0
        protected override void ProcessDivideProblemMessage(DivideProblemMessage message)
        {
            if (SolvableProblems.FirstOrDefault(x => x == message.ProblemType) == null)
            {
                EventLogger.GetLog().ErrorFormat("Nie obsługiwany problem: {0}", message.ProblemType);
                return;
            }

            TaskSolver taskSolver = null;

            switch (message.ProblemType)
            {
            case ("MultiplyProblem"):
                taskSolver = new MultiplyTaskSolver(message.Data);
                break;

            case ("DVRP"):
                taskSolver = new DllProject.DvrpTaskSolver(message.Data);
                break;
            }

            var problemSolvingHelper = new ProblemSolvingHelper()
            {
                ProblemId   = message.Id,
                ProblemType = message.ProblemType,
                TaskSolver  = taskSolver,
            };

            _problems.Add(message.Id, problemSolvingHelper);
            taskSolver.ProblemDividingFinished  += taskSolver_ProblemDividingFinished;
            taskSolver.SolutionsMergingFinished += taskSolver_SolutionsMergingFinished;

            var thread = new IOThread
            {
                ProblemType       = message.ProblemType,
                State             = EState.Busy,
                RealThread        = new Thread(() => DivideProblem(message, taskSolver)),
                ProblemInstanceId = message.Id
            };

            _runningThreads.Add(thread);
            thread.RealThread.Start();
        }