def _check_market(self, market: Market, ps_recipe: List[int], expected_num_of_deals: int, expected_prices: List[float]): trade = ascending_auction_protocol.budget_balanced_ascending_auction( market, ps_recipe) self.assertEqual(trade.num_of_deals(), expected_num_of_deals) for i, expected_price in enumerate(expected_prices): if expected_price is not None: self.assertEqual(trade.prices[i], expected_price)
Since: 2019-11 """ import sys, os sys.path.insert(0, os.path.abspath('..')) from markets import Market from agents import AgentCategory import ascending_auction_protocol from ascending_auction_protocol import budget_balanced_ascending_auction import logging ascending_auction_protocol.logger.setLevel(logging.INFO) print("\n\n###### RUNNING EXAMPLE 3 FROM THE PAPER FOR TYPE (2,2,3)") market = Market([ AgentCategory("buyer", [17, 16, 15, 14, 13, 12, 10, 6]), AgentCategory("mediator", [-3, -4, -5, -6, -7, -8, -9, -10]), AgentCategory("seller", [-1, -2, -3, -4, -5, -6, -7, -8]), ]) # print(budget_balanced_ascending_auction(market, [2,2,3])) print("\n\n###### OTHER EXAMPLES FOR (2,2,3)") market = Market([ AgentCategory("buyer", [17, 16, 15, 14, 13, 12, 10, 6]), AgentCategory("mediator", [-3, -4, -5, -6, -7, -8, -9, -10]), AgentCategory("seller", [-1, -2, -3, -4, -5, -6, -7, -8]), ]) print(budget_balanced_ascending_auction(market, [2, 2, 3]))
#!python3 """ Demonstration of a multiple-clock strongly-budget-balanced ascending auction for a multi-lateral market with one buyer per two sellers (recipe: 1,2) Author: Erel Segal-Halevi Since: 2019-08 """ from markets import Market from agents import AgentCategory import ascending_auction_protocol, prices from ascending_auction_protocol import budget_balanced_ascending_auction import logging ascending_auction_protocol.logger.setLevel(logging.INFO) prices.logger.setLevel(logging.INFO) print("\n\n###### EXAMPLE OF PS with GFT=0") market = Market([ AgentCategory("buyer", [1, 1, 1, 1, 1]), AgentCategory("seller", [-1, -1, -1, -1, -1]), ]) print(budget_balanced_ascending_auction(market, [1, 1]))
from agents import AgentCategory import ascending_auction_protocol from ascending_auction_protocol import budget_balanced_ascending_auction import logging ascending_auction_protocol.logger.setLevel(logging.INFO) ps_recipe = [1,1,1] print("\n\n###### RUNNING EXAMPLE FROM THE PAPER FOR TYPE (1,1,1)") # Price stops between buyers, k=3: market = Market([ AgentCategory("buyer", [17, 14, 13, 9, 6]), AgentCategory("seller", [-1, -4, -5, -8, -11]), AgentCategory("mediator", [-1, -3, -4, -7, -10])]) print(budget_balanced_ascending_auction(market, ps_recipe)) print("\n\n###### SIMILAR EXAMPLE, WHERE PRICE STOPS BETWEEN SELLERS:") market = Market([ AgentCategory("buyer", [17, 14, 13, 9, 6]), AgentCategory("seller", [-1, -4, -5, -8, -11]), AgentCategory("mediator", [-1, -3, -6, -7, -10])]) print(budget_balanced_ascending_auction(market, ps_recipe)) print("\n\n###### SIMILAR EXAMPLE, WHERE PRICE STOPS BETWEEN MEDIATORS:") market = Market([ AgentCategory("buyer", [17, 14, 13, 9, 6]), AgentCategory("seller", [-1, -4, -6.5, -8, -11]), AgentCategory("mediator", [-1, -3, -6, -7, -10])]) print(budget_balanced_ascending_auction(market, ps_recipe))
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()
-0.1523, -0.1445, -11.2, -11.2, -3.1406, -11.2, -11.2, -2.6875, -11.2 ] random.shuffle(buyers) random.shuffle(sellers) reduce_number += 1 print(reduce_number) buyers = removeSeconds(buyers, reduce_number) sellers = removeSeconds(sellers, reduce_number) # buyers1 = [4]*10 + [8]*20 + [12]*30 # sellers1 = [-2]*40 + [-2]*80 + [-3]*120 market = Market([ AgentCategory("buyer", buyers), AgentCategory("seller", sellers), ]) auction_trade = budget_balanced_ascending_auction(market, [1, 4]) (optimal_trade, _) = market.optimal_trade([1, 4]) auction_trade_num_of_deals = auction_trade.num_of_deals() optimal_trade_num_of_deals = optimal_trade.num_of_deals() print(auction_trade_num_of_deals) print("Optimal:", optimal_trade_num_of_deals) # print(len(buyers), ",", len(sellers)) # print("max buyer: ", max(buyers), ", min buyer: ", min(buyers), ", max seller: ", max(sellers), ", min seller: ", min(sellers)) # buyers.sort() # sellers.sort() print("buyers =", buyers) print("sellers =", sellers)