1
0
Fork 0
Python code for Maximum Weighted Matching in general graphs
Go to file
Joris van Rantwijk 77dac28056 Moved repository to Gitea 2024-03-08 12:09:30 +01:00
cpp Add corner cases to C++ unit test 2023-07-07 22:33:33 +02:00
doc Move Algorithm.md to doc folder 2023-04-15 12:03:39 +02:00
python Fix bug in C++ matching code 2023-07-07 22:33:33 +02:00
tests Simplify --solver syntax of run_test.py 2023-06-16 20:52:06 +02:00
.gitignore C++ command line tool to run matching 2023-07-07 22:33:33 +02:00
README.md Moved repository to Gitea 2024-03-08 12:09:30 +01:00
pylintrc Pylint cleanups 2023-03-12 12:16:29 +01:00
run_checks.sh Add script to run tests 2023-04-14 15:45:26 +02:00
run_tests.sh Moved repository to Gitea 2024-03-08 12:09:30 +01:00

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 

    cpp/
        mwmatching.h           : C++ implementation of maximum weight matching
        test_mwmatching.cpp    : Unit tests
        run_matching.cpp       : 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.

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.