Graphs with mutiple edges: obtaining neighbours of a vertex and generating random graphs of such nature

Suppose I have a multigraph $G$, i.e., When I call the function

IncidenceList[G,5]

I get the result

{5 <-> 1, 5 <-> 4, 5 <-> 4, 5 <-> 4}

What command should I use to convert this result to the list that contains neighbours of the vertex 5 with appropriate multiplicity, i.e. I would like to get the list

{1,4,4,4}

Additionally, is there a way in Mathematica to generate random graphs with multiple edges? This is needed since I am writing a particular function that computes a metric on such type of graph, and hence I would like to be able to test it.

• The beta version of IGraph/M has a preliminary function called IGAdjacencyList. It does take into account edge multiplicities (unlike AdjacencyList). Feedback is welcome, especially feedback arising from practical needs. Jun 18 '18 at 17:20
• As for "random graphs with multiple edges", you'd have to give a precise definition of what you want. There are countless possible interpretations of that description. Jun 18 '18 at 17:21
• For the random graph - anything that, say, emulates the behaviour of RandomGraph[{n,m}] and produces the graph with multiple edges between some of the pairs of the nodes. I am not necessarily looking for any particular degree distribution (although if it would be possible to simulate "small world" type of network with a power law degree distribution, that would be an added bonus). Jun 18 '18 at 17:25
• randomGraph[vcount_, ecount_] := Graph[UndirectedEdge @@@ Table[RandomSample[Range[vcount], 2], {ecount}]] Jun 18 '18 at 17:27
• I understand the set you want to sample from, but I do not understand what probabilities you would sample each element with. If uniform, randomGraph2[vcount_, ecount_] := Graph[RandomChoice[{UndirectedEdge, DirectedEdge}] @@ # & /@ Table[RandomSample[Range[vcount], 2], {ecount}]]. Terms like "random" shouldn't be thrown around loosely. You need to be aware of what distribution you are sampling from. It's an all too common mistake students make, and it will introduce biases in your results. Jun 18 '18 at 17:52

You could use

other[v1_][UndirectedEdge[v1_, v2_]] := v2
other[v1_][UndirectedEdge[v2_, v1_]] := v2

Then,

g = Graph[{1 <-> 2, 1 <-> 2, 2 <-> 3}]

other /@ IncidenceList[g, 2]
(* {1, 1, 3} *)
IncidenceList[##] /. UndirectedEdge[OrderlessPatternSequence[#2, v_]] :> v &[G, 5]

{1, 4, 4, 4}

Also

Cases[EdgeList[#] , UndirectedEdge[OrderlessPatternSequence[#2, v_]] :> v] &[G, 5]

{1, 4, 4, 4}

This was easier than I though - the result I was looking for could be obtained with:

DeleteCases[Flatten[List @@@ EdgeList[IncidenceList[G, 5]]], 5]