コード例 #1
0
ファイル: PvPh1Ph2.cs プロジェクト: dantes1844/DataExtractor
        public override ParallelLoopResult ParallelRun(CalculateConfig config, InputData inputData)
        {
            Stopwatch stopwatch = Stopwatch.StartNew();
            var       s1        = inputData.S1;
            var       s2        = inputData.S2;
            var       s3        = inputData.S3;

            //按配置来确定
            var randP = inputData.RandP;

            var dr    = inputData.Dr;
            var fenmu = inputData.S3 - inputData.S2 * dr;

            int coefficient;

            if (fenmu > 0)
            {
                coefficient = -1;
            }
            else
            {
                coefficient = 1;
            }
            var item  = coefficient * config.SanleiIncreaseNumber;
            var start = config.TypeThreeDefaultX ?? dr;

            return(Parallel.For(0, config.SanleiLoopCount, (i, state) =>
            {
                var x = item * i + start;
                var t = randP * (dr - x) / fenmu;

                if (t < config.TMinimumValue)
                {
                    return;
                }

                var pv = s3 * t + randP * x;
                var ph1 = s1 * t + randP * (2 - x);
                var ph2 = s2 * t + randP;

                var flag1 = pv > ph1 + config.DefaultDeviation && ph1 > ph2 + config.DefaultDeviation;
                var flag2 = Math.Abs(pv / ph2 - dr) <= FloatDeviation;

                if (!flag2 || !flag1)
                {
                    return;
                }

                inputData.X = x;
                inputData.T = t;
                inputData.Ph1 = ph1;
                inputData.Ph2 = ph2;
                inputData.Pv = pv;

                stopwatch.Stop();
                //Debug.WriteLine($"执行完一条耗时:{stopwatch.ElapsedMilliseconds}ms。符合条件:S1={s1},S2={s2},S3={s3},RandP={randP:F4},Dr={dr},X={x},T={t},Ph1={ph1},Ph2={ph2},Pv={pv},S3*Dr-S1={fenmu}");
                state.Stop();
            }));
        }
コード例 #2
0
ファイル: Ph1PvPh2.cs プロジェクト: dantes1844/DataExtractor
        public void FindOne(InputData inputData)
        {
            var config = new CalculateConfig()
            {
                ErleiLoopCount      = 20000000,
                RandomNumberType    = RandomNumberType.RandomNumberPerRecord,
                ErleiIncreaseNumber = 0.00001d
            };
            var s1 = inputData.S1;
            var s2 = inputData.S2;
            var s3 = inputData.S3;

            //按配置来确定
            var randP = inputData.RandP;

            var dr    = inputData.Dr;
            var fenmu = inputData.S1 - inputData.S2 * dr;

            var i          = 1;
            var basenumber = 2 * dr / (1 + dr);

            while (true)
            {
                var x   = basenumber + config.ErleiIncreaseNumber * i++;
                var t   = (dr * randP * (2 - x) - randP * x) / fenmu;
                var ph1 = s1 * t + randP * x;
                var pv  = s3 * t + randP;
                var ph2 = s2 * t + randP * (2 - x);

                Debug.WriteLine($"S1={s1},s2={s2},s3={s3},x={x},t={t},ph1={ph1:F4},pv={pv:F4},ph2={ph2:F4},ph1/ph2={ph1 / ph2:F4}");

                var flag1 = ph1 > pv + config.DefaultDeviation && pv > ph2 + config.DefaultDeviation;
                var flag2 = Math.Abs(ph1 / ph2 - dr) <= FloatDeviation;

                if (!flag2 || !flag1)
                {
                    continue;
                }

                inputData.X   = x;
                inputData.T   = t;
                inputData.Ph1 = ph1;
                inputData.Ph2 = ph2;
                inputData.Pv  = pv;

                // Debug.WriteLine($"符合条件:S1={s1},S2={s2},S3={s3},RandP={randP:F4},Dr={dr},X={x},T={t},Ph1={ph1},Ph2={ph2},Pv={pv},S3*Dr-S1={fenmu}");

                break;
            }
        }
