ningshuxia
2024-05-07 ad80204d8c020c626253da9547e5e192c2395195
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
namespace IStation.Algorithm
{
 
    #region ViewModel
 
    /// <summary>
    /// 
    /// </summary>
    public class FreCombine
    {
        public FreCombine() { }
        public List<int> Flags { get; set; }
        public int RunCount { get; set; }
        public double Flow { get; set; }
        public double Head { get; set; }
        public double Power { get; set; }
        public double Efficiency { get; set; }
        public double Frequency { get; set; }
        public double Speed { get; set; }
        public List<FrePump> FrePumps { get; set; }
 
        public void Round()
        {
            this.Flow = Math.Round(this.Flow, 1);
            this.Head = Math.Round(this.Head, 3);
            this.Power = Math.Round(this.Power, 1);
            this.Efficiency = Math.Round(this.Efficiency, 1);
            this.Frequency = Math.Round(this.Frequency, 1);
            this.Speed = Math.Round(this.Speed, 1);
        }
 
    }
 
 
    /// <summary>
    /// 
    /// </summary>
    public class FrePump
    {
        public FrePump() { }
        public int Flag { get; set; }
        public double Flow { get; set; }
        public double Head { get; set; }
        public double Power { get; set; }
        public double Efficiency { get; set; }
        public double Frequency { get; set; }
        public double Speed { get; set; }
 
        public void Round()
        {
            this.Flow = Math.Round(this.Flow, 1);
            this.Head = Math.Round(this.Head, 3);
            this.Power = Math.Round(this.Power, 1);
            this.Efficiency = Math.Round(this.Efficiency, 1);
            this.Frequency = Math.Round(this.Frequency, 1);
            this.Speed = Math.Round(this.Speed, 1);
        }
 
    }
 
 
 
    /// <summary>
    /// 分析泵项
    /// </summary>
    public class OptimalCombine
    {
        public OptimalCombine() { }
        public double Flow { get; set; }
        public double Head { get; set; }
        public double Power { get; set; }
        public double Efficiency { get; set; }
        public double WP { get; set; }
        public double UWP { get; set; }
        public List<FreCombine> Combines { get; set; }
        public List<int> Flags { get; set; }
        public int FlagCount { get; set; }
        public string Remark { get; set; }
        public double MeritRatio { get; set; }
 
        public void Round()
        {
            this.Flow = Math.Round(this.Flow, 1);
            this.Head = Math.Round(this.Head, 3);
            this.Power = Math.Round(this.Power, 1);
            this.Efficiency = Math.Round(this.Efficiency, 1);
            this.WP = Math.Round(this.WP, 2);
            this.UWP = Math.Round(this.UWP, 2);
 
            if (this.Combines != null && this.Combines.Any())
            {
                foreach (var combine in Combines)
                {
                    combine.Round();
                    if (combine.FrePumps != null && combine.FrePumps.Any())
                    {
                        foreach (var pump in combine.FrePumps)
                        {
                            pump.Round();
                        }
                    }
                }
            }
        }
    }
 
    #endregion
 
    /// <summary>
    /// 调度分析辅助类
    /// </summary>
    public class SchedulingHelper
    {
        decimal _frequency_min = 25;
        decimal _frequency_max = 50;
        decimal _frequency_space = 0.1m;//频率间隔  
 
        double _start_stop_loss_coefficient = 0.95;//泵启停损失系数
 
        double _sel_opt_flow_deviation_ratio = 0.05;//可选方案的流量偏差比
        double _sel_opt_reasonable_flow_deviation_ratio = 0.005;//合理的方案的流量偏差比
 
 
        #region RunFlag
        string _falgFrePumpTag = "B";
        string _falgFixPumpTag = "G";
        string _falgSpaceMark = "_";
 
 
        string GetRunFlag(int[] flags)
        {
            var runFlag = string.Empty;
            var index = 0;
            var count = flags.Length;
            foreach (var flag in flags)
            {
                runFlag += GetGFlag(flag);
                index++;
                if (index != count)
                {
                    runFlag += _falgSpaceMark;
                }
            }
            return runFlag;
        }
 
        string GetRunFlag(List<int> flags)
        {
            var runFlag = string.Empty;
            var index = 0;
            var count = flags.Count;
            foreach (var flag in flags)
            {
                runFlag += GetGFlag(flag);
                index++;
                if (index != count)
                {
                    runFlag += _falgSpaceMark;
                }
            }
            return runFlag;
        }
 
