Compliance / Requirements Algorithm
I am implementing an item trading system on a site with high traffic. I have a large number of users, each of which maintains a HAVE list and a WANT list for a number of specific items. I am looking for an algorithm that will allow me to effectively offer trading partners based on your HAVE and WANTs corresponding to them. Ideally, I want to find partners with the highest mutual trading potential (that is, I have a ton of things that you want, you have a ton of things that I want). I don't need to find a global pair with the highest potential (which sounds tough), just find the pairs with the highest potential for a given user (or even some pairs with the highest potential, not global max).
Example:
User 1 HAS A, C WANTS B, D
User 2 HAS D WANTS A
User 3 HAS A, B, D WANTS C
User 1 goes to the site and clicks a button that says
"Find Trading Partners" and the top-ranked result is
User 3, followed by User 2.
An additional source of complexity is that the elements have different meanings, and I want a match on the highest trade transaction, and not on most matches between the two traders. Therefore, in the above example, if all elements are worth 1, but A and D are worth 10, user 1 is now mapped to user 2 above User 3.
The naive way to do this is to calculate the maximum trading value between the user looking for partners and all other users in the database. I am thinking with some lookup tables on the right things, which I could do better. I tried searching, as this seems like a classic problem, but I don't know the name for it.
Can you recommend a good approach to solving this problem? I have seen sites like the Magic Online Trading League that seem to solve it in real time.
algorithm
John shedletsky
source share