user299791
user299791

Reputation: 2070

How to load a graphml file with Netlogo NW extension

I think there is a bug in the way nw:load-graphml works.

Take this graphml file with 3 nodes and 3 links of an undirected breed "parentals" and 2 links of a directed breed "diffusions" :

<?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">
<!-- Created by igraph -->
<key id="e_breed" for="edge" attr.name="breed" attr.type="string"/>
<graph id="G" edgedefault="undirected">
    <node id="n0">
    </node>
    <node id="n1">
    </node>
    <node id="n2">
    </node>
    <edge source="n0" target="n1">
       <data key="e_breed">parentals</data>
    </edge>
    <edge source="n0" target="n2">
       <data key="e_breed">parentals</data>
    </edge>
    <edge source="n1" target="n2">
       <data key="e_breed">diffusions</data>
    </edge>
    <edge source="n0" target="n1">
       <data key="e_breed">diffusions</data>
    </edge>
  </graph>
</graphml>

when you load the file with nw:load-graphml what happens is that all "parentals" links are created, while "diffusions" are only partially created: only "diffusions" links that involves nodes not already linked by parentals links are created, while the others are skipped... is this a bug or an intended behavior in the load-graphml primitive?

this is a short net logo code to demonstrate:

extensions [nw]

undirected-link-breed [parentals parental]
directed-link-breed [diffusions diffusion]

to setup
   ca
   nw:load-graphml "prova.graphml"
   layout-circle turtles 10
end

Upvotes: 3

Views: 204

Answers (1)

bergant
bergant

Reputation: 7232

In your NetLogo code the "diffusion" links are directed. Add directed = "true" attribute to diffusion links in the prova.graphml file:

<edge source="n0" target="n1">
   <data key="e_breed">parentals</data>
</edge>
<edge source="n0" target="n2">
   <data key="e_breed">parentals</data>
</edge>
<edge directed="true" source="n1" target="n2">
   <data key="e_breed">diffusions</data>
</edge>
<edge directed="true" source="n0" target="n1">
   <data key="e_breed">diffusions</data>
</edge>

I tried the corrected file and I think the links are OK now:

ask links [show self]

result:

(diffusion 2 1): (diffusion 2 1)
(diffusion 0 2): (diffusion 0 2)
(parental 0 1): (parental 0 1)
(parental 0 2): (parental 0 2)

Edit:

In the current version of NW extension there are some open issues in load-graphml function. I think it is a good idea to add some validation after importing the file to check the links' consistency. Maybe with is-directed-link? reporter for every "directed" links bread and also counting the links and comparing the expected number of links.

Upvotes: 1

Related Questions