Пример #1
0
	def auctioneer_start_from_master(self, master_ip, info):
		if self.auctioneer and self.auctioneer.running:
			self.auctioneer.close()
		auctioneer_params = setting.default_auctioneer_params(self.peername)
		auctioneer_params['delay'] = float(info)
		self.auctioneer = Auctioneer(auctioneer_params, self)
		self.auctioneer.run()
Пример #2
0
	def loop(self, streaming = False):
		self.run()
		self.introduce()
		self.bidder  = Bidder(setting.default_bidder_params(self.peername), self)
		self.auctioneer = Auctioneer(setting.default_auctioneer_params(self.peername), self)
		self.bidder.run()
		self.auctioneer.run()
		if streaming:
			if sys.platform.startswith('linux'):
				from vlc_player import VlcPlayer as Player
			elif sys.platform.startswith('darwin'):
				from qtvlc_player import QtvlcPlayer as Player
			player = Player()
			player.open_api_run()
		else:
			try:
				while True:
					command = raw_input().lower()
					if not command or command == 'exit':
						break
			except KeyboardInterrupt:
				pass
		self.bidder.close()
		self.auctioneer.close()
		self.close()
Пример #3
0
def check_price_stability_varying_ceiling():
    """
    Check the effect of modifying the ceiling for the strategy 2.
    The effect is presented with a plot where the x axis is the value of the ciling and the y axis the average
    difference between the initial prices and the market price of the last round.
    """

    iterations = 500

    ceilings = [top for top in np.arange(1.5, 5, 0.1)]
    # avg_market_prices = []
    # diff_marketprice_start_prices = []
    mrkt_price_starting_price_ratio = []

    for iter in range(len(ceilings)):
        auctioneer = Auctioneer(K_sellers=3,
                                N_buyers=10,
                                R_rounds=100,
                                debug=False,
                                bidding_factor_strategy=[3 for x in range(10)])
        auctioneer.ceiling = ceilings[iter]

        auctioneer.start_auction()

        mrkt_price_starting_price_ratio.append(
            np.mean(auctioneer.market_price[auctioneer.r_rounds - 1]) /
            np.mean(auctioneer.starting_prices))

    # plt.plot(ceilings, diff_marketprice_start_prices)
    plt.plot(ceilings, mrkt_price_starting_price_ratio)
    plt.xlabel("Ceiling")
    plt.ylabel("Ratio between market price and starting price of last round")
    plt.legend()

    plt.show()
Пример #4
0
class ManualSlave(Slave):

	def loop(self, streaming = False):
		self.run()
		self.introduce()
		self.bidder  = Bidder(setting.default_bidder_params(self.peername), self)
		self.auctioneer = Auctioneer(setting.default_auctioneer_params(self.peername), self)
		self.bidder.run()
		self.auctioneer.run()
		if streaming:
			if sys.platform.startswith('linux'):
				from vlc_player import VlcPlayer as Player
			elif sys.platform.startswith('darwin'):
				from qtvlc_player import QtvlcPlayer as Player
			player = Player()
			player.open_api_run()
		else:
			try:
				while True:
					command = raw_input().lower()
					if not command or command == 'exit':
						break
			except KeyboardInterrupt:
				pass
		self.bidder.close()
		self.auctioneer.close()
		self.close()
