stablematch
A pure javascript implementation of a Stable Matching Algorithm, which is used to provide a solution to the stable marriage problem (http://wikipedia.org/wiki/Stable_marriage_problem) using a left-optimized algorithm.
The core implementation was shamelessly scrubbed and adapted from the "toy" implementation by Paul Butler (https://github.com/paulgb/Python-Gale-Shapley/), adapted to javascript and improved to support asymmetric data sets.
Installation
This is the easy part, provided you have npm
installed:
npm install stablematch
Usage
Here is an example of how to pair up two six-element sets. Note the
use of amdefine, which allows
stablematch
to be used in any javascript-enabled context.
if typeofdefine !== 'function'var define = module;;
Performance and Optimality
The implementation is not intended to be the world's best... It was, after all, a quick-n-dirty implementation done one Saturday morning just so that a basic pairing could be done inside the syncml-js package...
If you care to improve it in any way, please do so! I'll accept any pull requests that don't break it and improve performance.