[Networkit] adding weights to a new created graph

Marvin Ritter marvin.ritter at gmail.com
Thu Jun 12 11:06:07 CEST 2014


Hi Michelangelo,

A graph can be either weighted or unweighted and this can not be changed
after it's creation. If you want to your graph to contain weights you have
to define that in the beginning:
G = Graph(0, True) # weighted graph with 0 nodes
G = Graph(0, False) # unweighted graph with 0 nodes
G = Graph() # use default values, unweighted graph with 0 nodes
G = Graph(2, True) # weighted graph with 2 nodes


In an unweighted graphs every edge will have weight 1.0. This cannot be
changed und every weight passed to addEdge, setWeight or increaseWeight
will be ignored. For edges that do not exists, weight() will return 0.0.
This behaviour is desired by design.

I'm not into the NetworkX stuff, so you will have to wait for someone else
to answer that.

Bests,
Marvin


On Thu, Jun 12, 2014 at 10:39 AM, Michelangelo Puliga <
michelangelo.puliga at imtlucca.it> wrote:

> Dear NetworKit developers,
>   I'm trying to use Networkit in the python realization to analyze a
> network for community detection. Instead of reading the data from a
> metis file I'm trying to create a graph (weidghted undirected)
>
> Here an example in ipython3
>
>
> In[1]: import NetworKit as nk
>
> In [2]: G = nk.Graph()
>
> In [3]: G.addNode()
> Out[3]: 0
>
> In [4]: G.addNode()
> Out[4]: 1
>
> In [5]: G.addNode()
> Out[5]: 2
>
> In [6]: G.addEdge(0,1,0.1)
>
> In [7]: G.edges()
> Out[7]: [(1, 0)]
>
> In [8]: G.weight(0,1)
> Out[8]: 1.0
>
> In [9]: G.weight(1,0)
> Out[9]: 1.0
>
> the weight associated to the edge (0,1) is always 1. while I defined
> in addEdge(0,1,0.1)  weight = 0.1
>
> finally if I try to convert an weighted graph from NetworkX to
> NetworKit I got the error that MarkAsWeighted function is not defined
> (there is a todo in the source code )...
>
> Any help/suggestion to load a weighted network programmatically from
> the code (addnode, addedge ?)
>
> thanks
>
> michelangelo
>
> _______________________________________________
> NetworKit mailing list
> NetworKit at ira.uni-karlsruhe.de
> https://lists.ira.uni-karlsruhe.de/mailman/listinfo/networkit
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ira.uni-karlsruhe.de/mailman/private/networkit/attachments/20140612/a750e1d1/attachment.html>


More information about the NetworKit mailing list