在我的模型中,我有"ai"
进程,这是在代理上下文中。我的代理商是买家和卖家,他们都有决策和支付(payoff_seller和payoff_buyer)变量。买家有买家_卖家有卖家_Price。当sell_Price< = buyer_Price时,他们互相交易。当他们交易时,他们将他们的价格保存到他们的决策变量,并且它发生在交互过程中。我这样编码:
to interaction
ask sellers [ set seller_Price (init_ownCosts + random (init_ownUtility - init_ownCosts))
if not any? buyers-here [set seller_Price 0]
set decision decision + seller_Price]
ask buyers [ set buyer_Price (init_ownUtility - random (init_ownUtility - init_ownCosts))
if not any? sellers-here [set buyer_Price 0]
set decision decision + buyer_Price]
ask buyers [ ask sellers [ if seller_Price <= [buyer_Price] of myself [ trade ]]]
to trade
ask sellers [set trade_Price trade_Price = seller_Price ]
ask buyers [set trade_Price trade_Price = buyer_Price ]
ask sellers [ set ownCosts ownCosts + seller_Price - trade_Price ]
ask sellers [ set payoff_Seller payoff_Seller + (trade_Price - seller_Price) ]
ask buyers [ set ownUtility ownUtility + (buyer_Price - trade_Price) ]
ask buyers [ set payoff_Buyer payoff_Buyer + trade_Price - buyer_Price ]
end
现在在ai进程中我必须编写代码,我的代理必须环顾四周并选择具有最高回报的邻居代理。并且代理商必须向该代理商提供其决策价值。我无法编码,任何人都可以提供一些提示吗?至少想法如何开始我的代码或过程?
答案 0 :(得分:1)
作为起点,您可能希望使用嵌套的ask构造进行交互,如下所示:
ask buyers [
let current-buyer self
ask sellers [
let current-seller self
let how-much 10 ;<---here you specify how much passes over between seller and buyer
set <name of variable containing the quantity to sell> (<name of variable containing the quantity to sell> - how-much)
ask current-buyer [
set <name of variable containing quantity owned> (<name of variable containing quantity owned> + how-much)
]
]
]