NetLogo substitute for breed - netlogo

I was wondering whether there is a substitute for the breed function in Net Logo?
I looked for a substitute in the dictionary but all I found was globals and I don't think that fully covers what the breed function can do. If there is a substitute, what is it?

Are you looking for turtle-set? This allows you to create an agentset from an arbitrary collection of turtles.

Related

How to switch agents from one breed to another during a simulation?

I have a stock market simulation with two types of breeds, passive and active. They both have different formulas for investing. However, I would like the agents to switch between the two breed types. I have a condition they should follow to decide when to switch. However, I am not sure how to program the agents to switch.
You should be able to simply set the breed of an agent, just as would any other variable:
ask one-of passives [ set breed actives ]
Assuming you used passives and actives as your breed plural names.
You can read more in the NetLogo programming guide.

Turtles changing more then one patch netlogo

I am new to programming and using netlogo so this question is probably too simple.
I am creating a model in which households decide their farming area each year (changing the location every year). I need to make them change the type of vegetation of n patches, according to the size they decided previously.
I know primitives like in-radius, neighbor and neighbor4 but all of them don't give me the freedom to change the exact number I want. For example, if the farming area is 3 hectares, how can i make one household change 3 patches vegetation type? How can I do that?
Thanks
How about:
n-of 3 neighbors
That would give you three random patches among the patche's neighbors, which may or may not be what you want, but your question isn't precise enough to say...
Let us know if that works for you. If not, give us a bit more detail.

does NetLogo's ask-with ensure lazy evaluation?

How equivalent are the following two lines of code?
ask agentset [if (attr > 0) [dosomething]]
ask agentset with [attr > 0] [dosomething]
Are there any expected (and explainable) differences
in speed or the use of memory?
In particular, does the use of with in the second
case lead to the creation of a temporary agentset,
or does the ask ... with combination ensure
lazy evaluation?
Just to expand on what Nicolas said:
ask-with is intentionally not lazy. Consider code where the agents are modifying the attribute of other agents that determines whether or not they should be asked, so to speak:
to go
ask patches with [ pcolor = red ] [
ask neighbors4 [ set pcolor red ]
]
tick
end
Because with creates a temporary agentset, which agents are asked is not changed mid-ask. This causes the red region to grow evenly as go is called repeatedly:
Now, consider it with if instead.
to go
ask patches [
if pcolor = red [
ask neighbors4 [ set color red ]
]
]
tick
end
Because patches that have not been asked yet might have have their color changed to red, the red region grows unevenly:
Thus, ask-with actually has different behavior then ask-if, and so cannot be optimized to it. That said, as Nicolas mentioned, some similar optimizations are done.
(Disclaimer: my familiarity with the compiler is very superficial, so I might be missing something.)
A (possibly outdated) list of the optimizations performed by the NetLogo compiler is available here:
https://github.com/NetLogo/NetLogo/wiki/Compiler-architecture#optimizer
The actual code for those (in NetLogo 6.0) is here:
https://github.com/NetLogo/NetLogo/blob/bd3da2bf5495674ce5690cbb2992de4036c9db03/netlogo-core/src/main/compile/middle/optimize/package.scala
As far as I can tell, there is no optimization for ask ... with. It means that ask ... with does create an intermediate agentset and, as such, probably requires more memory and time than ask ... [ if ... ].
Which one you should use probably depends on where you stand on the efficiency/readability trade-off. (I personally find ask ... with more readable.)
Would it be a good idea to optimize ask ... with? In my opinion, absolutely. That being said, there might have been a technical reason not to do it at the time the compiler was written. I just don't know about it.
There is, indeed, a very good reason why ask ... with is not optimized. And there are behavioral differences between the two versions; it's not just a matter of readability vs. efficiency. See Bryan's answer.

In NetLogo, what is the most efficient way to copy the values of variables in an agentset to another agentset with the same number of agents

In NetLogo, I have the same number of turtles on different patches. Now I want to copy the agent variable values of the agents on one patch to those agents on another patch. I know I can define a list of members for each patch, and then copy the values agent by agent according to the order of the list, but I have to define a list for each patch, which may take some memory and reduce the running speed.
In other words, I want the agents on one patch with their agent variable values the same as the agents on another patch.
Are there more efficient ways to do this?
I use something like this hatch makes exact duplicates of the original turtles same variables same color etc
targ is the patch you want them at
to dup-turtles-to [targ]
ask turtles-here
[
hatch 1 [move-to targ]
]
end
I hope that is helpful and I understood your question correctly.

Comparing two agent variables

I am currently making a simulation (for homework) using genetic algorithms. What I want to do is compare the fitness of agents on a specific patch and the one with the lowest fitness will die.
I have scoured the net and found this code: if any? breed1-here with [fitness > fitness-of myself] [die]]
But this doesn't seem to work and now I'm completely out of ideas.
let goner min-one-of breed1-here [fitness]
if is-turtle? goner [ ask goner [ die ] ]`
the is-turtle? check is necessary because the patch might be empty.
Yes, that code is from an old version of the NetLogo language. That line of code should be re-written as:
if any? breed1-here with [fitness > [fitness] of myself] [die]]
Of course, that code will kill all turtles in a patch except for the one(s) with maximum fitness, which is not exactly what you want.