Beispiel #1
0
def test_mechanism():
    num_slots = 4
    slot_clicks = [4, 3, 2, 1]
    bids = zip(range(1, 6), [10, 12, 18, 14, 20])

    # values, clicks: (20, 4); (18, 3); (14, 2); (12, 1); (10, 0)
    # payments: [18+14+12+10 = 54, 14+12+10 = 36, 10+12 = 22, 10] = [54, 36, 22, 10]

    def norm(totals):
        """Normalize total payments by the clicks in each slot"""
        return map(lambda (x, y): x / y, zip(totals, slot_clicks))

    # Allocs same as GSP, but payments are different
    reserve = 0
    (alloc, payments) = VCG.compute(slot_clicks, reserve, bids)
    # print 'payments ' + str(payments)
    assert alloc == [5, 3, 4, 2]
    assert payments == norm([54, 36, 22, 10])

    # print 'PASSED 1 TEST, RES 0'

    reserve = 11
    (alloc, payments) = VCG.compute(slot_clicks, reserve, bids)
    # print 'payments ' + str(payments)
    assert alloc == [5, 3, 4, 2]
    assert payments == norm([55, 37, 23,
                             11])  # off by literally one here..why??

    # print 'PASSED ANOTHER TEST, RES 11'

    reserve = 14
    (alloc, payments) = VCG.compute(slot_clicks, reserve, bids)
    assert alloc == [5, 3, 4]
    # values, clicks: (20, 4); (18, 3); (14, 2); "(14, 1)"; "(14,0)"
    # payments: [18+14+14+14 = 60, 14+14+14 = 42, 14, "14'] =

    assert payments == norm([60, 42, 28])

    reserve = 15
    (alloc, payments) = VCG.compute(slot_clicks, reserve, bids)
    assert alloc == [5, 3]
    assert payments == norm([63, 45])

    reserve = 19
    (alloc, payments) = VCG.compute(slot_clicks, reserve, bids)
    assert alloc == [5]
    assert payments == norm([76])

    reserve = 22
    (alloc, payments) = VCG.compute(slot_clicks, reserve, bids)
    assert alloc == []
    assert payments == []
Beispiel #2
0
    def runVickreyAuction(self, reqList, sellerGraph):
        '''
        Function to call VCG mechanism
        '''
        allocation = []
        self.__logger.debug("[AdExchange][runVickreyAuction]")
        self.__logger.debug("Allocation decisions.")

        allocationDict = {}
        for key, v in reqList.items():
            k1, k2 = key.split("#")
            # n denotes the number of customers bidding for that conduit
            n = len(v)
            slot_click = [1] * n

            shortestPath = nx.shortest_path(sellerGraph, source=k1, target=k2)
            gCoP = self.getCostOfPath(shortestPath, sellerGraph)
            lIP = self.linksInPath(shortestPath)
            k = len(lIP)
            reserve = max(self.__reserve, gCoP / k)

            bids = []
            for item in v:
                bids.append((item.clientName, item.bidPerStrand))

            if nx.has_path(sellerGraph, k1, k2) and self.resourceAvailable(
                    sellerGraph, shortestPath, v):
                (alloc, payments) = VCG.compute(slot_click, reserve, bids)
                allocation.extend(zip(alloc, [i * k for i in payments]))
                for (kTest, vTest) in allocation:
                    allocationDict[kTest] = vTest

                # Updates sellerGraph with the allocation
                self.__logger.debug("Before > {}".format(
                    self.availableAttributes(shortestPath, sellerGraph)))
                ip_port_pairs = self.updateSellerGraph_and_getResources(
                    sellerGraph, shortestPath, v)
                self.__logger.debug("After > {}".format(
                    self.availableAttributes(shortestPath, sellerGraph)))
            else:
                self.__logger.info(
                    "Link does not exists between {} and {}".format(k1, k2))
        return (self.updateRequestList(reqList, allocationDict), ip_port_pairs)
