Stable Marriage Algorithm

No algorithm description given

0. TL;DR This algorithm gives you the optimal matching for a preferred set. 1. Introduction The stable marriage problem (also known as stable matching problem) is the problem of finding a stable matching between two equally sized sets of elements given an ordering of preferences for each element. This is the McVitie-Wilson version of the Gale-Shapley Algorithm. This algorithm requires two sets of items where the algorithm gives the optimal matching for one of the groups. One example of a use-case could be matching customers with taxi drivers. You can get the optimal matching in favor of the customers by passing it under the "optimal" key. If not, you can pass the taxi drivers instead. It will express one matching among all other possible matches that is the most favorable to the preferred set of items. The algorithm will produce stable matches in all cases, but will always express a positive preference for a given match. If you get the same match after switching the preferred set of items, this means that you have a super-stable matching. A matching is super-stable if there is no couple each of whom either strictly prefers the other to his/her partner or is indifferent between them. Input (Required) : Optimal (preferred) dictionary of desired matches. (Required) : Pessimal dictionary desired matches. Output A dictionary of stable matches optimized for the optimal dictionary. 2. Dictionary of desired matches Optimal (preferred) dictionary of desired matches: A dictionary of lists. Algorithms optimizes the matching in favor of these lists.  (key = "optimal") Example dictionary of optimal (preferred) desired matches: {
 "optimal": {
 "reese": ["morgan", "groves", "carter", "shaw"],
 "finch": ["morgan", "carter", "shaw", "groves"],
 "fusco": ["shaw", "carter", "groves", "morgan"],
 "elias": ["groves", "carter", "shaw", "morgan"]
 }
} Pessimal dictionary of desired matches: A dictionary of lists. Algorithms doesn't optimize the matching in favor of these lists  (key = "pessimal") Example dictionary of pessimal desired matched: {
 "pessimal":{
 "carter": ["reese", "fusco", "elias", "finch"],
 "shaw": ["elias", "reese", "fusco", "finch"],
 "groves": ["reese", "fusco", "elias", "finch"],
 "morgan": ["finch", "fusco", "elias", "reese"]
 }
} 3. Output A dictionary of stable matches optimized for the optimal dictionary: Returns a list of matches between two sets that are optimized for the given optimal labelled list. (key = "matches") Example of Output: {
 "matches":{
 "fusco":"shaw",
 "reese":"morgan",
 "elias":"groves",
 "finch":"carter"}
} 4. Examples Example 1: Parameter 1: Optimal list of strings Parameter 2: Pessimal list of strings {
 "optimal": {
 "reese": ["morgan", "groves", "carter", "shaw"],
 "finch": ["morgan", "carter", "shaw", "groves"],
 "fusco": ["shaw", "carter", "groves", "morgan"],
 "elias": ["groves", "carter", "shaw", "morgan"]
 },
 "pessimal":{
 "carter": ["reese", "fusco", "elias", "finch"],
 "shaw": ["elias", "reese", "fusco", "finch"],
 "groves": ["reese", "fusco", "elias", "finch"],
 "morgan": ["finch", "fusco", "elias", "reese"]
 }
} Output: {
 "matches":{
 "fusco":"shaw",
 "reese":"morgan",
 "elias":"groves",
 "finch":"carter"}
} Example 2: Parameter 1: Optimal list of strings Parameter 2: Pessimal list of strings {
 "optimal":{
 "carter": ["reese", "fusco", "elias", "finch"],
 "shaw": ["elias", "reese", "fusco", "finch"],
 "groves": ["reese", "fusco", "elias", "finch"],
 "morgan": ["finch", "fusco", "elias", "reese"]
 },
 "pessimal": {
 "reese": ["morgan", "groves", "carter", "shaw"],
 "finch": ["morgan", "carter", "shaw", "groves"],
 "fusco": ["shaw", "carter", "groves", "morgan"],
 "elias": ["groves", "carter", "shaw", "morgan"]
 }
} Output: {
 "matches": {
 "groves": "reese",
 "carter": "fusco",
 "morgan": "finch",
 "shaw": "elias"
 }
} 5. Credits The implementation done here is the algorithm known as McVitie-Wilson version of the Gale-Shapley Algorithm. For more information, please refer to  D. G. McVitie and L. B. Wilson. 1971. The stable marriage problem. Commun. ACM 14, 7 (July 1971), 486-490. DOI=http://dx.doi.org/10.1145/362619.362631

