本文整理汇总了Python中market.Market.rationing_abstract方法的典型用法代码示例。如果您正苦于以下问题:Python Market.rationing_abstract方法的具体用法?Python Market.rationing_abstract怎么用?Python Market.rationing_abstract使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类market.Market
的用法示例。
在下文中一共展示了Market.rationing_abstract方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: consume_rationed
# 需要导入模块: from market import Market [as 别名]
# 或者: from market.Market import rationing_abstract [as 别名]
def consume_rationed(self, environment, time):
# We want the consumption to be done in random pairs
# We use rationing from market clearing class to do that
# Price is static for this example, otherwise we can't use rationing
# and need some other market clearing
price = 10.0
environment.variable_parameters["price_of_goods"] = price
# We need a list of agents and their demand or supply
# Supply is denoted with positive float, demand with negative float
for_rationing = []
# Firms give us their supply, we assume that since the goods are
# perishable their supply is all they have in stock
from src.helper import Helper
helper = Helper()
for firm in environment.firms:
# amount = round(helper.leontief([firm.get_account("labour")], [1/firm.productivity]), 0)
amount = helper.cobb_douglas(firm.get_account("labour"), firm.get_account("capital"),
firm.total_factor_productivity, firm.labour_elasticity, firm.capital_elasticity)*price
for_rationing.append([firm, amount])
# Households give use their demand, we assume that they want to
# consume the part of their wealth (cash and deposits) that they
# do not want to save (determined through propensity to save)
# We denote demand in units of the goods, so we divide the cash
# households want to spend by price to get the demand
for household in environment.households:
demand = 0.0
# demand = -round(((household.get_account("deposits") * (1 - household.propensity_to_save)) / price), 0)
demand = -((household.get_account("deposits") * (1 - household.propensity_to_save)) / price)
# demand = -household.get_account("deposits")/price
for_rationing.append([household, demand])
# We import the market clearing class
from market import Market
# Put the appropriate settings, i.e.
# tolerance of error, resolution of search
# and amplification for exponential search
# This does not matter for rationing
# But in principle we need to initialize
# with these values
market = Market("market")
# And we find the rationing, ie the amounts
# of goods sold between pairs of agents
# TESTING THE ABSTRACT RATIONING
# The matching function means that all pairs will have the same priority
def matching_agents_basic(agent_one, agent_two):
return 1.0
# The below function means that all pairs are allowed
def allow_match_basic(agent_one, agent_two):
return True
# We find the actual trades
rationed = market.rationing_abstract(for_rationing, matching_agents_basic, allow_match_basic)
# Then we go through the rationing
# and move the goods and cash appropriately
for ration in rationed:
#
# A (from) L (to)
# bank loan deposit
# household goods loan
# firm deposit goods
#
environment.new_transaction("goods", "", ration[1].identifier, ration[0].identifier,
ration[2], 0, 0, -1)
random_bank = random.choice(environment.banks)
environment.new_transaction("deposits", "", ration[0].identifier, random_bank.identifier,
ration[2]*price, random_bank.interest_rate_deposits, 0, -1)
environment.new_transaction("loans", "", random_bank.identifier, ration[1].identifier,
ration[2]*price, random_bank.interest_rate_loans, 0, -1)
# We print the action of selling to the screen
print("%s sold %d units of goods at a price %f to %s at time %d.") % (ration[0].identifier,
ration[2], price, ration[1].identifier, time)
logging.info(" goods consumed on step: %s", time)