Shuxia Ning
2024-07-17 fd681339c81201ed6fb3303647ecab89e3e6c0c1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
namespace IStation.Algorithm
{
    /// <summary>
    /// 调度分析辅助类
    /// </summary>
    public partial class ScheduleHelper
    {
        private class AnalysisConclusionViewModel : Model.AnalysisConclusion
        {
            public AnalysisConclusionViewModel() { }
            public AnalysisConclusionViewModel(Model.AnalysisConclusion rhs) : base(rhs) { }
            public AnalysisConclusionViewModel(Model.AnalysisConclusion rhs, int flag) : base(rhs)
            {
                this.Flag = flag;
            }
            public int Flag { get; set; }
        }
 
        readonly decimal _frequency_min = 25;
        readonly decimal _frequency_max = 50;
        readonly decimal _frequency_space = 1;//频率间隔 
 
        readonly double _start_stop_loss_coefficient = 0.95;//泵启停损失系数
 
        readonly double _sel_opt_flow_deviation_ratio = 0.05;//可选方案的流量偏差比
        readonly double _sel_opt_reasonable_flow_deviation_ratio = 0.005;//合理的方案的流量偏差比
 
        readonly Service.AnalysisCombine _service_analysis_combine = new();
        readonly Service.AnalysisConclusion _service_analysis_conclusion = new();
        readonly Service.AnalysisLog _service_analysis_log = new();
 
        int _min_open_count;//最小开泵数量
        int _max_open_count;//最大开泵数量
        List<int> _current_open_flag_list = null;// 当前开泵列表
        List<int> _must_open_flag_list = null; // 必开泵列表  
        List<int> _must_close_flag_list = null; // 必关泵列表 
        List<List<int>> _forbidden_flag_combine_list = null; // 禁用泵组合 
        List<List<int>> _associative_flag_combine_list = null; // 关联泵组合 
        List<List<int>> _same_section_flag_combine_list = null; // 同段泵组合  
        List<Model.WaterSupplyLimit> _water_supply_limit_list = null; //供水限制列表
        List<Model.FrequencyLimit> _frequency_limit_list = null; // 频率限制列表
 