        string GetGFlag(int flag)
        {
            return _falgFrePumpTag + flag;
        }
 
        #endregion
 
        DAL.ScheduleCombine _dal = new DAL.ScheduleCombine();
        DAL.ScheduleConclusion _dalScheduleConclusion = new DAL.ScheduleConclusion();
        DAL.ScheduleAnaLog _dalAnaLog = new DAL.ScheduleAnaLog();
 
 
        public OptimalCombine AnaOptimalCombine(List<Pump> pumps, List<int> flags_part1, List<int> flags_part2, double target_flow, double target_head, List<int> current_open_pump_flags, List<int> must_open_pump_flags, List<int> must_not_open_pump_flags)
        {
            if (pumps == null || !pumps.Any())
            {
                return default;
            }
            target_flow = Math.Round(target_flow, 1);
            target_head = Math.Round(target_head, 1);
 
            #region 存在-当前开泵列表
 
            var exist_current_open_pump_flags = current_open_pump_flags != null && current_open_pump_flags.Count > 0;
 
            #endregion
 
            #region 存在-必开泵列表
 
            var must_open_pump_flags_remark = string.Empty;
            var exist_must_open_pump_flags = must_open_pump_flags != null && must_open_pump_flags.Count > 0;
            if (exist_must_open_pump_flags)
            {
                must_open_pump_flags = must_open_pump_flags.OrderBy(x => x).ToList();
                must_open_pump_flags_remark = IntListHelper.ToString(must_open_pump_flags);
            }
 
            #endregion
 
            #region 存在-必不能开泵列表
 
            var exist_must_not_open_pump_flags = must_not_open_pump_flags != null && must_not_open_pump_flags.Count > 0;
 
            #endregion
 
            var pump_nr_dict = pumps.ToDictionary(x => x.ID, x => x.Nr);
            var pump_flag_list = pumps.Select(x => x.ID).ToList();
            var optimal_combine_list = new List<OptimalCombine>();
            for (int pumpCount = 1; pumpCount <= pumps.Count; pumpCount++)
            {
                if (pumpCount == 1)
                {
                    var max_total_flow = pumps.Max(x => x.Qr);
                    if (max_total_flow < target_flow)
                        continue;
                }
                var combine_list = PermutationAndCombination<int>.GetCombination(pump_flag_list.ToArray(), pumpCount);//排列组合
                foreach (var combine in combine_list)
                {
                    double combine_merit_ratio = 1;//组合择优率
                    if (exist_must_open_pump_flags)
                    {
                        var combine_remark = IntListHelper.ToString(combine.OrderBy(x => x));
                        if (!combine_remark.Contains(must_open_pump_flags_remark))
                            continue;
                    }
                    if (exist_must_not_open_pump_flags)
                    {
                        var exist_intersected = combine.Intersect(must_not_open_pump_flags).Count() > 0;
                        if (exist_intersected)
                            continue;
                    }
 
                    int start_stop_count = 0;//启停数量
                    if (exist_current_open_pump_flags)
                    {
                        var start_pump_count = combine.Except(current_open_pump_flags).Count();
                        var close_pump_count = current_open_pump_flags.Except(combine).Count();
                        start_stop_count = start_pump_count + close_pump_count;//启停数量 
                    }
                    else
                    {
                        start_stop_count = combine.Count();
                        if (exist_must_open_pump_flags)
                        {
                            start_stop_count = combine.Except(must_open_pump_flags).Count();
                        }
                    }
                    var total_loss_ratio = Math.Pow(_start_stop_loss_coefficient, start_stop_count);//启停一次损失些能耗
                    combine_merit_ratio *= total_loss_ratio;
 
                    List<int> combine_flag_list_part1 = new List<int>();
                    List<int> combine_flag_list_part2 = new List<int>();
                    foreach (var pump in combine)
                    {
                        if (flags_part1.Contains(pump))
                        {
                            combine_flag_list_part1.Add(pump);
                        }
                        else
                        {
                            combine_flag_list_part2.Add(pump);
                        }
                    }
 
                    //区分同型号泵
                    List<FreCombine> fre_combine_list_part1 = new List<FreCombine>();
                    List<FreCombine> fre_combine_list_part2 = new List<FreCombine>();
 
                    if (combine_flag_list_part1.Count > 0)
                    {
                        var conclusion_list_dic = new Dictionary<int, List<Entity.ScheduleConclusion>>();
                        foreach (var flag in combine_flag_list_part1)
                        {
                            var runFlag = GetGFlag(flag);
                            if (conclusion_list_dic.ContainsKey(flag))
                                continue;
                            var conclusionList = _dalScheduleConclusion.GetList(runFlag, target_head);
                            conclusion_list_dic[flag] = conclusionList;
                        }
 
                        if (conclusion_list_dic.Count < 1)
                        {
                            continue;
                        }
 
                        for (decimal fre = _frequency_max; fre >= _frequency_min; fre -= _frequency_space)
                        {
                            var freCombine = new FreCombine();
                            freCombine.Frequency = (double)fre;
                            freCombine.Flags = new List<int>();
                            freCombine.FrePumps = new List<FrePump>();
                            foreach (var item in conclusion_list_dic)
                            {
                                var conclusion = item.Value.Find(x => x.Pump1 == (double)fre);
                                if (conclusion != null)
                                {
                                    freCombine.Flags.Add(item.Key);
                                    freCombine.Flow += conclusion.Flow;
                                    freCombine.Power += conclusion.Power;
                                    freCombine.RunCount++;
 
                                    var fre_pump = new FrePump();
                                    fre_pump.Flag = item.Key;
                                    fre_pump.Flow = conclusion.Flow;
                                    fre_pump.Head = target_head;
                                    fre_pump.Power = conclusion.Power;
                                    fre_pump.Efficiency = CurveCalcuHelper.CalculateE(fre_pump.Flow, fre_pump.Head, fre_pump.Power);
                                    fre_pump.Frequency = freCombine.Frequency;
                                    fre_pump.Speed = (double)fre / 50 * pump_nr_dict[item.Key];
                                    freCombine.FrePumps.Add(fre_pump);
                                }
                            }
                            if (freCombine.Flags.Count < 1)
                                continue;
                            fre_combine_list_part1.Add(freCombine);
                        }
                    }
                    if (combine_flag_list_part2.Count > 0)
                    {
                        var conclusion_list_dic = new Dictionary<int, List<Entity.ScheduleConclusion>>();
                        foreach (var flag in combine_flag_list_part2)
                        {
                            var runFlag = GetGFlag(flag);
                            if (conclusion_list_dic.ContainsKey(flag))
                                continue;
                            var conclusionList = _dalScheduleConclusion.GetList(runFlag, target_head);
                            conclusion_list_dic[flag] = conclusionList;
                        }
 
                        if (conclusion_list_dic.Count < 1)
                        {
                            continue;
                        }
 
                        for (decimal fre = _frequency_max; fre >= _frequency_min; fre -= _frequency_space)
                        {
                            var freCombine = new FreCombine();
                            freCombine.Frequency = (double)fre;
                            freCombine.Flags = new List<int>();
                            freCombine.FrePumps = new List<FrePump>();
                            foreach (var item in conclusion_list_dic)
                            {
                                var conclusion = item.Value.Find(x => x.Pump1 == (double)fre);
                                if (conclusion != null)
                                {
                                    freCombine.Flags.Add(item.Key);
                                    freCombine.Flow += conclusion.Flow;
                                    freCombine.Power += conclusion.Power;
                                    freCombine.RunCount++;
 
                                    var fre_pump = new FrePump();
                                    fre_pump.Flag = item.Key;
                                    fre_pump.Flow = conclusion.Flow;
                                    fre_pump.Head = target_head;
                                    fre_pump.Power = conclusion.Power;
                                    fre_pump.Efficiency = CurveCalcuHelper.CalculateE(fre_pump.Flow, fre_pump.Head, fre_pump.Power);
                                    fre_pump.Frequency = freCombine.Frequency;
                                    fre_pump.Speed = (double)fre / 50 * pump_nr_dict[item.Key];
                                    freCombine.FrePumps.Add(fre_pump);
                                }
                            }
                            if (freCombine.Flags.Count < 1)
                                continue;
                            fre_combine_list_part2.Add(freCombine);
                        }
                    }
 
                    if (fre_combine_list_part1.Count == 0 && fre_combine_list_part2.Count == 0)
                        continue;
 
                    double total_flow_deviation = target_flow;//总流量偏差
                    double total_power = double.MaxValue;//总功率
                    double total_flow = double.MaxValue;//总流量
 
                    FreCombine optimal_combine_part1 = null;
                    FreCombine optimal_combine_part2 = null;
                    if (fre_combine_list_part1.Count < 1 || fre_combine_list_part2.Count < 1)
                    {
                        if (fre_combine_list_part1.Count < 1)
                        {
                            fre_combine_list_part1 = fre_combine_list_part2;
                        }
                        for (int Index_part1 = 0; Index_part1 < fre_combine_list_part1.Count; Index_part1++)
                        {
                            var fre_combine1 = fre_combine_list_part1[Index_part1];
                            var current_flow = fre_combine1.Flow;
                            var current_power = fre_combine1.Power;
 
                            var diff_flow = Math.Abs(current_flow - target_flow);
                            if (diff_flow < total_flow_deviation)
                            {
                                optimal_combine_part1 = fre_combine1;
                                total_power = fre_combine1.Power;
                                total_flow = current_flow;
                                total_flow_deviation = diff_flow;
                            }
 
                            if (diff_flow < target_flow * 0.01 && current_power < total_power)
                            {
                                optimal_combine_part1 = fre_combine1;
                                total_power = fre_combine1.Power;
                                total_flow = current_flow;
                            }
                        }
                    }
                    else
                    {
                        for (int Index_part1 = 0; Index_part1 < fre_combine_list_part1.Count; Index_part1++)
                        {
                            for (int Index_part2 = 0; Index_part2 < fre_combine_list_part2.Count; Index_part2++)
                            {
                                var fre_combine1 = fre_combine_list_part1[Index_part1];
                                var fre_combine2 = fre_combine_list_part2[Index_part2];
 
                                var current_flow = fre_combine1.Flow + fre_combine2.Flow;
                                var current_power = fre_combine1.Power + fre_combine2.Power;
 
                                var diff_flow = Math.Abs(current_flow - target_flow);
                                if (diff_flow < total_flow_deviation)
                                {
                                    optimal_combine_part1 = fre_combine1;
                                    optimal_combine_part2 = fre_combine2;
                                    total_power = fre_combine1.Power + fre_combine2.Power;
                                    total_flow = current_flow;
                                    total_flow_deviation = diff_flow;
                                }
 
                                if (diff_flow < target_flow * 0.01 && current_power < total_power)
                                {
                                    optimal_combine_part1 = fre_combine1;
                                    optimal_combine_part2 = fre_combine2;
                                    total_power = fre_combine1.Power + fre_combine2.Power;
                                    total_flow = current_flow;
                                }
 
                            }
                        }
                    }
 
                    if (optimal_combine_part1 == null && optimal_combine_part2 == null)
                        continue;
 
                    var total_flow_deviation_ratio = Math.Abs((1 - Math.Abs((total_flow / target_flow))));
                    if (total_flow_deviation_ratio > _sel_opt_flow_deviation_ratio)
                        continue;
                    if (total_flow_deviation_ratio > _sel_opt_reasonable_flow_deviation_ratio)
                    {
                        combine_merit_ratio -= total_flow_deviation_ratio;
                    }
 
 
                    var efficiency = CurveCalcuHelper.CalculateE(total_flow, target_head, total_power);
                    var wp = CurveCalcuHelper.CalculateWP(total_power, total_flow);
                    var uwp = CurveCalcuHelper.CalculateUWP(total_power, total_flow, target_head);
 
                    #region 分析最优组合方案
 
                    var optimal_combine = new OptimalCombine();
                    optimal_combine.Combines = new List<FreCombine>();
                    optimal_combine.Flags = new List<int>();
                    if (optimal_combine_part1 != null)
                    {
                        optimal_combine.Combines.Add(optimal_combine_part1);
                        optimal_combine.Flags.AddRange(optimal_combine_part1.Flags);
                    }
                    if (optimal_combine_part2 != null)
                    {
                        optimal_combine.Combines.Add(optimal_combine_part2);
                        optimal_combine.Flags.AddRange(optimal_combine_part2.Flags);
                    }
                    optimal_combine.Flow = total_flow;
                    optimal_combine.Head = target_head;
                    optimal_combine.Power = total_power;
                    optimal_combine.Efficiency = efficiency;
                    optimal_combine.WP = wp;
                    optimal_combine.UWP = uwp;
 
                    optimal_combine.Flags = optimal_combine.Flags.OrderBy(x => x).ToList();
                    optimal_combine.FlagCount = optimal_combine.Flags.Count;
                    optimal_combine.Remark = IntListHelper.ToString(optimal_combine.Flags);
                    optimal_combine.MeritRatio = combine_merit_ratio;
                    optimal_combine_list.Add(optimal_combine);
 
                    #endregion
                }
            }
 
            if (optimal_combine_list.Count < 1)
                return default;
 
            optimal_combine_list = optimal_combine_list.OrderByDescending(x => x.MeritRatio).ToList();
            var opt = optimal_combine_list.First();
            opt.Round();
            return opt;
        }
 
 
        public string Ana(List<Pump> pumps, List<int> flags_part1, List<int> flags_part2, double target_flow, double target_head, List<int> current_open_pump_flags, List<int> must_open_pump_flags, List<int> must_not_open_pump_flags)
        {
            if (pumps == null || !pumps.Any())
            {
                return "无方案:pumps is null";
            }
            target_flow = Math.Round(target_flow, 1);
            target_head = Math.Round(target_head, 1);
 
            #region 存在-当前开泵列表
 
            var exist_current_open_pump_flags = current_open_pump_flags != null && current_open_pump_flags.Count > 0;
 
            #endregion
 
            #region 存在-必开泵列表
 
            var must_open_pump_flags_remark = string.Empty;
            var exist_must_open_pump_flags = must_open_pump_flags != null && must_open_pump_flags.Count > 0;
            if (exist_must_open_pump_flags)
            {
                must_open_pump_flags = must_open_pump_flags.OrderBy(x => x).ToList();
                must_open_pump_flags_remark = IntListHelper.ToString(must_open_pump_flags);
            }
 
            #endregion
 
            #region 存在-必不能开泵列表
 
            var exist_must_not_open_pump_flags = must_not_open_pump_flags != null && must_not_open_pump_flags.Count > 0;
 
            #endregion
 
            var pump_flag_list = pumps.Select(x => x.ID).ToList();
            var optimal_combine_list = new List<OptimalCombine>();
            for (int pumpCount = 1; pumpCount <= pumps.Count; pumpCount++)
            {
                if (pumpCount == 1)
                {
                    var max_total_flow = pumps.Max(x => x.Qr);
                    if (max_total_flow < target_flow)
                        continue;
                }
                var combine_list = PermutationAndCombination<int>.GetCombination(pump_flag_list.ToArray(), pumpCount);//排列组合
                foreach (var combine in combine_list)
                {
                    double combine_merit_ratio = 1;//组合择优率
                    if (exist_must_open_pump_flags)
                    {
                        var combine_remark = IntListHelper.ToString(combine.OrderBy(x => x));
                        if (!combine_remark.Contains(must_open_pump_flags_remark))
                            continue;
                    }
                    if (exist_must_not_open_pump_flags)
                    {
                        var exist_intersected = combine.Intersect(must_not_open_pump_flags).Count() > 0;
                        if (exist_intersected)
                            continue;
                    }
 
                    int start_stop_count = 0;//启停数量
                    if (exist_current_open_pump_flags)
                    {
                        var start_pump_count = combine.Except(current_open_pump_flags).Count();
                        var close_pump_count = current_open_pump_flags.Except(combine).Count();
                        start_stop_count = start_pump_count + close_pump_count;//启停数量 
                    }
                    else
                    {
                        start_stop_count = combine.Count();
                        if (exist_must_open_pump_flags)
                        {
                            start_stop_count = combine.Except(must_open_pump_flags).Count();
                        }
                    }
                    var total_loss_ratio = Math.Pow(_start_stop_loss_coefficient, start_stop_count);//启停一次损失些能耗
                    combine_merit_ratio *= total_loss_ratio;
 
                    List<int> combine_flag_list_part1 = new List<int>();
                    List<int> combine_flag_list_part2 = new List<int>();
                    foreach (var pump in combine)
                    {
                        if (flags_part1.Contains(pump))
                        {
                            combine_flag_list_part1.Add(pump);
                        }
                        else
                        {
                            combine_flag_list_part2.Add(pump);
                        }
                    }
 
                    //区分同型号泵
                    List<FreCombine> fre_combine_list_part1 = new List<FreCombine>();
                    List<FreCombine> fre_combine_list_part2 = new List<FreCombine>();
 
                    if (combine_flag_list_part1.Count > 0)
                    {
                        var conclusion_list_dic = new Dictionary<int, List<Entity.ScheduleConclusion>>();
                        foreach (var flag in combine_flag_list_part1)
                        {
                            var runFlag = GetGFlag(flag);
                            if (conclusion_list_dic.ContainsKey(flag))
                                continue;
                            var conclusionList = _dalScheduleConclusion.GetList(runFlag, target_head);
                            conclusion_list_dic[flag] = conclusionList;
                        }
 
                        if (conclusion_list_dic.Count < 1)
                        {
                            continue;
                        }
 
                        for (decimal fre = _frequency_max; fre >= _frequency_min; fre -= _frequency_space)
                        {
                            var freCombine = new FreCombine();
                            freCombine.Frequency = (double)fre;
                            freCombine.Flags = new List<int>();
                            foreach (var item in conclusion_list_dic)
                            {
                                var conclusion = item.Value.Find(x => x.Pump1 == (double)fre);
                                if (conclusion != null)
                                {
                                    freCombine.Flags.Add(item.Key);
                                    freCombine.Flow += conclusion.Flow;
                                    freCombine.Power += conclusion.Power;
                                    freCombine.RunCount++;
                                }
                            }
                            if (freCombine.Flags.Count < 1)
                                continue;
                            fre_combine_list_part1.Add(freCombine);
                        }
                    }
                    if (combine_flag_list_part2.Count > 0)
                    {
                        var conclusion_list_dic = new Dictionary<int, List<Entity.ScheduleConclusion>>();
                        foreach (var flag in combine_flag_list_part2)
                        {
                            var runFlag = GetGFlag(flag);
                            if (conclusion_list_dic.ContainsKey(flag))
                                continue;
                            var conclusionList = _dalScheduleConclusion.GetList(runFlag, target_head);
                            conclusion_list_dic[flag] = conclusionList;
                        }
 
                        if (conclusion_list_dic.Count < 1)
                        {
                            continue;
                        }
 
                        for (decimal fre = _frequency_max; fre >= _frequency_min; fre -= _frequency_space)
                        {
                            var freCombine = new FreCombine();
                            freCombine.Frequency = (double)fre;
                            freCombine.Flags = new List<int>();
                            foreach (var item in conclusion_list_dic)
                            {
                                var conclusion = item.Value.Find(x => x.Pump1 == (double)fre);
                                if (conclusion != null)
                                {
                                    freCombine.Flags.Add(item.Key);
                                    freCombine.Flow += conclusion.Flow;
                                    freCombine.Power += conclusion.Power;
                                    freCombine.RunCount++;
                                }
                            }
                            if (freCombine.Flags.Count < 1)
                                continue;
                            fre_combine_list_part2.Add(freCombine);
                        }
                    }
 
                    if (fre_combine_list_part1.Count == 0 && fre_combine_list_part2.Count == 0)
                        continue;
 
                    double total_flow_deviation = target_flow;//总流量偏差
                    double total_power = double.MaxValue;//总功率
                    double total_flow = double.MaxValue;//总流量
 
                    FreCombine optimal_combine_part1 = null;
                    FreCombine optimal_combine_part2 = null;
                    if (fre_combine_list_part1.Count < 1 || fre_combine_list_part2.Count < 1)
                    {
                        if (fre_combine_list_part1.Count < 1)
                        {
                            fre_combine_list_part1 = fre_combine_list_part2;
                        }
                        for (int Index_part1 = 0; Index_part1 < fre_combine_list_part1.Count; Index_part1++)
                        {
                            var fre_combine1 = fre_combine_list_part1[Index_part1];
                            var current_flow = fre_combine1.Flow;
                            var current_power = fre_combine1.Power;
 
                            var diff_flow = Math.Abs(current_flow - target_flow);
                            if (diff_flow < total_flow_deviation)
                            {
                                optimal_combine_part1 = fre_combine1;
                                total_power = fre_combine1.Power;
                                total_flow = current_flow;
                                total_flow_deviation = diff_flow;
                            }
 
                            if (diff_flow < target_flow * 0.01 && current_power < total_power)
                            {
                                optimal_combine_part1 = fre_combine1;
                                total_power = fre_combine1.Power;
                                total_flow = current_flow;
                            }
                        }
                    }
                    else
                    {
                        for (int Index_part1 = 0; Index_part1 < fre_combine_list_part1.Count; Index_part1++)
                        {
                            for (int Index_part2 = 0; Index_part2 < fre_combine_list_part2.Count; Index_part2++)
                            {
                                var fre_combine1 = fre_combine_list_part1[Index_part1];
                                var fre_combine2 = fre_combine_list_part2[Index_part2];
 
                                var current_flow = fre_combine1.Flow + fre_combine2.Flow;
                                var current_power = fre_combine1.Power + fre_combine2.Power;
 
                                var diff_flow = Math.Abs(current_flow - target_flow);
                                if (diff_flow < total_flow_deviation)
                                {
                                    optimal_combine_part1 = fre_combine1;
                                    optimal_combine_part2 = fre_combine2;
                                    total_power = fre_combine1.Power + fre_combine2.Power;
                                    total_flow = current_flow;
                                    total_flow_deviation = diff_flow;
                                }
 
                                if (diff_flow < target_flow * 0.01 && current_power < total_power)
                                {
                                    optimal_combine_part1 = fre_combine1;
                                    optimal_combine_part2 = fre_combine2;
                                    total_power = fre_combine1.Power + fre_combine2.Power;
                                    total_flow = current_flow;
                                }
 
                            }
                        }
                    }
 
                    if (optimal_combine_part1 == null && optimal_combine_part2 == null)
                        continue;
 
                    var total_flow_deviation_ratio = Math.Abs((1 - Math.Abs((total_flow / target_flow))));
                    if (total_flow_deviation_ratio > _sel_opt_flow_deviation_ratio)
                        continue;
                    if (total_flow_deviation_ratio > _sel_opt_reasonable_flow_deviation_ratio)
                    {
                        combine_merit_ratio -= total_flow_deviation_ratio;
                    }
 
 
                    #region 分析最优组合方案
 
                    var optimal_combine = new OptimalCombine();
                    optimal_combine.Combines = new List<FreCombine>();
                    optimal_combine.Flags = new List<int>();
                    if (optimal_combine_part1 != null)
                    {
                        optimal_combine.Combines.Add(optimal_combine_part1);
                        optimal_combine.Flags.AddRange(optimal_combine_part1.Flags);
                    }
                    if (optimal_combine_part2 != null)
                    {
                        optimal_combine.Combines.Add(optimal_combine_part2);
                        optimal_combine.Flags.AddRange(optimal_combine_part2.Flags);
                    }
                    optimal_combine.Flow = total_flow;
                    optimal_combine.Power = total_power;
                    optimal_combine.Flags = optimal_combine.Flags.OrderBy(x => x).ToList();
                    optimal_combine.FlagCount = optimal_combine.Flags.Count;
                    optimal_combine.Remark = IntListHelper.ToString(optimal_combine.Flags);
 
                    optimal_combine.MeritRatio = combine_merit_ratio;
                    optimal_combine.Head = target_head;
                    optimal_combine_list.Add(optimal_combine);
 
                    #endregion
                }
            }
 
            if (optimal_combine_list.Count < 1)
                return "无方案";
 
            var sb = new StringBuilder();
            optimal_combine_list = optimal_combine_list.OrderByDescending(x => x.MeritRatio).ToList();
            foreach (var opt in optimal_combine_list)
            {
                sb.AppendLine($"MeritRatio:{opt.MeritRatio.ToString("N5")},Flow:{opt.Flow.ToString("N1")},Power:{opt.Power.ToString("N1")}," +
                    $"Flags:{opt.Remark};FlowDeviation:{(opt.Flow - target_flow).ToString("N1")}");
            }
            return sb.ToString();
 
        }
 
 
        /// <summary>
        /// 插入分析日志
        /// </summary> 
        private void InsertAnaLog(string info)
        {
            var entity = new Entity.ScheduleAnaLog(info);
            _dalAnaLog.Insert(entity);
        }
 
 
        /// <summary>
        /// 判断表是否存在
        /// </summary>
        public bool ExistTable(string runFlag)
        {
            return _dal.ExistTable(runFlag);
        }
 
    }
}