Show Path with Arrows in a Matrix
Easily style vertices, edges, and their labels, and apply interesting functions. For a small increase in code sophistication, you gain quite an advantage.
poli = {{1, 1}, {2, 1}, {3, 1}, {4, 1}, {5, 1}, {5, 2}, {4, 2}, {3, 2}, {2, 2}, {1, 2}, {1, 3}, {2, 3}, {3, 3}, {4, 3}, {5, 3}, {5, 4}, {4, 4}, {4, 5}, {5, 5}};arrow[coord_, e_] := Style[Arrow[coord], Red, Thickness[.01], Arrowheads[0.06]]pg = PathGraph[Range[19], VertexCoordinates -> poli, EdgeShapeFunction -> arrow, ImageSize -> 300, PlotRangePadding -> .2, VertexLabels -> ""]gg = GridGraph[{5, 5}, EdgeStyle -> Dashed, VertexLabels -> "Name", ImageSize -> 300, PlotRangePadding -> .2]Overlay[{gg, pg}]vertex = (5 (#[[1]] - 1) + #[[2]])& /@ poli;
edge = (#[[1]]#[[2]])& /@ Partition[vertex, 2, 1];lab = MapThread[Rule[#1, ToString@#2]&, {vertex, poli}];GridGraph[{5, 5}, EdgeStyle -> Dashed, GraphHighlight -> edge, VertexLabels -> lab, PlotRangePadding -> .3]arr[coord_, e_] := Style[Arrow[If[Positive[(e)[[2]] - (e)[[1]]], Identity[coord], Reverse[coord]]], Red, Thickness[.01], Arrowheads[0.06]]GridGraph[{5, 5}, EdgeStyle -> Dashed, GraphHighlight -> edge, VertexLabels -> lab, PlotRangePadding -> .5, EdgeShapeFunction -> (# -> arr& /@ edge)]