1
1
/* *
2
2
* @file
3
- * @brief [Gale Shapley](https://en.wikipedia.org/wiki/Gale%E2%80%93Shapley_algorithm)
3
+ * @brief [Gale Shapley Algorithm ](https://en.wikipedia.org/wiki/Gale%E2%80%93Shapley_algorithm)
4
4
* @details
5
5
* This implementation utilizes the Gale-Shapley algorithm to find stable matches
6
6
*
7
- * **Gale Shapley** aims to find a stable matching between two equally sized
7
+ * **Gale Shapley Algorithm ** aims to find a stable matching between two equally sized
8
8
* sets of elements given an ordinal preference for each element. The algorithm was
9
9
* introduced by David Gale and Lloyd Shapley in 1962.
10
10
*
11
11
* Reference:
12
12
* [Wikipedia](https://en.wikipedia.org/wiki/Gale%E2%80%93Shapley_algorithm)
13
- * [Wikipedia](https://en.wikipedia.org/wiki/Stable_marriage_problem )
13
+ * [Wikipedia](https://en.wikipedia.org/wiki/Stable_matching_problem )
14
14
*
15
15
* @author [B Karthik](https://github.com/BKarthik7)
16
16
*/
27
27
namespace greedy_algorithms {
28
28
/* *
29
29
* @namespace
30
- * @brief Functions for the [ Gale Shapley](https://en.wikipedia.org/wiki/Gale%E2%80%93Shapley_algorithm) algorithm
30
+ * @brief Functions for the Gale Shapley Algorithm
31
31
*/
32
- namespace stable_marriage {
32
+ namespace stable_matching {
33
33
void gale_shapley (const std::vector<std::vector<int >>& set_2_prefs, const std::vector<std::vector<int >>& set_1_prefs) {
34
34
int n = set_2_prefs.size ();
35
35
std::vector<int > engagements (n, -1 );
@@ -66,7 +66,7 @@ void gale_shapley(const std::vector<std::vector<int>>& set_2_prefs, const std::v
66
66
}
67
67
std::cout << std::endl;
68
68
}
69
- } // namespace stable_marriage
69
+ } // namespace stable_matching
70
70
} // namespace greedy_algorithms
71
71
72
72
/* *
@@ -78,17 +78,17 @@ static void tests() {
78
78
// Test Case 1
79
79
std::vector<std::vector<int >> set_1_prefs = {{0 , 1 , 2 , 3 }, {2 , 1 , 3 , 0 }, {1 , 2 , 0 , 3 }, {3 , 0 , 1 , 2 }};
80
80
std::vector<std::vector<int >> set_2_prefs = {{1 , 0 , 2 , 3 },{3 , 0 , 1 , 2 },{0 , 2 , 1 , 3 },{1 , 2 , 0 , 3 }};
81
- greedy_algorithms::stable_marriage ::gale_shapley (set_2_prefs, set_1_prefs);
81
+ greedy_algorithms::stable_matching ::gale_shapley (set_2_prefs, set_1_prefs);
82
82
83
83
// Test Case 2
84
84
set_1_prefs = {{0 , 2 , 1 , 3 }, {2 , 3 , 0 , 1 }, {3 , 1 , 2 , 0 }, {2 , 1 , 0 , 3 }};
85
85
set_2_prefs = {{1 , 0 , 2 , 3 },{3 , 0 , 1 , 2 },{0 , 2 , 1 , 3 },{1 , 2 , 0 , 3 }};
86
- greedy_algorithms::stable_marriage ::gale_shapley (set_2_prefs, set_1_prefs);
86
+ greedy_algorithms::stable_matching ::gale_shapley (set_2_prefs, set_1_prefs);
87
87
88
88
// Test Case 3
89
89
set_1_prefs = {{0 , 1 , 2 }, {2 , 1 , 0 }, {1 , 2 , 0 }};
90
90
set_2_prefs = {{1 , 0 , 2 },{2 , 0 , 1 },{0 , 2 , 1 }};
91
- greedy_algorithms::stable_marriage ::gale_shapley (set_2_prefs, set_1_prefs);
91
+ greedy_algorithms::stable_matching ::gale_shapley (set_2_prefs, set_1_prefs);
92
92
}
93
93
94
94
/* *
0 commit comments