In my model I use direct links to keep interaction value of each turtle to other turtles and each link has a different value for each end of the links which is exactly what I want and it was really easy to implement, However, I have a performance issue and my model is not working as fast as I think it should work.
Now I am trying different methods to decrease the computation needs. One of the things that crossed my mind is to integrate all directed links to undirected links and put the value of interaction value of end1 and end2 to each other as links attributes for example end1-end2-Relationship-Value and end2-end1-Relationship-Value and Frequency1 Frequency2. This implementation will make my whole model a bit more difficult to debug since the order of links will be much more difficult to keep track of and I use the calculation of these values a lot, so I was wondering if anyone has a better way to increase the performance :)
The reason I thought this might be better is that It will reduce the number of links to half, another method is forgetting links (kill old links or links with less significant relationship (insignificant relationship value and lower frequency of relationship) but this one is not totally compatible with my model setting.
agents-own [Belongs_to My-home popularity ]
patches-own [label_ storage]
links-own[Value-Of-The-Relationship frequency]
to Update_link_Values [Self_Agent Other_Agent Value]
ask Self_Agent
[ ifelse any? links with [end1 = Self_Agent and End2 = Other_Agent]
[ask out-link-to Other_Agent [ set Value-Of-The-Relationship Value-Of-The-Relationship + Value set Frequency Frequency + 1 ] set hidden? true]
[create-link-to Other_Agent [set Value-Of-The-Relationship Value-Of-The-Relationship + Value set Frequency Frequency + 1 ] set hidden? true ]
]
end
to SeTPoPularity
set Popularity sum[Value-Of-The-Relationship] of links with [end2 = mySelf]
end
Update 2 : I think I already found a better way (obvious one! Which I should have done in first place) to set popularity, instead of calling it every tick I just can update it only if it has changed, I even think I might don't need The variable called "popularity" every time I need it I just call the my-in-links
*Update 3 : *
to Update_link_Values [Self_Agent Other_Agent Value]
ask Self_Agent
[ ifelse out-link-neighbor? Other_Agent
[ask out-link-to Other_Agent [ set Value-Of-The-Relationship Value-Of-The-Relationship + Value set Frequency Frequency + 1 ] set hidden? true]
[create-link-to Other_Agent [set Value-Of-The-Relationship Value-Of-The-Relationship + Value set Frequency Frequency + 1 ] set hidden? true ]
]
end
Thank to Seth for his comments
Thanks . Marzy.
Your plan doesn't sound to me like it would help performance. It sounds just as likely to make things slower as faster.
Have you tried using the profiler extension to see which procedures are the ones using the most CPU? http://ccl.northwestern.edu/netlogo/5.0/docs/profiler.html
UPDATE: (now that code has been provided)
links with [end2 = mySelf]
is slow because it has to check every link to see whether it satisfies the given condition. I think you mean [my-in-links] of myself
; primitives like my-in-links
return answers immediately, without having to check every link.
Similarly, you have any? links with [end1 = Self_Agent and End2 = Other_Agent]
. Again, using with
means every link has to be checked if satisfies the condition. Instead, write [out-link-neighbor? Other_Agent] of Self_Agent
. out-link-neighbor?
can check for the existence of a link directly, without having to scan every link.
I have a hunch that eliminating unnecessary uses of with
will fix your performance problems. But, one additional, less important note:
Why foreach sort sss
? Why not just ask sss
? Is there some reason it needs to run in sorted order? ask
is faster than foreach
plus sort
plus ?
.