public void Execute(int capacity, KnapsackItem[] ksItems)
        {
            var collectedWeight = 0;
            var itemsToUpdate = ksItems.OrderByDescending(k => Convert.ToDouble(k.Value) / Convert.ToDouble(k.Weight))
                                       .ToArray();

            foreach (var itemToUpdate in itemsToUpdate)
            {
                if (itemToUpdate.Weight + collectedWeight <= capacity)
                {
                    collectedWeight += itemToUpdate.Weight;
                    itemToUpdate.Selected = 1;
                }
                if (collectedWeight == capacity) break;
            }
        }
        private int GetEstimatedValue(KnapsackItem[] ksItems)
        {
            var collectedWeight = 0;
            var estimatedValue = 0;
            var itemsByRatio = ksItems.OrderByDescending(k => Convert.ToDouble(k.Value) / Convert.ToDouble(k.Weight));

            foreach (var item in ksItems) item.EstimatedValue = item.Value;

            foreach (var item in itemsByRatio)
            {
                if (collectedWeight + item.Weight <= _capacity)
                {
                    collectedWeight += item.Weight;
                    estimatedValue += item.Value;
                    if (collectedWeight == _capacity) break;
                }
                else
                {
                    var percentOfItem = (_capacity - collectedWeight) / Convert.ToDouble(item.Weight);
                    var partialValue = Convert.ToInt32(percentOfItem*item.Value);
                    estimatedValue += partialValue;
                    item.EstimatedValue = partialValue;
                    break;
                }
            }
            return estimatedValue;
        }