コード例 #3
0
ファイル: PvPh1Ph2.cs プロジェクト: dantes1844/DataExtractor
        public void FindOne(InputData inputData)
        {
            var config = new CalculateConfig()
            {
                DefaultDeviation     = 2,
                SanleiLoopCount      = 20000,
                SanleiIncreaseNumber = 0.1
            };
            var fenmu       = inputData.S3 - inputData.S2 * inputData.Dr;
            var coefficient = ExtractCoefficient(inputData.Dr, inputData.RandP, inputData.S1, inputData.S2, inputData.S3, fenmu);

            var       item      = coefficient * config.SanleiIncreaseNumber;
            var       x         = inputData.Dr;
            var       i         = 0;
            Stopwatch stopwatch = Stopwatch.StartNew();

            do
            {
                x += item;
                var t   = inputData.RandP * (inputData.Dr - x) / fenmu;
                var pv  = inputData.S3 * t + inputData.RandP * x;
                var ph1 = inputData.S1 * t + inputData.RandP * (2 - x);
                var ph2 = inputData.S2 * t + inputData.RandP;

                var flag1 = pv > ph1 + config.DefaultDeviation && ph1 > ph2 + config.DefaultDeviation;
                var flag2 = Math.Abs(pv / ph2 - inputData.Dr) <= FloatDeviation;


                Debug.WriteLine($"S1={inputData.S1},S2={inputData.S2},S3={inputData.S3},RandP={inputData.RandP:F4},Dr={inputData.Dr},X={x},T={t},Pv={pv},Ph1={ph1},Ph2={ph2},pv-ph1={pv - ph1},fenmu={fenmu}");


                if (!flag2 || !flag1)
                {
                    i++;
                    continue;
                }

                inputData.X   = x;
                inputData.T   = t;
                inputData.Ph1 = ph1;
                inputData.Ph2 = ph2;
                inputData.Pv  = pv;

                stopwatch.Stop();
                Debug.WriteLine($"执行完一条耗时:{stopwatch.ElapsedMilliseconds}ms。符合条件:S1={inputData.S1},S2={inputData.S2},S3={inputData.S3},RandP={inputData.RandP:F4},Dr={inputData.Dr},X={x},T={t},Ph1={ph1},Ph2={ph2},Pv={pv},S3*Dr-S1={fenmu}");

                break;
            } while (i <= config.SanleiLoopCount);
        }
コード例 #4
0
ファイル: Ph2Ph1Pv.cs プロジェクト: dantes1844/DataExtractor
        public override ParallelLoopResult ParallelRun(CalculateConfig config, InputData inputData)
        {
            Stopwatch stopwatch = Stopwatch.StartNew();
            var       s1        = inputData.S1;
            var       s2        = inputData.S2;
            var       s3        = inputData.S3;

            //按配置来确定
            var randP = inputData.RandP;

            var dr    = inputData.Dr;
            var fenmu = inputData.S3 * dr - inputData.S1;

            var coefficient = ExtractCoefficient(dr, randP, s1, s2, s3, fenmu);
            var item        = coefficient * IncreaseNumber;

            return(Parallel.For(0, config.YileiLoopCount, (i, state) =>
            {
                var x = item * i + 1 / dr;
                var t = randP * (1 - x * dr) / fenmu;
                var ph1 = s1 * t + randP;
                var ph2 = s2 * t + randP * (2 - x);
                var pv = s3 * t + randP * x;

                var flag1 = ph1 > ph2 + config.DefaultDeviation && ph2 > pv + config.DefaultDeviation;
                var flag2 = Math.Abs(ph1 / pv - dr) <= 0.0001;

                if (!flag2 || !flag1)
                {
                    return;
                }

                inputData.X = x;
                inputData.T = t;
                inputData.Ph1 = ph1;
                inputData.Ph2 = ph2;
                inputData.Pv = pv;

                stopwatch.Stop();
                //Debug.WriteLine($"执行完一条耗时:{stopwatch.ElapsedMilliseconds}ms。符合条件:S1={s1},S2={s2},S3={s3},RandP={randP:F4},Dr={dr},X={x},T={t},Ph1={ph1},Ph2={ph2},Pv={pv},S3*Dr-S1={fenmu}");
                state.Stop();
            }));
        }
コード例 #5
0
        private void Calculate(InputData inputData, CalculateConfig config)
        {
            CalculateBase service;

            switch (inputData.DataType)
            {
            case DataType.Yilei:
                inputData.RandP = _sameRandomNumber1;
                service         = new Ph1Ph2Pv();
                break;

            case DataType.Erlei:
                inputData.RandP = _sameRandomNumber2;
                service         = new Ph1PvPh2();
                break;

            case DataType.Sanlei:
                inputData.RandP = _sameRandomNumber3;
                service         = new PvPh1Ph2();
                break;

            default:
                service = null;
                break;
            }

            if (config.RandomNumberType == RandomNumberType.RandomNumberPerRecord)
            {
                var random = new ThreadSafeRandom();
                var rp     = (inputData.RandomNumberEnd - inputData.RandomNumberStart) * random.NextDouble();
                inputData.RandP = rp + inputData.RandomNumberStart;
            }

            service?.ParallelRun(config, inputData);
            _recordStack.Add(inputData);
        }
コード例 #6
0
 public abstract ParallelLoopResult ParallelRun(CalculateConfig config, InputData inputData);