Beispiel #3
0
    def runVickreyAuction(self, reqList, sellerGraph):
        '''
        Function to call VCG mechanism
        '''
        allocation = []
        self.__logger.debug("[AdExchange][runVickreyAuction]")
        self.__logger.debug("Allocation decisions.")

        allocationDict = {}
        for key, v in reqList.items():
            k1,k2=key.split("#")
            # n denotes the number of customers bidding for that conduit
            n = len(v)
            slot_click = [1] * n

            shortestPath = nx.shortest_path(sellerGraph, source=k1, target=k2)
            gCoP = self.getCostOfPath(shortestPath, sellerGraph)
            lIP = self.linksInPath(shortestPath)
            k = len(lIP)
            reserve = max(self.__reserve, gCoP/k)

            bids = []
            for item in v:
                bids.append((item.clientName, item.bidPerStrand))

            if nx.has_path(sellerGraph, k1, k2) and self.resourceAvailable(sellerGraph, shortestPath, v):
                (alloc, payments) = VCG.compute(slot_click, reserve, bids)
                allocation.extend(zip(alloc, [i * k for i in payments]))
                for (kTest, vTest) in allocation:
                    allocationDict[kTest] = vTest

                # Updates sellerGraph with the allocation
                self.__logger.debug("Before > {}".format(self.availableAttributes(shortestPath, sellerGraph)))
                self.updateSellerGraph(sellerGraph, shortestPath, v)
                self.__logger.debug("After > {}".format(self.availableAttributes(shortestPath, sellerGraph)))
            else:
                self.__logger.info("Link does not exists")
        return self.updateRequestList(reqList, allocationDict)
def test_mechanism():
    num_slots = 4
    slot_clicks = [4,3,2,1]
    bids = zip(range(1,6), [10, 12, 18, 14, 20])
    # values, clicks: (20, 4); (18, 3); (14, 2); (12, 1); (10, 0)
    # payments: [18+14+12+10 = 54, 14+12+10 = 36, 10+12 = 22, 10] = [54, 36, 22, 10]

    def norm(totals):
        """Normalize total payments by the clicks in each slot"""
        return map(lambda (x,y): x/y, zip(totals, slot_clicks))
    
    # Allocs same as GSP, but payments are different
    reserve = 0
    (alloc, payments) = VCG.compute(slot_clicks, reserve, bids)
    assert alloc == [5,3,4,2]
    assert payments == norm([54, 36, 22, 10])

    reserve = 11
    (alloc, payments) = VCG.compute(slot_clicks, reserve, bids)
    assert alloc == [5,3,4,2]
    assert payments == norm([55, 37, 23, 11])

    reserve = 14
    (alloc, payments) = VCG.compute(slot_clicks, reserve, bids)
    assert alloc == [5,3,4]
    # values, clicks: (20, 4); (18, 3); (14, 2); "(14, 1)"; "(14,0)"
    # payments: [18+14+14+14 = 60, 14+14+14 = 42, 14, "14'] = 

    assert payments == norm([60, 42, 28])

    reserve = 15
    (alloc, payments) = VCG.compute(slot_clicks, reserve, bids)
    assert alloc == [5,3]
    assert payments == norm([63, 45])

    reserve = 19
    (alloc, payments) = VCG.compute(slot_clicks, reserve, bids)
    assert alloc == [5]
    assert payments == norm([76])

    reserve = 22
    (alloc, payments) = VCG.compute(slot_clicks, reserve, bids)
    assert alloc == []
    assert payments == []
Beispiel #5
0
 def bid_range(slot, reserve):
     return VCG.bid_range_for_slot(slot, slot_clicks, reserve, bids)
Beispiel #6
0
batch_size = 32
gradient_norm_threshold = 0.001

# Network Parameters
num_input = 3
num_steps = 120
num_hidden = 10
num_classes = 5

logs_path = 'data/'

# Initialize Placeholders and Variables
# ===========================================================================

# Initialize dataset iterator
data_sets = VCG("sequence.npy", "target.npy", 0.6, 0.2, 0.2, True)

# Declare placeholders for VCG and corresponding labels
sequence = tf.placeholder(dtype=tf.float32,
                          shape=[None, num_steps, num_input],
                          name="vcg_sequence")
target = tf.placeholder(dtype=tf.float32,
                        shape=[None, num_classes],
                        name="dyssynchrony_index")

# Declare weights used for linear activation on output of network
weights = tf.Variable(
    tf.truncated_normal(shape=[num_hidden, num_classes],
                        stddev=1.0 / math.sqrt(float(num_classes))))
biases = tf.Variable(tf.zeros([num_classes]))
 def bid_range(slot, reserve):
     return VCG.bid_range_for_slot(slot, slot_clicks, reserve, bids)