Example #1
0
        public List <Element> GetOptimaElements()
        {
            if (AlgorithmNotRun)
            {
                return(null);
            }

            var list = new List <Element>();

            var maxCost = GetMaxValue();

            for (int i = Categories.Count - 1; i >= 0; i--)
            {
                var category = Categories[i];
                var max      = Table
                               .Where(e => category.Elements.Contains(e.Key.Value))
                               .OrderByDescending(e => e.Value);
                var  max2      = max.FirstOrDefault(e => e.Value <= maxCost);
                bool maxChosen = false;
                if (!DecisionTable.TryGetValue(max2.Key, out maxChosen))
                {
                    continue;
                }
                ;
                if (maxChosen == false)
                {
                    continue;
                }
                ;
                list.Add(max2.Key.Value);
                var remainingMax = max2.Value - max2.Key.Value.Value;
                maxCost = remainingMax;
                if (maxCost == 0)
                {
                    break;
                }
            }


            return(list);
        }