<p>I ended up putting together some code to compute the assignment under Boston and deferred acceptance. It can be found at <a href="https://github.com/vanderlindenma/school_choice_python" rel="nofollow">https://github.com/vanderlindenma/school_choice_python</a>.</p>

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

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

CC BY-SA 3.0
2015-10-22T19:22:25.997Z
2015-10-22T19:22:25.997Z
Martin Van der Linden
<p>I found one implementation of TTC in <code>python</code> at <a href="http://www.dreamincode.net/forums/topic/377004-algorithmic-game-theory-top-trading-cycle-procedure/?ref=dzone" rel="nofollow">http://www.dreamincode.net/forums/topic/377004-algorithmic-game-theory-top-trading-cycle-procedure/?ref=dzone</a>.</p>

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

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

CC BY-SA 3.0
2015-09-09T20:53:00.293Z
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: https://michaellevet.wordpress.com/2015/06/01/algorithmic-game-theory-house-allocation-problem/
ml0105
CC BY-SA 3.0
2015-09-09T16:29:31.877Z
2016-01-07T05:31:12.433Z
2016-01-07T05:31:12.433Z
Martin Van der Linden
<p>This is somewhat of a follow up question to <a href="https://economics.stackexchange.com/questions/1638/available-code-for-computing-solutions-to-matching-algorithms">Available code for computing solutions to matching algorithms?</a>.</p>

<p>In the above question, I got great answers, but all of them were for <code>R</code>.</p>

<p>I am now programming a lab experiment in <a href="http://www.otree.org/" rel="nofollow">otree</a>, which means I am working with Python.</p>

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

<ul>
<li>The Boston mechanism (aka. Immediate acceptance)</li>
<li>The Top-trading cycle algorithm</li>
</ul>

<p>In the best of the worlds, these codes would </p>

<ul>
<li>Be compatible with the school choice model (i.e. many-to-one matching problem in which agents in one side of the "market" can be matched to many agents on the other side)</li>
<li>Allow for constrains on the lenght of the preference list agents can report (see <a href="http://www.sciencedirect.com/science/article/pii/S002205310900057X" rel="nofollow">http://www.sciencedirect.com/science/article/pii/S002205310900057X</a>)</li>
</ul>

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

CC BY-SA 3.0
2015-09-09T21:01:29.457Z
Just in case, Python can run R. See eg `rpy2`.
Anton Tarasenko
<mechanism-design><algorithms><python><matching>
Computing Boston and TTC in Python
Martin Van der Linden
# Computing Boston and TTC in Python

(Asked by: username_0 on 2015-09-09)

This is somewhat of a follow up question to [Available code for computing solutions to matching algorithms?](https://economics.stackexchange.com/questions/1638/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](http://www.otree.org/), 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

* Be compatible with the school choice model (i.e. many-to-one matching problem in which agents in one side of the "market" can be matched to many agents on the other side)
* Allow for constrains on the lenght of the preference list agents can report (see <http://www.sciencedirect.com/science/article/pii/S002205310900057X>)

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

**Tags:** mechanism-design, algorithms, python, matching
> **Comments:**
> **username_1**: Just in case, Python can run R. See eg `rpy2`.  

---

## 2 answers

### Answer by username_0 on 2015-10-22. Score: 0 | Accepted answer

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.


---

### Answer by username_0 on 2015-09-09. Score: 1

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.

> **Comments:**
> **username_2**: 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: https://michaellevet.wordpress.com/2015/06/01/algorithmic-game-theory-house-allocation-problem/  

---

