Reputation: 149
In my model I have "ai"
process and this is in agent context. My agents are buyers and sellers and both of them has decision and payoff (payoff_seller and payoff_buyer) variable. And buyers have buyer_Price sellers have seller_Price. They trade with each other when seller_Price <= buyer_Price. And when they trade they save their Price to their decision variable and it takes place in interaction process. I code it so:
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
Now in ai process I have to code that my agents have to look around and choose the neighbor agent with the highest payoff. and than the agent has to give his decision value to this agent. I couldnt code it, could anyone give some tips? At least idea how can I begin my code or process?
Upvotes: 1
Views: 44
Reputation: 51
As starting point, you probably want to use a nested ask construct for the interaction, like so:
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)
]
]
]
Upvotes: 1