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
using IStation.Algorithm;
using Yw.Calculation;
 
namespace IStation.Application
{
    /// <summary>
    /// 调度方案
    /// </summary>
    [Route("OpenApi/Dispatch/Solution")]
    [ApiDescriptionSettings("Solution", Name = "陈行调度方案", Order = 1)]
    public class DispatchSolution_Controller : IDynamicApiController
    {
        /// <summary>
        /// 计算
        /// </summary>
        [AllowAnonymous]
        [Route("Calculate@V1.0")]
        [HttpPost]
        [NonUnify]
        public async Task<StationDispatchOutput> Calculate([Required] StationDispatchInput input)
        {
            if (input == null)
                return null;
 
            var receipt_time = DateTime.Now;
            Log.Debug(JsonHelper.Object2Json(input));
            //获取Scada实时数据 
            //......
 
            var total_flow1 = input.objects["TotalFlow1"];
            var total_pressure1 = input.objects["TotalPressure1"];
            total_pressure1 = Mpa2M(total_pressure1);
            var total_flow2 = input.objects["TotalFlow2"];
            var total_pressure2 = input.objects["TotalPressure2"];
            total_pressure2 = Mpa2M(total_pressure2);
 
            var optimal_combine1 = GetOptimalCombine1(total_flow1, total_pressure1, null, null, null);
            var optimal_combine2 = GetOptimalCombine2(total_flow2, total_pressure2, null, null, null);
 
            var output = new StationDispatchOutput();
            output.objects = new Dictionary<string, double>();
            if (optimal_combine1 == null && optimal_combine2 == null)
            {
                output.flag = 0;
                output.message = "场内调度方案无法计算!";
                Log.Info("计算失败:场内调度方案无法计算!");
            }
            else
            {
                if (optimal_combine1 != null)
                {
                    output.objects["1输水总流量"] = optimal_combine1.Flow;
                    output.objects["1输水总压力"] = Math.Round(M2Mpa(optimal_combine1.Head), 4);
                    output.objects["1输水总功率"] = optimal_combine1.Power;
                    output.objects["1输水总效率"] = optimal_combine1.Efficiency;
                    output.objects["1输水总千吨能耗"] = optimal_combine1.WP;
                    output.objects["1输水总单位能耗"] = optimal_combine1.UWP;
                    foreach (var combine in optimal_combine1.Combines)
                    {
                        foreach (var fre_pump in combine.FrePumps)
                        {
                            var flag = fre_pump.Flag;
                            output.objects[$"1输水{flag}#流量"] = fre_pump.Flow;
                            output.objects[$"1输水{flag}#扬程"] = fre_pump.Head;
                            output.objects[$"1输水{flag}#功率"] = fre_pump.Power;
                            output.objects[$"1输水{flag}#效率"] = fre_pump.Efficiency;
                            output.objects[$"1输水{flag}#频率"] = fre_pump.Frequency;
                            output.objects[$"1输水{flag}#转速"] = fre_pump.Speed;
                        }
                    }
                }
                if (optimal_combine2 != null)
                {
                    output.objects["2输水总流量"] = optimal_combine2.Flow;
                    output.objects["2输水总压力"] = Math.Round(M2Mpa(optimal_combine2.Head), 4);
                    output.objects["2输水总功率"] = optimal_combine2.Power;
                    output.objects["2输水总效率"] = optimal_combine2.Efficiency;
                    output.objects["2输水总千吨能耗"] = optimal_combine2.WP;
                    output.objects["2输水总单位能耗"] = optimal_combine2.UWP;
                    foreach (var combine in optimal_combine2.Combines)
                    {
                        foreach (var fre_pump in combine.FrePumps)
                        {
                            var flag = fre_pump.Flag;
                            output.objects[$"2输水{flag}#流量"] = fre_pump.Flow;
                            output.objects[$"2输水{flag}#扬程"] = fre_pump.Head;
                            output.objects[$"2输水{flag}#功率"] = fre_pump.Power;
                            output.objects[$"2输水{flag}#效率"] = fre_pump.Efficiency;
                            output.objects[$"2输水{flag}#频率"] = fre_pump.Frequency;
                            output.objects[$"2输水{flag}#转速"] = fre_pump.Speed;
                        }
                    }
                }
                output.flag = 1;
                Log.Info("计算成功!");
            }
 
            output.ReceiptTime = receipt_time;
            output.ReturnTime = DateTime.Now;
            return output;
        }
 
 
        private string _data_floder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Data");
        private List<IStation.Model.Pump> _station_pumps1 = null;
        private List<IStation.Model.Pump> _station_pumps2 = null;
 
        /// <summary>
        /// 获取1输水最优调度方案
        /// </summary>
        /// <returns></returns>
        IStation.Algorithm.OptimalCombine GetOptimalCombine1(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 (_station_pumps1 == null)
            {
                var filePath = _data_floder + "\\" + "陈行一输.json";
                var jsonInfo = File.ReadAllText(filePath);
                _station_pumps1 = JsonHelper.Json2Object<List<Model.Pump>>(jsonInfo);
                if (_station_pumps1 == null)
                {
                    Log.Error($"文件缺失:{filePath}");
                    return default;
                }
            }
 
            var flags_part1 = new List<int>() { 11, 12, 13, 14, 16, 17, 18 };
            var flags_part2 = new List<int>() { 15 };
 
            var helper = new Algorithm.SchedulingHelper();
            var optimal_combine = helper.AnaOptimalCombine(_station_pumps1, flags_part1, flags_part2, target_flow, target_head, current_open_pump_flags, must_open_pump_flags, must_not_open_pump_flags);
            if (optimal_combine == null)
            {
                Log.Error($"一输水方案计算失败: optimal_combine1 is null");
            }
            return optimal_combine;
        }
 
        /// <summary>
        /// 获取2输水最优调度方案
        /// </summary>
        /// <returns></returns>
        IStation.Algorithm.OptimalCombine GetOptimalCombine2(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 (_station_pumps2 == null)
            {
                var filePath = _data_floder + "\\" + "陈行二输.json";
                var jsonInfo = File.ReadAllText(filePath);
                _station_pumps2 = JsonHelper.Json2Object<List<Model.Pump>>(jsonInfo);
                if (_station_pumps2 == null)
                {
                    Log.Error($"文件缺失:{filePath}");
                    return default;
                }
            }
 
            var flags_part1 = new List<int>() { 22, 23, 24, 25, 26 };
            var flags_part2 = new List<int>() { 21, 27 };
 
            var helper = new Algorithm.SchedulingHelper();
            var optimal_combine = helper.AnaOptimalCombine(_station_pumps2, flags_part1, flags_part2, target_flow, target_head, current_open_pump_flags, must_open_pump_flags, must_not_open_pump_flags);
            if (optimal_combine == null)
            {
                Log.Error($"二输水方案计算失败: optimal_combine1 is null");
            }
            return optimal_combine;
        }
 
 
        #region Mpa<=>m
 
        /// <summary>
        /// Mpa=>m
        /// </summary>
        public static double Mpa2M(double mpa)
        {
            return mpa * ConstantParas.WaterDensity / ConstantParas.g;
        }
 
        /// <summary>
        /// m=>Mpa
        /// </summary>
        public static double M2Mpa(double m)
        {
            return m * ConstantParas.g / ConstantParas.WaterDensity;
        }
 
        #endregion
 
    }
}