        /// <summary>
        /// 初始化
        /// </summary>
        public void Initial(List<int> current_open_flag_list, Model.ScheduleConfig schedule_config)
        {
            _min_open_count = 1;
            _max_open_count = 0;
            _current_open_flag_list = current_open_flag_list;
            _must_open_flag_list = null;
            _must_close_flag_list = null;
            _forbidden_flag_combine_list = null;
            _associative_flag_combine_list = null;
            _same_section_flag_combine_list = null;
            _water_supply_limit_list = null;
            _frequency_limit_list = null;
            if (schedule_config != null)
            {
                _min_open_count = schedule_config.MinOpenCount;
                _max_open_count = schedule_config.MaxOpenCount;
                _must_open_flag_list = schedule_config.MustOpenFlagList;
                _must_close_flag_list = schedule_config.MustCloseFlagList;
                _forbidden_flag_combine_list = schedule_config.ForbiddenFlagCombineList;
                _associative_flag_combine_list = schedule_config.AssociativeFlagCombineList;
                _same_section_flag_combine_list = schedule_config.SameSectionFlagCombineList;
                _water_supply_limit_list = schedule_config.WaterSupplyLimitList;
                _frequency_limit_list = schedule_config.FrequencyLimitList;
            }
        }
 
 
        /// <summary>
        /// 获取最优组合 工况计算
        /// </summary>
        /// <param name="pumps"></param>
        /// <param name="flag_rpm_dic"></param>
        /// <param name="flag_head_dic"></param>
        /// <param name="target_flow"></param>
        /// <param name="target_head"></param>
        /// <returns></returns>
        public AnaCombine GetOptAnaCombineByWorking(
            List<Model.Pump> pumps,
            Dictionary<int, double> flag_rpm_dic,
            Dictionary<int, double> flag_head_dic,
            double target_flow,
            double target_head
            )
        {
            if (pumps == null || !pumps.Any())
            {
                return default;
            }
 
            if (flag_rpm_dic == null || !flag_rpm_dic.Any())
            {
                return default;
            }
            target_flow = Math.Round(target_flow, 1);
            target_head = Math.Round(target_head, 1);
 
            double total_flow = 0;
            double total_power = 0;
            var ana_fre_pump_list = new List<AnaFrePump>();
            foreach (var item in flag_rpm_dic)
            {
                var pump = pumps.Find(x => x.Flag == item.Key);
                if (pump == null)
                    continue;
                var rpm = Math.Round(item.Value, 1);
                if (rpm == 0)
                    continue;
                var curveQH = Curve.PumpCalculateHelper.CalculateSimilarQH(pump.CurveQH, pump.Nr, rpm);
                var curveQP = Curve.PumpCalculateHelper.CalculateSimilarQP(pump.CurveQP, pump.Nr, rpm);
 
                double flow = 0, head = target_head;
                if (flag_head_dic != null && flag_head_dic.ContainsKey(pump.Flag))
                    head = flag_head_dic[pump.Flag];
 
                flow = curveQH.GetInterPointLastX(head) ?? 0;
                if (flow < 0)
                    continue;
 
                var fre_pump = new AnaFrePump();
                fre_pump.Flag = item.Key;
                fre_pump.Flow = flow;
                fre_pump.Head = target_head;
                fre_pump.Power = curveQP.GetFitPointY(flow);
                fre_pump.Efficiency = Curve.PumpCalculateHelper.CalculateE(fre_pump.Flow, fre_pump.Head, fre_pump.Power);
                fre_pump.Frequency = rpm;
                fre_pump.Speed = (double)rpm / 50 * pump.Nr;
 
 
                total_flow += flow;
                total_power += fre_pump.Power;
                ana_fre_pump_list.Add(fre_pump);
            }
 
 
            var efficiency = Curve.PumpCalculateHelper.CalculateE(total_flow, target_head, total_power);
            var wp = Curve.PumpCalculateHelper.CalculateWP(total_power, total_flow);
            var uwp = Curve.PumpCalculateHelper.CalculateUWP(total_power, total_flow, target_head);
 
            var opt = new AnaCombine();
            opt.AnaFrePumps = ana_fre_pump_list;
            opt.Flags = new List<int>();
            opt.TotalFlow = total_flow;
            opt.TotalHead = target_head;
            opt.TotalPower = total_power;
            opt.TotalEfficiency = efficiency;
            opt.WP = wp;
            opt.UWP = uwp;
 
            opt.Flags = opt.Flags.OrderBy(x => x).ToList();
            opt.FlagCount = opt.Flags.Count;
            opt.Remark = IntListHelper.ToString(opt.Flags);
            opt.MeritRatio = 1;
 
            opt.Round();
            return opt;
        }
 
 
        /// <summary>
        /// 获取最优组合
        /// </summary>
        /// <param name="pump_list"></param>
        /// <param name="same_type_flag_group_first"></param>
        /// <param name="flag_inlet_water_level_dict"></param>
        /// <param name="target_flow"></param>
        /// <param name="target_head"></param>
        /// <returns></returns>
        public AnaCombine GetOptAnaCombine
            (
            List<Model.Pump> pump_list,
            List<int> same_type_flag_group_first,
            Dictionary<int, double> flag_inlet_water_level_dict,
            double target_flow,
            double target_head
            )
        {
            if (pump_list == null || !pump_list.Any())
                return default;
 
            var min_open_count = _min_open_count;
            var max_open_count = _max_open_count < 1 ? pump_list.Count : _max_open_count;
            var current_open_flag_list = _current_open_flag_list;
            var must_open_flag_list = _must_open_flag_list;
            var must_close_flag_list = _must_close_flag_list;
            var forbidden_flag_combine_list = _forbidden_flag_combine_list;
            var associative_flag_combine_list = _associative_flag_combine_list;
            var same_section_flag_combine_list = _same_section_flag_combine_list;
            var water_supply_limit_list = _water_supply_limit_list;
            var frequency_limit_list = _frequency_limit_list;
 
            var pump_bp_dict = pump_list.ToDictionary(x => x.Flag, x => x.IsBp);
            var pump_nr_dict = pump_list.ToDictionary(x => x.Flag, x => x.Nr);
            var pump_flag_list = pump_list.Select(x => x.Flag).ToList();
 
            target_flow = Math.Round(target_flow, 1);
            target_head = Math.Round(target_head, 1);
 
            double combine_merit_ratio = 1;//组合择优率
 
            #region 存在-必开泵列表
 
            var must_open_flag_list_remark = string.Empty;
            var exist_must_open_flag_list = must_open_flag_list != null && must_open_flag_list.Count > 0;
            if (exist_must_open_flag_list)
            {
                must_open_flag_list = must_open_flag_list.OrderBy(x => x).ToList();
                must_open_flag_list_remark = IntListHelper.ToString(must_open_flag_list);
            }
 
            #endregion
 
            #region 存在-必关泵列表
 
            var exist_must_close_flag_list = must_close_flag_list != null && must_close_flag_list.Count > 0;
 
            #endregion
 
            #region 存在-禁用组合
 
            var exist_forbidden_flag_combine_list = forbidden_flag_combine_list != null && forbidden_flag_combine_list.Count > 0;
 
            #endregion
 
            #region 存在-关联组合
 
            var exist_associative_flag_combine_list = associative_flag_combine_list != null && associative_flag_combine_list.Count > 0;
 
            #endregion 
 
            #region 存在-同段泵组合
 
            Dictionary<int, List<int[]>> same_section_combine_dict = new();
            var exist_same_section_flag_combine_list = _same_section_flag_combine_list != null && _same_section_flag_combine_list.Count > 0;
            if (exist_same_section_flag_combine_list)
            {
                for (int pump_count = 1; pump_count <= pump_list.Count; pump_count++)
                {
                    same_section_combine_dict[pump_count] = new List<int[]>();
                    switch (pump_count)
                    {
                        case 2:
                            {
                                foreach (var same_section_flag_combine in same_section_flag_combine_list)
                                {
                                    var combine_list = GetCombineList(same_section_flag_combine, 2);
                                    same_section_combine_dict[pump_count].AddRange(combine_list);
                                }
                            }
                            break;
                        case 3:
                            {
                                foreach (var same_section in same_section_flag_combine_list)
                                {
                                    var combine_list = GetCombineList(same_section, 3);
                                    same_section_combine_dict[pump_count].AddRange(combine_list);
                                }
                            }
                            break;
                        case 4:
                            {
                                foreach (var same_section in same_section_flag_combine_list)
                                {
                                    var combine_list3 = GetCombineList(same_section, 3);
                                    same_section_combine_dict[pump_count].AddRange(combine_list3);
                                    if (same_section.Count > 3)
                                    {
                                        var combine_list = GetCombineList(same_section, 4);
                                        same_section_combine_dict[pump_count].AddRange(combine_list);
                                    }
                                }
                            }
                            break;
                        case 5:
                            {
                                foreach (var same_section in same_section_flag_combine_list)
                                {
                                    if (same_section.Count > 3)
                                    {
                                        var combine_list = GetCombineList(same_section, 4);
                                        same_section_combine_dict[pump_count].AddRange(combine_list);
                                    }
                                }
                            }
                            break;
                        case 6:
                            {
                                foreach (var same_section in same_section_flag_combine_list)
                                {
                                    if (same_section.Count > 3)
                                    {
                                        var combine_list = GetCombineList(same_section, 4);
                                        same_section_combine_dict[pump_count].AddRange(combine_list);
                                    }
                                }
                            }
                            break;
                        default:
                            break;
                    }
                }
            }
            #endregion
 
            #region 存在-供水限制
 
            var exist_water_supply_limit_list = water_supply_limit_list != null && water_supply_limit_list.Count > 0;
 
            #endregion 
 
            #region 存在-频率限制
 
            var frequency_limit_flag_dict = new Dictionary<int, Model.FrequencyLimit>();
            var exist_frequency_limit_list = frequency_limit_list != null && frequency_limit_list.Count > 0;
            if (exist_frequency_limit_list)
            {
                frequency_limit_flag_dict = frequency_limit_list.ToDictionary(x => x.Flag, x => x);
            }
 
            #endregion
 
            #region 存在-当前开泵列表 (是否切泵) 逻辑待补充
 
            var exist_current_open_flag_list = current_open_flag_list != null && current_open_flag_list.Count > 0;
            if (exist_current_open_flag_list)
            {
                var opt_ana_combine = GetOptAnaCombine
                        (
                        current_open_flag_list,
                        1,
                        flag_inlet_water_level_dict,
                        pump_nr_dict,
                        pump_bp_dict,
                        exist_frequency_limit_list,
                        frequency_limit_flag_dict,
                        target_flow,
                        target_head
                        );
                if (opt_ana_combine != null)
                    return opt_ana_combine;
            }
 
            #endregion
 
            var opt_ana_combine_list = new List<AnaCombine>();
            for (int pump_count = min_open_count; pump_count <= max_open_count; pump_count++)
            {
                if (pump_count == 1)
                {
                    var max_total_flow = pump_list.Max(x => x.Qr);
                    if (max_total_flow < target_flow)
                        continue;
                }
 
                #region 供水限制
 
                //供水限制
                if (exist_water_supply_limit_list)
                {
                    var exist_limit = false;
                    foreach (var limit in water_supply_limit_list)
                    {
                        if (limit.PumpCount == pump_count)
                        {
                            if (target_flow < limit.Min || target_flow > limit.Max)
                            {
                                exist_limit = true;
                                break;
                            }
                        }
                        //if (target_flow >= limit.Min && target_flow <= limit.Max)
                        //{
                        //    if (limit.PumpCount != pump_count)
                        //    {
                        //        exist_limit = true;
                        //        break;
                        //    }
                        //}
                    }
                    if (exist_limit)
                        continue;
                }
 
                #endregion
 
                var combine_list = GetCombineList(pump_flag_list, pump_count);//排列组合
                foreach (var combine in combine_list)
                {
                    combine_merit_ratio = 1;
 
                    #region 规则过滤
                    //必开
                    if (exist_must_open_flag_list)
                    {
                        var combine_remark = IntListHelper.ToString(combine.OrderBy(x => x));
                        if (!combine_remark.Contains(must_open_flag_list_remark))
                            continue;
                    }
 
                    //必关
                    if (exist_must_close_flag_list)
                    {
                        var exist_intersected = combine.Intersect(must_close_flag_list).Count() > 0;
                        if (exist_intersected)
                            continue;
                    }
 
                    //禁用组合
                    if (exist_forbidden_flag_combine_list)
                    {
                        var exist_equal = false;
                        foreach (var flag_list in forbidden_flag_combine_list)
                        {
                            if (combine.SequenceEqual(flag_list))
                            {
                                exist_equal = true;
                                break;
                            }
                        }
                        if (exist_equal)
                            continue;
                    }
 
                    //同段泵组合
                    if (exist_same_section_flag_combine_list)
                    {
                        var exist_equal = false;
                        foreach (var flag_list in same_section_combine_dict[pump_count])
                        {
                            //相同
                            if (combine.SequenceEqual(flag_list))
                            {
                                exist_equal = true;
                                break;
                            }
 
                            //包含
                            if (flag_list.Intersect(combine).Count() == flag_list.Length)
                            {
                                exist_equal = true;
                                break;
                            }
                        }
                        if (exist_equal)
                            continue;
                    }
 
                    //关联组合
                    if (exist_associative_flag_combine_list)
                    {
                        var exist_intersected = false;
                        foreach (var flag_list in associative_flag_combine_list)
                        {
                            var except_count = combine.Except(flag_list).Count();
                            if (except_count != flag_list.Count && except_count > 0)
                            {
                                exist_intersected = true;
                            }
                        }
                        if (exist_intersected)
                            continue;
                    }
 
                    int start_stop_count = 0;//启停数量
 
                    //当前开泵列表
                    if (exist_current_open_flag_list)
                    {
                        var start_pump_count = combine.Except(current_open_flag_list).Count();
                        var close_pump_count = current_open_flag_list.Except(combine).Count();
                        start_stop_count = start_pump_count + close_pump_count;//启停数量 
                    }
                    else
                    {
                        start_stop_count = combine.Count();
                        if (exist_must_open_flag_list)
                        {
                            start_stop_count = combine.Except(must_open_flag_list).Count();
                        }
                    }
 
                    #endregion
 
                    var total_loss_ratio = Math.Pow(_start_stop_loss_coefficient, start_stop_count);//启停一次损失些能耗
                    combine_merit_ratio *= total_loss_ratio;
 
                    var opt_ana_combine = GetOptAnaCombine
                        (
                        combine,
                        combine_merit_ratio,
                        flag_inlet_water_level_dict,
                        pump_nr_dict,
                        pump_bp_dict,
                        exist_frequency_limit_list,
                        frequency_limit_flag_dict,
                        target_flow,
                        target_head
                        );
                    if (opt_ana_combine == null)
                        continue;
                    opt_ana_combine_list.Add(opt_ana_combine);
                }
            }
 
            if (opt_ana_combine_list.Count < 1)
                return default;
 
            opt_ana_combine_list = opt_ana_combine_list.OrderByDescending(x => x.MeritRatio).ToList();
            var opt = opt_ana_combine_list.First();
            opt.Round();
            return opt;
        }
 
 
        /// <summary>
        /// 获取最优组合
        /// </summary>
        /// <param name="combine"></param>
        /// <param name="combine_merit_ratio"></param>
        /// <param name="flag_inlet_water_level_dict"></param>
        /// <param name="pump_nr_dict"></param>
        /// <param name="pump_bp_dict"></param>
        /// <param name="exist_frequency_limit_list"></param>
        /// <param name="frequency_limit_flag_dict"></param>
        /// <param name="target_flow"></param>
        /// <param name="target_head"></param>
        /// <returns></returns>
        private AnaCombine GetOptAnaCombine
            (
            IEnumerable<int> combine,
            double combine_merit_ratio,
            Dictionary<int, double> flag_inlet_water_level_dict,
            Dictionary<int, double> pump_nr_dict,
            Dictionary<int, bool> pump_bp_dict,
            bool exist_frequency_limit_list,
            Dictionary<int, Model.FrequencyLimit> frequency_limit_flag_dict,
            double target_flow,
            double target_head
            )
        {
            if (combine == null || !combine.Any())
                return default;
 
            var combine_correction_factor_dict = GetCombineCorrectionFactor(combine);
            var conclusion_ex_list_list = new List<List<AnalysisConclusionViewModel>>();
            var conclusion_ex_list_dict = new Dictionary<int, List<AnalysisConclusionViewModel>>();
            double max_supply_flow = 0;
            foreach (var flag in combine)
            {
                var run_flag = RunFlagHelper.GetRunFlag(flag, pump_bp_dict[flag]);
 
                //进口水位
                var inlet_water_level = flag_inlet_water_level_dict[flag];
 
                //组合修正系数
                var combine_correction_factor = combine_correction_factor_dict[flag];
                var current_target_head = target_head - inlet_water_level + combine_correction_factor;
                current_target_head = Math.Round(current_target_head, 1);
 
                //频率限制
                var conclusion_list = new List<Model.AnalysisConclusion>();
                if (exist_frequency_limit_list && frequency_limit_flag_dict.ContainsKey(flag))
                {
                    var limit = frequency_limit_flag_dict[flag];
                    conclusion_list = _service_analysis_conclusion.GetList(run_flag, limit.Min, limit.Max, current_target_head);
                }
                else
                {
                    var min_head_conclusion = _service_analysis_conclusion.GetMinHead(run_flag);
                    if (min_head_conclusion != null && min_head_conclusion.Head > current_target_head)
                    {
                        conclusion_list = new List<Model.AnalysisConclusion>() { min_head_conclusion };
                    }
                    else
                    {
                        conclusion_list = _service_analysis_conclusion.GetList(run_flag, current_target_head);
                    }
                }
                if (conclusion_list == null || !conclusion_list.Any())
                {
                    break;
                }
                max_supply_flow += conclusion_list.Max(x => x.Flow);
                var conclusion_ex_list = conclusion_list.Select(x => new AnalysisConclusionViewModel(x, flag)).ToList();
                conclusion_ex_list_list.Add(conclusion_ex_list);
                conclusion_ex_list_dict[flag] = conclusion_ex_list;
            }
 
            if (conclusion_ex_list_list.Count != combine.Count())
                return default;
 
            if (max_supply_flow < target_flow)
                return default;
 
            var opt_ana_combine = GetOptAnaCombine(conclusion_ex_list_dict, pump_nr_dict, pump_bp_dict, target_flow);
            if (opt_ana_combine == null)
                return default;
 
            var total_flow = opt_ana_combine.TotalFlow;
            var total_power = opt_ana_combine.TotalPower;
            if (total_flow < target_flow * 0.99)
                return default;
 
 
            var total_flow_deviation_ratio = Math.Abs((1 - Math.Abs((total_flow / target_flow))));
            if (total_flow_deviation_ratio > _sel_opt_flow_deviation_ratio)
                return default;
            if (total_flow_deviation_ratio > _sel_opt_reasonable_flow_deviation_ratio)
            {
                combine_merit_ratio -= total_flow_deviation_ratio;
            }
 
            var actual_target_head = target_head;
            var inlet_water_head = flag_inlet_water_level_dict.Average(x => x.Value);
            if (inlet_water_head > 0)
            {
                actual_target_head = target_head - inlet_water_head;
                actual_target_head = Math.Round(actual_target_head, 2);
            }
 
            var efficiency = Curve.PumpCalculateHelper.CalculateE(total_flow, actual_target_head, total_power);
            var wp = Curve.PumpCalculateHelper.CalculateWP(total_power, total_flow);
            var uwp = Curve.PumpCalculateHelper.CalculateUWP(total_power, total_flow, actual_target_head);
 
            opt_ana_combine.TotalFlow = total_flow;
            opt_ana_combine.TotalHead = target_head;
            opt_ana_combine.TotalPower = total_power;
            opt_ana_combine.TotalEfficiency = efficiency;
            opt_ana_combine.WP = wp;
            opt_ana_combine.UWP = uwp;
            opt_ana_combine.MeritRatio = combine_merit_ratio;
            return opt_ana_combine;
        }
 
