Using/type setting agent/instance attributes for arithmetics in wealth model #39
-
Hi all, Hi Joel, well done. Super work and documentation. Super efficient code and everything. I am currently trying to teach myself OOP and in parallel agentpy. First newbie problem I seem to not overcome is with the def setup() function. I wonder why not use the init method? Like Mesa does , is there a specific reason? My specific issue I would like to change the rules of the wealth transfer model from
to something like this (just for learning purposes)
It gives me the error TypeError: unsupported operand type(s) for *: 'int' and 'AgentIter' It does not seem to allow the arithmetic useing the instance attr. I tried to somehow typeset the attribute but did not succeed so far. However in Mesa with the init method it works without issues. I just wonder what's the difference? Thanks a lot! Yannick |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi Yannik, glad you like the package! regarding
regarding your problem
if you want to be more explicit, you can also use:
let me know if that solves the problem. I should add that info to the documentation, then Best, |
Beta Was this translation helpful? Give feedback.
Hi Yannik,
glad you like the package!
regarding
setup()
, you can also overwrite__init__()
instead. If you look at the source, the agent's__init__()
looks just like this:regarding your problem
self.model.agents.random()
returns an iterator of agents (even if in your case it is only one agent). the iterator can support some operations but not all. an easy way to unpack the agent from the iterator is this (notice the comma after partner):if you want to be more explicit, you can also use:
let me k…