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