lundi 23 mars 2015

Algorithm that generates a group of men and women who are each interested in everyone from the other gender


In my dating app, I need to compile lists of men and women where all of the men in the list are potentially interested in all of the women in the list, and vice versa.


That is, in a list of 10 men and 10 women, any given women matches the criteria set by all 10 men and any given man matches the criteria of all 10 women. I don't want any men in the group who aren't of interest to all the women, and vice versa.


The criteria is very simple. The properties for each person are:



  • Age

  • Interests (array)

  • Desired partner's age range


Example: if Man1 is described as



  • 31

  • Cooking, tennis, math

  • 20, 31


A 29 year old woman who likes tennis and is looking for a man between x<=31 and y>=31 is a match.


I've been thinking about how to implement this, but it's unlike any simple data fetching/manipulation I've ever done. The reason is because rather than being a single query, (i.e. get all people where gender=female AND age>=low & age<=hight etc..) the query has to be checked anew each time when a new person is added. That is, each time a new man or woman is added to the list, all subsequent people have to be checked against them too (because I don't want to add a man who one or more women don't find interesting).


Does anyone have any ideas on a strategy for implementing this algorithm.


As an aside, I am using MongoDB, so if comfortable for you, it would be great to speak in those terms.


Thank you very much in advance!





Aucun commentaire:

Enregistrer un commentaire