I'm building a model loosely based on the Sugarscape model to look at corporate takeovers. I need to check the attributes of a neighbouring turtle, perform a calculation on it's attributes and then choose if the acting turtle wishes to eat the neighbouring turtle. I'm having some trouble extracting the relevant information as I'm unfamiliar with the data structures and how to cycle through each individual agent in the agentset.
I want to extract the breed, vision, metabolism and current sugar balance from each agent in the agentset, perform a calculation using both this information and information about the acting turtle and then eat the 'best' one if they meet certain conditions.
to financials-kill ;; turtle proceedure
;; buy another company
let candidates []
ask neighbors4 [
ask turtles-here [set candidates fput self candidates]
]
foreach candidates[
let best-candidate max-one-of candidates with
;; checking some conditions etc here and performing the calculations but unsure how to proceed
if breed of candidates = financials[
;
]
if breed = healthcare [ ]
if breed = industrials [ ]
print candidates
end
In python, I would cycle through each of the individual agents in the agentset using a counter and have an array storing the 'fitness' of the agent and some identifying number but having looked at the documentation, I can't see how to do this.
Any pointers would be great thanks!
So, the main structure to use when dealing with groups of turtles in the "agentset". Many NetLogo primitives take or report agentsets. An agentset can contain zero, one, or many agents.
The
TURTLES-ONreporter takes a turtle or patch or set of either, as input, and reports an agentset containing the turtles standing on those patches, or standing on the same patches as those turtles.The
WITHoperator reports an agentset containing those members of the agentset on the left side that reportTRUEas the result of the expression on the right side. Example:turtles with [ color = blue ]The
OFoperator reports the value of the expression on the left, as evaluated by the agent or agentset on the right. If an agentset, the result is a list of the values. Note that the expression is actually evaluated by the agent--if the expression has 'side effects' they will apply to that agent.So, usually, we just use the agentset, we don't bother converting it to a list.
If we need a list of agents, there a a handful of primitives do to that:
So, a general pattern might be:
So your example might look like this:
Your question, though, doesn't just want to use
cash-- you want to perform some evaluation, and pick the one that gets the best result. For that, I'd make a reporter that does the valuation, and reports the result. You can refer to the calling agent usingMYSELF. You may need two reporters: one that reports true/false to select possible candidates, and another that reports a value to select the best of those candidates.now you can do something like
Last, I see you are trying to use breeds. Breeds should be treated like agentsets. So you can do things like:
or
and so on.