Including Netlogo Source File in Another

How to include procedures from one Netlogo file to another? Basically, I want to separate the genetic algorithm code from my (rather complex) fitness function, but obviously I want the fitness reporter who will be in "fitness.nlogo" to be available in the genetic algorithm code, probably " gene.nlogo ".

If this can be done, how are the procedures imported and the code executed? Is it like Python, where importing a module pretty much does everything in the module, or like C / C ++, where the file is blindly "connected"?

This may be a stupid question, but I did not find anything on Google. Netlogo's documentation talks about __includes , an experimental keyword that can do the trick, but there isn't much to explain. There is no example.

Any clues? Should I go with __includes ? How it works?

+6
source share
1 answer

To include the file you are using

 __includes["libfile.nls"] 

After adding and clicking 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 is just a text file containing NetLogo code. This is not a netlogo model that always ends with .nlogo, since the NetLogo model contains a lot of other information besides NetLogo code.

Including a file is the equivalent of just pasting all of its contents at that point. To make it work in such a way as multiple library files, you should create procedures that use agents and parameters, since the input variables do not depend on global definitions or interface settings.

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

+12
source

Source: https://habr.com/ru/post/886947/


All Articles