Check if you like this combo:
Updated to minimize |a-b| and |c-d|.
I have a real life business math problem. I need to allocate pay for multiple people across multiple locations with the following constraints.
Let a = Hours to allocate to Place01 for Sue
Let b = Hours to allocate to Place02 for Sue
Let c = Hours to allocate to Place01 for Bob
Let d = Hours to allocate to Place02 for Bob
Bob's Hourly rate = 500 dollars/hour
Sue's Hourly rate = 1000 dollars/hour
Bob's Hours worked = 70 Hours
Sue's Hours worked= 90 Hours
The following must be true in any reasonable solution:
1000*a + 500*c = $50,000 where 1000 represents Sue's hourly rate and 500 represents Bob's hourly rate.
1000*b + 500*d = $75,000 where 1000 represents Sue's hourly rate and 500 represents Bob's hourly rate.
c+d = 70 hours
a+b = 90 hours
I need to distribute the 160 total hours as evenly as possible across Place01 and Place02 for each Person.
Thus, in math terms I would like to minimize the absolute difference between a and b
I would also like to minimize the absolute difference between c and d.
e.g. I want to select the solution from the universe of possible solutions such that:
|a-b| is at a minimum and |c-d| is also minimized
Notice that the total dollars allocated $125,000 = total dollars paid = $125,000
Normally, to do this I would just split the hours for each person between each place. But as noted above, I now have the constraint that Place01 must get exactly $50,000 allocated and place two must get $75,000.
How can I solve this in the best way possible that distributes the hours as evenly as possible for each employee across the two Places? Bear in mind that the solution will need to be scalable in the sense that I actually have about 100 places and as many people. Rates and hours for each person are known in advance and are constant. I simplified the example for the purpose of illustrating the problem at hand.
Thanks in advance!
MaxJasper, Thanks for the quick response.
I do like combo. What technique did you use to the solve the problem and how do I know that the differences are minimized? Also, how can I do it if I have more than two people and more than two places to allocate cost?
Edit: MaxJasper. Your modified answer indeed minimizes the difference between both (a and b) and (c and d). However, that change made it yield the wrong allocation for Place01 and Place02 if a and c are equal. Specifically Place01 now gets $62,500 allocated yet it must get $50,000 exactly.
The answer you posted previously worked...I just didn't know if that was yielded the smallest difference between (a and b) and (c and d) subject to the requirement that Place01 get $50k and Place02 get $75k.
No problem on not being able to get closer. I am more interest in the specific technique you are using to arrive at your answer. Can you point me in the right direction for how to solve this problem in a general case?