コード例 #1
0
    def expected_utils(self, t, history, reserve):
        """
        Figure out the expected utility of bidding such that we win each
        slot, assuming that everyone else keeps their bids constant from
        the previous round.

        returns a list of utilities per slot.
        """
        # TODO: Fill this in
        last_round = history.round(t-1)
        last_round_bids = filter(lambda (ID, bid):ID != self.id, last_round.bids)


        last_round_clicks = last_round.clicks

        allocation, _ = GSP.compute(last_round_clicks, reserve, last_round_bids)
        num_slots = len(allocation)

        utilities = []

        for slot in range(num_slots):
            last_round_k = allocation[slot] #take the person from last round in slot k
            bid_i = reserve # default bid to reserve price
            for ID, bid in last_round_bids: # go through each of last rounds' bids, and set that slot's bid 
                if last_round_k == ID:
                    bid_i = bid
            utilities += [(self.value - bid_i) * last_round_clicks[slot]]

        if utilities == []:
            return [0]

        return utilities
コード例 #2
0
    def runSecondPriceAuction(self, reqList, seller):
        '''
        Function to call GSP mechanism
        '''
        sellerGraph = seller.getSellerGraph()

        allocation = []
        self.__logger.debug("[AdExchange][runSecondPriceAuction]")
        self.__logger.debug("Fiber allocation decisions.")

        allocationDict = {}
        ip_port_pairs = []
        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

            try:
                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) = GSP.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(
                        seller, shortestPath, v)
                    self.__logger.debug("After > {}".format(
                        self.availableAttributes(shortestPath, sellerGraph)))

                else:
                    self.__logger.info(
                        "Link does not exists between {} and {}. No resource available for request"
                        .format(k1, k2))

            except nx.NodeNotFound:
                self.__logger.info(
                    "Path does not exists between {} and {}. No resource available for request"
                    .format(k1, k2))
                allocationDict = {}
                break
        return (self.updateRequestList(reqList, allocationDict), ip_port_pairs)
コード例 #3
0
def test_mechanism():
    num_slots = 4
    slot_clicks = [1] * 4  # don't actually matter for gsp
    bids = zip(range(1, 6), [10, 12, 18, 14, 20])

    reserve = 0

    (alloc, payments) = GSP.compute(slot_clicks, reserve, bids)
    assert alloc == [5, 3, 4, 2]
    assert payments == [18, 14, 12, 10]

    reserve = 11
    (alloc, payments) = GSP.compute(slot_clicks, reserve, bids)
    assert alloc == [5, 3, 4, 2]
    assert payments == [18, 14, 12, 11]

    reserve = 14
    (alloc, payments) = GSP.compute(slot_clicks, reserve, bids)
    assert alloc == [5, 3, 4]
    assert payments == [18, 14, 14]

    reserve = 15
    (alloc, payments) = GSP.compute(slot_clicks, reserve, bids)
    assert alloc == [5, 3]
    assert payments == [18, 15]

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

    reserve = 22
    (alloc, payments) = GSP.compute(slot_clicks, reserve, bids)
    assert alloc == []
    assert payments == []
コード例 #4
0
ファイル: adexchange.py プロジェクト: 52-41-4d/GreyFiber
    def runSecondPriceAuction(self, reqList, sellerGraph):
        '''
        Function to call GSP mechanism
        '''
        allocation = []
        self.__logger.debug("[AdExchange][runSecondPriceAuction]")
        self.__logger.debug("Fiber 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) = GSP.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 or No resources available for the request")
        return self.updateRequestList(reqList, allocationDict)
コード例 #5
0
def test_mechanism():
    num_slots = 4
    slot_clicks = [1] * 4   # don't actually matter for gsp
    bids = zip(range(1,6), [10, 12, 18, 14, 20])

    reserve = 0

    (alloc, payments) = GSP.compute(slot_clicks, reserve, bids)
    assert alloc == [5,3,4,2]
    assert payments == [18, 14, 12, 10]

    reserve = 11
    (alloc, payments) = GSP.compute(slot_clicks, reserve, bids)
    assert alloc == [5,3,4,2]
    assert payments == [18, 14, 12, 11]

    reserve = 14
    (alloc, payments) = GSP.compute(slot_clicks, reserve, bids)
    assert alloc == [5,3,4]
    assert payments == [18, 14, 14]

    reserve = 15
    (alloc, payments) = GSP.compute(slot_clicks, reserve, bids)
    assert alloc == [5,3]
    assert payments == [18, 15]

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


    reserve = 22
    (alloc, payments) = GSP.compute(slot_clicks, reserve, bids)
    assert alloc == []
    assert payments == []