using Yw.Calculation;
namespace IStation.Application
{
///
/// 调度方案
///
[Route("OpenApi/Dispatch/Solution")]
[ApiDescriptionSettings("Solution", Name = "陈行调度方案", Order = 1)]
public class DispatchSolution_Controller : IDynamicApiController
{
///
/// 计算
///
[AllowAnonymous]
[Route("Calculate@V1.0")]
[HttpPost]
[NonUnify]
public async Task 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();
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输水总压力"] = M2Mpa(optimal_combine1.Head);
foreach (var combine in optimal_combine1.Combines)
{
foreach (var pump_flag in combine.Flags)
{
output.objects[$"1输水{pump_flag}#频率"] = combine.Frequency;
}
}
}
if (optimal_combine2 != null)
{
output.objects["2输水总流量"] = optimal_combine2.Flow;
output.objects["2输水总压力"] = M2Mpa(optimal_combine2.Head);
foreach (var combine in optimal_combine2.Combines)
{
foreach (var pump_flag in combine.Flags)
{
output.objects[$"2输水{pump_flag}#频率"] = combine.Frequency;
}
}
}
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 _station_pumps1 = null;
private List _station_pumps2 = null;
///
/// 获取1输水最优调度方案
///
///
IStation.Algorithm.OptimalCombine GetOptimalCombine1(double target_flow, double target_head, List current_open_pump_flags, List must_open_pump_flags, List must_not_open_pump_flags)
{
if (_station_pumps1 == null)
{
var filePath = _data_floder + "\\" + "陈行一输.json";
var jsonInfo = File.ReadAllText(filePath);
_station_pumps1 = JsonHelper.Json2Object>(jsonInfo);
if (_station_pumps1 == null)
{
Log.Error($"文件缺失:{filePath}");
return default;
}
}
var flags_part1 = new List() { 11, 12, 13, 14, 16, 17, 18 };
var flags_part2 = new List() { 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;
}
///
/// 获取2输水最优调度方案
///
///
IStation.Algorithm.OptimalCombine GetOptimalCombine2(double target_flow, double target_head, List current_open_pump_flags, List must_open_pump_flags, List must_not_open_pump_flags)
{
if (_station_pumps2 == null)
{
var filePath = _data_floder + "\\" + "陈行二输.json";
var jsonInfo = File.ReadAllText(filePath);
_station_pumps2 = JsonHelper.Json2Object>(jsonInfo);
if (_station_pumps2 == null)
{
Log.Error($"文件缺失:{filePath}");
return default;
}
}
var flags_part1 = new List() { 22, 23, 24, 25, 26 };
var flags_part2 = new List() { 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
///
/// Mpa=>m
///
public static double Mpa2M(double mpa)
{
return mpa * ConstantParas.WaterDensity / ConstantParas.g;
}
///
/// m=>Mpa
///
public static double M2Mpa(double m)
{
return m * ConstantParas.g / ConstantParas.WaterDensity;
}
#endregion
}
}