ningshuxia
2024-04-30 d63b83c2c745c1f8a140221c28c0e6dbe61d6110
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
using IStation.Model;
 
namespace IStation.Algorithm
{
 
    #region ViewModel
 
    /// <summary>
    /// 分析泵项
    /// </summary>
    public class Combine
    {
        public Combine() { }
        public List<int> PumpIds { get; set; }
        public string RunFlag { get; set; }
        public int RunCount { get; set; }
        public double Frequency { get; set; }
        public double Flow { get; set; }
        public double Head { get; set; }
        public double Power { get; set; }
    }
 
 
 
    /// <summary>
    /// 分析泵项
    /// </summary>
    public class OptimalCombine
    {
        public OptimalCombine() { }
        public List<int> PumpIds { get; set; }
        public double Flow { get; set; }
        public double Head { get; set; }
        public double Power { get; set; }
        public List<Combine> Combines { get; set; }
    }
 
    #endregion
 
    /// <summary>
    /// 调度分析辅助类
    /// </summary>
    public class SchedulingHelper
    {
        double _frequency_def = 50;
        double _frequency_min = 25;
        double _frequency_max = 50;
        double _frequency_space = 0.1;//频率间隔  
 
        double _head_space = 0.1;//扬程间隔
 
        #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();
 
 
        private List<int> _combineFlags1 = new List<int>() { 11, 12, 13, 14, 16, 17, 18 };
        private List<int> _combineFlags2 = new List<int>() { 15 };
 
        public void Ana(List<Pump> pumps, double tagetFlow, double tagetHead, List<int> openPumpCombine)
        {
            List<int> open_combine_flags_1 = new List<int>();
            List<int> open_combine_flags_2 = new List<int>();
 
            if (openPumpCombine != null && openPumpCombine.Any())
            {
                foreach (var pump in openPumpCombine)
                {
                    if (_combineFlags1.Contains(pump))
                    {
                        open_combine_flags_1.Add(pump);
                    }
                    else
                    {
                        open_combine_flags_2.Add(pump);
                    }
                }
            }
            else
            {
                open_combine_flags_1 = _combineFlags1.ToList();
                open_combine_flags_2 = _combineFlags2.ToList();
            }
 
            List<Combine> combineList1 = null;
            List<Combine> combineList2 = null;
 
            var open_combine_flags_1_count = open_combine_flags_1.Count;
            if (open_combine_flags_1_count > 0)
            {
                bool isSingular = false;
                var combine_flags_combination_list = PermutationAndCombination<int>.GetCombination(open_combine_flags_1.ToArray(), 2);
                if ((open_combine_flags_1_count % 2) > 0)
                {
                    isSingular = true;
                    foreach (var flag in open_combine_flags_1)
                    {
                        combine_flags_combination_list.Add(new int[] { flag });
                    }
                }
 
                var combine_conclusion_dic = new Dictionary<string, List<Entity.ScheduleConclusion>>();
                foreach (var combine_flags in combine_flags_combination_list)
                {
                    var runFlag = GetRunFlag(combine_flags);
                    if (combine_conclusion_dic.ContainsKey(runFlag))
                        continue;
                    var conclusionList = _dalScheduleConclusion.GetList(runFlag, tagetHead);
                    combine_conclusion_dic[runFlag] = conclusionList;
                }
 
                if (combine_conclusion_dic.Count < 1)
                {
                    ////无法计算
                    //return;
                }
 
                var combine_flags_permutation_list = PermutationAndCombination<int>.GetPermutation(open_combine_flags_1.ToArray());
                foreach (var combine_flags_permutation in combine_flags_permutation_list)
                {
                    var combine_part_flags_list = new List<int[]>();
                    for (int i = 0; i < combine_flags_permutation.Length / 2; i++)
                    {
                        var flags = combine_flags_permutation.Skip(i * 2).Take(2).ToArray();
                        combine_part_flags_list.Add(flags);
                    }
                    if (isSingular)
                    {
                        var last_flag = combine_flags_permutation[combine_flags_permutation.Length - 1];
                        combine_part_flags_list.Add(new int[] { last_flag });
                    }
                    if (combine_part_flags_list.Count < 1)
                        continue;
 
 
                    List<Combine> combines = new List<Combine>();
                    foreach (var combine_part_flags in combine_part_flags_list)
                    {
                        var runFlag = GetRunFlag(combine_part_flags);
 
                    }
 
 
                }
 
 
            }
 
        }
 
 
 
 
        private OptimalCombine AnaOptimalCombine(List<Combine> combineList1, List<Combine> combineList2, double targetFlow, double targetHead)
        {
            double flowDeviation = targetFlow;
            double totalPower = double.MaxValue;
            double totalFlow = double.MaxValue;
 
            Combine optimalCombine1 = null;
            Combine optimalCombine2 = null;
            for (int combineIndex1 = 0; combineIndex1 < combineList1.Count; combineIndex1++)
            {
                for (int combineIndex2 = 0; combineIndex2 < combineList2.Count; combineIndex2++)
                {
                    var combine1 = combineList1[combineIndex1];
                    var combine2 = combineList2[combineIndex2];
 
                    var combineTotalFlow = combine1.Flow + combine2.Flow;
                    var combineTotalPower = combine1.Power + combine2.Power;
 
                    var diffFlow = Math.Abs(combineTotalFlow - targetFlow);
                    if (diffFlow < flowDeviation)
                    {
                        optimalCombine1 = combine1;
                        optimalCombine2 = combine2;
                        totalPower = combine1.Power + combine2.Power;
                        totalFlow = combineTotalFlow;
                        flowDeviation = diffFlow;
                    }
 
                    if (diffFlow < targetFlow * 0.01 && combineTotalPower < totalPower)
                    {
                        optimalCombine1 = combine1;
                        optimalCombine2 = combine2;
                        totalPower = combine1.Power + combine2.Power;
                        totalFlow = combineTotalFlow;
                    }
 
                }
            }
            if (optimalCombine1 == null && optimalCombine2 == null)
                return default;
            var optimalCombine = new OptimalCombine();
            optimalCombine.Combines = new List<Combine>();
            if (optimalCombine1 != null)
            {
                optimalCombine.Combines.Add(optimalCombine1);
            }
            if (optimalCombine2 != null)
            {
                optimalCombine.Combines.Add(optimalCombine2);
            }
            optimalCombine.Flow = totalFlow;
            optimalCombine.Power = totalPower;
            return optimalCombine;
        }
 
        /// <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);
        }
 
    }
}