当前位置: 首页>>代码示例>>Python>>正文


Python GSP.compute方法代码示例

本文整理汇总了Python中gsp.GSP.compute方法的典型用法代码示例。如果您正苦于以下问题:Python GSP.compute方法的具体用法?Python GSP.compute怎么用?Python GSP.compute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在gsp.GSP的用法示例。


在下文中一共展示了GSP.compute方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: expected_utils

# 需要导入模块: from gsp import GSP [as 别名]
# 或者: from gsp.GSP import compute [as 别名]
    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
开发者ID:buffalohird,项目名称:Marfalo-and-Bark,代码行数:34,代码来源:bugsbb.py

示例2: runSecondPriceAuction

# 需要导入模块: from gsp import GSP [as 别名]
# 或者: from gsp.GSP import compute [as 别名]
    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)
开发者ID:52-41-4d,项目名称:GreyFiber,代码行数:40,代码来源:adexchange.py

示例3: test_mechanism

# 需要导入模块: from gsp import GSP [as 别名]
# 或者: from gsp.GSP import compute [as 别名]
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 == []
开发者ID:philipjlin,项目名称:Sponsored_Search_Auctions,代码行数:38,代码来源:test_gsp.py


注:本文中的gsp.GSP.compute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。