I can very quickly generate random geometric graphs with
density = 1600; r0 = 0.05; Ngraphs = 100;
n = RandomVariate[PoissonDistribution[density], Ngraphs];
graphs = Table[
RandomGraph[SpatialGraphDistribution[n[[k]], r0]], {k, 1,
Ngraphs}]; // AbsoluteTiming
{0.890343, Null}
but would like to add a vertex at the exact center position {0.5,0.5} in each graph, and then connect it to all vertices within range r0.
I have used
pts = PropertyValue[graphs[[1]], VertexCoordinates]; // AbsoluteTiming
Nearest[pts, {0.5, 0.5}] // AbsoluteTiming
{0.000062, Null}
{0.000145, {{0.507425, 0.491059}}}
but then EdgeAdd is quite slow since I have to use Position to find the name of the vertex at those coordinates. Is there some efficient way to do this?
My problem has been that this SpatialGraphDistribution technique is the fastest way to generate large graphs, but I need to fix vertices at a specific Euclidean separation in order to measure the graph distance/Euclidean distance relation.
Note: Slyvniak's Theorem is related to this idea of conditioning the graph to contain a vertex at a point, though that refers to the Poisson point process specifically.
Nearest[Thread[pts -> Range[Length[pts]]], {0.5, 0.5}, {Infinity, r0}], can I then add a vertex at {0.5,0.5}? – apg Mar 08 '18 at 14:17Threadthe rules forNearest, at least from version 11 onwards:Nearest[pts -> Range[Length[pts]], {0.5, 0.5}]works as well and is much faster (internally, the list of rules has to be decomposed and packed again into two seperate arrays). Note also that this is equivalent toNearest[pts -> Automatic, {0.5, 0.5}]andNearest[pts -> "Index", {0.5, 0.5}](the latter only available in version 11.2. – Henrik Schumacher Mar 08 '18 at 18:42