I have a question regarding this Q&A.
Let's call a vertex that is not the tail of any directed edge an output of the graph. The graph below has only one output (at the far right). If I want the distance from each vertex to the output of the graph, what should I do?
This one is on my graph:
matOP = {{0, 1, 0, 0, 1, 0, 1, 0}, {0, 1, 0, 0, 1, 0, 1, 0}, {0, 0, 1, 0, 1, 0, 1, 0},
{0, 0, 0, 1, 0, 0, 1, 0}, {0, 0, 0, 0, 1, 1, 0, 0}, {0, 0, 0, 0, 1, 0, 0, 0}};
pos = Position[matOP, 1];
edge = Subsets[Range@Length@pos, {2}];
dedge = DeleteDuplicates[
DirectedEdge @@@ (Extract[edge, #] & /@
With[{dist =
N@(EuclideanDistance[pos[[#]], pos[[#2]]] & @@@ edge)},
Flatten[Position[dist, #] & /@
DeleteDuplicates@N@Select[dist, # <= 1.5 &]]])];
Graph[dedge,
VertexCoordinates -> Rule @@@ Thread[{Range@Length@pos, pos}]]


FindShortestPath. – Michael E2 Jun 09 '14 at 14:23With[{spFN = FindShortestPath[gr, All, First@DeleteCases[Sort@VertexList[gr], n_ /; MemberQ[EdgeList[gr], n \[DirectedEdge] _]]]}, dist[v_] := Length[spFN[v]] - 1 ], wheregris your graph. Test withGraphPlot[gr, VertexRenderingFunction -> ({EdgeForm[Black], White, Disk[#1, 0.15], Black, Text[dist@VertexList[gr][[#2]], #1]} &)]. – Michael E2 Jun 10 '14 at 13:10