I have a table of random geometric graphs
graphs = Table[
RandomGraph[
SpatialGraphDistribution[
RandomVariate[PoissonDistribution[100]], 0.2]], {k, 1,
10}];
but I need the EdgeWeights
of each graph to be the Euclidean distances between the vertices of the respective edge. At the moment they are all unity.
I tried using
graphs = SetProperty[#,
EdgeWeight -> EuclideanDistance @@@ EdgeList[#]] & /@ graphs;
but this obviously requires the vertex names to be position vectors. I also tried using
vertlist[graph_] :=
VertexCoordinates /. AbsoluteOptions[graph, VertexCoordinates]
with another function which threads over the edges, but it seems inelegant...
Is there a simpler way?
VertexNames
asVertexCoordinates
viaSetProperty
, then again useSetProperty[#, EdgeWeight -> EuclideanDistance @@@ EdgeList[#]] & /@ graphs
? $\endgroup$VertexReplace[rg, Thread[VertexList[rg] -> GraphEmbedding[rg]]]
$\endgroup$IGEdgeVertexProp
(not sure what's a good name...) which could be used asIGEdgeMap[Apply[EuclideanDistance], EdgeWeight -> IGEdgeVertexProp[VertexCoordinates], rg]
. I'm not 100% happy with this though ... Any feedback is welcome. $\endgroup$