ShortestPathFunction[type,data]
グラフ中のソース頂点 s からターゲット頂点 t までの最短経路を与える関数を表す.
ShortestPathFunction
ShortestPathFunction[type,data]
グラフ中のソース頂点 s からターゲット頂点 t までの最短経路を与える関数を表す.
詳細
- ShortestPathFunction[…]はFindShortestPathによって生成される.
- ShortestPathFunction[{s,All},…][t]は s から t までの最短経路を与える.
- ShortestPathFunction[{All,t},…][s]は s から t までの最短経路を与える.
- ShortestPathFunction[{All,All},…][s,t]は s から t までの最短経路を与える.
例題
すべて開く すべて閉じる例 (1)
スコープ (7)
ShortestPathFunctionは無向グラフに使うことができる:
s = 3;
g = GridGraph[{2, 3}, VertexSize -> {s -> Small}]spf = FindShortestPath[g, s, All]Table[HighlightGraph[g, PathGraph@spf[t]], {t, VertexList[g]}]s = 3;
g = GridGraph[{2, 3}, DirectedEdges -> True, VertexSize -> Small, VertexLabels -> {s -> "s"}, ImagePadding -> 10, EdgeStyle -> Arrowheads[Small]]spf = FindShortestPath[g, s, All]Table[HighlightGraph[g, {PathGraph[spf[t], DirectedEdges -> True], Labeled[t, "t", {Above, Before}]}], {t, VertexList[g]}]s = 1;
g = PetersenGraph[4, 1, EdgeWeight -> {4, 0, 3, 1, 3, 2, 7, 8, 5, 2, 1, 6}, VertexSize -> {s -> Medium}]spf = FindShortestPath[g, s, All]Table[HighlightGraph[g, PathGraph@spf[t]], {t, VertexList[g]}]ShortestPathFunctionはある決まった頂点からの最短経路を与えることができる:
g = CycleGraph[8, DirectedEdges -> True, EdgeStyle -> Arrowheads[Small]];spf = FindShortestPath[g, 5, All]Table[HighlightGraph[g, PathGraph[spf[t], DirectedEdges -> True]], {t, VertexList[g]}]g = CycleGraph[8, DirectedEdges -> True, EdgeStyle -> Arrowheads[Small]];spf = FindShortestPath[g, All, 5]Table[HighlightGraph[g, PathGraph[spf[t], DirectedEdges -> True]], {t, VertexList[g]}]g = GridGraph[{4, 7}, VertexShapeFunction -> "Name"]spf = FindShortestPath[g, All, All]spf[8, 18]経路が存在しない場合はShortestPathFunctionは{}を返す:
GridGraph[{2, 3}, DirectedEdges -> True, VertexShapeFunction -> "Name"]FindShortestPath[%, 3, All]%[1]関連するガイド
テキスト
Wolfram Research (2010), ShortestPathFunction, Wolfram言語関数, https://reference.wolfram.com/language/ref/ShortestPathFunction.html.
CMS
Wolfram Language. 2010. "ShortestPathFunction." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/ShortestPathFunction.html.
APA
Wolfram Language. (2010). ShortestPathFunction. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/ShortestPathFunction.html
BibTeX
@misc{reference.wolfram_2026_shortestpathfunction, author="Wolfram Research", title="{ShortestPathFunction}", year="2010", howpublished="\url{https://reference.wolfram.com/language/ref/ShortestPathFunction.html}", note=[Accessed: 24-November-2026]}
BibLaTeX
@online{reference.wolfram_2026_shortestpathfunction, organization={Wolfram Research}, title={ShortestPathFunction}, year={2010}, url={https://reference.wolfram.com/language/ref/ShortestPathFunction.html}, note=[Accessed: 24-November-2026]}