/// <summary> /// /// </summary> /// <param name="cacheq"></param> /// <param name="rt"></param> /// <param name="cancachecount">可缓存卷数</param> /// <returns></returns> private static bool CanIgo(IEnumerable <LableCode> cacheq, CalResult rt, int cancachecount) { var go = false; var biggers = 0; switch (cancachecount) { case 0: break; case 1: biggers = GetBiggerCount(cacheq, rt, 1); if (biggers >= 1) { go = true; } break; case 2: biggers = GetBiggerCount(cacheq, rt, 2); if (biggers >= 2) { go = true; } break; } return(go); }
/// <summary> /// 2期缓存计算办法 /// </summary> /// <param name="pinfo"></param> /// <param name="lc"></param> /// <param name="lcs"></param> /// <param name="cacheq">缓存队列</param> /// <returns>返回的是需要从缓存位取出的布卷。如果不需要取出,返回null。</returns> private static CalResult CalculateCache(PanelInfo pinfo, LableCode lc) { var cr = new CalResult(CacheState.Go, lc, null); var cachecount = (pinfo.OddStatus ? 0 : 1) + (pinfo.EvenStatus ? 0 : 1); List <LableCode> cachedRolls; lock (TaskQueues.LOCK_LOCHELPER) { cachedRolls = FrmMain.taskQ.CacheSide.Where(x => x.labelcode != null && x.labelcode.ToLocation == lc.ToLocation) .Select(x => x.labelcode) .ToList(); } switch (cachedRolls.Count()) { case 0: //当前层已没有了缓存。//当前布卷直接缓存起来。 cr.state = CacheState.Cache; break; case 1: //当前层只有一卷缓存。 case 2: //当前层有两卷缓存。 if (cachedRolls.Count() == cachecount) //缓存卷数与需要缓存卷数相等 { var smaller = cachedRolls.Where(x => x.Diameter + clsSetting.CacheIgnoredDiff < lc.Diameter) .OrderBy(x => x.Diameter) .FirstOrDefault(); if (smaller != null) { cr.CodeFromCache = smaller; lc.GetOutLCode = cr.CodeFromCache.LCode; cr.state = CacheState.GetThenCache; } else { cr.state = CacheState.Go; } } else if (cachedRolls.Count() < cachecount) { cr.state = CacheState.Cache; } else { cr.state = CacheState.Go; } break; } return(cr); }
private static CacheResult CalculateCacheState(CalResult rt, PanelInfo pinfo, List <LableCode> layerLabels, Action <string> onlog) { // debug 2017.97.24 if (rt == null) { throw new Exception("rt空值。"); } if (rt.CodeCome == null) { throw new Exception("rt.codecome空值。"); } var cre = new CacheResult { SideState = new SideFullState(SideFullState.NO_FULL, null) }; if (layerLabels != null && layerLabels.Count > 0) { // 最近一层没满。 cre.SideState = IsPanelFullPro(layerLabels, rt.CodeCome); rt.CodeFromCache = cre.SideState.fromCache; if (cre.SideState.state == SideFullState.FULL) { // rt.CodeFromCache可能是null. var cachedRollDiameter = rt.CodeFromCache != null ? rt.CodeFromCache.Diameter : 0; if (rt.CodeFromCache == null) { rt.state = CacheState.Go; } else if (rt.CodeCome.Diameter > cachedRollDiameter + clsSetting.CacheIgnoredDiff) { rt.state = CacheState.GetThenGo; } else { rt.state = CacheState.GoThenGet; } } else if (cre.SideState.state == SideFullState.NO_FULL) { var cr = CalculateCache(pinfo, rt.CodeCome); rt.CodeFromCache = cr.CodeFromCache; rt.state = cr.state; } else if (cre.SideState.state == SideFullState.EXCEED) { if (rt.CodeFromCache == null) { onlog($"布卷exceed状态时,codefromcache空值。"); } // debug 2017.97.24 var cachedRollDiameter = rt.CodeFromCache != null ? rt.CodeFromCache.Diameter : 0; if (rt.CodeCome.Diameter + clsSetting.CacheIgnoredDiff > cachedRollDiameter) { rt.CodeFromCache = null; rt.state = CacheState.Go; } else { rt.state = CacheState.GetThenCache; } pinfo.HasExceed = true; } } cre.CResult = rt; if (cre.CResult.CodeFromCache != null && cre.CResult.CodeCome.PanelNo != cre.CResult.CodeFromCache.PanelNo) { cre.CResult.CodeFromCache.PanelNo = cre.CResult.CodeCome.PanelNo; cre.CResult.CodeFromCache.Floor = cre.CResult.CodeCome.Floor; } if (cre.CResult.CodeFromCache != null && cre.CResult.CodeFromCache.Floor != cre.CResult.CodeCome.Floor) { cre.CResult.CodeFromCache.Floor = cre.CResult.CodeCome.Floor; } return(cre); }
private static int GetBiggerCount(IEnumerable <LableCode> cacheq, CalResult rt, int takeCount) { return((from s in cacheq.Take(takeCount) where s.Diameter > rt.CodeCome.Diameter + clsSetting.CacheIgnoredDiff select s).Count()); }