Пример #5
0
class AutoSlave(Slave):

	def loop(self, streaming = False):
		self.run()
		self.introduce()
		#auctioneer bidder
		self.bidder = None
		self.auctioneer = None
		if streaming:
			if sys.platform.startswith('linux'):
				import qtvlc_player.QtvlcPlayer as Player
			elif sys.platform.startswith('darwin'):
				import vlc_player.VlcPlayer as Player
			player = Player()
			player.open_api_run()
		else:
			try:
				while True:
					command = raw_input().lower()
					if not command or command == 'exit':
						break
			except KeyboardInterrupt:
				pass
		if self.bidder and self.bidder.running:
			self.bidder.close()
		if self.auctioneer and self.auctioneer.running:
			self.auctioneer.close()
		self.close()

	'Override'
	def bidder_start_from_master(self, master_ip, info):
		if self.bidder and self.bidder.running:
			self.bidder.close()
		bidder_params = setting.default_bidder_params(self.peername)
		bidder_params['bnumber'] = int(info)
		self.bidder  = Bidder(bidder_params, self)
		self.bidder.run()

	def bidder_stop_from_master(self, master_ip, info):
		if self.bidder:
			self.bidder.close()

	def auctioneer_start_from_master(self, master_ip, info):
		if self.auctioneer and self.auctioneer.running:
			self.auctioneer.close()
		auctioneer_params = setting.default_auctioneer_params(self.peername)
		auctioneer_params['delay'] = float(info)
		self.auctioneer = Auctioneer(auctioneer_params, self)
		self.auctioneer.run()

	def auctioneer_stop_from_master(self, master_ip, info):
		if self.auctioneer:
			self.auctioneer.close()
Пример #6
0
 def ready(self):
     global AUCTIONEER
     try:
         from auctioneer import Auctioneer
         from models import Auction  # Here to avoid 1.9 deprecation warning
         
         AUCTIONEER = Auctioneer()
         # create channels for all the auctions that are still pending
         now = pytz.utc.localize(datetime.now())
         auctions = Auction.objects.filter(expires__gt=now)
         for auction in auctions:
             AUCTIONEER.create(auction, int((auction.expires - now).seconds))
             
     except Exception as err:
         print 'Exception while creating auctioneer,', err
         return
Пример #7
0
    def ready(self):
        global AUCTIONEER
        try:
            from auctioneer import Auctioneer
            from models import Auction  # Here to avoid 1.9 deprecation warning

            AUCTIONEER = Auctioneer()
            # create channels for all the auctions that are still pending
            now = pytz.utc.localize(datetime.now())
            auctions = Auction.objects.filter(expires__gt=now)
            for auction in auctions:
                AUCTIONEER.create(auction, int(
                    (auction.expires - now).seconds))

        except Exception as err:
            print 'Exception while creating auctioneer,', err
            return
Пример #8
0
def check_bias(times=1000):
    """
    Experiment to check if there is a bias in the setting. All buyers have an initial bidding factor random
    between 1 and 1.001 and the same increasing and decreasing factor.
    The result is presented as the number of times that each buyer wins the simulation.
    :param times: Number of times to execute the test
    """
    max_profit = np.zeros(n_buyers)
    for n in range(times):
        auctioneer = Auctioneer(
            bidding_factor_strategy=2,
            R_rounds=100,
        )
        auctioneer.bidding_factor = []
        for buyer in range(n_buyers):
            bid_fact = np.random.uniform(1, 1.001, 3)
            auctioneer.bidding_factor.append(bid_fact)

        auctioneer.increase_bidding_factor = [1.2 for n in range(n_buyers)]
        auctioneer.decrease_bidding_factor = [0.8 for n in range(n_buyers)]
        auctioneer.start_auction()
        buyers_prof = auctioneer.cumulative_buyers_profits[:, auctioneer.
                                                           r_rounds - 1]

        for buyer in range(n_buyers):
            if buyers_prof[buyer] == max(buyers_prof):
                max_profit[buyer] += 1

    [
        print("Buyer", buyer, "was the one with more profit",
              max_profit[buyer], "times") for buyer in range(n_buyers)
    ]
Пример #9
0
def create_auctioneer(strategy=0,
                      penalty_factor=0.1,
                      level_flag=True,
                      types=3,
                      sellers=k_sellers,
                      buyers=n_buyers):
    return Auctioneer(
        penalty_factor=penalty_factor,
        bidding_factor_strategy=[strategy for n in range(buyers)],
        M_types=types,
        K_sellers=sellers,
        N_buyers=buyers,
        R_rounds=rounds,
        level_comm_flag=level_flag,
        debug=False)
