Exemplo n.º 1
0
def calc_half_cut(allocation, proportional_value, fraud_agent_index, allocations):

    calculated_sum = allocation.values_sum(allocation.fromIndex, allocation.toIndex)
    target_sum = proportional_value * calculated_sum
    host_cut_index = Numbersutil.cut_index(allocation.values, target_sum, allocation.fromIndex, allocation.toIndex)

    if allocations is not None:

        allocation.halfCut = host_cut_index
        current_cut_location = cut_index(allocations[:])
        first_part, second_part = split_by_cut_location(allocations, current_cut_location, False)

        first_part.sort(key=operator.attrgetter('halfCut'))
        second_part.sort(key=operator.attrgetter('halfCut'))

        is_fraud_in_first_part = False

        for first_allocation in first_part:
            if first_allocation is allocations[fraud_agent_index]:
                is_fraud_in_first_part = True
                break

        first_index_right_item = first_part[len(first_part)-1]
        second_index_left_item = second_part[0]
        #todo: remove halfcut from fraud index..
        if is_fraud_in_first_part:
            return second_index_left_item.halfCut - 0.000001
        else:
            return first_index_right_item.halfCut + 0.000001

    else:
        return host_cut_index
Exemplo n.º 2
0
def divide_smaller_for_agent(allocation, from_index, to_index, number_of_agents):
    agent_fair_value = numbersUtils.current_split_allocation_value(
        allocation, allocation.fromIndex, allocation.toIndex, number_of_agents
    )
    agent_to_index = numbersUtils.cut_index(allocation.values, agent_fair_value, from_index, allocation.toIndex)

    allocation.fromIndex = from_index
    allocation.toIndex = agent_to_index

    return allocation