ningshuxia
2024-04-30 b50a06a3185619c4cbbc521ab026f1bfa4d13aae
Schedule/IStation.Algorithm/Schedule/SchedulingHelper.cs
@@ -1,4 +1,6 @@
namespace IStation.Algorithm
using System;
namespace IStation.Algorithm
{
    #region ViewModel
@@ -61,11 +63,13 @@
        string GetRunFlag(Dictionary<int, bool> dic)
        {
            var tableName = string.Empty;
            var count = dic.Count;
            for (int i = 0; i < count; i++)
            var index = 0;
            var count = dic.Count;
            foreach (var item in dic)
            {
                tableName += GetRunFlag(dic);
                if ((i + 1) != count)
                tableName += GetRunFlag(item.Key, item.Value);
                index++;
                if (index != count)
                {
                    tableName += _falgSpaceMark;
                }
@@ -78,12 +82,49 @@
            return (isBp ? _falgFrePumpTag : _falgFixPumpTag) + id;
        }
        string GetRunFlag(List<string> flags)
        {
            var tableName = string.Empty;
            var count = flags.Count;
            var index = 0;
            foreach (var flag in flags)
            {
                tableName += flag;
                index++;
                if (index != count)
                {
                    tableName += _falgSpaceMark;
                }
            }
            return tableName;
        }
        #endregion
        DAL.ScheduleCombine _dal = new DAL.ScheduleCombine();
        DAL.ScheduleConclusion _dalScheduleConclusion = new DAL.ScheduleConclusion();
        DAL.ScheduleAnaLog _dalAnaLog = new DAL.ScheduleAnaLog();
        public class CurrentViewModel : Entity.ScheduleConclusion
        {
            public CurrentViewModel(Entity.ScheduleConclusion rhs) : base(rhs)
            {
                this.Flags = new List<int>();
                var flags = rhs.RunFlag.Split('_');
                foreach (var item in flags)
                {
                    if (int.TryParse(item.Substring(1), out int flag))
                    {
                        this.Flags.Add(flag);
                    }
                }
            }
            public List<int> Flags { get; set; }
        }
        public void Ana(List<Pump> pumps, double tagetFlow, double tagetHead, List<int> openPumpCombine)
@@ -93,27 +134,76 @@
            if (openPumpCombine != null && openPumpCombine.Any())
            {
                var allCombineList = PermutationAndCombination<int>.GetCombination(pumpIds.ToArray(), 2);
                var combineList = new List<int[]>();
                var combineList = new List<List<int>>();
                foreach (var combine in allCombineList)
                {
                    foreach (var pump in combine)
                    {
                        if (openPumpCombine.Contains(pump))
                        {
                            combineList.Add(combine);
                            break;
                        }
                    }
                    var pump1 = combine[0];
                    var pump2 = combine[1];
                    if (!openPumpCombine.Contains(pump1))
                        continue;
                    if (!openPumpCombine.Contains(pump2))
                        continue;
                    combineList.Add(combine.ToList());
                }
                if (combineList.Count < 1)
                    return;
                var avgFlow = tagetFlow / 2;
                var optimalConclusionList = new List<CurrentViewModel>();
                foreach (var combine in combineList)
                {
                  //  var runFlag = getal
                    var dic = new Dictionary<int, bool>();
                    foreach (var pump in combine)
                    {
                        if (dic_pump.ContainsKey(pump))
                        {
                            dic.Add(pump, dic_pump[pump]);
                        }
                    }
                    var runFalg = GetRunFlag(dic);
                    var list = _dalScheduleConclusion.GetList(runFalg, avgFlow, tagetHead, 1);
                    if (list != null && list.Any())
                    {
                        var vmList = list.Select(x => new CurrentViewModel(x)).ToList();
                        optimalConclusionList.AddRange(vmList);
                    }
                }
                if (optimalConclusionList == null || !optimalConclusionList.Any())
                {
                    return;
                }
                var optimalConclusionCombineList = PermutationAndCombination<CurrentViewModel>.GetCombination(optimalConclusionList.ToArray(), 2);
                var combines = new List<Combine>();
                foreach (var arr in optimalConclusionCombineList)
                {
                    var falgs = arr.SelectMany(x => x.Flags).ToList();
                    if (falgs.GroupBy(x => x).Where(x => x.Count() > 1).Count() > 0)
                    {
                        continue;
                    }
                    var combine = new Combine();
                    combine.Power = arr.Sum(x => x.Power);
                    combine.Head = arr.Average(x => x.Head);
                    combine.Flow = arr.Sum(x => x.Flow);
                    combine.RunFlagList = falgs;
                    combines.Add(combine);
                }
                var a = combines;
            }
        }
        private class Combine
        {
            public double Flow { get; set; }
            public double Head { get; set; }
            public double Power { get; set; }
            public List<int> RunFlagList { get; set; }
        }
        /// <summary>
        /// 插入分析日志