public List <int> GetBestFactors(int dilutionTimes, bool isMRD = false) { if (dilutionTimes == 1) { return new List <int>() { 1 } } ; if (Configurations.Instance.IsGradualPipetting) { return(GetGradualFactors(dilutionTimes)); } //400's factors FactorFinder finder = new FactorFinder(); FactorInfo rootFactor = new FactorInfo(dilutionTimes); List <FactorInfo> childrenFactor = new List <FactorInfo>(); List <FactorInfo> finalFactors = new List <FactorInfo>(); childrenFactor = finder.GetFactors(rootFactor, possibleFactors, finalFactors); List <FactorInfo> thisStepFactorInfos = new List <FactorInfo>(); for (int i = 1; i < Configurations.Instance.DilutionWells; i++) //4 or 6 steps { thisStepFactorInfos = new List <FactorInfo>(); RemoveDuplicated(finalFactors); if (finalFactors.Count != 0) { break; } foreach (var childFactor in childrenFactor) { thisStepFactorInfos.AddRange(finder.GetFactors(childFactor, possibleFactors, finalFactors)); } childrenFactor = RemoveDuplicated(thisStepFactorInfos); if (thisStepFactorInfos.Count == 0) { break; } } finalFactors.AddRange(thisStepFactorInfos); //add last step; if (finalFactors.Count == 0) { throw new Exception("Cannot find factors for dilution times: " + dilutionTimes.ToString()); } int minSum = finalFactors.Min(x => x.factors.Sum()); var best = finalFactors.Where(x => x.factors.Sum() == minSum).First(); //if(isMRD) //{ // int maxSum = finalFactors.Max(x => x.factors.Sum()); // best = finalFactors.Where(x => x.factors.Sum() == maxSum).First(); //} return(best.factors.OrderByDescending(x => x).ToList()); }
public List <FactorInfo> GetFactors(FactorInfo factorInfo, List <int> possibleFactors, List <FactorInfo> finalFactors) { List <FactorInfo> childrenFactorInfos = new List <FactorInfo>(); foreach (var possibleFactor in possibleFactors) { if (factorInfo.currentVal % possibleFactor == 0) { FactorInfo childInfo = new FactorInfo(factorInfo); childInfo.factors.Add(possibleFactor); childInfo.currentVal /= possibleFactor; if (childInfo.currentVal <= 40 && //can find factor directly (childInfo.currentVal == 1 || possibleFactors.Contains(childInfo.currentVal))) { if (childInfo.currentVal == 1) { finalFactors.Add(childInfo); } else { childInfo.factors.Add(childInfo.currentVal); finalFactors.Add(childInfo); } } else //need further process { childrenFactorInfos.Add(childInfo); } } } return(childrenFactorInfos); }
public FactorInfo(FactorInfo factorInfo) { // TODO: Complete member initialization rootVal = factorInfo.rootVal; currentVal = factorInfo.currentVal; factors = new List <int>(); foreach (var factor in factorInfo.factors) { factors.Add(factor); } }