def galeshapley(): if not 'users' in flask.request.json or sum([ not 'ranks' in user or not 'pid' in user for user in flask.request.json['users'] ]) > 0: #check for required fields in json request here flask.abort(400) data = extract_reviews( flask.request.json) #extract json data into necessary format assignments = gs.gale_shapley( data['users'], data['user_size'], data['item_size']) #method where assignment algorithm is run return send_assigned_reviews_as_json( assignments) #returning a flask response object
def solve_matching_problem(raw_players): tied_preferences = obtain_tied_preferences(raw_players) preferences = solve_tied_preferences(tied_preferences, tie_solver_method) players_names = list(map(lambda x: x[1], raw_players)) players = obtain_players(players_names, preferences) half = int(number_of_players / 2) best_half = players[:half] matches = gale_shapley(best_half) print_matches(matches) print() weakly_stable_matching_validator(matches)
def test_three_pair_lying(self): result = gale_shapley([[1, 2, 3], [2, 1, 3], [1, 2, 3]], [[2, 1, 3], [1, 3, 2], [2, 1, 3]]) self.assertEqual({(1, 2), (2, 1), (3, 3)}, result)
def test_single_matching(self): result = gale_shapley([[1]], [[1]]) self.assertEqual({(1, 1)}, result)
def test_two_pair(self): result = gale_shapley([[1, 2], [2, 1]], [[2, 1], [1, 2]]) self.assertEqual({(1, 1), (2, 2)}, result)