Exemplo n.º 1
0
def get_matching_cost_pos_swap(election_1: OrdinalElection, election_2: OrdinalElection,
                               matching) -> List[list]:
    """ Return: Cost table """
    votes_1 = election_1.votes
    votes_2 = election_2.votes
    size = election_1.num_voters
    return [[swap_distance(votes_1[i], votes_2[j], matching=matching) for i in range(size)]
            for j in range(size)]
Exemplo n.º 2
0
def compute_pos_swap_distance(instance_1: Marriages, instance_2: Marriages,
                              inner_distance: Callable) -> (float, list):
    """ Compute Positionwise distance between ordinal elections """
    cost_table = get_matching_cost_positionwise(instance_1, instance_2, inner_distance)
    obj_val, matching = solve_matching_vectors(cost_table)
    votes_1 = instance_1.votes
    votes_2 = instance_2.votes
    size = instance_1.num_agents
    return sum([swap_distance(votes_1[i], votes_2[matching[i]], matching=matching) for i in range(size)])
Exemplo n.º 3
0
def compute_swap_bf_distance(instance_1: Roommates, instance_2: Roommates) -> int:
    obj_values = []
    tmp = True
    for matching in permutations(range(instance_1.num_agents)):
        votes_1 = instance_1.votes
        votes_2 = instance_2.votes
        size = instance_1.num_agents
        value = sum([swap_distance(votes_1[matching[i]], votes_2[i], matching=matching) for i in
                     range(size)])
        obj_values.append(value)
        if tmp:
            print(matching, value)
            tmp = False

    return min(obj_values)