From b50a06a3185619c4cbbc521ab026f1bfa4d13aae Mon Sep 17 00:00:00 2001
From: ningshuxia <ningshuxia0927@outlook.com>
Date: 星期二, 30 四月 2024 11:13:08 +0800
Subject: [PATCH] 调度

---
 Schedule/IStation.Algorithm/Schedule/SchedulingHelper.cs |  120 ++++++++++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 105 insertions(+), 15 deletions(-)

diff --git a/Schedule/IStation.Algorithm/Schedule/SchedulingHelper.cs b/Schedule/IStation.Algorithm/Schedule/SchedulingHelper.cs
index d94b38f..9f08205 100644
--- a/Schedule/IStation.Algorithm/Schedule/SchedulingHelper.cs
+++ b/Schedule/IStation.Algorithm/Schedule/SchedulingHelper.cs
@@ -1,4 +1,6 @@
-锘縩amespace IStation.Algorithm
+锘縰sing 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>
         /// 鎻掑叆鍒嗘瀽鏃ュ織

--
Gitblit v1.9.3