I'm trying to implement an application which uses random geometric graphs in Mathematica, but it seems Mathematica lacks the functionality. I need the following functionalities:
- Generate a set of uniformly distributed vertices on $[0,1]^2$ with certain properties (this really helps)
- Add an edge in between the vertices that are closer than a given radius $d$
- Display the graph (this is not like a regular graph display since the location of each vertex is important)
- Generate some random source-destination pairs and find the shortest path between them
- Highlight the path on the displayed graph.
Note that, Mathematica has all of the required functionality for non-geometric graphs. However, when it comes to the geo-graphs, the functionality is quite useless. Here is the code I already have:
Module[
{nOld, kOld, v, edges},
nOld = -1;
kOld = -1;
Manipulate[
If[
n != nOld,
v = RandomReal[{0, 1}, {n, 2}];
nOld = n
];
edges =
Select[Flatten[Table[{a, b}, {a, v}, {b, v}],
1], (#[[1, 1]] > #[[2, 1]] &&
EuclideanDistance[#[[1]], #[[2]]] < d) &];
Graphics[
{Red, Point[v],
Blue, Thin, Line /@ edges
}
]
,
{n, 10, 100, 10},
{d, 0, 1}
]
]
It generates and shows the random graph. But generating and highlighting the shortest paths are not so simple since I don't have any data-structure to keep the graph. What is the best way to implement a geo-graph in Mathematica? Sparse matrices
or System`Graph
or Combinatorica`Graph
? Can I use some of the built-in graph functions of Mathematica to implement geo-graphs?