Пример #10
0
    def test_real_case_scenario(self):
        starting_prices = [[40, 50, 20]]

        auctioneer = Auctioneer(starting_prices=starting_prices,
                                M_types=2,
                                K_sellers=3,
                                N_buyers=5,
                                R_rounds=2,
                                level_comm_flag=False)
        auctioneer.increase_bidding_factor = [2, 3, 4, 5, 6]
        auctioneer.decrease_bidding_factor = [0.6, 0.5, 0.4, 0.3, 0.2]
        auctioneer.sellers_types = [1, 1, 0]
        # auctioneer.bidding_factor = np.array([
        #     # Buyer 0
        #     [
        #
        #         [1, 2, 3],  # Type 0
        #         [4, 5, 6]   # Type 1
        #     ],
        #     # Buyer 1
        #     [
        #         [1.68791717, 1.43217411, 1.1566692],
        #         [1.20532547, 1.05372195, 1.19885528]
        #     ],
        #     # Buyer 2
        #     [
        #         [1.71709178, 1.83604667, 1.4957177],
        #         [1.50015315, 1.77615324, 1.00780864]
        #     ],
        #     # Buyer 3
        #     [
        #         [1.62403167, 1.51698165, 1.74709901],
        #         [1.84536679, 1.29700791, 1.08997174]
        #     ],
        #     # Buyer 4
        #     [
        #         [1.81391097, 1.2531242, 1.01217679],
        #         [1.15969576, 1.55215565, 1.34450197]
        #     ]
        # ])

        auctioneer.start_auction()

        self.assertEqual([], auctioneer.market_price)
Пример #11
0
    def test_constructor_is_initializing_correct_values(self):
        random.seed(0)
        auctioneer = Auctioneer(2, 3, 5, 3, False)

        self.assertEqual(range(2), auctioneer.m_item_types)
        self.assertEqual(3, auctioneer.k_sellers)
        self.assertEqual(5, auctioneer.n_buyers)
        self.assertEqual(3, auctioneer.r_rounds)

        self.assertEqual(100, auctioneer.max_starting_price)
        self.assertEqual(0.1, auctioneer.penalty_factor)

        self.assertEqual([False, False, False, False, False],
                         auctioneer.buyers_already_won)
        self.assertTrue(
            auctioneer.increase_bidding_factor.all() in range(1, 2))
        # self.assertTrue(auctioneer.decrease_bidding_factor.all() in float(0, 1))

        self.assertEqual(0, auctioneer.market_price.all())
        self.assertEqual(0, auctioneer.buyers_profits.all())
        self.assertEqual(0, auctioneer.sellers_profits.all())

        self.assertEqual(0, len(auctioneer.history))
Пример #12
0
    def buy(buyer, product):
        Market.lock.acquire()
        # get the seller for product from catalogue
        storage_dict = Market.catalogue[product]
        seller_list = [seller for seller in storage_dict if storage_dict[seller] > 0]
        market_storage = sum([seller.product_storage[product] for seller in seller_list])

        # call seller's sold function
        if len(seller_list) > 0:
            if market_storage > shortage:
                seller_index = 0
                min_price = seller_list[0].price_history[product][-1]
                for seller in seller_list:
                    index = 0
                    if seller.price_history[product][-1] < min_price:
                        seller_index = index
                    index += 1
                seller = seller_list[seller_index]
                seller.sold(product)
                Market.catalogue[product][seller] -= 1
                # deduct price from user's balance
                buyer.deduct(seller.price_history[product][-1])

                # track user
                GoogleAds.track_user_purchase(buyer, product)
                Market.lock.release()
                return seller
            else:
                price = max([seller.price_history[product][-1]] for seller in seller_list)
                deal, seller, buyer = Auctioneer.bid_buy(buyer, product, market_storage, seller_list, price)
                if deal:
                    Market.catalogue[product][seller] -= 1
                    GoogleAds.track_user_purchase(buyer, product)

        else:
            Market.lock.release()
            return 0
Пример #13
0
#!usr/bin/env python
import argparse
import setting
from auctioneer import Auctioneer
from bidder import Bidder


def parse_args():
    # argument formats
    parser = argparse.ArgumentParser(description='AuctionTv')
    parser.add_argument('--script', required=False, help='script file')
    return parser.parse_args()


