Pregunta

I have a .gml file (Nor graphML) which has details of my nodes and edges. I am importing the graph in python making use of the igraph library by the following code:

g = igraph.read("mydata.gml")"

I have given values in my .gml file for edges:

edge
[
source 1
target 0
value 6.25
]

Also the file starts with

graph
[
  directed 0
  weighted 1

However when I check, g.is_weighted() it returns false. How do I make igraph take the values in .gml file as weights for the edges of the graph?

¿Fue útil?

Solución

The is_weighted() method simply checks whether your graph has an edge attribute named weight. In your case, you don't because the values from the GML file are stored in the value edge attribute, not in weight. The solution is either to replace every occurrence of value with weight in your input file, or to rename the attribute in igraph after you have loaded the file as follows:

g.es["weight"] = g.es["value"]
del g.es["value"]
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top