将 Netlogo 源文件包含到另一个文件中

发布于 2024-11-04 01:56:40 字数 381 浏览 5 评论 0原文

如何将一个 Netlogo 文件中的过程包含到另一个 Netlogo 文件中?基本上,我想将遗传算法的代码与我的(相当复杂的)适应度函数分开,但是,显然,我希望将驻留在“fitness.nlogo”中的适应度报告器在遗传算法代码中可用,可能是“遗传.nlogo”。

如果可以的话,程序是如何导入的,代码是如何执行的?是像Python一样,导入模块几乎会执行模块中的所有内容,还是像C/C++一样,文件被盲目地“加入”?

这可能是一个愚蠢的问题,但我在谷歌上找不到任何东西。 Netlogo 文档提到了一些关于 __includes 的内容,这是一个可以实现这一目的的实验性关键字,但没有太多解释。也没有例子。

有什么提示吗?我应该选择__includes吗?它是如何运作的?

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

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

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.

Any hints? Should I go with __includes? How does it work?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

小耗子 2024-11-11 01:56:40

包含您使用的文件

__includes["libfile.nls"]

添加此文件并按“检查”按钮后,“程序”下拉菜单旁边将出现一个新按钮。您可以在那里创建和管理多个源文件。

libfile.nls 只是一个包含 NetLogo 代码的文本文件。它不是 netlogo 模型,它总是以 .nlogo 结尾,因为 NetLogo 模型除了 NetLogo 代码之外还包含许多其他信息。

包含文件相当于在此时插入其所有内容。为了使其像可重用库文件一样工作,应该创建使用代理集和参数作为输入变量的过程,以独立于全局定义或接口设置。

该功能记录在 NetLogo 用户手册中,网址为 http://ccl.northwestern.edu /netlogo/docs/programming.html#includes

To include a file you use

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

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.

The feature is documented in the NetLogo User Manual at http://ccl.northwestern.edu/netlogo/docs/programming.html#includes.

幸福丶如此 2024-11-11 01:56:40

您可以创建一个文件 libfile.nls 并在同一文件夹中创建主模型 model.nlogo

之后,转到您的 model.nlogo 并写入:

__includes["libfile.nls"]  

此文件包含您可以在模型中调用的报告器和过程。

You can create a file libfile.nls and in the same folder create your main model model.nlogo.

After that, go to your model.nlogo and write:

__includes["libfile.nls"]  

This file contains your reporters and procedures that you can call in your model.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文