Search code examples
netlogographml

Importing link breed in netlogo using nw:load-graphml


How can I get NetLogo to recognize link breeds when importing a graphml file?

I have specified breed attributes in the graphml file and named the breeds in NetLogo. When imported into NetLogo using nw:load-graphml, I believe NetLogo should assign breed to links by reading the breed attribute in the graphml file. As described in NetLogo documentation:

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

However, despite specifying link breeds in NetLogo and the graphml file, links are assigned the generic "links" breed upon import.

Example graphml file:

<?xml version="1.0" encoding="UTF-8"?>
<graphml xmlns="http://graphml.graphdrawing.org/xmlns"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns
         http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd">
  <key id="v_name" for="node" attr.name="name" attr.type="string"/>
  <key id="e_breed" for="edge" attr.name="breed" attr.type="string"/>
  <graph id="G" edgedefault="undirected">
    <node id="n0">
      <data key="v_name">1</data>
    </node>
    <node id="n1">
      <data key="v_name">2</data>
    </node>
    <node id="n2">
      <data key="v_name">3</data>
    </node>
    <node id="n3">
      <data key="v_name">4</data>
    </node>
    <node id="n4">
      <data key="v_name">5</data>
    </node>
    <edge source="n1" target="n2">
      <data key="e_breed">ftf-tie</data>
    </edge>
    <edge source="n0" target="n3">
      <data key="e_breed">ftf-tie</data>
    </edge>
    <edge source="n0" target="n4">
      <data key="e_breed">ftf-tie</data>
    </edge>
    <edge source="n1" target="n4">
      <data key="e_breed">ftf-tie</data>
    </edge>
    <edge source="n1" target="n4">
      <data key="e_breed">sns-tie</data>
    </edge>
  </graph>
</graphml>

NetLogo import code:

extensions [ nw ]

undirected-link-breed [ ftf-ties ftf-tie ]
undirected-link-breed [ sns-ties sns-tie ]

to setup
  clear-all
  nw:load-graphml "test.graphml"
  repeat 30 [ layout-spring turtles links 0.2 5 1 ]
end

Thank you!


Solution

  • Changing from singular-breed to plural-breed in the graphml file (e.g., from ftf-tie to ftf-ties) resolves this issue completely.

    See: https://github.com/NetLogo/NW-Extension/issues/189