如何改善NetLogo中的跟踪功能? [英] How can I improve following function in NetLogo?

查看:93
本文介绍了如何改善NetLogo中的跟踪功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我更改了代码的许多部分以提高性能,现在,以下是代码中最耗时的过程之一:

I have changed many parts of my code to improve performance, now following is one of the most time consuming procedures in my code:

to deduct [Picking_Agent C]
  If label_ = "Common Food Source"   
    [

      Let witnesses_From_Other_Village other (agents in-radius vision with [Belongs_to !=  [Belongs_to] of Picking_Agent and member? Picking_Agent agents in-cone vision  100 ])
      if any? witnesses_From_Other_Village
        [Let Penalty (0 - (C / count witnesses_From_Other_Village * 10))
          ask witnesses_From_Other_Village 
          [
            Update_link_Values  Picking_Agent Penalty
          ]
        ]
    ]

end




to Update_link_Values  [Other_Agent Value]

  if self != Other_Agent

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

  ]

end

我必须使用条件if self != Other_Agent只是为了确保我的实验不会以代理无法与其自身建立链接"的错误结束,即使我试图确保该代理要求其他代理来更新链接并且从不本身就是

I had to use condition if self != Other_Agent only to make sure my experiments does not end with error "that agent can not have links to itself", even I tried to make sure that agent asks other agents to update the link and never is itself!!

Name                               Calls Incl T(ms) Excl T(ms) Excl/calls
DAILY-TASK-WITH-LEADER           4598209    271.667 169791.762      0.037
DEDUCT                            248639 168314.428 104789.036      0.421
....

更新: 如果性能问题出在Picking_Agent agents in-cone vision 100中,那么我认为正确的问题是如何找到能够以最有效的方式看到主叫座席的座席?使用这种方法,我最多可以有10位目击者见证大部分活动,如果我使用半径范围内的活动,则可能多达90位特工!

UPDATE: If the performance problem is in Picking_Agent agents in-cone vision 100 Then I think the right question to ask is how to find agents who can see the calling agent in the most efficient way? Using this method I have up to 10 eye witnesses for most of activities that can be witnessed, if I use in-radius this could be as high as 90 agents!

推荐答案

我很确定您的问题在这里:

I'm pretty sure your problem is here:

member? Picking_Agent agents in-cone vision  100

这是一种确定一种药剂是否在另一种药剂的视锥中的极其缓慢的方法.为什么?因为它包含此子表达式:

This is an extraordinarily slow means of determining whether one agent is in another agent's vision cone. Why? Because it includes this subexpression:

agents in-cone vision 100

计算圆锥体中所有 all 代理的集合.这样做非常昂贵; in-cone进行大量的距离和角度计算.但是您不必知道锥中所有这些特工是谁!您已经有一个特工,您只需要知道一个单独的特工是否在圆锥体中即可.

which computes the set of all agents in the cone. Doing that is very expensive; in-cone does tons of distance and angle calculations. But you don't need to know who all of those agents in the cone are! You already have an agent, and you just need to know if that one single agent is in the cone or not.

您应该避免使用in-cone,并使用诸如distancetowards之类的原语直接计算是或否答案.我建议将计算结果放在一个单独的过程中,并在继续进行之前单独测试该过程,以确保您设置正确.它不需要非常多的代码,但所需的代码很难正确. (可能是该语言应该包括一个能做到这一点的原语,而不是让您自己编写它.)

You should avoid in-cone and compute your yes-or-no answer directly using such primitives as distance and towards. I'd suggest putting that computation in a separate procedure, and testing that procedure thoroughly in isolation to make sure you've got it right, before moving on. It doesn't take very much code, but the code it requires is tricky to get right. (Probably the language ought to include a primitive that does it, instead of making you write it yourself.)

这篇关于如何改善NetLogo中的跟踪功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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