https://github.com/mattkrick/edmondsblossom
Edmond's maximum weighted matching algorithm (Blossom algorithm) in O(n^3)
https://github.com/mattkrick/edmondsblossom
Last synced: about 1 month ago
JSON representation
Edmond's maximum weighted matching algorithm (Blossom algorithm) in O(n^3)
- Host: GitHub
- URL: https://github.com/mattkrick/edmondsblossom
- Owner: mattkrick
- License: mit
- Created: 2015-09-02T15:52:46.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2022-01-26T00:53:14.000Z (over 3 years ago)
- Last Synced: 2025-04-08T01:49:29.154Z (about 2 months ago)
- Language: JavaScript
- Size: 8.79 KB
- Stars: 33
- Watchers: 2
- Forks: 7
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# EdmondsBlossom
Edmond's maximum weighted matching algorithm (Blossom algorithm) in O(n^3)##Installation
`npm install edmonds-blossom --save`##How to use
```
var blossom = require('./edmonds-blossom');
var data = [
[0, 1, 6],
[0, 2, 10],
[1, 2, 5]
];
var results = blossom(data);
//results: [2,-1,0];
```
The results are read as follows: index 0 is matchced up with index 2. Index 1 is not used. Index 2 is matched up with index 0 (redundant information).
###What's the most basic example of a problem that this solves?
Let's assume I own a store & only sell items in groups of two.- If I sell a PENCIL and an ERASER, I earn $3
- If I sell a PENCIL and a MARBLE , I earn $2
- If I sell a RULER and an ERASER, I earn $2Each customer is willing to buy up to 1 item of each & I want to maximize profit. Therefore, selling #1 AND #2 is illegal because that would be 2 pencils. #1 AND #3 would is also illegal due to the erasers. So, legal moves are: only #1, only #2, only #3, or #2 AND #3. Since the last option has a profit of $4, I should do that.