How to create a multigraph with weights?

Hi.
I have now been searching through multiple source codes within the different Julia graphs packages ( Graphs, MetaGraphs, SimpleWeightedGraphs) and also found the package called Multigraphs. However, I cannot seem to figure out how to create a multigraph with weights - It might be highly simple, but I cannot really find it…
Ideally, I would like to do something like (just an example):

network = MetaGraph(Multigraph(10),1)

I would like to use the label features of MetaGraphs, but it is not highly necessary.

I hope you can help me!

Hi! What is the maximum multiplicity of an edge? And what do you use this graph for?
An easy workaround would be adding the multiplicity as an attribute of the edge metadata

Thanks for replying!

The maximum multiplicity is four. However, I am going to use it for a transportation network, so the arcs (between the same nodes) have different weights (and potentially also different capacities). In that case, I’m not sure your workaround would work?

If it is just for storing, then you could add the different weights of the four arcs as edge metadata too. However, if you want to run shortest path or flow algorithms, I think you may have to reimplement them yourself.
With small multiplicities like yours, would it make sense to use 4 different graphs instead of 1 multigraph?

Thanks for your input, but yeah I have started to implement my own version!

1 Like