for std::vector
for uint32_t
+
for assert
for assert for INT_MAX for IO operations
Greedy Algorithms
+
for std::u32int_t for std::vector for std::find
+
Greedy Algorithms
for assert for std::cout
Greedy Algorithms
for array for IO operations for numeric limits
diff --git a/d2/d90/namespacegreedy__algorithms.js b/d2/d90/namespacegreedy__algorithms.js
index 26286de02..db534295e 100644
--- a/d2/d90/namespacegreedy__algorithms.js
+++ b/d2/d90/namespacegreedy__algorithms.js
@@ -1,6 +1,9 @@
var namespacegreedy__algorithms =
[
[ "dijkstra", "d2/d2f/namespacegreedy__algorithms_1_1dijkstra.html", "d2/d2f/namespacegreedy__algorithms_1_1dijkstra" ],
+ [ "stable_matching", "dd/d9a/namespacegreedy__algorithms_1_1stable__matching.html", [
+ [ "gale_shapley", "dd/d9a/namespacegreedy__algorithms_1_1stable__matching.html#a6d7e84df47dcf19e88f95f8f9040306c", null ]
+ ] ],
[ "can_jump", "d2/d90/namespacegreedy__algorithms.html#a33e3819aa9ffec0e380383c52603b502", null ],
[ "findMinimumEdge", "d2/d90/namespacegreedy__algorithms.html#a349e4ab9a97532c3931a2bd2a19c0098", null ]
];
\ No newline at end of file
diff --git a/db/d80/gale__shapley_8cpp.html b/db/d80/gale__shapley_8cpp.html
new file mode 100644
index 000000000..46981694d
--- /dev/null
+++ b/db/d80/gale__shapley_8cpp.html
@@ -0,0 +1,250 @@
+
+
+
+
+
+
+
+
Algorithms_in_C++: greedy_algorithms/gale_shapley.cpp File Reference
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Algorithms_in_C++ 1.0.0
+
+ Set of algorithms implemented in C++.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Loading...
+
Searching...
+
No Matches
+
+
+
+
+
+
+
+
+
Gale Shapley Algorithm
+More...
+
#include <iostream>
+#include <vector>
+#include <algorithm>
+#include <cassert>
+
+
+
Gale Shapley Algorithm
+
This implementation utilizes the Gale-Shapley algorithm to find stable matches.
+
Gale Shapley Algorithm aims to find a stable matching between two equally sized sets of elements given an ordinal preference for each element. The algorithm was introduced by David Gale and Lloyd Shapley in 1962.
+
Reference: Wikipedia Wikipedia
+
Author B Karthik
+
+
+
◆ main()
+
+
+
+
+
+ int main
+ (
+ void )
+
+
+
+
+
+
Main function.
+
Returns 0 on exit
+
126 {
+
+
128 return 0;
+
129 }
+
static void tests()
Self-test implementations.
Definition gale_shapley.cpp:100
+
+
+
+
+
+
+
◆ tests()
+
+
+
+
+
+
+
+
+ static void tests
+ (
+ )
+
+
+
+
+
+static
+
+
+
+
+
Self-test implementations.
+
Returns void
+
100 {
+
101
+
102 std::vector<std::vector<std::uint32_t> > primary_preferences = {{0, 1, 2, 3}, {2, 1, 3, 0}, {1, 2, 0, 3}, {3, 0, 1, 2}};
+
103 std::vector<std::vector<std::uint32_t> > secondary_preferences = {{1, 0, 2, 3}, {3, 0, 1, 2}, {0, 2, 1, 3}, {1, 2, 0, 3}};
+
+
105
+
106
+
107 primary_preferences = {{0, 2, 1, 3}, {2, 3, 0, 1}, {3, 1, 2, 0}, {2, 1, 0, 3}};
+
108 secondary_preferences = {{1, 0, 2, 3}, {3, 0, 1, 2}, {0, 2, 1, 3}, {1, 2, 0, 3}};
+
+
110
+
111
+
112 primary_preferences = {{0, 1, 2}, {2, 1, 0}, {1, 2, 0}};
+
113 secondary_preferences = {{1, 0, 2}, {2, 0, 1}, {0, 2, 1}};
+
+
115
+
116
+
117 primary_preferences = {};
+
118 secondary_preferences = {};
+
+
120 }
+
std::vector< std::uint32_t > gale_shapley(const std::vector< std::vector< std::uint32_t > > &secondary_preferences, const std::vector< std::vector< std::uint32_t > > &primary_preferences)
The main function that finds the stable matching between two sets of elements using the Gale-Shapley ...
Definition gale_shapley.cpp:42
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/db/d80/gale__shapley_8cpp.js b/db/d80/gale__shapley_8cpp.js
new file mode 100644
index 000000000..cbbc4e83a
--- /dev/null
+++ b/db/d80/gale__shapley_8cpp.js
@@ -0,0 +1,6 @@
+var gale__shapley_8cpp =
+[
+ [ "gale_shapley", "db/d80/gale__shapley_8cpp.html#a6d7e84df47dcf19e88f95f8f9040306c", null ],
+ [ "main", "db/d80/gale__shapley_8cpp.html#ae66f6b31b5ad750f1fe042a706a4e3d4", null ],
+ [ "tests", "db/d80/gale__shapley_8cpp.html#a483bb8ccf42aaf7375a83e91490eda1e", null ]
+];
\ No newline at end of file
diff --git a/db/d80/gale__shapley_8cpp_a483bb8ccf42aaf7375a83e91490eda1e_cgraph.map b/db/d80/gale__shapley_8cpp_a483bb8ccf42aaf7375a83e91490eda1e_cgraph.map
new file mode 100644
index 000000000..ff6f9b14b
--- /dev/null
+++ b/db/d80/gale__shapley_8cpp_a483bb8ccf42aaf7375a83e91490eda1e_cgraph.map
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
diff --git a/db/d80/gale__shapley_8cpp_a483bb8ccf42aaf7375a83e91490eda1e_cgraph.md5 b/db/d80/gale__shapley_8cpp_a483bb8ccf42aaf7375a83e91490eda1e_cgraph.md5
new file mode 100644
index 000000000..2402d847e
--- /dev/null
+++ b/db/d80/gale__shapley_8cpp_a483bb8ccf42aaf7375a83e91490eda1e_cgraph.md5
@@ -0,0 +1 @@
+10eb6585cdd9e9d606f67df39451ea7a
\ No newline at end of file
diff --git a/db/d80/gale__shapley_8cpp_a483bb8ccf42aaf7375a83e91490eda1e_cgraph.svg b/db/d80/gale__shapley_8cpp_a483bb8ccf42aaf7375a83e91490eda1e_cgraph.svg
new file mode 100644
index 000000000..9173c590b
--- /dev/null
+++ b/db/d80/gale__shapley_8cpp_a483bb8ccf42aaf7375a83e91490eda1e_cgraph.svg
@@ -0,0 +1,85 @@
+
+
+
+
+
+
+
+
+
+
+
+
+tests
+
+
+Node1
+
+
+tests
+
+
+
+
+
+Node2
+
+
+greedy_algorithms::
+stable_matching::gale
+_shapley
+
+
+
+
+
+Node1->Node2
+
+
+
+
+
+
+
+
+Node3
+
+
+std::find
+
+
+
+
+
+Node2->Node3
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/db/d80/gale__shapley_8cpp_a483bb8ccf42aaf7375a83e91490eda1e_cgraph_org.svg b/db/d80/gale__shapley_8cpp_a483bb8ccf42aaf7375a83e91490eda1e_cgraph_org.svg
new file mode 100644
index 000000000..c739c840e
--- /dev/null
+++ b/db/d80/gale__shapley_8cpp_a483bb8ccf42aaf7375a83e91490eda1e_cgraph_org.svg
@@ -0,0 +1,59 @@
+
+
+
+
+
+
+tests
+
+
+Node1
+
+
+tests
+
+
+
+
+
+Node2
+
+
+greedy_algorithms::
+stable_matching::gale
+_shapley
+
+
+
+
+
+Node1->Node2
+
+
+
+
+
+
+
+
+Node3
+
+
+std::find
+
+
+
+
+
+Node2->Node3
+
+
+
+
+
+
+
+
diff --git a/db/d80/gale__shapley_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.map b/db/d80/gale__shapley_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.map
new file mode 100644
index 000000000..436cb36a7
--- /dev/null
+++ b/db/d80/gale__shapley_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.map
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
diff --git a/db/d80/gale__shapley_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.md5 b/db/d80/gale__shapley_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.md5
new file mode 100644
index 000000000..4dcf2c6b0
--- /dev/null
+++ b/db/d80/gale__shapley_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.md5
@@ -0,0 +1 @@
+57ab2bbadab7072265c0260236c9486c
\ No newline at end of file
diff --git a/db/d80/gale__shapley_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.svg b/db/d80/gale__shapley_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.svg
new file mode 100644
index 000000000..8e2dac034
--- /dev/null
+++ b/db/d80/gale__shapley_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.svg
@@ -0,0 +1,103 @@
+
+
+
+
+
+
+
+
+
+
+
+
+main
+
+
+Node1
+
+
+main
+
+
+
+
+
+Node2
+
+
+tests
+
+
+
+
+
+Node1->Node2
+
+
+
+
+
+
+
+
+Node3
+
+
+greedy_algorithms::
+stable_matching::gale
+_shapley
+
+
+
+
+
+Node2->Node3
+
+
+
+
+
+
+
+
+Node4
+
+
+std::find
+
+
+
+
+
+Node3->Node4
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/db/d80/gale__shapley_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph_org.svg b/db/d80/gale__shapley_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph_org.svg
new file mode 100644
index 000000000..de38bb30c
--- /dev/null
+++ b/db/d80/gale__shapley_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph_org.svg
@@ -0,0 +1,77 @@
+
+
+
+
+
+
+main
+
+
+Node1
+
+
+main
+
+
+
+
+
+Node2
+
+
+tests
+
+
+
+
+
+Node1->Node2
+
+
+
+
+
+
+
+
+Node3
+
+
+greedy_algorithms::
+stable_matching::gale
+_shapley
+
+
+
+
+
+Node2->Node3
+
+
+
+
+
+
+
+
+Node4
+
+
+std::find
+
+
+
+
+
+Node3->Node4
+
+
+
+
+
+
+
+
diff --git a/dd/d9a/namespacegreedy__algorithms_1_1stable__matching.html b/dd/d9a/namespacegreedy__algorithms_1_1stable__matching.html
new file mode 100644
index 000000000..70e7e6004
--- /dev/null
+++ b/dd/d9a/namespacegreedy__algorithms_1_1stable__matching.html
@@ -0,0 +1,229 @@
+
+
+
+
+
+
+
+
Algorithms_in_C++: greedy_algorithms::stable_matching Namespace Reference
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Algorithms_in_C++ 1.0.0
+
+ Set of algorithms implemented in C++.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Loading...
+
Searching...
+
No Matches
+
+
+
+
+
+
+
+
+
Functions for the Gale-Shapley Algorithm.
+More...
+
+
+
Functions for the Gale-Shapley Algorithm.
+
+
+
◆ gale_shapley()
+
+
+
+
+
The main function that finds the stable matching between two sets of elements using the Gale-Shapley Algorithm.
+
Note This doesn't work on negative preferences. the preferences should be continuous integers starting from 0 to number of preferences - 1.
+
Parameters
+
+ primary_preferences the preferences of the primary set should be a 2D vector
+ secondary_preferences the preferences of the secondary set should be a 2D vector
+
+
+
+
Returns matches the stable matching between the two sets
+
42 {
+
+
+
+
+
47
+
48 while (true ) {
+
49 int free_primary_index = -1;
+
50
+
51
+
+
53 if (is_free_primary[i]) {
+
54 free_primary_index = i;
+
55 break ;
+
56 }
+
57 }
+
58
+
59
+
60 if (free_primary_index == -1) break ;
+
61
+
62
+
63 std::uint32_t secondary_to_propose = primary_preferences[free_primary_index][proposal_index[free_primary_index]];
+
64 proposal_index[free_primary_index]++;
+
65
+
66
+
+
68
+
69
+
70 if (current_match == -1) {
+
71 matches[secondary_to_propose] = free_primary_index;
+
72 is_free_primary[free_primary_index] = false ;
+
73 } else {
+
74
+
75 auto new_proposer_rank =
std::find (secondary_preferences[secondary_to_propose].
begin (),
+
76 secondary_preferences[secondary_to_propose].
end (),
+
77 free_primary_index);
+
78 auto current_match_rank =
std::find (secondary_preferences[secondary_to_propose].
begin (),
+
79 secondary_preferences[secondary_to_propose].
end (),
+
80 current_match);
+
81
+
82
+
83 if (new_proposer_rank < current_match_rank) {
+
84 matches[secondary_to_propose] = free_primary_index;
+
85 is_free_primary[free_primary_index] = false ;
+
86 is_free_primary[current_match] = true ;
+
87 }
+
88 }
+
89 }
+
90
+
91 return matches;
+
92 }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/dd/d9a/namespacegreedy__algorithms_1_1stable__matching_a6d7e84df47dcf19e88f95f8f9040306c_cgraph.map b/dd/d9a/namespacegreedy__algorithms_1_1stable__matching_a6d7e84df47dcf19e88f95f8f9040306c_cgraph.map
new file mode 100644
index 000000000..f55e87aff
--- /dev/null
+++ b/dd/d9a/namespacegreedy__algorithms_1_1stable__matching_a6d7e84df47dcf19e88f95f8f9040306c_cgraph.map
@@ -0,0 +1,5 @@
+
+
+
+
+
diff --git a/dd/d9a/namespacegreedy__algorithms_1_1stable__matching_a6d7e84df47dcf19e88f95f8f9040306c_cgraph.md5 b/dd/d9a/namespacegreedy__algorithms_1_1stable__matching_a6d7e84df47dcf19e88f95f8f9040306c_cgraph.md5
new file mode 100644
index 000000000..3265fd704
--- /dev/null
+++ b/dd/d9a/namespacegreedy__algorithms_1_1stable__matching_a6d7e84df47dcf19e88f95f8f9040306c_cgraph.md5
@@ -0,0 +1 @@
+d3562925c9ac7b7d6fd2b415f97bed7a
\ No newline at end of file
diff --git a/dd/d9a/namespacegreedy__algorithms_1_1stable__matching_a6d7e84df47dcf19e88f95f8f9040306c_cgraph.svg b/dd/d9a/namespacegreedy__algorithms_1_1stable__matching_a6d7e84df47dcf19e88f95f8f9040306c_cgraph.svg
new file mode 100644
index 000000000..ec79edb87
--- /dev/null
+++ b/dd/d9a/namespacegreedy__algorithms_1_1stable__matching_a6d7e84df47dcf19e88f95f8f9040306c_cgraph.svg
@@ -0,0 +1,67 @@
+
+
+
+
+
+
+
+
+
+
+
+
+greedy_algorithms::stable_matching::gale_shapley
+
+
+Node1
+
+
+greedy_algorithms::
+stable_matching::gale
+_shapley
+
+
+
+
+
+Node2
+
+
+std::find
+
+
+
+
+
+Node1->Node2
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/dd/d9a/namespacegreedy__algorithms_1_1stable__matching_a6d7e84df47dcf19e88f95f8f9040306c_cgraph_org.svg b/dd/d9a/namespacegreedy__algorithms_1_1stable__matching_a6d7e84df47dcf19e88f95f8f9040306c_cgraph_org.svg
new file mode 100644
index 000000000..f0b464cbb
--- /dev/null
+++ b/dd/d9a/namespacegreedy__algorithms_1_1stable__matching_a6d7e84df47dcf19e88f95f8f9040306c_cgraph_org.svg
@@ -0,0 +1,41 @@
+
+
+
+
+
+
+greedy_algorithms::stable_matching::gale_shapley
+
+
+Node1
+
+
+greedy_algorithms::
+stable_matching::gale
+_shapley
+
+
+
+
+
+Node2
+
+
+std::find
+
+
+
+
+
+Node1->Node2
+
+
+
+
+
+
+
+
diff --git a/dd/dab/gale__shapley_8cpp__incl.map b/dd/dab/gale__shapley_8cpp__incl.map
new file mode 100644
index 000000000..c1ed2a86b
--- /dev/null
+++ b/dd/dab/gale__shapley_8cpp__incl.map
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/dd/dab/gale__shapley_8cpp__incl.md5 b/dd/dab/gale__shapley_8cpp__incl.md5
new file mode 100644
index 000000000..cf6c49b4e
--- /dev/null
+++ b/dd/dab/gale__shapley_8cpp__incl.md5
@@ -0,0 +1 @@
+4b4ec511a50c6aac961709ae72aea6f2
\ No newline at end of file
diff --git a/dd/dab/gale__shapley_8cpp__incl.svg b/dd/dab/gale__shapley_8cpp__incl.svg
new file mode 100644
index 000000000..bab59d6ca
--- /dev/null
+++ b/dd/dab/gale__shapley_8cpp__incl.svg
@@ -0,0 +1,120 @@
+
+
+
+
+
+
+
+
+
+
+
+
+greedy_algorithms/gale_shapley.cpp
+
+
+Node1
+
+
+greedy_algorithms/gale
+_shapley.cpp
+
+
+
+
+
+Node2
+
+
+iostream
+
+
+
+
+
+Node1->Node2
+
+
+
+
+
+
+
+
+Node3
+
+
+vector
+
+
+
+
+
+Node1->Node3
+
+
+
+
+
+
+
+
+Node4
+
+
+algorithm
+
+
+
+
+
+Node1->Node4
+
+
+
+
+
+
+
+
+Node5
+
+
+cassert
+
+
+
+
+
+Node1->Node5
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/dd/dab/gale__shapley_8cpp__incl_org.svg b/dd/dab/gale__shapley_8cpp__incl_org.svg
new file mode 100644
index 000000000..0880c972d
--- /dev/null
+++ b/dd/dab/gale__shapley_8cpp__incl_org.svg
@@ -0,0 +1,94 @@
+
+
+
+
+
+
+greedy_algorithms/gale_shapley.cpp
+
+
+Node1
+
+
+greedy_algorithms/gale
+_shapley.cpp
+
+
+
+
+
+Node2
+
+
+iostream
+
+
+
+
+
+Node1->Node2
+
+
+
+
+
+
+
+
+Node3
+
+
+vector
+
+
+
+
+
+Node1->Node3
+
+
+
+
+
+
+
+
+Node4
+
+
+algorithm
+
+
+
+
+
+Node1->Node4
+
+
+
+
+
+
+
+
+Node5
+
+
+cassert
+
+
+
+
+
+Node1->Node5
+
+
+
+
+
+
+
+
diff --git a/dir_0eaa691bd54ab0922ca7f50599de6d22.html b/dir_0eaa691bd54ab0922ca7f50599de6d22.html
index 76af28ba1..67907aafb 100644
--- a/dir_0eaa691bd54ab0922ca7f50599de6d22.html
+++ b/dir_0eaa691bd54ab0922ca7f50599de6d22.html
@@ -116,6 +116,9 @@ Files
dijkstra.cpp
Dijkstra algorithm implementation
+
gale_shapley.cpp
+
Gale Shapley Algorithm
+
jump_game.cpp
Jumping Game algorithm implementation
diff --git a/dir_0eaa691bd54ab0922ca7f50599de6d22.js b/dir_0eaa691bd54ab0922ca7f50599de6d22.js
index 1372d9b9f..174d12979 100644
--- a/dir_0eaa691bd54ab0922ca7f50599de6d22.js
+++ b/dir_0eaa691bd54ab0922ca7f50599de6d22.js
@@ -2,6 +2,7 @@ var dir_0eaa691bd54ab0922ca7f50599de6d22 =
[
[ "boruvkas_minimum_spanning_tree.cpp", "d4/d6c/boruvkas__minimum__spanning__tree_8cpp.html", "d4/d6c/boruvkas__minimum__spanning__tree_8cpp" ],
[ "dijkstra.cpp", "df/dcb/greedy__algorithms_2dijkstra_8cpp.html", "df/dcb/greedy__algorithms_2dijkstra_8cpp" ],
+ [ "gale_shapley.cpp", "db/d80/gale__shapley_8cpp.html", "db/d80/gale__shapley_8cpp" ],
[ "jump_game.cpp", "d6/dba/jump__game_8cpp.html", "d6/dba/jump__game_8cpp" ],
[ "kruskals_minimum_spanning_tree.cpp", "d8/d7d/kruskals__minimum__spanning__tree_8cpp.html", "d8/d7d/kruskals__minimum__spanning__tree_8cpp" ]
];
\ No newline at end of file
diff --git a/doxygen_crawl.html b/doxygen_crawl.html
index b13b35395..ac13aa3fc 100644
--- a/doxygen_crawl.html
+++ b/doxygen_crawl.html
@@ -118,6 +118,7 @@
+
@@ -509,6 +510,7 @@
+
@@ -3102,6 +3104,10 @@
+
+
+
+
@@ -3590,6 +3596,8 @@
+
+
diff --git a/files.html b/files.html
index 04c0a932d..0944e54f5 100644
--- a/files.html
+++ b/files.html
@@ -219,8 +219,9 @@ solve-a-rat-in-a-maze-c-java-pytho/" target="_blank">Rat in a Maze algorithm
► greedy_algorithms
boruvkas_minimum_spanning_tree.cpp [Borůvkas Algorithm](https://en.wikipedia.org/wiki/Borůvka's_algorithm ) to find the Minimum Spanning Tree
dijkstra.cpp Dijkstra algorithm implementation
-
jump_game.cpp Jumping Game algorithm implementation
-
kruskals_minimum_spanning_tree.cpp Kruskals Minimum Spanning Tree implementation
+
gale_shapley.cpp Gale Shapley Algorithm
+
jump_game.cpp Jumping Game algorithm implementation
+
kruskals_minimum_spanning_tree.cpp Kruskals Minimum Spanning Tree implementation
► hashing
chaining.cpp Implementation of hash chains
double_hash_hash_table.cpp Storage mechanism using double-hashed keys
diff --git a/globals_func_m.html b/globals_func_m.html
index e147301aa..2553d7c76 100644
--- a/globals_func_m.html
+++ b/globals_func_m.html
@@ -107,7 +107,7 @@ $(function(){initNavTree('globals_func_m.html',''); initResizable(true); });
Here is a list of all documented functions with links to the documentation:
- m -