1

在我的模型中,我使用直接链接来保持每个海龟与其他海龟的交互值,并且每个链接对于链接的每一端都有不同的值,这正是我想要的,而且它真的很容易实现,但是,我有一个表现问题,我的模型没有我认为它应该工作的那么快。

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

我认为这可能更好的原因是它将链接数量减少到一半,另一种方法是忘记链接(杀死旧链接或关系不太重要的链接(关系值不重要和关系频率较低)但这个不是与我的模型设置完全兼容。

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: 我想我已经找到了一种更好的方法(很明显!我应该首先做的)来设置流行度,而不是每次都调用它,我只能在它发生变化时更新它,我什至认为我可能不需要每次我需要它时称为“流行度”的变量我只是调用 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

感谢赛斯的评论

谢谢 。马齐。

4

2 回答 2

1

你的计划听起来对我没有帮助。这听起来就像让事情变慢和变快一样可能。

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

更新:(现在已经提供了代码)

links with [end2 = mySelf]很慢,因为它必须检查每个链接以查看它是否满足给定条件。我想你的意思是[my-in-links] of myself;像立即返回答案这样的原语my-in-links,无需检查每个链接。

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

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

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

于 2013-11-03T13:23:00.197 回答
1

只是为了总结我首先将定向链接更改为无向链接的结果,这在此之后造成了很多麻烦,所以我仍然会使用定向链接:

这是我使用的代码:

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] ;IF already has a link 
         [create-link-to Other_Agent [set Value-Of-The-Relationship Value-Of-The-Relationship + Value set Frequency Frequency + 1 ] set hidden? true ] ;If they meet for the first time

     ] 

end

;Update_Friendship_Values 
to Update_Friendship_Values  [Self_Agent Other_Agent Value]
  ask Self_Agent 
    [     
      ifelse any? Friendships with [end1 = Self_Agent and End2 = Other_Agent]

      [
        ask Friendships with [end1 = Self_Agent and End2 = Other_Agent] 
        [ 
          set End1-End2-Value-Of-The-Relationship End1-End2-Value-Of-The-Relationship + Value  
          set End1-End2-Frequency End1-End2-Frequency + 1  
        ]  
       ; set hidden? true
      ] ;IF already has a link and first agent is end1
      [  
        ifelse any? Friendships with [end2 = Self_Agent and End1 = Other_Agent]

          [
            ask Friendships with [end2 = Self_Agent and End1 = Other_Agent] 
            [ 
              set End2-End1-Value-Of-The-Relationship End2-End1-Value-Of-The-Relationship + Value  
              set End2-End1-Frequency End2-End1-Frequency + 1
            ]  
            ;set hidden? true
          ] ;IF already has a link and first agent is end2 
          [ ifelse count Other_Agent = 1 
            [create-Friendship-with Other_Agent [
              set End1-End2-Value-Of-The-Relationship End1-End2-Value-Of-The-Relationship + Value
              set End1-End2-Frequency End1-End2-Frequency + 1 
            ]] [
            create-Friendships-with Other_Agent [
              set End1-End2-Value-Of-The-Relationship End1-End2-Value-Of-The-Relationship + Value
              set End1-End2-Frequency End1-End2-Frequency + 1]
            ;set hidden? true 
          ] ]
      ]
    ] 

end

通过 Seth 建议的更正,我认为拥有更多链接比使用更复杂的计算来找到正确的无向链接更好(这里称为友谊)

于 2013-11-05T03:03:42.100 回答