Tags
(no tags)

Cost Breakdown

0 cr
royalty per call
1 cr
usage per second
avg duration

Cost Calculator

API call duration (sec)
×
API calls
=
Estimated cost
per calls
for large volume discounts
For additional details on how pricing works, see Algorithmia pricing.

No permissions required

This algorithm does not require any special permissions.


To understand more about how algorithm permissions work, see the permissions documentation.

1. Type your input

2. See the result

Running algorithm...

3. Use this algorithm

curl -X POST -d '{{input | formatInput:"curl"}}' -H 'Content-Type: application/json' -H 'Authorization: Simple YOUR_API_KEY' https://api.algorithmia.com/v1/algo/matching/StableMarriageAlgorithm/0.1.1
View cURL Docs
algo auth
# Enter API Key: YOUR_API_KEY
algo run algo://matching/StableMarriageAlgorithm/0.1.1 -d '{{input | formatInput:"cli"}}'
View CLI Docs
import com.algorithmia.*;
import com.algorithmia.algo.*;

String input = "{{input | formatInput:"java"}}";
AlgorithmiaClient client = Algorithmia.client("YOUR_API_KEY");
Algorithm algo = client.algo("algo://matching/StableMarriageAlgorithm/0.1.1");
AlgoResponse result = algo.pipeJson(input);
System.out.println(result.asJsonString());
View Java Docs
import com.algorithmia._
import com.algorithmia.algo._

val input = {{input | formatInput:"scala"}}
val client = Algorithmia.client("YOUR_API_KEY")
val algo = client.algo("algo://matching/StableMarriageAlgorithm/0.1.1")
val result = algo.pipeJson(input)
System.out.println(result.asJsonString)
View Scala Docs
var input = {{input | formatInput:"javascript"}};
Algorithmia.client("YOUR_API_KEY")
           .algo("algo://matching/StableMarriageAlgorithm/0.1.1")
           .pipe(input)
           .then(function(output) {
             console.log(output);
           });
View Javascript Docs
var input = {{input | formatInput:"javascript"}};
Algorithmia.client("YOUR_API_KEY")
           .algo("algo://matching/StableMarriageAlgorithm/0.1.1")
           .pipe(input)
           .then(function(response) {
             console.log(response.get());
           });
View NodeJS Docs
import Algorithmia

input = {{input | formatInput:"python"}}
client = Algorithmia.client('YOUR_API_KEY')
algo = client.algo('matching/StableMarriageAlgorithm/0.1.1')
print algo.pipe(input)
View Python Docs
library(algorithmia)

input <- {{input | formatInput:"r"}}
client <- getAlgorithmiaClient("YOUR_API_KEY")
algo <- client$algo("matching/StableMarriageAlgorithm/0.1.1")
result <- algo$pipe(input)$result
print(result)
View R Docs
require 'algorithmia'

input = {{input | formatInput:"ruby"}}
client = Algorithmia.client('YOUR_API_KEY')
algo = client.algo('matching/StableMarriageAlgorithm/0.1.1')
puts algo.pipe(input).result
View Ruby Docs
use algorithmia::*;

let input = {{input | formatInput:"rust"}};
let client = Algorithmia::client("YOUR_API_KEY");
let algo = client.algo('matching/StableMarriageAlgorithm/0.1.1');
let response = algo.pipe(input);
View Rust Docs
Discussion
  • {{comment.username}}