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


Python Inventory.shortage方法代码示例

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


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

示例1: Agent

# 需要导入模块: from inventory import Inventory [as 别名]
# 或者: from inventory.Inventory import shortage [as 别名]
class Agent(object):
    newid = itertools.count()
    SIGNIFICANT = .25
    LOW_INVENTORY = .1
    HIGH_INVENTORY = 2
    def __init__(self, class_name, id=None):
        # Each agent has a unique id... should probably get rid of this and just let logic handle it
        if not id:
            self.id = next(Agent.newid)
        else:
            self.id = id
        
        self.class_name = class_name
        self.price_beliefs = {}
        self.observed_trading_range = {}
        self.inventory = Inventory()
        
        # FIXME: Using preloaded test values, this should be changed later
        self.money = 100

        self.price_beliefs = {key: {'min':.5, 'max':1.5} for key in self.inventory.goods}
        self.observed_trading_range = {key: [] for key in self.inventory.goods} # was keys
        self.lookback = 15

        # Add two fake trades so range exists
        for trade_range in self.observed_trading_range.values():
            trade_range.append(.5)
            trade_range.append(1.5)

        # This is temporary
        self.load_logic(manual_logic.agent_logic_data)



        

    def create_bid(self, market, good, limit):
        bid_price = self.determine_price_of(good)
        ideal = self.determine_purchase_quantity(market, good)
        #input('ideal {} limit {}'.format(ideal, limit))

        # Can't buy more than the limit
        if limit < ideal:
            quantity_to_buy = limit
        else:
            quantity_to_buy = ideal

        if quantity_to_buy > 0:
            return Offer(self.id, good, quantity_to_buy, bid_price)

        return None
        
    def create_ask(self, market, good, limit):
        ask_price = self.determine_price_of(good)
        ideal = self.determine_sale_quantity(market, good)

        # must sell at least the limit
        if limit > ideal:
            quantity_to_sell = limit
        else:
            quantity_to_sell = ideal

        if quantity_to_sell > 0:
            return Offer(self.id, good, quantity_to_sell, ask_price)

        return None


    def generate_offer(self, market, good):
        if self.inventory.surplus(good):
            offer = self.create_ask(market, good, 1)
            if offer:
                market.ask_book[good].append(offer)

        else:
            shortage = self.inventory.shortage(good)
            # TODO: Look in original here, at this point there is logic done to check if there
            # is space in inventory
            if shortage:
                offer = self.create_bid(market, good, shortage) # for now no now limit, this will change
                if offer:
                   market.bid_book[good].append(offer)


    def determine_price_of(self, good):
        belief = self.price_beliefs[good]
        return random.uniform(belief['min'], belief['max'])


    def determine_sale_quantity(self, market, good):
        # TODO: probably could combine determine sale and determine purchase into one method
        mean = market.history.prices.average(good, self.lookback)
        trade_range = self.observe_trade_range(good) 
           
        if trade_range:
            # TODO: clean this up and create a method for it 
            mean -= trade_range['min']
            trade_range['max'] -= trade_range['min']
            try:
                favorability = mean / trade_range['max'] # Determine where mean falls in trade range 
#.........这里部分代码省略.........
开发者ID:johny5w,项目名称:market_sim,代码行数:103,代码来源:agent.py


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