Joris van Rantwijk 76de35471f | ||
---|---|---|
.github/workflows | ||
doc | ||
python | ||
tests | ||
.gitignore | ||
README.md | ||
pylintrc | ||
run_checks.sh |
README.md
Maximum Weighted Matching
This repository contains a Python 3 implementation of maximum weighted matching in general graphs.
In graph theory, a matching is a subset of edges that does not use any vertex more than once. For an edge-weighted graph, a maximum weight matching is a matching that achieves the largest possible sum of weights of matched edges.
The code in this repository is based on a variant of the blossom algorithm that runs in O(n3) steps. See the file Algorithm.md for a detailed description.
You may find this repository useful if ...
- you want a stand-alone, pure Python module that calculates maximum weight matchings with reasonable efficiency;
- or you want to play around with a maximum weight matching algorithm to learn how it works.
This repository is probably not the best place if ...
- you need a very fast routine that quickly matches large graphs (more than ~ 1000 vertices). In that case I recommend LEMON, a C++ library that provides a blazingly fast implementation.
- or you want a high quality Python package that provides abstract graph data structures and graph algorithms. In that case I recommend NetworkX.
- or you are only interested in bipartite graphs. There are simpler and faster algorithms for matching bipartite graphs.
Repository structure
python/
mwmatching.py : Python implementation of maximum weight matching
test_mwmatching.py : Unit tests
run_matching.py : Command-line program to run the matching algorithm
tests/
generate/ : Python programs to generate graphs
graphs/ : Collection of graphs and matching outputs
lemon/ : C++ program to run LEMON's matching algorithm
run_test.py : Command-line program to test/benchmark matching solvers
doc/
Algorithm.md : Description of the algorithm
Status of this software
The code is finished and tested and it works.
I ran extensive tests on random graphs and compared the results against another solver. It seems to me that most bugs would have been found through these tests. But it is definitely still possible that I overlooked something.
This repository is just a side-project for me. I don't have any plans to develop this into a polished, full-featured, supported software package.
If you find any bugs in this code, please let me know by reporting an issue in the Github repository. I will try to respond to issue reports and fix bugs. I will probably not accept pull requests.
Credits
The code in this repository was written by me, but it implements an algorithm that has been known for decades. This algorithm is entirely the work of other people. I did not invent any part of it, and deserve no credit for it.
My implementation follows the description of the algorithm as it appears in the paper "Efficient Algorithms for Finding Maximum Matching in Graphs" by Zvi Galil (1986). However, earlier versions of the algorithm were invented and improved by several other scientists. See the file Algorithm.md for links to the most important papers.
I used Fortran programs hardcard.f
, t.f
and tt.f
by R. B. Mattingly and N. Ritchey
to generate test graphs.
These programs are part of the DIMACS Network Flows and Matching implementation challenge.
They can be found in the
DIMACS Netflow archive.
To check the correctness of my results, I used other maximum weight matching solvers:
the MaxWeightedMatching
module in LEMON,
and the program
wmatch
by Edward Rothberg.
License
The following license applies to the software in this repository, excluding the folder doc
.
This license is sometimes called the MIT License or the Expat License:
Copyright (c) 2023 Joris van Rantwijk
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice (including the next paragraph) shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
The following applies to the documentation in the folder doc:
Written in 2023 by Joris van Rantwijk.
This work is licensed under a Creative Commons Attribution-NoDerivatives 4.0 International License.