## Searching for the best fit price for multiple cust

2019-10-09 17:22发布

This question is an exact duplicate of:

A restatement of Comparing multiple price options for many customers algorithmically without nearly as much cruft.

We have 1,000,000 customers. The cost of goods sold for each of them can be expressed as price A or price B.

Price A << Price B.

Price A and Price B are not linear to each other. In some cases B is 2 times as expensive, in some it is 100 times.

cost of all the customers on A is

``````min( (sum(A)/count(A)) , 100 ) * count(A)
``````

Effectively, the average cost of all the customers on A will be rounded up to 100 if it is less than 100.

There is no such restriction on B.

I would like to spend the least amount of money on their goods.

How do I maximize

``````cost=min( (sum(A)/count(A)) , 100 ) * count(A) + sum(B)
``````

I keep seeing this as a form of a dual knapsack problem, but I can't get it right ...

I'd be probably solving this in Python, most likely, although I doubt that matters much.

I've done manual analyses by assigning scores to x y z and filtering based upon that, I'm interested in more of a computational solution.

Any approaches to recommend?

1条回答

Each customer can be assigned to the A side or the B side. If I handed you the best possible solution you would find that you could not improve it by changing the assignment of any single customer. Given this, there are two cases to check, if I can ignore a borderline case:

1) In the best solution the average cost of the A side customers is at least 100, so the minimum price does not come into effect. If I switch a customer from A to B or vice versa the cost changes by the difference in A and B prices for that customer. Since I have a perfect solution, each customer must be assigned to whichever of A or B cost is less, which in your case means that everybody goes to A.

2) The minimum 100 charge per customer is in effect on the A side, so changing a customer from A and B or vice versa amounts to charging them a cost of 100 for A. Since I have a perfect solution, the customers on the A side must be the customers whose B prices are at least 100, and the customers on the B side must be those whose B prices are 100 or less.

The only catch here is if switching a customer means that the 100 minimum comes into effect or stops coming into effect. In case (1) if somebody switched to B the price would increase even without the minimum coming into effect for the A prices, so this cannot happen. In case(2) if a B side customer switched to A this could only make things worse, since their B prices was 100 or less so their A price must be 100 or less. An A customer must have a B price of 100 or more. If their A price is 100 or more they should definitely stay on A as moving them to B cannot make the minimum A cost stop applying. If their A price is < 100 and moving them to B stops the minimum A price from kicking in then you pay less for As of the true A price of that customer but you still have to pay a B price of at least 100 instead so there is nothing to be gained here either.

So I think you work out the cost of two possibilities - case 1 is where you assign everything to A and case 2 is where you assign stuff to A where the B price is 100 or more. Chose whichever of these works out cheapest.