if __name__ == "__main__":
    auctioneer = Auctioneer()
    bidder = Bidder()
    auctioneer.start()
    bidder.start()
    try:
        while True:
            command = raw_input().lower()
            if not command or command == 'exit':
                break
            elif command == 'play':
                auctioneer.play(setting.PLAYER_URL)
            else:
                print "Usage :"
                print "\tplay [url]\tPlay a streaming."
                print "\texit\t\tExit."
    except KeyboardInterrupt:
Пример #14
0
        "the decreasing factor while if it is lower multiply by the increasing factor.\n"
strategy = request_integer_input(strat)
level_commitment_activated = request_boolean_input(
    "Should use level commitment? y/n ")
if level_commitment_activated:
    penalty_factor = request_float_input("Penalty factor: ")
else:
    penalty_factor = 0

alpha = 0
while alpha != 1 and alpha != 2:
    alpha = request_integer_input(
        "Bidding factor depends on the sellers (1) or types of items (2): ")
debug = request_boolean_input(
    "Print the debug information on every round? (y/n): ")

# Execute with parameters
auctioneer = Auctioneer(
    penalty_factor=penalty_factor,
    bidding_factor_strategy=[strategy for n in range(number_of_buyers)],
    use_seller=(alpha == 1),
    M_types=number_of_product_types,
    K_sellers=number_of_sellers,
    N_buyers=number_of_buyers,
    R_rounds=number_of_rounds,
    level_comm_flag=level_commitment_activated,
    debug=debug)

auctioneer.start_auction()
auctioneer.plot_statistics()
from auction_env import Auction_env
from auctioneer import Auctioneer
from bidder import Bidder
import random

import threading

#put the code for multithreading and instantiation of the auctioneers and different bidders

##ticket one
#generate bidder

auctioneer_agent1 = Auctioneer('ticket1', 1000)

#generate the different  12 agents for ticket  one   -> 3 for each type of sting-0-meter
#generate bidding agents
#bidding agent arguments are product_id,price_ceiling,bank_capacity,will_power

bidding_agents1 = []
#random agents will power 1
for i in range(3):
    #bidding_agents.append(Bidder('ticket1',random.randint(995,1000),random.randint(990,1100),1))
    bidding_agents1.append(Bidder('ticket1', 1200, 2000, 1))

#random agents will power 2
for i in range(3):
    #bidding_agents.append(Bidder('ticket1',random.randint(995,1000),random.randint(990,1100),2))
    bidding_agents1.append(Bidder('ticket1', 1300, 2000, 2))

#random agents will power 3
for i in range(3):
Пример #16
0
        'default': 4
    },
    '-s': {
        'name': 'standard_deviation',
        'type': 'float',
        'default': 2.0
    },
    '--omega': {
        'name': 'omega',
        'type': 'float',
        'default': 0.5
    }
}
arg = ArgParser(sys.argv[2:], opt_pattern)
opt = arg.read()

grid = Grid(json.loads(open(sys.argv[1], 'r').read()), opt)

messageserver = MessageServer(opt)
auctioneer = Auctioneer(grid, messageserver, opt)

agents = {}
for a in grid.agents:
    agent = Agent(a, grid, messageserver, opt)
    agents[a] = agent

scheduler = Scheduler(grid, agents, auctioneer, messageserver, opt)

scheduler.initialize()
scheduler.run()
scheduler.terminate()
Пример #17
0
#!usr/bin/env python
import argparse
import setting
from auctioneer import Auctioneer
from bidder import Bidder

def parse_args():
	# argument formats
	parser = argparse.ArgumentParser(description='AuctionTv')
	parser.add_argument('--script', required=False, help='script file')
	return parser.parse_args()
	

if __name__ == "__main__":
	auctioneer  = Auctioneer()
	bidder  = Bidder()
	auctioneer.start()
	bidder.start()
	try:
		while True:
			command = raw_input().lower()
			if not command or command == 'exit':
				break
			elif command == 'play':
				auctioneer.play(setting.PLAYER_URL)
			else:
				print "Usage :"
				print "\tplay [url]\tPlay a streaming."
				print "\texit\t\tExit."
	except KeyboardInterrupt:
		pass