NetLogo 7.0.0-beta2:

nw:load-graphml

nw:load-graphml file-name optional-command-block

Loading a GraphML file into NetLogo with the network extension should be as simple as calling nw:load-graphml "example.graphml", but there is a bit of preparation involved.

The key idea is that nw:load-graphml will try to assign the attribute values defined in the GraphML file to NetLogo agent variables of the same names (this is not case sensitive). The first one it tries to set is breed if it is there, so the turtle or link will get the right breed and, hence, the right breed variables. The load expects the plural form of the breed for a turtle or link, it will not recognize the singular form.

One special case is the who number, which is ignored by the importer if it is present as a GraphML attribute: NetLogo does not allow you to modify this number once a turtle is created and, besides, there could already be an existing turtle with that number.

The simplest case to handle is when the original GraphML file has been saved from NetLogo by using nw:save-graphml. In this case, all you should have to do is to make sure that you have the same breed and variables definition as when you saved the file and you should get back your original graph. For example, if you want to load the file from the nw:save-graphml example above, you should have the following definitions:

Loading a graph that was saved from a different program than NetLogo is quite possible as well, but it may take a bit of tinkering to get all the attribute-variable match up right. If you encounter major problems, please do not hesitate to open an issue.

The extension will try to assign the type defined by attr.type to each variable that it loads. If it’s unable to convert it to that type, it will load it as a string. If attr.type is not defined, or is set to an unknown value, the extension will first try to load the value as a double, then try it as a boolean, and finally fall back on a string.

If you specify an optional-command-block, it is executed for each turtle in the newly created network. For example:

Note that this command block can be used to build a list or an agentset containing the newly created nodes:

Take me to the full Networks Extension Dictionary