According to the documentation the way SimpleWeightedDiGraph works is something like a g = SimpleWeightedDiGraph(heads, tails, weights). If so and if having a three list of requirements:
Is it possible when creating graph, directly exclude those edges that has same head and tails (eliminating loops) ?
And it seems that when we create g with graph package it starts at 1 regardless of the smallest node ID. For instance, in this simple example, if we call vertices(g) it return 1:62. This creates lots of single nodes that has degree of zero and makes my computations difficult when I want to work with node IDs that starts at 1000. I mean I have 1000 nodes that are empty and makes my graph very spars. When I call density on g it shows a very small number although my graph should be very dense. Is there any way to force SimpleWeightedDiGraph to not start at 1 but at the smallest node ID?
Hi,
The best answer to both of your questions at the moment is to take care of it manually outside of the graph structure.
For self-edges, it is not hard to scan heads and tails and exclude pairs where both are identical:
new_heads = [h for (h, t, w) in zip(heads, tails, weights) if h != t]
new_tails = [t for (h, t, w) in zip(heads, tails, weights) if h != t]
new_weights = [w for (h, t, w) in zip(heads, tails, weights) if h != t]
Regarding vertex indices, the convention in the Graphs.jl ecosystem is that vertices should go from 1 to n. If you want to circumvent that, you can either
Translate the indices manually by keeping a dict outside of the graph
Use a more sophisticated structure for graphs with metadata, such as MetaGraphsNext.jl
Hi again @gdalle I just wanted to ask what do you suggest for translating indices?
The way I did it is in spreadsheet. But is there any direct way in julia to change IDs while keeping the relationship between nodes (how they form edges)?