Skip to content

Commit e80f593

Browse files
authored
Prepare for version v1.4.0 (#132)
* Move algorithms to submodule (#121) * Update imports and wording in tests. * Update subpackage inits and util files. * Move algorithm funcs to algorithm subpackage. * Format codebase with isort, black, flake8. * Update API docs. * Make `Player.forget()` protected. i.e. /forget/_forget * Move to `_forget` in all tests. * Move to `_forget` in SA player classes. These players have their own forget methods. * Move to `_forget` in base game and util function. * Move to `_forget` in games. * Protect `Player.match()` and `Player.unmatch()` * Move to `_(un)match` in other player tests. * Move to `_unmatch` in SR example test. * Move to `_(un)match` in all player classes. * Move to `_(un)match` in games and util functions. * Protect the `delete` and `match` functions. The ones in `matching.games.util` are for matching/deleting pairs. * Make relevant changes to game calls. * Minor formatting fixes. * Implement extended algorithms (from book) (#130) * Implement extended algorithms (from book) Thanks to The Good Book (citation in `stable_roommates.py`), some minor adjustments to HR and SM (nothing functionally different), and a complete overhaul of SR have been implemented. * Fix formatting. * Add GusfieldIrving citation to bibliography. * Add more abstract classes (#122) * Write tests for new matching classes. * Write tests for new base class structure. * Clean up old tests. * Implement base classes for players and matchings. * Add compatability to games and hospital classes. * Update game class tests. * Catch attribute typo in supervisor. * Add compatability to other player tests. * Catch attribute typo in SR test. * Implement composite strategies for HR tests. * Update game class tests. Catch attribute typo in supervisor. Add compatability to other player tests. Catch attribute typo in SR test. * Start implementing composites with SR. * Format codebase. * Catch typo in SA tutorial. * Update classes in README * Format codebase with black>19 * Add first phase check to SR. * Fix (now-outdated) logic in tests. * Add `NoStableMatchingWarning` for SR (#131) * Add warning catcher to algorithm tests. * Add warning catcher to solver tests. * Add no solution example from GS62. * Implement `NoStableMatchingWarning` source code. * Drop CI support for 3.6 (add in 3.9) Also, run the flake8 linter. * Fix typo in CI flake8 call (snuck in last commit) * Update changelog and version number.
1 parent c843102 commit e80f593

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+2061
-1579
lines changed

.github/workflows/ci.yml

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: CI/CD
1+
name: CI
22

33
on:
44
push:
@@ -14,7 +14,7 @@ jobs:
1414
strategy:
1515
matrix:
1616
os: [ubuntu-latest, macOS-latest]
17-
python-version: [3.6, 3.7, 3.8]
17+
python-version: [3.7, 3.8, 3.9]
1818

1919
steps:
2020
- uses: actions/checkout@master
@@ -27,20 +27,25 @@ jobs:
2727
python -m pip install --upgrade pip setuptools wheel
2828
python -m pip install -r requirements.txt
2929
python -m pip install -q --no-cache-dir -e .
30-
python -m pip install -q --no-cache-dir pytest pytest-cov isort black
30+
python -m pip install -q --no-cache-dir pytest pytest-cov
31+
python -m pip install -q --no-cache-dir isort black flake8
3132
python -m pip install -q --no-cache-dir sphinx sphinx_rtd_theme
3233
python -m pip install -q --no-cache-dir nbval sphinxcontrib-bibtex
3334
python -m pip install -q --no-cache-dir matplotlib pandas PyYAML
3435
python -m pip install -q --no-cache-dir ipython==7.10
3536
python -m pip list
3637
- name: Lint with Black
37-
if: matrix.python-version == 3.7 && matrix.os == 'ubuntu-latest'
38+
if: matrix.python-version == 3.8 && matrix.os == 'ubuntu-latest'
3839
run: |
3940
python -m black --check --diff -l 80 .
4041
- name: Lint imports with isort
41-
if: matrix.python-version == 3.7 && matrix.os == 'ubuntu-latest'
42+
if: matrix.python-version == 3.8 && matrix.os == 'ubuntu-latest'
4243
run: |
4344
python -m isort -w 80 -m 3 --trailing-comma --check-only .
45+
- name: Lint with flake8
46+
if: matrix.python-version == 3.8 && matrix.os == 'ubuntu-latest'
47+
run: |
48+
python -m flake8 --max-line-length=80 --ignore=E203,W503 .
4449
- name: Test with pytest
4550
run: |
4651
python -m pytest --cov=matching --cov-fail-under=100 tests

CHANGES.rst

+7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
History
22
=======
33

4+
v1.4 - 2020-11-04
5+
-----------------
6+
7+
- Add abstract classes for players, games and matchings.
8+
- Implement extended algorithm for SR, and clean up HR/SM algorithms.
9+
- Move all of the algorithms to their own module, `matching.algorithms`.
10+
411
v1.3.3 - 2020-10-15
512
-------------------
613

README.rst

+5-5
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,11 @@ The ``Matching`` object
9797
+++++++++++++++++++++++
9898

9999
This matching is not a standard Python dictionary, though it does largely look
100-
and behave like one. It is in fact an instance of the ``Matching`` class:
100+
and behave like one. It is in fact an instance of the ``SingleMatching`` class:
101101

102102
>>> matching = game.matching
103103
>>> type(matching)
104-
<class 'matching.matching.Matching'>
104+
<class 'matching.matchings.SingleMatching'>
105105

106106
This dictionary-like object is primarily useful as a teaching device that eases
107107
the process of manipulating a matching after a solution has been found.
@@ -116,9 +116,9 @@ Despite passing dictionaries of strings here, the matching displays instances of
116116
>>> matching = game.matching
117117
>>> for suitor in matching:
118118
... print(type(suitor))
119-
<class 'matching.player.Player'>
120-
<class 'matching.player.Player'>
121-
<class 'matching.player.Player'>
119+
<class 'matching.players.player.Player'>
120+
<class 'matching.players.player.Player'>
121+
<class 'matching.players.player.Player'>
122122

123123
This is because ``create_from_dictionaries`` creates instances of the
124124
appropriate player classes first and passes them to the game class. Using

docs/bibliography.bib

+11-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ @book{Aus13
1212
title = {Pride and Prejudice},
1313
year = {1813},
1414
author = {Austen, Jane},
15-
publisher = {T. Egerton, Military Library, Whitehall, London, UK},
15+
publisher = {T. Egerton, Military Library},
16+
address = {Whitehall, London, UK},
1617
}
1718

1819
@article{DF81,
@@ -26,6 +27,15 @@ @article{DF81
2627
doi = {10.2307/2321753}
2728
}
2829

30+
@book{GI89,
31+
author = {Gusfield, Dan and Irving, Robert W.},
32+
title = {The Stable Marriage Problem: Structure and Algorithms},
33+
year = {1989},
34+
isbn = {0262071185},
35+
publisher = {MIT Press},
36+
address = {Cambridge, MA, USA},
37+
}
38+
2939
@article{GS62,
3040
title = {College Admissions and the Stability of Marriage},
3141
author = {Gale, David and Shapley, Lloyd},
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
matching.algorithms package
2+
===========================
3+
4+
Submodules
5+
----------
6+
7+
matching.algorithms.hospital\_resident module
8+
---------------------------------------------
9+
10+
.. automodule:: matching.algorithms.hospital_resident
11+
:members:
12+
:undoc-members:
13+
:show-inheritance:
14+
15+
matching.algorithms.stable\_marriage module
16+
-------------------------------------------
17+
18+
.. automodule:: matching.algorithms.stable_marriage
19+
:members:
20+
:undoc-members:
21+
:show-inheritance:
22+
23+
matching.algorithms.stable\_roommates module
24+
--------------------------------------------
25+
26+
.. automodule:: matching.algorithms.stable_roommates
27+
:members:
28+
:undoc-members:
29+
:show-inheritance:
30+
31+
matching.algorithms.student\_allocation module
32+
----------------------------------------------
33+
34+
.. automodule:: matching.algorithms.student_allocation
35+
:members:
36+
:undoc-members:
37+
:show-inheritance:
38+
39+
matching.algorithms.util module
40+
-------------------------------
41+
42+
.. automodule:: matching.algorithms.util
43+
:members:
44+
:undoc-members:
45+
:show-inheritance:
46+
47+
48+
Module contents
49+
---------------
50+
51+
.. automodule:: matching.algorithms
52+
:members:
53+
:undoc-members:
54+
:show-inheritance:

docs/reference/source/matching.games.rst

-8
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,6 @@ matching.games.student\_allocation module
3636
:undoc-members:
3737
:show-inheritance:
3838

39-
matching.games.util module
40-
--------------------------
41-
42-
.. automodule:: matching.games.util
43-
:members:
44-
:undoc-members:
45-
:show-inheritance:
46-
4739

4840
Module contents
4941
---------------

docs/reference/source/matching.rst

+9
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,21 @@ Subpackages
66

77
.. toctree::
88

9+
matching.algorithms
910
matching.games
1011
matching.players
1112

1213
Submodules
1314
----------
1415

16+
matching.exceptions module
17+
--------------------------
18+
19+
.. automodule:: matching.exceptions
20+
:members:
21+
:undoc-members:
22+
:show-inheritance:
23+
1524
matching.game module
1625
--------------------
1726

docs/tutorials/project_allocation/main.ipynb

+4-4
Original file line numberDiff line numberDiff line change
@@ -1054,7 +1054,7 @@
10541054
{
10551055
"data": {
10561056
"text/plain": [
1057-
"<matplotlib.legend.Legend at 0x7f922586fc10>"
1057+
"<matplotlib.legend.Legend at 0x7fbcc9eadbb0>"
10581058
]
10591059
},
10601060
"execution_count": 27,
@@ -1172,7 +1172,7 @@
11721172
{
11731173
"data": {
11741174
"text/plain": [
1175-
"<matplotlib.legend.Legend at 0x7f922723e670>"
1175+
"<matplotlib.legend.Legend at 0x7fbccb877cd0>"
11761176
]
11771177
},
11781178
"execution_count": 30,
@@ -1235,7 +1235,7 @@
12351235
"for project, project_students in matching.items():\n",
12361236
" for student in project_students:\n",
12371237
" inverted_matching[student.name] = project.name\n",
1238-
" student_preference_of_matching.append(student.pref_names.index(project.name))"
1238+
" student_preference_of_matching.append(student._pref_names.index(project.name))"
12391239
]
12401240
},
12411241
{
@@ -1547,7 +1547,7 @@
15471547
{
15481548
"data": {
15491549
"text/plain": [
1550-
"<matplotlib.legend.Legend at 0x7f920ae2a820>"
1550+
"<matplotlib.legend.Legend at 0x7fbcaf634dc0>"
15511551
]
15521552
},
15531553
"execution_count": 36,

src/matching/__init__.py

+15-6
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,23 @@
22

33
import sys
44

5-
from .game import BaseGame
6-
from .matching import Matching
7-
from .player import Player
8-
from .version import __version__
9-
105
if not sys.warnoptions:
116
import warnings
127

138
warnings.simplefilter("always")
149

15-
__all__ = ["BaseGame", "Matching", "Player", "__version__"]
10+
from .base import BaseGame, BaseMatching, BasePlayer
11+
from .matchings import MultipleMatching, SingleMatching
12+
from .players import Player
13+
from .version import __version__
14+
15+
__all__ = [
16+
"BaseGame",
17+
"BaseMatching",
18+
"BasePlayer",
19+
"Matching",
20+
"MultipleMatching",
21+
"Player",
22+
"SingleMatching",
23+
"__version__",
24+
]

src/matching/algorithms/__init__.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
""" Top-level imports for the `matching.algorithms` subpackage. """
2+
3+
from .hospital_resident import hospital_resident
4+
from .stable_marriage import stable_marriage
5+
from .stable_roommates import stable_roommates
6+
from .student_allocation import student_allocation
7+
8+
__all__ = [
9+
"hospital_resident",
10+
"stable_marriage",
11+
"stable_roommates",
12+
"student_allocation",
13+
]

0 commit comments

Comments
 (0)