using IStation.Algorithm;
using System.Collections.Generic;
using System.Diagnostics;
using Yw.Untity;
namespace IStation
{
///
/// 调度分析辅助类
///
public partial class ScheduleHelper_Update
{
readonly decimal _frequency_min = 25;
readonly decimal _frequency_max = 50;
readonly decimal _frequency_space = 0.1m;//频率间隔
readonly double _start_stop_loss_coefficient = 0.95;//泵启停损失系数
readonly double _sel_opt_flow_deviation_ratio = 0.05;//可选方案的流量偏差比
readonly double _sel_opt_reasonable_flow_deviation_ratio = 0.005;//合理的方案的流量偏差比
readonly Service.AnalysisCombine _service_analysis_combine = new();
readonly Service.AnalysisConclusion _service_analysis_conclusion = new();
readonly Service.AnalysisLog _service_analysis_log = new();
int _min_open_count;
int _max_open_count;
List _current_open_flag_list = null;// 当前开泵列表
List _must_open_flag_list = null; // 必开泵列表
List _must_close_flag_list = null; // 必关泵列表
List> _forbidden_flag_combine_list = null; // 禁用泵组合
List> _associative_flag_combine_list = null; // 关联泵组合
List> _same_section_flag_combine_list = null; // 同段泵组合
List _water_supply_limit_list = null; //供水限制列表
List _frequency_limit_list = null; // 频率限制列表
///
/// 初始化
///
public void Initial(List current_open_flag_list, Model.ScheduleConfig schedule_config)
{
_min_open_count = schedule_config.MinOpenCount;
_max_open_count = schedule_config.MaxOpenCount;
_current_open_flag_list = current_open_flag_list;
_must_open_flag_list = null;
_must_close_flag_list = null;
_forbidden_flag_combine_list = null;
_associative_flag_combine_list = null;
_same_section_flag_combine_list = null;
_water_supply_limit_list = null;
_frequency_limit_list = null;
if (schedule_config != null)
{
_must_open_flag_list = schedule_config.MustOpenFlagList;
_must_close_flag_list = schedule_config.MustCloseFlagList;
_forbidden_flag_combine_list = schedule_config.ForbiddenFlagCombineList;
_associative_flag_combine_list = schedule_config.AssociativeFlagCombineList;
_same_section_flag_combine_list = schedule_config.SameSectionFlagCombineList;
_water_supply_limit_list = schedule_config.WaterSupplyLimitList;
_frequency_limit_list = schedule_config.FrequencyLimitList;
}
}
///
/// 计算(待修改 进口水位 和频率)
///
///
///
///
///
///
///
public AnaOptimalCombine Calc(List pump_list, List same_type_flag_group_first, Dictionary flag_inlet_water_level_dict, double target_flow, double target_head)
{
var min_open_count = _min_open_count;
var max_open_count = _max_open_count;
var current_open_flag_list = _current_open_flag_list;
var must_open_flag_list = _must_open_flag_list;
var must_close_flag_list = _must_close_flag_list;
var forbidden_flag_combine_list = _forbidden_flag_combine_list;
var associative_flag_combine_list = _associative_flag_combine_list;
var same_section_flag_combine_list = _same_section_flag_combine_list;
var water_supply_limit_list = _water_supply_limit_list;
var frequency_limit_list = _frequency_limit_list;
if (pump_list == null || !pump_list.Any())
{
return default;
}
target_flow = Math.Round(target_flow, 1);
target_head = Math.Round(target_head, 1);
#region 存在-当前开泵列表
var exist_current_open_flag_list = current_open_flag_list != null && current_open_flag_list.Count > 0;
#endregion
#region 存在-必开泵列表
var must_open_flag_list_remark = string.Empty;
var exist_must_open_flag_list = must_open_flag_list != null && must_open_flag_list.Count > 0;
if (exist_must_open_flag_list)
{
must_open_flag_list = must_open_flag_list.OrderBy(x => x).ToList();
must_open_flag_list_remark = IntListHelper.ToString(must_open_flag_list);
}
#endregion
#region 存在-必关泵列表
var exist_must_close_flag_list = must_close_flag_list != null && must_close_flag_list.Count > 0;
#endregion
#region 存在-禁用组合
var exist_forbidden_flag_combine_list = forbidden_flag_combine_list != null && forbidden_flag_combine_list.Count > 0;
#endregion
#region 存在-关联组合
var exist_associative_flag_combine_list = associative_flag_combine_list != null && associative_flag_combine_list.Count > 0;
#endregion
#region 存在-同段泵组合
Dictionary> same_section_combine_dict = new();
var exist_same_section_flag_combine_list = _same_section_flag_combine_list != null && _same_section_flag_combine_list.Count > 0;
if (exist_same_section_flag_combine_list)
{
for (int pump_count = 1; pump_count <= pump_list.Count; pump_count++)
{
same_section_combine_dict[pump_count] = new List();
switch (pump_count)
{
case 2:
{
foreach (var same_section_flag_combine in same_section_flag_combine_list)
{
var combine_list = GetCombineList(same_section_flag_combine, 2);
same_section_combine_dict[pump_count].AddRange(combine_list);
}
}
break;
case 3:
{
foreach (var same_section in same_section_flag_combine_list)
{
var combine_list = GetCombineList(same_section, 3);
same_section_combine_dict[pump_count].AddRange(combine_list);
}
}
break;
case 4:
{
foreach (var same_section in same_section_flag_combine_list)
{
var combine_list3 = GetCombineList(same_section, 3);
same_section_combine_dict[pump_count].AddRange(combine_list3);
if (same_section.Count > 3)
{
var combine_list = GetCombineList(same_section, 4);
same_section_combine_dict[pump_count].AddRange(combine_list);
}
}
}
break;
case 5:
{
foreach (var same_section in same_section_flag_combine_list)
{
if (same_section.Count > 3)
{
var combine_list = GetCombineList(same_section, 4);
same_section_combine_dict[pump_count].AddRange(combine_list);
}
}
}
break;
case 6:
{
foreach (var same_section in same_section_flag_combine_list)
{
if (same_section.Count > 3)
{
var combine_list = GetCombineList(same_section, 4);
same_section_combine_dict[pump_count].AddRange(combine_list);
}
}
}
break;
default:
break;
}
}
}
#endregion
#region 存在-供水限制
var exist_water_supply_limit_list = water_supply_limit_list != null && water_supply_limit_list.Count > 0;
#endregion
#region 存在-频率限制
var frequency_limit_flag_dict = new Dictionary();
var exist_frequency_limit_list = frequency_limit_list != null && frequency_limit_list.Count > 0;
if (exist_frequency_limit_list)
{
frequency_limit_flag_dict = frequency_limit_list.ToDictionary(x => x.Flag, x => x);
}
#endregion
#region 存在-优先度排序 暂未考虑
// var exist_priority_order_flag_list = priority_order_flag_list != null && priority_order_flag_list.Count > 0;
#endregion
var pump_bp_dict = pump_list.ToDictionary(x => x.Flag, x => x.IsBp);
var pump_nr_dict = pump_list.ToDictionary(x => x.Flag, x => x.Nr);
var pump_flag_list = pump_list.Select(x => x.Flag).ToList();
var optimal_combine_list = new List();
for (int pumpCount = _min_open_count; pumpCount <= _max_open_count; pumpCount++)
{
if (pumpCount == 1)
{
var max_total_flow = pump_list.Max(x => x.Qr);
if (max_total_flow < target_flow)
continue;
}
//供水限制
if (exist_water_supply_limit_list)
{
var exist_limit = false;
foreach (var limit in water_supply_limit_list)
{
if (target_flow >= limit.Min && target_flow <= limit.Max)
{
if (limit.PumpCount != pumpCount)
{
exist_limit = true;
break;
}
}
}
if (exist_limit)
continue;
}
var combine_list = GetCombineList(pump_flag_list, pumpCount);//排列组合
foreach (var combine in combine_list)
{
double combine_merit_ratio = 1;//组合择优率
//必开
if (exist_must_open_flag_list)
{
var combine_remark = IntListHelper.ToString(combine.OrderBy(x => x));
if (!combine_remark.Contains(must_open_flag_list_remark))
continue;
}
//必关
if (exist_must_close_flag_list)
{
var exist_intersected = combine.Intersect(must_close_flag_list).Count() > 0;
if (exist_intersected)
continue;
}
//禁用组合
if (exist_forbidden_flag_combine_list)
{
var exist_equal = false;
foreach (var flag_list in forbidden_flag_combine_list)
{
if (combine.SequenceEqual(flag_list))
{
exist_equal = true;
break;
}
}
if (exist_equal)
continue;
}
//同段泵组合
if (exist_same_section_flag_combine_list)
{
var exist_equal = false;
foreach (var flag_list in same_section_combine_dict[pumpCount])
{
//相同
if (combine.SequenceEqual(flag_list))
{
exist_equal = true;
break;
}
//包含
if (flag_list.Intersect(combine).Count() == flag_list.Length)
{
exist_equal = true;
break;
}
}
if (exist_equal)
continue;
}
//关联组合
if (exist_associative_flag_combine_list)
{
var exist_intersected = false;
foreach (var flag_list in associative_flag_combine_list)
{
var except_count = combine.Except(flag_list).Count();
if (except_count != flag_list.Count && except_count > 0)
{
exist_intersected = true;
}
}
if (exist_intersected)
continue;
}
int start_stop_count = 0;//启停数量
if (exist_current_open_flag_list)
{
var start_pump_count = combine.Except(current_open_flag_list).Count();
var close_pump_count = current_open_flag_list.Except(combine).Count();
start_stop_count = start_pump_count + close_pump_count;//启停数量
}
else
{
start_stop_count = combine.Count();
if (exist_must_open_flag_list)
{
start_stop_count = combine.Except(must_open_flag_list).Count();
}
}
var total_loss_ratio = Math.Pow(_start_stop_loss_coefficient, start_stop_count);//启停一次损失些能耗
combine_merit_ratio *= total_loss_ratio;
var combine_correction_factor_dict = GetCombineCorrectionFactor(combine); //获取组合修正系数
var is_ok = true;
var conclusion_list_dic = new Dictionary>();
foreach (var flag in combine)
{
var runFlag = RunFlagHelper.GetRunFlag(flag, pump_bp_dict[flag]);
if (conclusion_list_dic.ContainsKey(flag))
continue;
//进口水位
var inlet_water_level = flag_inlet_water_level_dict[flag];
//组合修正系数
var combine_correction_factor = combine_correction_factor_dict[flag];
var current_target_head = target_head - inlet_water_level + combine_correction_factor;
current_target_head = Math.Round(current_target_head, 1);
//频率限制
var conclusionList = new List();
if (exist_frequency_limit_list && frequency_limit_flag_dict.ContainsKey(flag))
{
var limit = frequency_limit_flag_dict[flag];
conclusionList = _service_analysis_conclusion.GetList(runFlag, limit.Min, limit.Max, current_target_head);
}
else
{
conclusionList = _service_analysis_conclusion.GetList(runFlag, current_target_head);
}
conclusion_list_dic[flag] = conclusionList;
if (conclusionList==null|| !conclusionList.Any())
{
is_ok = false;
}
}
if (!is_ok)
{
continue;
}
var max_supply_flow = conclusion_list_dic.Sum(x => x.Value.Max(c => c.Flow));
if (max_supply_flow < target_flow * 0.99)
{
continue;
}
AnaFreCombine optimal_combine_part1 = null;
if (pumpCount == 3)
{
optimal_combine_part1 = AddAnaFreCombine(target_flow, conclusion_list_dic, pump_nr_dict);
}
else if (pumpCount == 4)
{
optimal_combine_part1 = AddAnaFreCombine(target_flow, conclusion_list_dic, pump_nr_dict);
}
else if (pumpCount == 5)
{
optimal_combine_part1 = AddAnaFreCombine(target_flow, conclusion_list_dic, pump_nr_dict);
}
else
{
continue;
}
if (optimal_combine_part1 == null)
continue;
var total_flow = optimal_combine_part1.Flow;
var total_power = optimal_combine_part1.Power;
if (total_flow < target_flow * 0.99)
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 actual_target_head = target_head;
var inlet_water_head = flag_inlet_water_level_dict.Average(x => x.Value);
if (inlet_water_head > 0)
{
actual_target_head = target_head - inlet_water_head;
actual_target_head = Math.Round(actual_target_head, 2);
}
var efficiency = Curve.PumpCalculateHelper.CalculateE(total_flow, actual_target_head, total_power);
var wp = Curve.PumpCalculateHelper.CalculateWP(total_power, total_flow);
var uwp = Curve.PumpCalculateHelper.CalculateUWP(total_power, total_flow, actual_target_head);
#region 分析最优组合方案
var optimal_combine = new AnaOptimalCombine();
optimal_combine.Combines = new List();
optimal_combine.Flags = new List();
if (optimal_combine_part1 != null)
{
optimal_combine.Combines.Add(optimal_combine_part1);
optimal_combine.Flags.AddRange(optimal_combine_part1.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;
}
///
/// 获取排列组合
///
///
///
///
private List GetCombineList(List flags, int count)
{
var combine = IStation.Curve.PermutationAndCombination.GetCombination(flags.ToArray(), count);
return combine;
}
///
/// 获取组合修正系数
///
///
///
private Dictionary GetCombineCorrectionFactor(IEnumerable flags)
{
var correction_factor_dict = new Dictionary();
var r = new Random(0);
foreach (var flag in flags)
{
double factor = 0;
//factor += r.NextDouble();
correction_factor_dict.Add(flag, factor);
}
return correction_factor_dict;
}
private double _fre_diff_value = 2;
private bool IsFrequencyDiffTooLarge(IEnumerable frequency_list)
{
if (frequency_list == null || !frequency_list.Any())
return true;
var max_frequency = frequency_list.Max();
var min_frequency = frequency_list.Min();
var diff_frequency = Math.Round(max_frequency - min_frequency, 1);
return diff_frequency > _fre_diff_value;
}
private class AnalysisConclusionEx : Model.AnalysisConclusion
{
public AnalysisConclusionEx() { }
public AnalysisConclusionEx(Model.AnalysisConclusion rhs) : base(rhs) { }
public AnalysisConclusionEx(Model.AnalysisConclusion rhs, int flag) : base(rhs)
{
this.Flag = flag;
}
public int Flag { get; set; }
}
#region 添加项目 只有N台变频泵:AddAnaFreCombine
private AnaFreCombine AddAnaFreCombine(double target_flow, Dictionary> conclusion_list_dic, Dictionary pump_nr_dict)
{
var list_group_temp = new List>();
foreach (var item in conclusion_list_dic)
{
var list = new List();
foreach (var item_cl in item.Value)
{
list.Add(new AnalysisConclusionEx(item_cl, item.Key));
}
list_group_temp.Add(list);
}
var lst_fre_group_temp= new List>>();
var fre_min= (double)_frequency_min;
var fre_max= (double)_frequency_max;
var fre_diff = _fre_diff_value;
for (double fre_this = fre_min; fre_this <= fre_max; fre_this++)
{
var fre_max_ = fre_this + fre_diff;
var gr = new List>();
var skip_this = false;
double total_flow = 0;
foreach (var item in list_group_temp)
{
var cl_fr_list = item.Where(x => x.Pump1 <= fre_max_ && x.Pump1 >= fre_this).ToList();
if (cl_fr_list == null || !cl_fr_list.Any())
{
skip_this = true;
break;
}
total_flow += cl_fr_list.Max(x => x.Flow);
gr.Add(cl_fr_list);
}
if (skip_this)
continue;
if (total_flow < target_flow)
continue;
lst_fre_group_temp.Add(gr);
}
var lst_ls = lst_fre_group_temp;
if (lst_ls==null|| !lst_ls.Any())
{
return default;
}
foreach (var item in lst_ls)
{
var sw1 = new Stopwatch();
sw1.Start();
var lst_CartesianProduct = CartesianProduct(target_flow, item);
var top_first = lst_CartesianProduct.OrderBy(x => x.Sum(x => x.Power)).First();
var b_s = sw1.Elapsed;
var sw = new Stopwatch();
sw.Start();
var top = CartesianProduct_Top(target_flow,item);
var a_s = sw.Elapsed;
var c_s = b_s- a_s;
var d = c_s;
}
return new AnaFreCombine() ;
}
///
/// 笛卡尔乘积
///
private List CartesianProduct_Top(double target_flow, List> lstSplit)
{
long count = 1;
lstSplit.ForEach(item => count *= item.Count);
//count = lstSplit.Aggregate(1, (result, next) => result * next.Count);
double total_flow_deviation = target_flow;//总流量偏差
double total_power = double.MaxValue;//总功率
double total_flow = double.MaxValue;//总流量
var lstResult = new List();
for (long i = 0; i < count; ++i)
{
var lstTemp = new List();
long j = 1;
var lstFre = new List();
double current_flow = 0;
double current_power = 0;
lstSplit.ForEach(item =>
{
j *= item.Count;
var index = (i / (count / j)) % item.Count;
var index_int = (int)index;
var obj = item[index_int];
current_flow += obj.Flow;
current_power += obj.Power;
lstTemp.Add(obj);
});
if (current_flow < target_flow)
continue;
var diff_flow = Math.Abs(current_flow - target_flow);
if (diff_flow < total_flow_deviation)
{
lstResult = lstTemp;
total_flow = current_flow;
total_flow_deviation = diff_flow;
}
if (diff_flow < target_flow * 0.01 && current_power < total_power)
{
lstResult = lstTemp;
total_power = current_power;
total_flow = current_flow;
}
}
return lstResult;
}
///
/// 笛卡尔乘积
///
private List> CartesianProduct(double target_flow, List> lstSplit)
{
long count = 1;
lstSplit.ForEach(item => count *= item.Count);
//count = lstSplit.Aggregate(1, (result, next) => result * next.Count);
var lstResult = new List>();
for (long i = 0; i < count; ++i)
{
var lstTemp = new List();
long j = 1;
var lstFre = new List();
double totalFlow = 0;
lstSplit.ForEach(item =>
{
j *= item.Count;
var index = (i / (count / j)) % item.Count;
var index_int = (int)index;
var obj = item[index_int];
totalFlow += obj.Flow;
lstTemp.Add(obj);
});
if (totalFlow < target_flow)
continue;
lstResult.Add(lstTemp);
}
return lstResult;
}
#endregion
#region 添加项目 只有3台变频泵:AddAnaFreCombine
private AnaFreCombine AddAnaFreCombine3(double target_flow, Dictionary> conclusion_list_dic, Dictionary pump_nr_dict)
{
var ana_cl_item1 = conclusion_list_dic.ElementAt(0);
var ana_cl_item2 = conclusion_list_dic.ElementAt(1);
var ana_cl_item3 = conclusion_list_dic.ElementAt(2);
var ana_pump1_flag = ana_cl_item1.Key;
var ana_pump2_flag = ana_cl_item2.Key;
var ana_pump3_flag = ana_cl_item3.Key;
var ana_cl_list_pump1 = ana_cl_item1.Value;
var ana_cl_list_pump2 = ana_cl_item2.Value;
var ana_cl_list_pump3 = ana_cl_item3.Value;
double total_flow_deviation = target_flow;//总流量偏差
double total_power = double.MaxValue;//总功率
double total_flow = double.MaxValue;//总流量
Model.AnalysisConclusion opt_cl_pump1 = null;
Model.AnalysisConclusion opt_cl_pump2 = null;
Model.AnalysisConclusion opt_cl_pump3 = null;
for (int Index_pump1 = 0; Index_pump1 < ana_cl_list_pump1.Count; Index_pump1++)
{
for (int Index_pump2 = 0; Index_pump2 < ana_cl_list_pump2.Count; Index_pump2++)
{
for (int Index_pump3 = 0; Index_pump3 < ana_cl_list_pump3.Count; Index_pump3++)
{
var cl_pump1 = ana_cl_list_pump1[Index_pump1];
var cl_pump2 = ana_cl_list_pump2[Index_pump2];
var cl_pump3 = ana_cl_list_pump3[Index_pump3];
var frequency_list = new List()
{
cl_pump1.Pump1,
cl_pump2.Pump1,
cl_pump3.Pump1
};
if (IsFrequencyDiffTooLarge(frequency_list))
continue;
var current_flow = cl_pump1.Flow + cl_pump2.Flow + cl_pump3.Flow;
var current_power = cl_pump1.Power + cl_pump2.Power + cl_pump3.Power;
if (current_flow < target_flow * 0.95)
continue;
var diff_flow = Math.Abs(current_flow - target_flow);
if (diff_flow < total_flow_deviation)
{
opt_cl_pump1 = cl_pump1;
opt_cl_pump2 = cl_pump2;
opt_cl_pump3 = cl_pump3;
total_power = cl_pump1.Power + cl_pump2.Power + cl_pump3.Power;
total_flow = current_flow;
total_flow_deviation = diff_flow;
}
if (diff_flow < target_flow * 0.01 && current_power < total_power)
{
opt_cl_pump1 = cl_pump1;
opt_cl_pump2 = cl_pump2;
opt_cl_pump3 = cl_pump3;
total_power = cl_pump1.Power + cl_pump2.Power + cl_pump3.Power;
total_flow = current_flow;
}
}
}
}
var opt_cl_dict = new Dictionary()
{
{ ana_pump1_flag,opt_cl_pump1},
{ ana_pump2_flag,opt_cl_pump2},
{ ana_pump3_flag,opt_cl_pump3}
};
var fre_combine = new AnaFreCombine();
fre_combine.Frequency = 0;
fre_combine.Flags = new List();
fre_combine.FrePumps = new List();
foreach (var item in opt_cl_dict)
{
var flag = item.Key;
var cl = item.Value;
fre_combine.Flags.Add(flag);
fre_combine.Flow += cl.Flow;
fre_combine.Power += cl.Power;
fre_combine.RunCount++;
var fre_pump = new AnaFrePump();
fre_pump.Flag = flag;
fre_pump.Flow = cl.Flow;
fre_pump.Head = cl.Head;
fre_pump.Power = cl.Power;
fre_pump.Efficiency = Curve.PumpCalculateHelper.CalculateE(fre_pump.Flow, fre_pump.Head, fre_pump.Power);
fre_pump.Frequency = fre_combine.Frequency;
fre_pump.Speed = cl.Pump1 / 50 * pump_nr_dict[item.Key];
fre_combine.FrePumps.Add(fre_pump);
}
return fre_combine;
}
#endregion
#region 添加项目 只有4台变频泵:AddAnaFreCombine
private AnaFreCombine AddAnaFreCombine4(double target_flow, Dictionary> conclusion_list_dic, Dictionary pump_nr_dict)
{
var ana_cl_item1 = conclusion_list_dic.ElementAt(0);
var ana_cl_item2 = conclusion_list_dic.ElementAt(1);
var ana_cl_item3 = conclusion_list_dic.ElementAt(2);
var ana_cl_item4 = conclusion_list_dic.ElementAt(3);
var ana_pump1_flag = ana_cl_item1.Key;
var ana_pump2_flag = ana_cl_item2.Key;
var ana_pump3_flag = ana_cl_item3.Key;
var ana_pump4_flag = ana_cl_item4.Key;
var ana_cl_list_pump1 = ana_cl_item1.Value;
var ana_cl_list_pump2 = ana_cl_item2.Value;
var ana_cl_list_pump3 = ana_cl_item3.Value;
var ana_cl_list_pump4 = ana_cl_item4.Value;
double total_flow_deviation = target_flow;//总流量偏差
double total_power = double.MaxValue;//总功率
double total_flow = double.MaxValue;//总流量
Model.AnalysisConclusion opt_cl_pump1 = null;
Model.AnalysisConclusion opt_cl_pump2 = null;
Model.AnalysisConclusion opt_cl_pump3 = null;
Model.AnalysisConclusion opt_cl_pump4 = null;
for (int Index_pump1 = 0; Index_pump1 < ana_cl_list_pump1.Count; Index_pump1++)
{
for (int Index_pump2 = 0; Index_pump2 < ana_cl_list_pump2.Count; Index_pump2++)
{
for (int Index_pump3 = 0; Index_pump3 < ana_cl_list_pump3.Count; Index_pump3++)
{
for (int Index_pump4 = 0; Index_pump4 < ana_cl_list_pump4.Count; Index_pump4++)
{
var cl_pump1 = ana_cl_list_pump1[Index_pump1];
var cl_pump2 = ana_cl_list_pump2[Index_pump2];
var cl_pump3 = ana_cl_list_pump3[Index_pump3];
var cl_pump4 = ana_cl_list_pump4[Index_pump4];
var frequency_list = new List()
{
cl_pump1.Pump1,
cl_pump2.Pump1,
cl_pump3.Pump1,
cl_pump4.Pump1
};
if (IsFrequencyDiffTooLarge(frequency_list))
continue;
var current_flow = cl_pump1.Flow + cl_pump2.Flow + cl_pump3.Flow + cl_pump4.Flow;
if (current_flow < target_flow * 0.95)
continue;
var current_power = cl_pump1.Power + cl_pump2.Power + cl_pump3.Power + cl_pump4.Power;
var diff_flow = Math.Abs(current_flow - target_flow);
if (diff_flow < total_flow_deviation)
{
opt_cl_pump1 = cl_pump1;
opt_cl_pump2 = cl_pump2;
opt_cl_pump3 = cl_pump3;
opt_cl_pump4 = cl_pump4;
total_power = cl_pump1.Power + cl_pump2.Power + cl_pump3.Power + cl_pump4.Power;
total_flow = current_flow;
total_flow_deviation = diff_flow;
}
if (diff_flow < target_flow * 0.01 && current_power < total_power)
{
opt_cl_pump1 = cl_pump1;
opt_cl_pump2 = cl_pump2;
opt_cl_pump3 = cl_pump3;
opt_cl_pump4 = cl_pump4;
total_power = cl_pump1.Power + cl_pump2.Power + cl_pump3.Power + cl_pump4.Power;
total_flow = current_flow;
}
}
}
}
}
var opt_cl_dict = new Dictionary()
{
{ ana_pump1_flag,opt_cl_pump1},
{ ana_pump2_flag,opt_cl_pump2},
{ ana_pump3_flag,opt_cl_pump3},
{ ana_pump4_flag,opt_cl_pump4},
};
var fre_combine = new AnaFreCombine();
fre_combine.Frequency = 0;
fre_combine.Flags = new List();
fre_combine.FrePumps = new List();
foreach (var item in opt_cl_dict)
{
var flag = item.Key;
var cl = item.Value;
fre_combine.Flags.Add(flag);
fre_combine.Flow += cl.Flow;
fre_combine.Power += cl.Power;
fre_combine.RunCount++;
var fre_pump = new AnaFrePump();
fre_pump.Flag = flag;
fre_pump.Flow = cl.Flow;
fre_pump.Head = cl.Head;
fre_pump.Power = cl.Power;
fre_pump.Efficiency = Curve.PumpCalculateHelper.CalculateE(fre_pump.Flow, fre_pump.Head, fre_pump.Power);
fre_pump.Frequency = fre_combine.Frequency;
fre_pump.Speed = cl.Pump1 / 50 * pump_nr_dict[item.Key];
fre_combine.FrePumps.Add(fre_pump);
}
return fre_combine;
}
#endregion
#region 添加项目 只有5台变频泵:AddAnaFreCombine
private AnaFreCombine AddAnaFreCombine5(double target_flow, Dictionary> conclusion_list_dic, Dictionary pump_nr_dict)
{
var ana_cl_item1 = conclusion_list_dic.ElementAt(0);
var ana_cl_item2 = conclusion_list_dic.ElementAt(1);
var ana_cl_item3 = conclusion_list_dic.ElementAt(2);
var ana_cl_item4 = conclusion_list_dic.ElementAt(3);
var ana_cl_item5 = conclusion_list_dic.ElementAt(4);
var ana_pump1_flag = ana_cl_item1.Key;
var ana_pump2_flag = ana_cl_item2.Key;
var ana_pump3_flag = ana_cl_item3.Key;
var ana_pump4_flag = ana_cl_item4.Key;
var ana_pump5_flag = ana_cl_item5.Key;
var ana_cl_list_pump1 = ana_cl_item1.Value;
var ana_cl_list_pump2 = ana_cl_item2.Value;
var ana_cl_list_pump3 = ana_cl_item3.Value;
var ana_cl_list_pump4 = ana_cl_item4.Value;
var ana_cl_list_pump5 = ana_cl_item5.Value;
double total_flow_deviation = target_flow;//总流量偏差
double total_power = double.MaxValue;//总功率
double total_flow = double.MaxValue;//总流量
Model.AnalysisConclusion opt_cl_pump1 = null;
Model.AnalysisConclusion opt_cl_pump2 = null;
Model.AnalysisConclusion opt_cl_pump3 = null;
Model.AnalysisConclusion opt_cl_pump4 = null;
Model.AnalysisConclusion opt_cl_pump5 = null;
for (int Index_pump1 = 0; Index_pump1 < ana_cl_list_pump1.Count; Index_pump1++)
{
for (int Index_pump2 = 0; Index_pump2 < ana_cl_list_pump2.Count; Index_pump2++)
{
for (int Index_pump3 = 0; Index_pump3 < ana_cl_list_pump3.Count; Index_pump3++)
{
for (int Index_pump4 = 0; Index_pump4 < ana_cl_list_pump4.Count; Index_pump4++)
{
for (int Index_pump5 = 0; Index_pump5 < ana_cl_list_pump5.Count; Index_pump5++)
{
var cl_pump1 = ana_cl_list_pump1[Index_pump1];
var cl_pump2 = ana_cl_list_pump2[Index_pump2];
var cl_pump3 = ana_cl_list_pump3[Index_pump3];
var cl_pump4 = ana_cl_list_pump4[Index_pump4];
var cl_pump5 = ana_cl_list_pump5[Index_pump5];
var frequency_list = new List()
{
cl_pump1.Pump1,
cl_pump2.Pump1,
cl_pump3.Pump1,
cl_pump4.Pump1,
cl_pump5.Pump1,
};
if (IsFrequencyDiffTooLarge(frequency_list))
continue;
var current_flow = cl_pump1.Flow + cl_pump2.Flow + cl_pump3.Flow + cl_pump4.Flow + cl_pump5.Flow;
if (current_flow < target_flow * 0.95)
continue;
var current_power = cl_pump1.Power + cl_pump2.Power + cl_pump3.Power + cl_pump4.Power + cl_pump5.Power;
var diff_flow = Math.Abs(current_flow - target_flow);
if (diff_flow < total_flow_deviation)
{
opt_cl_pump1 = cl_pump1;
opt_cl_pump2 = cl_pump2;
opt_cl_pump3 = cl_pump3;
opt_cl_pump4 = cl_pump4;
opt_cl_pump5 = cl_pump5;
total_power = cl_pump1.Power + cl_pump2.Power + cl_pump3.Power + cl_pump4.Power + cl_pump5.Power;
total_flow = current_flow;
total_flow_deviation = diff_flow;
}
if (diff_flow < target_flow * 0.01 && current_power < total_power)
{
opt_cl_pump1 = cl_pump1;
opt_cl_pump2 = cl_pump2;
opt_cl_pump3 = cl_pump3;
opt_cl_pump4 = cl_pump4;
opt_cl_pump5 = cl_pump5;
total_power = cl_pump1.Power + cl_pump2.Power + cl_pump3.Power + cl_pump4.Power + cl_pump5.Power;
total_flow = current_flow;
}
}
}
}
}
}
var opt_cl_dict = new Dictionary()
{
{ ana_pump1_flag,opt_cl_pump1},
{ ana_pump2_flag,opt_cl_pump2},
{ ana_pump3_flag,opt_cl_pump3},
{ ana_pump4_flag,opt_cl_pump4},
{ ana_pump5_flag,opt_cl_pump5},
};
var fre_combine = new AnaFreCombine();
fre_combine.Frequency = 0;
fre_combine.Flags = new List();
fre_combine.FrePumps = new List();
foreach (var item in opt_cl_dict)
{
var flag = item.Key;
var cl = item.Value;
fre_combine.Flags.Add(flag);
fre_combine.Flow += cl.Flow;
fre_combine.Power += cl.Power;
fre_combine.RunCount++;
var fre_pump = new AnaFrePump();
fre_pump.Flag = flag;
fre_pump.Flow = cl.Flow;
fre_pump.Head = cl.Head;
fre_pump.Power = cl.Power;
fre_pump.Efficiency = Curve.PumpCalculateHelper.CalculateE(fre_pump.Flow, fre_pump.Head, fre_pump.Power);
fre_pump.Frequency = fre_combine.Frequency;
fre_pump.Speed = cl.Pump1 / 50 * pump_nr_dict[item.Key];
fre_combine.FrePumps.Add(fre_pump);
}
return fre_combine;
}
#endregion
}
}