Searching for the best fit price for multiple customers [duplicate]

2024/11/16 9:52:03

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?

Answer

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.

https://en.xdnf.cn/q/120344.html

Related Q&A

Can we chain the ternary operator in Python? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.Want to improve this question? Add details and clarify the problem by editing this post.Closed 4 years ago.The com…

evaluate a python string expression using dictionary values

I am parsing a text file which contain python "string" inside it. For e.g.:my_home1 in houses.split(,) and 2018 in iphone.split(,) and 14 < maskfor the example above, I wrote a possible di…

How to simply get the master volume of Windows in Python? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.Want to improve this question? Add details and clarify the problem by editing this post.Closed 1 year ago.Improve …

Python: Adding positive values in a list [closed]

Closed. This question needs debugging details. It is not currently accepting answers.Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to repro…

Python IM Program [closed]

Its difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying thi…

Changes in Pandas DataFrames dont preserved after end of for loop

I have a list of Pandas DataFrames and I want to perform some operations on them. To be more precise, I want to clean their names and add new column. So I have written the following code:import numpy a…

How can I prevent self from eating one of my test parameters?

I have in my test module:import pytest from src.model_code.central import AgentBasicclass AgentBasicTestee(AgentBasic):pass@pytest.fixture() def agentBasic():return AgentBasicTestee()@pytest.mark.param…

distance from a point to the nearest edge of a polygon

in the below code i want to calculate the distance from a point to the nearest edge of a polygon.as shown in the results section below, the coordinates are provided.the code posted below shows how i fi…

Is there a netcat alternative on Linux using Python? [closed]

Closed. This question is seeking recommendations for software libraries, tutorials, tools, books, or other off-site resources. It does not meet Stack Overflow guidelines. It is not currently accepting …

keras/tensorflow model: gradient w.r.t. input return the same (wrong?) value for all input data

Given a trained keras model I am trying to compute the gradient of the output with respect to the input. This example tries to fit the function y=x^2 with a keras model composed by 4 layers of relu act…