コード例 #1
0
    # sellers = removeSeconds(sellers, reduce_number)
    # mediators = removeSeconds(mediators, reduce_number)
    # mediatorsB = removeSeconds(mediatorsB, reduce_number)
    #
    # random.shuffle(buyers)
    # random.shuffle(sellers)
    # random.shuffle(mediators)
    # random.shuffle(mediatorsB)

    market = Market([
        AgentCategory("buyer", buyers),
        AgentCategory("seller", sellers),
        AgentCategory("mediator", mediators),
        AgentCategory("mediatorB", mediatorsB),
    ])
    without_gft0 = budget_balanced_trade_reduction(market, recipe, False)
    with_gft0 = budget_balanced_trade_reduction(market, recipe, True)
    print(without_gft0)
    print(with_gft0)

    without_count = without_gft0.num_of_deals()
    with_count = with_gft0.num_of_deals()
    without_gft = without_gft0.gain_from_trade()
    with_gft = with_gft0.gain_from_trade()

    print('Compare: Without:', without_gft, "With:", with_gft)
    print('Compare: Without:', without_count, "With:", with_count)
    break
# print("    buyers =", buyers)
# print("    sellers =", sellers)
# print("    mediators =", mediators)
コード例 #2
0
def experiment(results_csv_file: str, recipes: tuple, value_ranges: list,
               nums_of_agents: list, num_of_iterations: int):
    """
    Run an experiment similar to McAfee (1992) experiment on the given auction.

    :param recipes: list of recipes.
    :param nums_of_agents: a list of the numbers of agents with which to run the experiment.
    :param value_ranges: for each category, a pair (min_value,max_value). The value for each agent in this category is selected uniformly at random between min_value and max_value.
    :param num_of_iterations: how many times to repeat the experiment for each num of agents.
    """
    results_table = TeeTable(TABLE_COLUMNS, results_csv_file)
    for recipe in recipes:
        recipe_str = ":".join(map(str, recipe))
        num_of_categories = len(recipe)
        external_wins_gft = tie_gft = ascending_wins_gft = 0
        external_wins_k = tie_k = ascending_wins_k = 0
        for num_of_agents_per_category in nums_of_agents:
            external_sum_auction_count = ascending_sum_auction_count = 0  # count the number of deals done the ascending auction.
            external_sum_auction_gft = ascending_sum_auction_gft = 0
            agents_recipe_values = [sum(recipe) - recipe[0]] + [
                recipe[0] for _ in range(1, len(recipe))
            ]
            for _ in range(num_of_iterations):
                market = Market([
                    AgentCategory.uniformly_random(
                        "agent", num_of_agents_per_category * recipe[category],
                        value_ranges[category][0] *
                        agents_recipe_values[category],
                        value_ranges[category][1] *
                        agents_recipe_values[category])
                    for category in range(num_of_categories)
                ])
                (optimal_trade, _) = market.optimal_trade(recipe)
                external_auction_trade = budget_balanced_trade_reduction(
                    market, recipe)
                ascending_auction_trade = budget_balanced_ascending_auction(
                    market, recipe)

                external_sum_auction_count += external_auction_trade.num_of_deals(
                )
                ascending_sum_auction_count += ascending_auction_trade.num_of_deals(
                )

                external_sum_auction_gft += external_auction_trade.gain_from_trade(
                )
                ascending_sum_auction_gft += ascending_auction_trade.gain_from_trade(
                )

            if external_sum_auction_count > ascending_sum_auction_count:
                external_wins_k += 1
            elif external_sum_auction_count == ascending_sum_auction_count:
                tie_k += 1
            else:
                ascending_wins_k += 1

            if external_sum_auction_gft > ascending_sum_auction_gft:
                external_wins_gft += 1
            elif external_sum_auction_gft == ascending_sum_auction_gft:
                tie_gft += 1
            else:
                ascending_wins_gft += 1
        num_agents = len(nums_of_agents)

        results_table.add(
            OrderedDict((
                ("recipe", recipe),
                ("external_wins_gft",
                 int(external_wins_gft * 100 / num_agents)),
                ("tie_gft", int(tie_gft * 100 / num_agents)),
                ("ascending_wins_gft",
                 int(ascending_wins_gft * 100 / num_agents)),
                ("external_wins_k", int(external_wins_k * 100 / num_agents)),
                ("tie_k", int(tie_k * 100 / num_agents)),
                ("ascending_wins_k", int(ascending_wins_k * 100 / num_agents)),
                ("external_wins", external_wins_gft),
                ("tie", tie_gft),
                ("ascending_wins", ascending_wins_gft),
            )))
    results_table.done()
コード例 #3
0
print(
    "\n\n###### RUNNING EXAMPLE FROM THE PAPER FOR TYPE (1,1,1): buyers-sellers-mediators"
)

buyers = [17, 14, 13, 9, 6]
sellers = [-1, -4, -5, -8, -11]
mediators = [-1, -3, -4, -7, -10]
recipe = [1, 1, 1]

market = Market([
    AgentCategory("buyer", buyers),
    AgentCategory("seller", sellers),
    AgentCategory("mediator", mediators),
])
print(budget_balanced_trade_reduction(market, recipe))

print("\n\n###### SAME EXAMPLE WITH DIFFERENT ORDER: buyers-mediators-sellers")
market = Market([
    AgentCategory("buyer", buyers),
    AgentCategory("mediator", mediators),
    AgentCategory("seller", sellers),
])
print(budget_balanced_trade_reduction(market, recipe))

print("\n\n###### SAME EXAMPLE WITH DIFFERENT ORDER: sellers-buyers-mediators")
market = Market([
    AgentCategory("seller", sellers),
    AgentCategory("buyer", buyers),
    AgentCategory("mediator", mediators),
])
コード例 #4
0
print("\n\n###### RUNNING mcafee_trade_reduction")

market = Market([
    AgentCategory("buyer", [1, 1, 1]),
    AgentCategory("seller", [-1, -1, -0.5]),
])
print(mcafee_trade_reduction(market, [1, 1]))

print("\n\n###### RUNNING budget_balanced_trade_reduction")

market = Market([
    AgentCategory("buyer", [1, 1, 1]),
    AgentCategory("seller", [-1, -1, -0.5]),
])
print(budget_balanced_trade_reduction(market, [1, 1], True))

print("\n\n###### RUNNING EXPERIMENT FOR DEMO OF TYPE (1,1)")

ascending_auction_protocol.logger.setLevel(logging.ERROR)
prices.logger.setLevel(logging.ERROR)

results_file = "results/ascending_auction_demo_11.csv"
SBB_ASCENDING_STOCKS = "SBB Ascending Prices"

experiment(results_file,
           mcafee_trade_reduction,
           "McAfee Stock", (1, 1),
           value_ranges=[(1, 2), (-1, -2)],
           nums_of_agents=(50, 50),
           num_of_iterations=1)