将Netlogo源文件包含在另一个中 [英] Including a Netlogo source file into another
问题描述
如何将一个Netlogo文件中的过程包含在另一个文件中?基本上,我想将遗传算法的代码与我的(相当复杂的)适应度函数分开,但是,显然,我希望健身记者(将驻留在fitness.nlogo中)可用于遗传算法代码,可能是genetic.nlogo。
How can I include the procedures from one Netlogo file into another? Basically, I want to separate the code of a genetic algorithm from my (quite complicated) fitness function, but, obviously, I want the fitness reporter, which will reside in "fitness.nlogo", to be available in the genetic algorithm code, probably "genetic.nlogo".
如果可以,如何导入程序,执行代码?它是否像Python一样,导入模块几乎执行模块中的所有内容,或者像C / C ++那样,文件是盲目加入的?
If it can be done, how are the procedures imported, and the code executed? Is it like Python, where importing a module pretty much executes everything in the module, or like C/C++, where the file is blindly "joined"?
这可能是一个愚蠢的问题,但我在谷歌上找不到任何东西。 Netlogo文档中提到了一些关于 __包含
的内容,这是一个可以解决问题的实验性关键字,但是那里没有太多解释。没有例子。
This may be a stupid question, but I couldn't find anything on Google. The Netlogo documentation says something about __includes
, an experimental keyword that may do the trick, but there's not much explained there. No example either.
任何提示?我应该使用 __ includes
吗?它是如何工作的?
Any hints? Should I go with __includes
? How does it work?
推荐答案
要包含您使用的文件
__includes["libfile.nls"]
添加此项后然后按检查按钮,程序下拉菜单旁边会出现一个新按钮。在那里,您可以创建和管理多个源文件。
After adding this and pressing the "Check" button, a new button will appear next to the Procedures drop-down menu. There you can create and manage multiple source files.
libfile.nls 只是一个包含NetLogo代码的文本文件。它是不一个netlogo模型,它总是以.nlogo结尾,因为NetLogo模型除了NetLogo代码之外还包含很多其他信息。
The libfile.nls is just a text file that contains NetLogo code. It is not a netlogo model, which always end in .nlogo, as a NetLogo model contains a lot of other information besides the NetLogo code.
包含文件相当于在该点插入所有内容。为了使其以可重用的库文件的方式工作,应该创建使用代理集和参数作为输入变量的过程,使其独立于全局定义或接口设置。
Including a file is the equivalent of just inserting all its contents at that point. In order to make it work in a way like reusable library files, one should create procedures which use agentsets and parameters as input variables to be independent of global definitions or interface settings.
该功能记录在NetLogo用户手册中,网址为 http://ccl.northwestern。 edu / netlogo / docs / programming.html #include 。
The feature is documented in the NetLogo User Manual at http://ccl.northwestern.edu/netlogo/docs/programming.html#includes.
这篇关于将Netlogo源文件包含在另一个中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!