コード例 #1
0
ファイル: MMTaskSolver.cs プロジェクト: progala2/DVRP
        public override byte[][] DivideProblem(int threadCount)
        {
            if (threadCount < 1)
                throw new ArgumentOutOfRangeException("threadCount");
            var partialProblemsNumbers = new List<int>[threadCount];
            for (var i = 0; i < partialProblemsNumbers.Length; i++)
            {
                partialProblemsNumbers[i] = new List<int>(_minMaxProblem.Numbers.Length/partialProblemsNumbers.Length);
            }
            for (var i = 0; i < _minMaxProblem.Numbers.Length; i++)
            {
                partialProblemsNumbers[i%partialProblemsNumbers.Length].Add(_minMaxProblem.Numbers[i]);
            }

            var partialProblemsData = new byte[partialProblemsNumbers.Length][];
            for (var i = 0; i < partialProblemsNumbers.Length; i++)
            {
                using (var memoryStream = new MemoryStream())
                {
                    var partialProblem = new MmPartialProblem(partialProblemsNumbers[i]);
                    _formatter.Serialize(memoryStream, partialProblem);
                    partialProblemsData[i] = memoryStream.ToArray();
                }
            }
            return partialProblemsData;
        }
コード例 #2
0
        public override byte[][] DivideProblem(int threadCount)
        {
            if (threadCount < 1)
            {
                throw new ArgumentOutOfRangeException("threadCount");
            }
            var partialProblemsNumbers = new List <int> [threadCount];

            for (var i = 0; i < partialProblemsNumbers.Length; i++)
            {
                partialProblemsNumbers[i] = new List <int>(_minMaxProblem.Numbers.Length / partialProblemsNumbers.Length);
            }
            for (var i = 0; i < _minMaxProblem.Numbers.Length; i++)
            {
                partialProblemsNumbers[i % partialProblemsNumbers.Length].Add(_minMaxProblem.Numbers[i]);
            }

            var partialProblemsData = new byte[partialProblemsNumbers.Length][];

            for (var i = 0; i < partialProblemsNumbers.Length; i++)
            {
                using (var memoryStream = new MemoryStream())
                {
                    var partialProblem = new MmPartialProblem(partialProblemsNumbers[i]);
                    _formatter.Serialize(memoryStream, partialProblem);
                    partialProblemsData[i] = memoryStream.ToArray();
                }
            }
            return(partialProblemsData);
        }