【发布时间】:2013-11-27 12:46:45
【问题描述】:
我已经更改了我的代码的许多部分以提高性能,现在以下是我的代码中最耗时的过程之一:
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 只是为了确保我的实验不会以错误“代理不能与自身建立链接”而结束,即使我试图确保代理要求其他代理更新链接并且永远不会本身就是!!
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 个代理!
【问题讨论】:
标签: performance optimization netlogo