Suppose we have 2 random graphs, each spatially embedded in a square plane, and vertices connected according to a distance criterion (or different degrees of nearest neighbour). I am trying to figure out if there's a way to create a 3D embedded graph by embedding our 2 graphs exactly on top of each other (their square embedding has same area), and wire the two stacks together by randomly creating edges between nodes of the two stacked graphs, based on nearest neighbours/distance criterion again.
Let us create our two 2D random graphs that we want to stack together to create a 3D graph:
SeedRandom[124]
g1 = RandomGraph[SpatialGraphDistribution[30, 0.3, 2],
VertexStyle -> Green]
SeedRandom[150]
g2 = RandomGraph[SpatialGraphDistribution[30, 0.3, 2],
VertexStyle -> Red]
Question:
- How can we stack
g1
andg2
on top of each other, separated by a given distance, and add random edges in this new 3rd dimension between the nodes (i.e. connecting nearby red-green nodes)?
Using SpatialGraphDistribution
with d
(dimension) set to $3$ does not produce the wanted setup as it distributes the nodes uniformly in the unit cube, instead of 2 separated parallel planes. But maybe if we can manually stack g1
and g2
, then we can use NearestNeighborGraph
to wire them together, but I haven't been able to get far with that yet.
Different attempts:
To ensure the layered (or in plane) stacking of the graphs in 3D, one can try and start from a 3d GridGraph
:
grid3 = GridGraph[{5, 5, 5}, VertexLabels -> "Name"]
coords3 = GraphEmbedding[grid3, "SpringElectricalEmbedding", 3];
and one could try to rewire the edges randomly (with a given probability $p$) but according to a 1st,2nd... nearest neighbour criterion, but such specific rewiring scheme does not seem to exist built-in or in other libraries as far as I know. For instance, using IGraphM
, one can rewire the 3D grid, but it rewires edges completely randomly without any constraints, e.g. after $10$ rewirings grid3
becomes:
IGRewire[grid3, 10, VertexCoordinates -> coords3]
But this approach does not seem promising, as not only we cannot (?) constrain the rewiring, the stacked layers are perfect lattices as opposed to random graphs.