Exemplo n.º 1
0
        public async Task WriteSolution()
        {
            var bag = _bagRepository.GetBag();

            StringBuilder sb = new StringBuilder();

            sb.AppendLine($"{bag.ValueInsideBag} 0");

            foreach (var isItemChosen in _itemRepository.GetSolution())
            {
                sb.Append($"{isItemChosen} ");
            }

            await _dtoStore.WriteSolution(sb.ToString());
        }
        public void Optimize()
        {
            if (!AlgorithmPicker.ShouldRunOnThisDataSet(this, _itemRepository.GetItemCount()))
            {
                return;
            }

            var bag   = _bagRepository.GetBag();
            var items = _itemRepository.GetAllItems();

            var solutionMatrix = new SolutionMatrix(bag.RemainingCapacity + 1, items.Count);

            UpdateSolutionMatrix(items, bag, solutionMatrix);
            TraceBackSolution(bag, items, solutionMatrix);
        }
        public void Optimize()
        {
            if (!AlgorithmPicker.ShouldRunOnThisDataSet(this, _itemRepository.GetItemCount()))
            {
                return;
            }

            Bag bag   = _bagRepository.GetBag();
            var items = _itemRepository.GetAllItems().OrderByDescending(x => x.ValuePerUnitWeight);

            foreach (var item in items)
            {
                if (item.Weight <= bag.RemainingCapacity)
                {
                    bag.UpdateSolution(item);
                    _itemRepository.UpdateSolution(item);
                }

                if (bag.RemainingCapacity == 0)
                {
                    break;
                }
            }
        }