コード例 #1
0
ファイル: MyersonAuction.py プロジェクト: pabloazar/Auctions
def ironedMyersonAuction(bids, distributions,flagReserveInfo=False):
    if bids==[] or bids is None:
        raise AuctionExceptions.EmptyBidsException
    if len(bids)!=len(distributions):
        raise AuctionExceptions.DifferentBidsAndReservesSize(bids,distributions)
    #change name of this last exception
    virtualValues=[ironedVirtualValuation(bids[i], distributions[i]) for i in range(len(bids)) ] 
    virtualValuesCheck=[virtualValuation(bids[i], distributions[i]) for i in range(len(bids)) ]  #TODO REMOVE
    
    #print "virtualValues",virtualValues
    #print "virtualValuesCheck",virtualValuesCheck


    reserves=[0]*len(bids)#  print "virtualValues", virtualValues
    (allocation, priceListAux) = eagerVickrey(virtualValues,reserves)

    if sum(allocation) == 0:
        if (flagReserveInfo==False):
            return (allocation, priceListAux)
        else:
            return (allocation, priceListAux, None, None)
    
    
    for i in range(len(allocation)):
        if allocation[i]!=0: #in this case there is only one winner, with allocation set to 1
            winner = i    
    secondVirtualValue = priceListAux[winner]
    secondVirtualValue = max(secondVirtualValue,0)
    firstVirtualValue = max(virtualValues)
    #this function find root of auxRootFinding in the interval [0,bids[winner]]
    #in fact fsolve does not guarantee interval [0,bids[winner], it just gives x0 as the initial guess (include this login in aux function)
    #if (secondVirtualValue > ironedVirtualValuation(bids[winner], distributions[winner])):
    #    print "error: secondVirtualValue >bids[winner]", secondVirtualValue, ironedVirtualValuation(bids[winner], distributions[winner])
    priceAux = scipy.optimize.fsolve(auxRootFindingIroned, bids[winner], (secondVirtualValue, distributions[winner], 0, bids[winner])) 
    myersonReserve = scipy.optimize.fsolve(auxRootFindingIroned, bids[winner], (0, distributions[winner], 0, bids[winner]))
    
    price = [0 for i in allocation]
    price[winner]=priceAux[0]
    if (flagReserveInfo==True):
        winner = None
        for i in range(len(allocation)):
            if allocation[i]!=0: #in this case there is only one winner, with allocation set to 1
                winner = i 
        if winner==None:
            return (allocation,price,None,None)
        if priceListAux[winner]==reserves[winner]: # equivalent to secondVirtualValue < 0
            isPriceFromReserve = True
        else:
            isPriceFromReserve = False
        return (allocation,price,isPriceFromReserve,myersonReserve)
    else:
        return (allocation,price)
コード例 #2
0
ファイル: MyersonAuction.py プロジェクト: pabloazar/Auctions
def revenueIronedMyersonAuctionFromSamples(trainingSamples,testSamples):
    # trainingSamples = float[NUM_PLAYERS][NUM_TEST_SAMPLES]
    '''generate many means and sigmas from trainingSamples'''
    distributions=[getDistribution(trainingSet) for trainingSet in trainingSamples]
    '''           
    test for exceptions  
    '''
    '''testSamples are the new bids'''
    #DO FOR ALL TEST SAMPLES
    totalRevenue=0
    revenues=[]
    samples = zip(*testSamples)
    numSamples = len(samples)
    for i in xrange(numSamples):
        bids = samples[i]
        
        #call to regular ironedMyersonAuction since I know bids and distribution
        virtualValues=[ironedVirtualValuation(bids[i], distributions[i]) for i in range(len(bids)) ]  
        reserves=[0]*len(bids)
        (allocation, priceListAux) = eagerVickrey(virtualValues,reserves)
        if sum(allocation) == 0:
            priceList = priceListAux
        else:
            for i in range(len(allocation)):
                if allocation[i]!=0: #in this case there is only one winner, with allocation set to 1
                    winner = i 
            secondVirtualValue = priceListAux[winner]
            secondVirtualValue = max(secondVirtualValue,0)
            price = scipy.optimize.fsolve(auxRootFindingIroned, bids[winner], (secondVirtualValue, distributions[winner], 0, bids[winner])) 
            priceList = [0 for i in allocation]
            priceList[winner]=price

        revenue = sum(priceList)
        totalRevenue+=revenue
        revenues.append(revenue)
    return revenues
コード例 #3
0
ファイル: MyersonAuction.py プロジェクト: pabloazar/Auctions
def auxRootFindingIroned(value,secondVirtualValue, distribution, minPrice, maxPrice):
    return ironedVirtualValuation(value,distribution) - secondVirtualValue + isNotInInterval(value,minPrice,maxPrice)