Saturday, February 1, 2020

How to match two datasets with constraints?

Hello,

This is my first time posting on this forum so thank you to everyone in advance.

The simplest way for me to describe my problem is as follows: I have two datasets. The first dataset consists of a list of suppliers and their capacities. It looks like

Code:
<supplierid> <capacity>
A 20
B 30
C 10
D 15
The second dataset consists of buyers, how much they want to buy, and who they want to buy from (preferences).

Code:
<buyerid> <quantity> <preference> <supplierid>
1 15 1 A
1 15 2 C
2 10 1 A
2 10 2 C
3 20 1 B
3 20 2 A
To explain a little bit further, each buyer wants to buy a fixed amount of quantity. Each buyer also has a preference for who they want to buy from (in general buyers are not willing to buy from all suppliers). A buyer must buy the entire quantity from one supplier i.e. it is not possible for a buyer to buy 1 unit from supplier A and 1 unit from supplier C. Supplier don't have preferences and don't care who they sell to.

What I want to do is make my way down the list of buyers and assign a supplier to each buyer (to the extent that I can). So for example, buyer 1 will buy 15 units from supplier A. Buyer 2 will buy 10 units from supplier C (since supplier A won't have 10 units of capacity left after buyer 1 has purchased 15 units), and buyer 3 will buy 20 units from supplier B. I want my final dataset to look as follows:

Code:
<buyerid> <quantity> <sellerid>
1 15 A
2 10 C
3 20 B
Total capacity is much lower than total quantity demanded so, at the end, most buyers will not be able to buy anything.

Any help will be greatly appreciated.


Thanks!

No comments:

Post a Comment