Two-sided matching with time preferences


Standard matching mechanisms work well for two-sided preferences. A classical example is Gale-Shapley deferred acceptance algorithm, in which two sets of agents make preference rankings regarding each other. The greatest advantage of the algorithm is that it is efficient, and every agent gets a match. However, what if we want to matchtwo sets of agents, say students and tutors, who have preferences with respect to time slots and not each other?
I claim that we can tweak DA mechanism to make this matching, so that no one is left out. To do that, we have to create an availability
matrix from our data. This matrix consists of zeros and ones, where time slots that match both a student and a teacher, are marked with 1. Below is an example availability matrix:

As you might have noticed, it is very easy to convert any Doodle output to this matrix. Now, this matrix will serve as a preference ordering for our algorithm. In other words, a match in required time slots, marked by 1, is more preferrable than no match, marked by 0, but the latter is not completely ruled out. The alogrithm works as follows:
- Every unmatched student submits to any tutor.
- Every tutor says yes if she is (a) idle and (b) (i.e. the allocation matrix for the matching cell is higher than the current value)
- As soon, as some tutor says yes, the student ends the round and next student starts submission process.
- The next round starts where only unmatched students go through steps 1-3.
- When some critical number of iterations is reached, new rounds start where in step 2, tutors will also accept students with zero time slot match.
- The process stops when all students are matched to tutors.
The code representation for this is as follows:
This returns the following result
matrix:

Great! We are done here.
Bonus
As a bonus I include a matching code for creating the availability
matrix. First of all, create the following two dataframes for tutors and students:

Once you have these for every agent type, it is very easy to compare their matching hours:
Voila! We are done here… but if you are too busy to create your own availability
matrix, here is the code:
One final bonus
Fine, if you really don’t have time, here is the code that transforms time slots in columns (probably obtained from your questionnaire), then you can convert them to the format I suggested above, as follows:
OK, now we are really done. Good luck and follow me on Twitter: @ravshansk.