Exemplo n.º 1
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()
Exemplo n.º 2
0
	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()
Exemplo n.º 3
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()
Exemplo n.º 4
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()
Exemplo n.º 5
0
def deal(bidders):
    ma, mi = -1e99, 1e99
    jma, jmi = '', ''
    cnt = {}
    revenue = {}
    bid = {}
    for i in range(len(bidders)):
        cnt[bidders[i].strategy.name], revenue[bidders[i].strategy.name] = 0, 0
    for i in range(len(bidders)):
        #print(bidders[i].cnt,'BBBBBBB')
        cnt[bidders[i].strategy.name] += bidders[i].cnt
        bid[bidders[i].strategy.name] = bidders[i]
        revenue[bidders[i].strategy.name] += bidders[i].revenue
    for x in cnt.keys():
        #print(revenue[x],cnt[x],'AAAAAAAAAAAAAAAAAA')
        revenue[x] /= cnt[x]
        if (revenue[x] > ma):
            ma = revenue[x]
            jma = x
        if (revenue[x] < mi):
            mi = revenue[x]
            jmi = x
    for i in range(len(bidders)):
        if bidders[i].strategy.name == jmi:
            bidders[i] = Bidder(uniformValuationGenerator(l, r), stra[jma])
            break
    return bidders
Exemplo n.º 6
0
def main():

    bidders = []
    n_kind = 3
    n = [30, 30, 30]
    List_Of_Strategy = [
        CoefficientStrategy(0.95),
        CRecorderStrategy(0.95, 4),
        CoefficientStrategy(1.0)
    ]
    for i in range(n_kind):
        stra[List_Of_Strategy[i].name] = List_Of_Strategy[i]

    for i in range(n_kind):
        for j in range(n[i]):
            bidders.append(
                Bidder(uniformValuationGenerator(l, r), List_Of_Strategy[i]))

    sum_n = get_sum_int(n)
    n_auction, n_circle, n_once, m, n_lost = 10000, 100, 10, 10, 10
    ctrs = [(m - i + 0.0) / m for i in range(m)]

    #x_axis,bidders_revenue,auction_revenue,social_welfare_revenue = [],[[] for i in range(n_kind)],[],[]
    print(0)
    out(bidders)

    for k in range(n_auction):

        for i in range(sum_n):
            bidders[i].revenue = 0
            bidders[i].cnt = 0

        #print([bidders[i].cnt for i in range(len(bidders))])

        for k2 in range(n_circle):
            temp_bidders_i = random.sample(range(sum_n), m)
            #print(temp_bidders_i)
            temp_bidders = []
            for x in temp_bidders_i:
                #print('AAA',bidders[x].cnt)
                bidders[x].cnt += 1
                temp_bidders.append(bidders[x])

            auction = Auction(temp_bidders, VCG(ctrs))
            for k3 in range(n_once):
                auction.takeAuction()
            for i in range(len(temp_bidders_i)):
                bidders[temp_bidders_i[i]].revenue += temp_bidders[i].revenue

        bidders = deal(bidders)
        print('case\n', k, '\n')
        out(bidders)
    '''
Exemplo n.º 7
0
def read_bidders(filename):
    with open('clean_%s' % filename, 'wb') as cbfile:
        fieldnames = [
            'bidder_id', 'pmt_type', 'pmt_account', 'addr_1', 'addr_2'
        ]
        if 'train' in filename:
            fieldnames.append('outcome')
        writer = csv.DictWriter(cbfile, fieldnames=fieldnames)
        writer.writeheader()
        with open(filename, 'rb') as bidsfile:
            reader = csv.reader(bidsfile, delimiter=',', quotechar='|')
            skip(reader, 1)
            for row in reader:
                b = Bidder(row[0], row[1], row[2],
                           row[3] if len(row) > 3 else None)
                bidders[b.bidder_id] = b
                mrow = {
                    'bidder_id': b.bidder_id,
                    'pmt_type': b.get_payment_type(),
                    'pmt_account': b.get_payment_acct(),
                    'addr_1': b.get_addr_1(),
                    'addr_2': b.get_addr_2(),
                }
                if 'train' in filename:
                    mrow['outcome'] = b.outcome
                writer.writerow(mrow)
Exemplo n.º 8
0
def read_bidders(filename):
    with open('clean_%s' % filename, 'wb') as cbfile:
        fieldnames = ['bidder_id', 'pmt_type', 'pmt_account', 'addr_1', 'addr_2']
        if 'train' in filename:
            fieldnames.append('outcome')
        writer = csv.DictWriter(cbfile, fieldnames=fieldnames)
        writer.writeheader()
        with open(filename, 'rb') as bidsfile:
            reader = csv.reader(bidsfile,  delimiter=',',  quotechar='|')
            skip(reader, 1)
            for row in reader:
                b = Bidder(row[0], row[1], row[2], row[3] if len(row) > 3 else None)
                bidders[b.bidder_id] = b
                mrow = {
                    'bidder_id': b.bidder_id,
                    'pmt_type': b.get_payment_type(),
                    'pmt_account': b.get_payment_acct(),
                    'addr_1': b.get_addr_1(),
                    'addr_2': b.get_addr_2(),
                }
                if 'train' in filename:
                    mrow['outcome'] = b.outcome
                writer.writerow(mrow)
Exemplo n.º 9
0
def read_bidders(filename):
    with open(filename, 'rb') as bidsfile:
        reader = csv.reader(bidsfile, delimiter=',', quotechar='|')
        skip(reader, 1)
        for row in reader:
            b = Bidder(row[0], row[1], row[2],
                       row[3] if len(row) > 3 else None)
            #if b.bidder_id in ['f5b2bbad20d1d7ded3ed960393bec0f40u6hn', 'e90e4701234b13b7a233a86967436806wqqw4']:
            #    b.outcome = 1

            add_bidder(b)

            shared.addr_1[b.get_addr_1()].add(b.bidder_id)
            shared.addr_2[b.get_addr_2()].add(b.bidder_id)

            shared.pmt_type[b.get_payment_type()].add(b.bidder_id)
            shared.pmt_accnt[b.get_payment_acct()].add(b.bidder_id)

        print "%s data done" % filename
        rc = sum([1 for i in shared.bidders.values() if utils.is_robot(i)])
        hc = sum([1 for i in shared.bidders.values() if utils.is_human(i)])
        uc = sum([1 for i in shared.bidders.values() if i.outcome is None])
        print "Found %s robots, %s humans, %s unknown" % (rc, hc, uc)
#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):
    #bidding_agents.append(Bidder('ticket1',random.randint(995,1000),random.randint(990,1100),3))
    bidding_agents1.append(Bidder('ticket1', 1500, 1900, 3))

#random agents will power 4
for i in range(3):
    #bidding_agents.append(Bidder('ticket1',random.randint(995,1000),random.randint(990,1100),4))
    bidding_agents1.append(Bidder('ticket1', 1500, 2500, 4))
Exemplo n.º 11
0
Arquivo: app.py Projeto: jzh14/Auction
#!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
Exemplo n.º 12
0
Arquivo: app.py Projeto: jzh14/Auction
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