使用无向链接而不是有向链接 [英] Use undirected links instead of Directed links

查看:90
本文介绍了使用无向链接而不是有向链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的模型中,我使用直接链接来保持每个乌龟与其他乌龟的交互值,并且每个链接在链接的每个末端都有不同的值,这正是我想要的,并且确实易于实现,但是,我遇到性能问题,并且我的模型无法以我认为应该的速度运行.

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.

现在,我正在尝试其他方法来减少计算需求.我想到的一件事是将所有定向链接集成到无向链接,并将end1和end2的交互值相互作为链接属性,例如 end1-end2-Relationship-Value end2-end1-Relationship-Value Frequency1 Frequency2 .这种实现将使我的整个模型更加难以调试,因为链接的顺序将更加难以跟踪,而且我经常使用这些值的计算,因此我想知道是否有人有更好的方法来增加这些值性能:)

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 

更新2: 我想我已经找到了一种更好的方式(显而易见的方式!我应该首先做到这一点)来设置受欢迎程度,而不是每次都打一个勾号,而只是改变了它才可以更新它,我什至认为我可能不会每次需要它时,我都会调用我的链接

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

* 更新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

感谢塞思(Seth)的评论

Thank to Seth for his comments

谢谢. 疯了.

推荐答案

您的计划对我来说听起来并不像它会帮助提高性能.听起来可能使速度变慢或变快.

Your plan doesn't sound to me like it would help performance. It sounds just as likely to make things slower as faster.

您是否尝试过使用探查器扩展来查看哪些程序使用了最多的CPU? http://ccl.northwestern.edu/netlogo/5.0/docs/profiler.html

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]很慢,因为它必须检查每个链接以查看其是否满足给定条件.我认为您的意思是[my-in-links] of myself;像my-in-links这样的原语可以立即返回答案,而不必检查每个链接.

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.

同样,您有any? links with [end1 = Self_Agent and End2 = Other_Agent].同样,使用with意味着必须检查每个链接是否满足条件.而是写[out-link-neighbor? Other_Agent] of Self_Agent. out-link-neighbor?可以直接检查链接是否存在,而不必扫描每个链接.

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.

我有一种直觉,消除对with的不必要使用将解决您的性能问题.但是,还有一个不太重要的注意事项:

I have a hunch that eliminating unnecessary uses of with will fix your performance problems. But, one additional, less important note:

为什么foreach sort sss?为什么不只是ask sss?是否有某些原因需要按排序顺序运行? askforeachsort?快.

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 ?.

这篇关于使用无向链接而不是有向链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