        /// <summary>
        /// 获取最优组合
        /// </summary>
        /// <param name="conclusion_ex_list_dict"></param>
        /// <param name="pump_nr_dict"></param>
        /// <param name="pump_bp_dict"></param>
        /// <param name="target_flow"></param>
        /// <returns></returns>
        private AnaCombine GetOptAnaCombine(
            Dictionary<int, List<AnalysisConclusionViewModel>> conclusion_ex_list_dict,
            Dictionary<int, double> pump_nr_dict,
            Dictionary<int, bool> pump_bp_dict,
            double target_flow
            )
        {
            if (conclusion_ex_list_dict == null || !conclusion_ex_list_dict.Any())
                return default;
            var frequency_min = (double)_frequency_min;
            var frequency_max = (double)_frequency_max;
            var frequency_space = (double)_frequency_space;
 
            var all_fre_conclusion_ex_list_list = new List<List<AnalysisConclusionViewModel>>();
            var all_fix_conclusion_ex_list_list = new List<List<AnalysisConclusionViewModel>>();
            foreach (var item in conclusion_ex_list_dict)
            {
                var flag = item.Key;
                var cl_list = item.Value;
                if (pump_bp_dict[flag])
                {
                    all_fre_conclusion_ex_list_list.Add(cl_list);
                }
                else
                {
                    all_fix_conclusion_ex_list_list.Add(cl_list);
                }
            }
            double fix_total_flow = 0;
            var exist_all_fix_conclusion_ex_list_list = all_fix_conclusion_ex_list_list.Any();
            if (exist_all_fix_conclusion_ex_list_list)
            {
                fix_total_flow = all_fix_conclusion_ex_list_list.Sum(x => x.Sum(x => x.Flow));
            }
 
            //频率按间隔分组
            var cl_ex_list_list_list = new List<List<List<AnalysisConclusionViewModel>>>();
            for (double fre_current_min = frequency_min; fre_current_min <= frequency_max; fre_current_min++)
            {
                var fre_current_max = fre_current_min + frequency_space;
                var skip_current = false;
                var total_flow_current = 0d;
                var cl_ex_list_list = new List<List<AnalysisConclusionViewModel>>();
                foreach (var conclusion_ex_list in all_fre_conclusion_ex_list_list)
                {
                    var cl_ex_list = conclusion_ex_list.Where(x => x.Pump1 <= fre_current_max && x.Pump1 >= fre_current_min).ToList();
                    if (cl_ex_list == null || !cl_ex_list.Any())
                    {
                        skip_current = true;
                        break;
                    }
                    total_flow_current += cl_ex_list.Max(x => x.Flow);
                    cl_ex_list_list.Add(cl_ex_list);
                }
                if (skip_current)
                    continue;
                if (exist_all_fix_conclusion_ex_list_list)
                {
                    total_flow_current += fix_total_flow;
                    cl_ex_list_list.AddRange(all_fix_conclusion_ex_list_list);
                }
                if (total_flow_current < target_flow)
                    continue;
                cl_ex_list_list_list.Add(cl_ex_list_list);
            }
 
            if (!cl_ex_list_list_list.Any())
            {
                return default;
            }
 
            //分组排列组合求最优
            var ana_combine_list = new List<AnaCombine>();
            foreach (var item_cl_ex_list_list in cl_ex_list_list_list)
            {
                var cl_ex_list_list = CartesianProduct(item_cl_ex_list_list, target_flow);
                var opt_cl_ex_list = cl_ex_list_list.OrderBy(x => x.Sum(x => x.Power)).FirstOrDefault();
                if (opt_cl_ex_list != null && opt_cl_ex_list.Any())
                {
                    var ana_combine = new AnaCombine();
                    ana_combine.Flags = new List<int>();
                    ana_combine.AnaFrePumps = new List<AnaFrePump>();
                    foreach (var opt_cl_ex in opt_cl_ex_list)
                    {
                        var flag = opt_cl_ex.Flag;
                        ana_combine.Flags.Add(flag);
                        ana_combine.TotalFlow += opt_cl_ex.Flow;
                        ana_combine.TotalPower += opt_cl_ex.Power;
 
                        var ana_fre_pump = new AnaFrePump();
                        ana_fre_pump.Flag = flag;
                        ana_fre_pump.Flow = opt_cl_ex.Flow;
                        ana_fre_pump.Head = opt_cl_ex.Head;
                        ana_fre_pump.Power = opt_cl_ex.Power;
                        ana_fre_pump.Efficiency = Curve.PumpCalculateHelper.CalculateE(ana_fre_pump.Flow, ana_fre_pump.Head, ana_fre_pump.Power);
                        ana_fre_pump.Frequency = opt_cl_ex.Pump1;
                        ana_fre_pump.Speed = opt_cl_ex.Pump1 / 50 * pump_nr_dict[flag];
                        ana_combine.AnaFrePumps.Add(ana_fre_pump);
                    }
 
                    ana_combine.FlagCount = opt_cl_ex_list.Count;
                    ana_combine.Remark = IntListHelper.ToString(ana_combine.Flags);
                    ana_combine_list.Add(ana_combine);
                }
            }
            if (!ana_combine_list.Any())
                return default;
            var opt_ana_combine = ana_combine_list.OrderBy(x => x.TotalPower).First();
            return opt_ana_combine;
        }
 
 
        /// <summary>
        /// 获取排列组合列表(笛卡尔乘积)
        /// </summary>
        private List<List<AnalysisConclusionViewModel>> CartesianProduct(List<List<AnalysisConclusionViewModel>> lstSplit, double target_flow)
        {
            long count = 1;
            lstSplit.ForEach(item => count *= item.Count);
            var lstResult = new List<List<AnalysisConclusionViewModel>>();
            for (long i = 0; i < count; ++i)
            {
                var lstTemp = new List<AnalysisConclusionViewModel>();
                long j = 1;
                var lstFre = new List<double>();
                double totalFlow = 0;
                lstSplit.ForEach(item =>
                {
                    j *= item.Count;
                    var index = (i / (count / j)) % item.Count;
                    var index_int = (int)index;
                    var obj = item[index_int];
                    totalFlow += obj.Flow;
                    lstTemp.Add(obj);
                });
                if (totalFlow < target_flow)
                    continue;
                lstResult.Add(lstTemp);
            }
            return lstResult;
        }
 
 
        /// <summary>
        /// 获取排列组合
        /// </summary>
        /// <param name="flags"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        private List<int[]> GetCombineList(List<int> flags, int count)
        {
            var combine = IStation.Curve.PermutationAndCombination<int>.GetCombination(flags.ToArray(), count);
            return combine;
        }
 
        /// <summary>
        /// 获取组合修正系数
        /// </summary>
        /// <param name="flags"></param>
        /// <returns></returns>
        private Dictionary<int, double> GetCombineCorrectionFactor(IEnumerable<int> flags)
        {
            var correction_factor_dict = new Dictionary<int, double>();
 
            var r = new Random(0);
            foreach (var flag in flags)
            {
                double factor = 0;
                //factor += r.NextDouble();
                correction_factor_dict.Add(flag, factor);
            }
 
            return correction_factor_dict;
        }
 
 
 
    }
}