コード例 #1
0
        public Message DivideProblem(DivideProblem divideProblem)
        {
            log.DebugFormat("Division of problem has started. ({0})", divideProblem.Id);

            if (!SolvableProblems.Contains(divideProblem.ProblemType))
            {
                log.Debug("Not supported problem type.");
                return(new Error()
                {
                    ErrorMessage = "not supported problem type",
                    ErrorType = ErrorErrorType.InvalidOperation
                });
            }

            var commonData = divideProblem.Data;
            var taskSolver = _resolver.GetInstanceByBaseTypeName(divideProblem.ProblemType, commonData);
            var bytes      = taskSolver.DivideProblem(0);

            log.DebugFormat("Length of divide problem message: {0}", bytes?.Sum(x => x.Length));
            //adding info about partial problems, their task ids, and partialProblem
            //some things can be temporary (partialProblems?)
            storage.AddIssue(divideProblem.Id, new ProblemInfo()
            {
                ProblemsCount  = bytes?.GetLength(0) ?? 0,
                ProblemType    = divideProblem.ProblemType,
                SolutionsCount = 0,
                CommonData     = commonData
            });

            var problemsList = new List <SolvePartialProblemsPartialProblem>();

            //iterate through all partial problems and create proper messages
            for (var i = 0; i < (bytes?.GetLength(0) ?? 0); i++)
            {
                var partialProblem = new SolvePartialProblemsPartialProblem()
                {
                    TaskId = (ulong)i,
                    Data   = bytes[i],
                    NodeID = componentId
                };

                problemsList.Add(partialProblem);
                //adding info about subtask to task manager memory
                storage.AddTaskToIssue(divideProblem.Id, partialProblem);
            }

            log.DebugFormat("Division finished. ({0})", divideProblem.Id);
            //creating msg
            var partialProblems = new SolvePartialProblems()
            {
                ProblemType     = divideProblem.ProblemType,
                Id              = divideProblem.Id,
                CommonData      = divideProblem.Data,
                PartialProblems = problemsList.ToArray()
            };

            return(partialProblems);
        }
コード例 #2
0
        private TaskSolver GetProperTaskSolver(string problemType, byte[] data)
        {
            if (!SolvableProblems.Contains(problemType))
            {
                throw new KeyNotFoundException();
            }
            switch (problemType)
            {
            case ("MultiplyProblem"):
                return(new MultiplyTaskSolver(data));

            case ("DVRP"):
                return(new DllProject.DvrpTaskSolver(data));
            }

            return(null);
        }
        public Message ComputeSubtask(SolvePartialProblems solvePartialProblems)
        {
            log.DebugFormat("Computation started. ({0})", solvePartialProblems.Id);

            if (!SolvableProblems.Contains(solvePartialProblems.ProblemType))
            {
                return new Error()
                       {
                           ErrorMessage = "Not supported problem type",
                           ErrorType    = ErrorErrorType.InvalidOperation
                       }
            }
            ;
            //task solver stuff:
            var taskSolver    = _resolver.GetInstanceByBaseTypeName(solvePartialProblems.ProblemType, solvePartialProblems.CommonData);
            var solutionsList = new List <SolutionsSolution>();

            foreach (var partialProblem in solvePartialProblems.PartialProblems)
            {
                var newSolution = new SolutionsSolution()
                {
                    TaskId          = partialProblem.TaskId,
                    TaskIdSpecified = true,
                    //TimeoutOccured = false,
                    Type = SolutionsSolutionType.Partial,
                    //ComputationsTime = 0
                };

                newSolution.Data = taskSolver.Solve(partialProblem.Data, TimeSpan.Zero);
                solutionsList.Add(newSolution);
            }
            log.DebugFormat("Length of solution message: {0}", solutionsList.Sum(x => x.Data.Length));
            log.DebugFormat("Computation finished. ({0})", solvePartialProblems.Id);

            return(new Solutions()
            {
                CommonData = solvePartialProblems.CommonData,
                Id = solvePartialProblems.Id,
                ProblemType = solvePartialProblems.ProblemType,
                SolutionsList = solutionsList.ToArray()
            });
        }