A
A
Aitd2022-04-02 10:23:16
Algorithms
Aitd, 2022-04-02 10:23:16

What is the best way to organize the benefit calculation algorithm?

Given:
A standard basket of goods in a store

  • Product1 - 100 rub
  • Product2 - 120r (share), base price -150r
  • Product3 - 90r (share), base price 100r

Total amount: 350r Promotional
benefit : 40r
Total: 310r

You can use promotional codes for a discount in the basket, the number of promotional codes is unlimited.
The promo code can be
  1. Commodity. This means that the benefits of the promotional code are applied to each product, for example, a promotional code for 10r valid for 3 products will give 30r benefits
  2. basket. This means that it is applied 1 time to the goods for which it is valid (not to the entire basket), for example, a promotional code for 10 rubles valid for 3 products will give 10 rubles of benefit

Each promo code can be summed with others (i.e. the benefits add up) or not (then it can be the only active one in the cart if it gives the greatest benefit, and the rest are disabled), it can also work from the price before the discount or after the discount (which it matters if the discount is in percent, not in currency) and the most important thing is that the promotional code can be combined with the promotion, or maybe not (in this case, the benefit search mode is turned on - what is the best benefit of the promotional code after applying or the promotion)
It is also taken into account that the promotional codes may not affect the entire basket as a whole, but only on a part of the goods (i.e. the settings themselves may exclude specific goods and will not exist for this promotional code)

If the total discount of promo codes goes beyond the value of the basket or the amount of goods for which they apply, such a combination is considered
invalid
.
Are there algorithms that can help, or somehow distribute the data so that the final benefit can be calculated?

At the moment, as I understand it, there is a need to calculate the possible correct combinations and choose from these combinations with the largest amount, but the question is even how to correctly compose these combinations.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
Wataru, 2022-04-02
@wataru

You need to formalize the task. Carefully, with formulas, describe all types of promotional codes, how they work and interact.
If all promo codes gave a percentage discount, then you could take it greedily, but these absolute codes break everything. Here you can see not the solution of the problem of a backpack or the exchange of coins (dynamic programming), it seems that this will speed up the solution. It seems like - they sorted out which percentage codes you use and now you have the amount X. You need to dial the maximum number no more than X with absolute codes.
And so you will have to do a complete enumeration at least partially. This recursive function will have to be implemented - google "brute force" even here.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question