Including a Netlogo source file into another

前端 未结 2 1944
广开言路
广开言路 2021-01-05 07:19

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 functi

相关标签:
2条回答
  • 2021-01-05 08:07

    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.

    0 讨论(0)
  • 2021-01-05 08:20

    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.

    0 讨论(0)
提交回复
热议问题