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
|
|
}
|
}
|