本文整理汇总了Python中agent.Agent.rand方法的典型用法代码示例。如果您正苦于以下问题:Python Agent.rand方法的具体用法?Python Agent.rand怎么用?Python Agent.rand使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类agent.Agent
的用法示例。
在下文中一共展示了Agent.rand方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: gen_market
# 需要导入模块: from agent import Agent [as 别名]
# 或者: from agent.Agent import rand [as 别名]
def gen_market(n, r, seed=None):
""" Generate a market with n agents and n goods,
with each agent interested in r goods, and endowed with r goods.
Arranged so that each good is wanted by someone, provided by someone.
"""
assert r <= n
if seed is not None:
np.random.seed(seed)
random.seed(seed)
# goods interested in
a = np.random.permutation(n)
# initial endowment
b = np.random.permutation(n)
market = Market()
for a_ind, b_ind in izip(a, b):
#util_fn = random.choice([util.Linear, util.CES, util.CobbDouglas])
#util_fn = util_fn.rand(p, n)
#util_fn = util.Linear.rand(n, r, a_ind)
agent = Agent.rand(util.Linear, n, r, a_ind, b_ind)
market.add(agent)
print 'goods: ', len(market.goods), ' agents: ', len(market.agents)
print "market is sane: ", market.sane()
print "market is really sane: ", market.really_sane()
return market