This is somewhat of a follow up question to Available code for computing solutions to matching algorithms?.

In the above question, I got great answers, but all of them were for R.

I am now programming a lab experiment in otree, which means I am working with Python.

It is fairly easy to find code in python solving matching problems using the Deferred Acceptance mechanism, but I wondered if anyone knew of python code for some of the other common mechanisms in the literature. Specifically, I am looking for python code for

  • The Boston mechanism (aka. Immediate acceptance)
  • The Top-trading cycle algorithm

In the best of the worlds, these codes would

However, I would already be very happy with python code for Boston and TTC, even if the two last features are not implemented.

  • 3
    $\begingroup$ Just in case, Python can run R. See eg rpy2. $\endgroup$ Commented Sep 9, 2015 at 21:01

2 Answers 2


I found one implementation of TTC in python at http://www.dreamincode.net/forums/topic/377004-algorithmic-game-theory-top-trading-cycle-procedure/?ref=dzone.

However, it does not seem to include the two additional features I was mentionning.

With of without these two features : I would still love to hear about more implementation of TTC, and about implementations of Boston.

  • 2
    $\begingroup$ I'm the author of that article. I cross-post both on Dream.in.Code and my personal blog. The math is cleaner on my blog, which supports LaTeX rendering. For reference: michaellevet.wordpress.com/2015/06/01/… $\endgroup$
    – ml0105
    Commented Sep 9, 2015 at 20:53

I ended up putting together some code to compute the assignment under Boston and deferred acceptance. It can be found at https://github.com/vanderlindenma/school_choice_python.

The code there uses and modifies former code from Jeremy Kun, stable-marriage, (2014), GitHub repository, https://github.com/j2kun/stable-marriages, described in one of Jeremy's blog posts at http://jeremykun.com/2014/04/02/stable-marriages-and-designing-markets/.

I hope to expend on the code that’s currently available and add more functionalities soon. Any participation is welcome.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.