def test_encoder_score_use_correct_default(encoder_context): reviewers = [1, 2] papers = [1, 2, 3] scores_by_type = { 'Bid': { 'default': 0.25, 'edges': [(1, 1, 0.7), (2, 2, 0.5), (3, 2, 0.1)] } } weight_by_type = {'Bid': 1} constraints = [] encoder = Encoder(reviewers, papers, constraints, scores_by_type, weight_by_type, ['Affinity']) encoded_aggregate_matrix = encoder.aggregate_score_matrix # Following expected matrix assumes a default of 0.25 for bid scores expected_matrix = [[0.7, 0.25], [0.25, 0.5], [0.25, 0.1]] for a in range(0, 3): assert_arrays(encoded_aggregate_matrix[a], expected_matrix[a])
def test_solvers_fairflow_random(): '''When costs are all zero, compute random assignments''' aggregate_score_matrix_A = np.transpose( np.array([[0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0]])) constraint_matrix = np.zeros(np.shape(aggregate_score_matrix_A)) demands = [1, 1, 2] solver_A = FairFlow([1, 1, 1, 1], [2, 2, 2, 2], demands, encoder(aggregate_score_matrix_A, constraint_matrix)) res_A = solver_A.solve() assert res_A.shape == (3, 4) assert solver_A.solved aggregate_score_matrix_B = np.transpose( np.array([[0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0]])) constraint_matrix = np.zeros(np.shape(aggregate_score_matrix_B)) solver_B = FairFlow([1, 1, 1, 1], [2, 2, 2, 2], demands, encoder(aggregate_score_matrix_B, constraint_matrix)) res_B = solver_B.solve() assert res_B.shape == (3, 4) assert solver_B.solved # ensure that the affinity matrices are random # (i.e. overwhelmingly likely to be different) assert not np.array_equal(solver_A.affinity_matrix, solver_B.affinity_matrix) result_A = [assignments for assignments in np.sum(res_A, axis=1)] assert_arrays(result_A, demands) result_B = [assignments for assignments in np.sum(res_B, axis=1)] assert_arrays(result_B, demands)
def test_solvers_fairflow_custom_demand_and_supply(): ''' Tests 3 papers, 4 reviewers. Reviewers review min: 0, max: [2,1,3,1] papers. The 3 Papers need 2,1,3 reviews. No constraints. Purpose: Assert that custom demand and supply are matched. ''' aggregate_score_matrix_A = np.transpose( np.array([[0.2, 0.1, 0.4], [0.5, 0.2, 0.3], [0.2, 0.0, 0.6], [0.7, 0.9, 0.3]])) constraint_matrix = np.zeros(np.shape(aggregate_score_matrix_A)) demands = [2, 1, 3] solver_A = FairFlow([0, 0, 0, 0], [2, 1, 3, 1], demands, encoder(aggregate_score_matrix_A, constraint_matrix)) res_A = solver_A.solve() assert res_A.shape == (3, 4) result = [assignments for assignments in np.sum(res_A, axis=1)] assert_arrays(result, demands)
def test_solvers_fairflow_custom_supply(): ''' Tests 3 papers, 4 reviewers. Reviewers review min: 1, max: [2,1,3,1] papers respectively. Each papers needs 2 reviews. No constraints. Purpose: Assert that reviewers are assigned papers correctly based on their supply. ''' aggregate_score_matrix_A = np.transpose( np.array([[0.2, 0.1, 0.4], [0.5, 0.2, 0.3], [0.2, 0.0, 0.6], [0.7, 0.9, 0.3]])) constraint_matrix = np.zeros(np.shape(aggregate_score_matrix_A)) demands = [2, 2, 2] solver_A = FairFlow([1, 1, 1, 1], [2, 1, 3, 1], demands, encoder(aggregate_score_matrix_A, constraint_matrix)) res_A = solver_A.solve() assert res_A.shape == (3, 4) result = [assignments for assignments in np.sum(res_A, axis=1)] assert_arrays(result, demands)
def test_encoder_average_weighting(encoder_context): reviewers = [1, 2, 3, 4] papers = [1, 2, 3] scores_by_type = { 'TPMS': { 'edges': [(1, 1, 0), (1, 2, 1), (1, 3, 1), (1, 4, 1), (2, 1, 0.7), (2, 2, 1), (2, 3, 0), (2, 4, 1), (3, 1, 0.6), (3, 2, 0), (3, 3, 1), (3, 4, 0.3)] }, 'Affinity': { 'edges': [(1, 1, 0), (1, 2, 1), (1, 3, 1), (1, 4, 1), (2, 1, 0), (2, 2, 1), (2, 3, 1), (2, 4, 1), (3, 1, 0), (3, 2, 1), (3, 3, 0.5), (3, 4, 0.8)] }, 'Bid': { 'edges': [(1, 1, 0), (1, 2, 1), (1, 3, 1), (1, 4, 1), (2, 1, 0), (2, 2, -1), (2, 3, 1), (2, 4, -0.5), (3, 1, 0), (3, 2, 1), (3, 3, 0.5), (3, 4, 0.75)] } } weight_by_type = {'TPMS': 0.8, 'Affinity': 0.2, 'Bid': 1} constraints = [] encoder = Encoder(reviewers, papers, constraints, scores_by_type, weight_by_type, ['TPMS', 'Affinity']) encoded_aggregate_matrix = encoder.aggregate_score_matrix print(encoded_aggregate_matrix) expected_matrix = [[0, 2, 2, 2], [0.7, 0, 2, 0.5], [0.6, 2, 1.4, 1.15]] print('expected', expected_matrix) for a in range(0, 3): assert_arrays(encoded_aggregate_matrix[a], expected_matrix[a])