After reading....
Finding all shortest paths between two vertices
which addresses an important topic in Mathematica graph visualisation, I use
paths[gr_, {i_, j_}] := Module[{sub, dist, indices, dd, nbrs},
dist = GraphDistance[gr, i, j];
indices = {};
dd = dist;
Reap[Nest[
Function[{vv},
dd -= 1;
nbrs = VertexList[NeighborhoodGraph[gr, #]] & /@ vv;
nbrs = Pick[#, GraphDistance[gr, #, j] & /@ #, dd] & /@ nbrs;
Sow /@ Flatten[Thread /@ Thread[vv \[UndirectedEdge] nbrs]];
Union[Flatten[nbrs]]
], {i}, dist]][[2, 1]]]
after Heike's answer, then
gr = Import["/home/graph.gml"];
ends = {1, 30};
sub = paths[gr, ends];
HighlightGraph[gr, {Graph[sub], Style[ends, Green]}]
where graph.gml
is a spatial network. This appears:
If, however, I want to display just the union of geodesics, I enter
Graph[sub]
but the graph is no longer geometric (the vertex coordinates have gone):
How can I keep everything spatial and get Graph[sub...}
to give me a geometric graph, instead of this non-spatial one?