It's not a good idea. Links in NetLogo are implemented efficiently; whatever you substitute for them is very likely to be slower rather than faster.
You seem eager for this to be NetLogo's fault, but it probably isn't; the problem is almost certainly a problem in your own code, a problem that would have arisen in whatever programming language you were working in.
In most NetLogo simulations, the runtime increases linearly with the number of agents, i.e., doubling the number of agents. From the numbers you give, it sounds like you have written code that takes time proportional to the square of the number of agents. (It might be exponential in the number of agents, but it's much more common for people to accidentally write code that takes polynomial time.)
There are two ways this might have happened:
- The algorithm you are implementing is inherently one that takes polynomial time to compute.
- The algorithm you are implementing can be coded such that it executes in linear time, but you accidentally coded it in a way that takes polynomial time.
You need to ask yourself, what is it about my code that makes it not run in linear time?
You need to look at every loop in your code that loops over all of the agents in the model and ask yourself, is there anything in the body of this loop which can't be executed in constant time?
Primitives that loop over all the agents include ask
and with
. So the most common mistake is to write something like:
ask turtles [
... turtles with [ ... ] ...
]
without knowing anything else about the code, I can look at this and know that the model it occurs in will be a slow model, because the above code requires polynomial time to execute. Every possible pair of turtles executes the both of the with
, so e.g. if there are 100 turtles, the code will take 10,000 steps to execute. If there are twice as many turtles, the code will take 40,000 steps to execute — doubling the number of turtles causes the runtime to quadruple, not just double.
We already saw once that at Use undirected links instead of Directed links that code of this form was the reason your model was slow.
So, you need to find where it is in your model that you have nested loops like this, where the size of both loops is proportional to the total number of agents. (The two loops might not necessarily be ask
and with
, and they might not even be in the same procedure.)
And when you find a place where you're doing this, you need to figure out whether you're doing a computation that inherently takes this long, or whether you've accidentally coded it in an unnecessarily slow form. If the latter, fix it. If the former, you'll need to rethink your requirements.
And it sounds like it's your requirements that are fault. You write "In the current version I am using links to keep track of agent relationship and there is no limit on how many links each agent can have". So the number of links is proportional to the number of turtles, right? That means that you don't even need nested loops in order to have written a program with polynomial runtime; if you ever do ask links [ ... ]
, even once, you're dead, since the number of links is already proportional to the square of the number of turtles.
As an example of how to fix it, you might consider putting some fixed size on the number of relationships each turtle can have. That would make it possible again for your model to run in linear time.
That doesn't mean you shouldn't also scrutinize your code for accidental problems though; it's possible that you have both problems, essential and accidental slowness. You may have accidentally done ask links [ ... ask turtles ...
or ask turtles [ ... ask links ...
in which case your runtime will increase as the cube of the number of turtles, or if you've done ask links [ ... ask links ...
, as the fourth power.
None of this advice is especially specific to NetLogo. If it's easy to write slow programs in NetLogo, it's only because it's easy to write all kinds of programs in NetLogo — including slow ones. In particular, NetLogo makes it very easy to write loops. A short snippet of code like turtles with [color = red]
is a loop, but it's so short and easy to write that it doesn't necessarily look or feel like a loop, so it's easy to miss the performance implications.