KnightTourGraph[m,n]
mn のチェス盤上のナイトの巡回グラフを与える.
KnightTourGraph
KnightTourGraph[m,n]
mn のチェス盤上のナイトの巡回グラフを与える.
詳細とオプション
- KnightTourGraph[m,n]は,mn のチェス盤に対応する m n 個の頂点と,そのチェス盤上の規則に従うすべてのナイトの動きに対応する辺を持つグラフである.
- KnightTourGraphにはGraphと同じオプションを使うことができる.
全オプションのリスト
例題
すべて開く すべて閉じる例 (1)
オプション (80)
AnnotationRules (3)
KnightTourGraph[3, 3, AnnotationRules -> {1 -> {VertexLabels -> "hello"}}]KnightTourGraph[3, 3, AnnotationRules -> {16 -> {EdgeLabels -> "hello"}}]KnightTourGraph[3, 3, AnnotationRules -> {"GraphProperties" -> {"Message" -> "hello"}}]AnnotationValue[%, "Message"]EdgeLabels (7)
KnightTourGraph[3, 3, EdgeLabels -> {16 -> "Hello"}]el = EdgeList[KnightTourGraph[3, 3]]KnightTourGraph[3, 3, EdgeLabels -> Table[el[[i]] -> Subscript["e", i], {i, Length[el]}]]KnightTourGraph[3, 3, EdgeLabels -> {16 -> [image], 18 -> [image], 29 -> [image]}]Placedを記号位置と一緒に使って辺に沿ったラベルの置き方を制御する:
Table[KnightTourGraph[3, 3, EdgeLabels -> {16 -> Placed["■■■", p]}, PlotLabel -> p], {p, {"Start", "Middle", "End"}}]Table[KnightTourGraph[3, 3, EdgeLabels -> {16 -> Placed["■■■", p]}, PlotLabel -> p, BaselinePosition -> Bottom], {p, {0, 1 / 4, 1 / 3}}]Table[KnightTourGraph[3, 3, EdgeLabels -> {16 -> Placed["■■■", {1 / 2, p}]}, PlotLabel -> p, BaselinePosition -> Bottom], {p, {{0, 0}, {1 / 2, 1 / 2}, {1, 1}}}]KnightTourGraph[3, 3, EdgeLabels -> {16 -> Placed[{"lbl1", "lbl2"}, {"Start", "End"}]}]KnightTourGraph[3, 3, EdgeLabels -> {16 -> Placed[{"lbl1", "lbl2", "lbl3"}, {"Start", "Middle", "End"}]}]TooltipとStatusAreaの値で自動的にラベルを付ける:
KnightTourGraph[3, 3, EdgeLabels -> Placed["Name", Tooltip]]KnightTourGraph[3, 3, EdgeLabels -> Placed["Name", StatusArea]]EdgeShapeFunction (6)
EdgeShapeFunctionの組込み設定のリストを得る:
ResourceData["EdgeShapeFunction"]KnightTourGraph[3, 3, EdgeShapeFunction -> "Line"]Table[KnightTourGraph[3, 3, EdgeShapeFunction -> {{ef, "ArrowSize" -> 0.1}}, PlotLabel -> ef], {ef, {"BoxLine", "DiamondLine", "DotLine"}}]Table[KnightTourGraph[3, 3, EdgeShapeFunction -> {{ef, "ArrowSize" -> 0.1}}, PlotLabel -> ef], {ef, ResourceData["EdgeShapeFunction", "FilledArrow"]}]Table[KnightTourGraph[3, 3, EdgeShapeFunction -> {{ef, "ArrowSize" -> 0.1}}, PlotLabel -> ef], {ef, ResourceData["EdgeShapeFunction", "UnfilledArrow"]}]Table[KnightTourGraph[3, 3, EdgeShapeFunction -> {{ef, "ArrowSize" -> 0.1}}, PlotLabel -> ef], {ef, ResourceData["EdgeShapeFunction", "CarvedArrow"]}]KnightTourGraph[3, 3, EdgeShapeFunction -> {16 -> "DotLine"}]KnightTourGraph[3, 3, EdgeShapeFunction -> {16 -> "BoxLine", "DotLine"}]ef[pts_List, e_] :=
Block[{s = 0.015, g = [image]}, {Arrowheads[{{s, 0.33, g}, {s, 0.67, g}}], Arrow[pts]}]KnightTourGraph[3, 3, EdgeShapeFunction -> ef]EdgeShapeFunctionはEdgeStyleと組み合せることができる:
KnightTourGraph[3, 3, EdgeStyle -> Blue, EdgeShapeFunction -> (Line[#1]&)]EdgeShapeFunctionはEdgeStyleより優先順位が高い:
KnightTourGraph[3, 3, EdgeStyle -> Blue, EdgeShapeFunction -> ({Red, Line[#1]}&)]EdgeStyle (2)
EdgeWeight (2)
KnightTourGraph[3, 3, EdgeWeight -> RandomInteger[5, 8]]WeightedAdjacencyMatrix[%]//MatrixFormKnightTourGraph[3, 3, EdgeWeight -> {a, b, c, d, e, f, g, h}]WeightedAdjacencyMatrix[%]//MatrixFormGraphHighlight (3)
KnightTourGraph[3, 3, VertexSize -> Medium, GraphHighlight -> {1}]KnightTourGraph[3, 3, VertexSize -> Tiny, GraphHighlight -> {16}]KnightTourGraph[3, 3, VertexSize -> Tiny, GraphHighlight -> {1, 2, 16, 18}]GraphHighlightStyle (2)
GraphHighlightStyleの組込み設定のリストを得る:
ResourceData["GraphHighlightStyle"]GraphHighlightStyleの組込み設定を使う:
KnightTourGraph[3, 3, GraphHighlight -> {1, 16}, VertexSize -> Small, GraphHighlightStyle -> #, PlotLabel -> #]& /@ Select[ResourceData["GraphHighlightStyle"], # =!= Automatic&]GraphLayout (5)
デフォルトでKnightTourGraphにはカスタムレイアウトが選ばれる:
KnightTourGraph[3, 3, GraphLayout -> Automatic]Table[KnightTourGraph[8, 8, GraphLayout -> l, PlotLabel -> l], {l, {"LinearEmbedding", "CircularEmbedding", "SpiralEmbedding"}}]Table[KnightTourGraph[8, 8, GraphLayout -> l, PlotLabel -> l], {l, {"SpringEmbedding", "SpringElectricalEmbedding", "HighDimensionalEmbedding"}}]VertexCoordinatesはGraphLayoutの座標を無効にする:
{KnightTourGraph[3, 3, GraphLayout -> "SpringElectricalEmbedding"],
KnightTourGraph[3, 3, GraphLayout -> "SpringElectricalEmbedding", VertexCoordinates -> Table[{i, i}, {i, 0, 8}]]}AbsoluteOptionsを使ってレイアウトアルゴリズムで計算されたVertexCoordinatesを抽出する:
KnightTourGraph[3, 3]AbsoluteOptions[%, VertexCoordinates]PlotTheme (4)
基本テーマ (2)
VertexCoordinates (3)
KnightTourGraph[3, 3]AbsoluteOptionsを使って結果の頂点座標を抽出する:
AbsoluteOptions[%, VertexCoordinates]ellipseLayout[n_, {a_, b_}] := Table[{a Cos[2Pi / n u], b Sin[2Pi / n u]}, {u, 1, n}]Graphics[Point[ellipseLayout[20, {2, 1}]]]KnightTourGraph[4, 4, VertexCoordinates -> ellipseLayout[16, {2, 1}]]VertexCoordinatesはGraphLayoutより優先順位が高い:
KnightTourGraph[3, 3, VertexCoordinates -> Table[{i, i}, {i, 9}], GraphLayout -> "CircularEmbedding"]VertexLabels (13)
KnightTourGraph[3, 3, VertexLabels -> "Name"]KnightTourGraph[3, 3, VertexLabels -> {2 -> "one"}]KnightTourGraph[3, 3, VertexLabels -> Table[i -> Subscript[v, i], {i, 9}]]KnightTourGraph[3, 3, VertexLabels -> {1 -> [image], 2 -> [image], 7 -> [image]}]Placedを記号位置と一緒に使って外側の位置も含むラベルの置き方を制御する:
Table[KnightTourGraph[3, 3, VertexSize -> 0.1, VertexShapeFunction -> "Square", VertexLabels -> Table[i -> Placed["■■■", p], {i, 9}], PlotLabel -> p, ImagePadding -> 20], {p, {Before, After, Below, Above}}]pl = {{Before, Below}, {After, Below}, {Before, Above}, {After, Above}};Table[KnightTourGraph[3, 3, VertexSize -> 0.1, VertexShapeFunction -> "Square", ImagePadding -> 20, VertexLabels -> Table[i -> Placed["■■■", p], {i, 9}], PlotLabel -> p], {p, pl}]Table[KnightTourGraph[3, 3, VertexSize -> 0.45, VertexLabels -> Table[i -> Placed["■■■", p], {i, 9}], VertexShapeFunction -> "Square", PlotLabel -> p], {p, {Left, Top, Right, Bottom}}]pl = {{Left, Bottom}, {Right, Bottom}, {Left, Top}, {Right, Top}};Table[KnightTourGraph[3, 3, VertexSize -> 0.45, VertexShapeFunction -> "Square", VertexLabels -> Table[i -> Placed["■■■", p], {i, 9}], PlotLabel -> p], {p, pl}]Table[KnightTourGraph[3, 3, VertexSize -> 0.35, VertexShapeFunction -> "Square", VertexLabels -> Table[i -> Placed[[image], p], {i, 9}], PlotLabel -> p, BaselinePosition -> Bottom], {p, {{0, 0}, {1 / 2, 1 / 2}, {1, 1}}}]すべてのラベルを頂点の右上コーナーの位置に置き,ラベル内で座標を変化させる:
Table[KnightTourGraph[3, 3, VertexSize -> 0.35, VertexShapeFunction -> "Square", VertexLabels -> Table[i -> Placed[[image], {{1, 1}, p}], {i, 9}], PlotLabel -> p, BaselinePosition -> Bottom], {p, {{0, 0}, {1 / 2, 1 / 2}, {1, 1}}}]KnightTourGraph[3, 3, VertexLabels -> {1 -> Placed[{"lbl1", "lbl2"}, {Above, Below}]}]KnightTourGraph[3, 3, VertexLabels -> {1 -> Placed[{"lbl1", "lbl2", "lbl3", "lbl4"}, {Above, After, Below, Before}]}]Placedの引数を使ってTooltipを含むフォーマットを制御する:
KnightTourGraph[3, 3, VertexLabels -> Placed["Name", Tooltip]]あるいはStatusAreaを含むフォーマットを制御する:
KnightTourGraph[3, 3, VertexLabels -> Placed["Name", StatusArea]]rotateLabel[lab_] := Rotate[lab, 45Degree]KnightTourGraph[3, 3, VertexLabels -> Table[i -> Placed["xxx", Below, rotateLabel], {i, 9}]]panelLabel[lab_] := Panel[lab, FrameMargins -> 0, Background -> StandardBlue]KnightTourGraph[3, 3, VertexLabels -> Table[i -> Placed["xxx", Center, panelLabel], {i, 9}]]hyperlinkLabel[lab_] := Hyperlink[lab, "http://www.wolfram.com"]KnightTourGraph[3, 3, VertexLabels -> Table[i -> Placed["xxx", Center, hyperlinkLabel], {i, 9}]]VertexShape (5)
Graphics,ImageあるいはGraphics3Dを頂点の形として使う:
Table[KnightTourGraph[3, 3, VertexShape -> s, VertexSize -> Medium], {s, {[image], [image], [image]}}]KnightTourGraph[3, 3, VertexShape -> {2 -> [image]}, VertexSize -> Large]VertexShapeはVertexSizeと組み合せることができる:
Table[KnightTourGraph[3, 3, VertexSize -> s, VertexShape -> [image], PlotLabel -> s], {s, {Medium, Large}}]VertexShapeはVertexStyleの影響を受けない:
KnightTourGraph[3, 3, VertexSize -> 0.2, VertexShape -> [image], VertexStyle -> Blue]VertexShapeFunctionはVertexShapeより優先順位が高い:
KnightTourGraph[3, 3, VertexSize -> 0.1, VertexShapeFunction -> "Square", VertexShape -> [image]]VertexShapeFunction (10)
組込みのVertexShapeFunctionコレクションのリストを得る:
ResourceData["VertexShapeFunction"]"Basic"コレクションのVertexShapeFunctionの組込み設定を使う:
ResourceData["VertexShapeFunction", "Basic"]Table[KnightTourGraph[3, 3, VertexShapeFunction -> vf, VertexSize -> 0.2, PlotLabel -> vf], {vf, {"Triangle", "Square", "Rectangle", "Pentagon", "Hexagon", "Octagon"}}]Table[KnightTourGraph[3, 3, VertexShapeFunction -> vf, VertexSize -> 0.2, PlotLabel -> vf], {vf, {"DownTrapezoid", "UpTrapezoid", "Parallelogram", "FiveDown", "Circle", "Diamond", "Star", "Capsule"}}]"Rounded"コレクションのVertexShapeFunctionの組込み設定を使う:
ResourceData["VertexShapeFunction", "Rounded"]Table[KnightTourGraph[3, 3, VertexShapeFunction -> vf, VertexSize -> 0.2, PlotLabel -> vf], {vf, ResourceData["VertexShapeFunction", "Rounded"]}]"Concave"コレクションのVertexShapeFunctionの組込み設定を使う:
ResourceData["VertexShapeFunction", "Concave"]Table[KnightTourGraph[3, 3, VertexShapeFunction -> vf, VertexSize -> 0.2, PlotLabel -> vf], {vf, ResourceData["VertexShapeFunction", "Concave"]}]KnightTourGraph[3, 3, VertexShapeFunction -> { 1 -> "Square"}, VertexSize -> 0.2]KnightTourGraph[3, 3, VertexShapeFunction -> { 1 -> "Square", "Triangle"}, VertexSize -> 0.2]KnightTourGraph[3, 3, VertexShapeFunction -> (Inset[[image], #]&)]vf[{xc_, yc_}, name_, {w_, h_}] :=
Block[{xmin = xc - w, xmax = xc + w, ymin = yc - h, ymax = yc + h},
Polygon[{{xmin, ymin}, {xmax, ymax}, {xmin, ymax}, {xmax, ymin}}]
];KnightTourGraph[3, 3, VertexShapeFunction -> vf, VertexSize -> 0.2]VertexShapeFunctionはVertexStyleと組み合せることができる:
vf1[{xc_, yc_}, name_, {w_, h_}] := Rectangle[{xc - w, yc - h}, {xc + w, yc + h}]KnightTourGraph[3, 3, VertexSize -> 0.2, VertexStyle -> Blue, VertexShapeFunction -> vf1]VertexShapeFunctionはVertexStyleより優先順位が高い:
vf2[{xc_, yc_}, name_, {w_, h_}] := {Red, Rectangle[{xc - w, yc - h}, {xc + w, yc + h}]}KnightTourGraph[3, 3, VertexSize -> 0.2, VertexStyle -> Blue, VertexShapeFunction -> vf2]VertexShapeFunctionはVertexSizeと組み合せることができる:
KnightTourGraph[3, 3, VertexShapeFunction -> "Star", VertexSize -> {1 -> Small, Medium}]VertexShapeFunctionはVertexShapeより優先順位が高い:
KnightTourGraph[3, 3, VertexSize -> 0.3, VertexShapeFunction -> "Star", VertexShape -> [image]]VertexSize (8)
KnightTourGraph[3, 3, VertexSize -> Automatic]Table[KnightTourGraph[3, 3, VertexSize -> s, PlotLabel -> s], {s, {Tiny, Small, Medium, Large}}]Table[KnightTourGraph[3, 3, VertexSize -> s, PlotLabel -> s], {s, 0.1, 1, 0.3}]Table[KnightTourGraph[3, 3, VertexSize -> {"Scaled", s}, PlotLabel -> {"Scaled", s}], {s, 0.1, 1, 0.3}]Table[KnightTourGraph[3, 3, VertexSize -> s, PlotLabel -> s], {s, {{0.1, 0.2}, {0.2, 0.1}}}]KnightTourGraph[3, 3, VertexSize -> {1 -> 0.2, 2 -> 0.3}]VertexSizeはVertexShapeFunctionと組み合せることができる:
Table[KnightTourGraph[3, 3, VertexSize -> s, VertexShapeFunction -> "Square", PlotLabel -> s], {s, {0.05, 0.1, 0.2}}]VertexSizeはVertexShapeと組み合せることができる:
Table[KnightTourGraph[3, 3, VertexSize -> s, VertexShape -> [image], PlotLabel -> s], {s, {0.1, 0.2, 0.4}}]VertexStyle (5)
Table[KnightTourGraph[3, 3, VertexStyle -> style, VertexSize -> 0.3, PlotLabel -> style], {style, {Yellow, EdgeForm[Dashed]}}]KnightTourGraph[3, 3, VertexStyle -> {1 -> Blue, 2 -> Red}, VertexSize -> 0.2]VertexShapeFunctionはVertexStyleと組み合せることができる:
vf1[{xc_, yc_}, name_, {w_, h_}] := Rectangle[{xc - w, yc - h}, {xc + w, yc + h}]KnightTourGraph[3, 3, VertexSize -> 0.2, VertexStyle -> Blue, VertexShapeFunction -> vf1]VertexShapeFunctionはVertexStyleより優先順位が高い:
vf2[{xc_, yc_}, name_, {w_, h_}] := {Red, Rectangle[{xc - w, yc - h}, {xc + w, yc + h}]}KnightTourGraph[3, 3, VertexSize -> 0.2, VertexStyle -> Blue, VertexShapeFunction -> vf2]VertexStyleはBaseStyleと組み合せることができる:
KnightTourGraph[3, 3, VertexStyle -> LightBlue, BaseStyle -> EdgeForm[Dotted], VertexSize -> 0.2]VertexStyleはBaseStyleより優先順位が高い:
KnightTourGraph[3, 3, VertexStyle -> LightBlue, BaseStyle -> Gray, VertexSize -> 0.2]VertexShapeはVertexStyleの影響を受けない:
KnightTourGraph[3, 3, VertexSize -> 0.2, VertexShape -> [image], VertexStyle -> Blue]VertexWeight (2)
KnightTourGraph[3, 3, VertexWeight -> RandomInteger[5, 9]]AnnotationValue[{%, 1}, VertexWeight]KnightTourGraph[3, 3, VertexWeight -> {a, b, c, d, e, f, g, h, i}]AnnotationValue[{%, 1}, VertexWeight]アプリケーション (6)
ナイトの巡回グラフのGraphCenter:
Table[HighlightGraph[#, GraphCenter[#]]&[KnightTourGraph[i, 3, VertexSize -> 0.2]], {i, 4, 6}]Table[HighlightGraph[#, GraphPeriphery[#]]&[KnightTourGraph[i, 3, VertexSize -> 0.2]], {i, 4, 6}]VertexEccentricity[KnightTourGraph[4, 3], #]& /@ VertexList[KnightTourGraph[4, 3]]FindVertexEccentricityPath[g_ ? UndirectedGraphQ, u_] /; MemberQ[VertexList[g], u] := Module[{d = GraphDistanceMatrix[g], posu, posv, vl = VertexList[g]}, posu = VertexIndex[g, u];
posv = First@First@Position[d[[posu]], Max[d[[posu]]]];
PathGraph[FindShortestPath[g, u, vl[[posv]]]]]Table[HighlightGraph[g = KnightTourGraph[4, 3], FindVertexEccentricityPath[g, u]], {u, Range[3]}]Table[GraphRadius[KnightTourGraph[i, 3]], {i, 4, 6}]FindRadiusPath[g_ ? UndirectedGraphQ] := Module[{c = First@GraphCenter[g], d, v, pos}, d = Table[GraphDistance[g, c, u], {u, VertexList[g]}];
pos = First@Position[d, Max[d]];
v = First@Part[VertexList[g], pos];
PathGraph[FindShortestPath[g, c, v]]]Table[HighlightGraph[#, FindRadiusPath[#]]&[KnightTourGraph[i, 3, VertexSize -> Tiny]], {i, 4, 6}]Table[GraphDiameter[KnightTourGraph[i, 3]], {i, 4, 6}]FindDiameterPath[g_ ? UndirectedGraphQ] := Module[{d = GraphDistanceMatrix[g], u, v, pos}, pos = First@Position[d, Max[d]];
{u, v} = Part[VertexList[g], pos];
PathGraph[FindShortestPath[g, u, v]]]Table[HighlightGraph[#, FindDiameterPath[#]]&[KnightTourGraph[i, 3, VertexSize -> Tiny]], {i, 4, 6}]KnightTourGraphの頂点次数をハイライトする:
HighlightCentrality[g_, cc_] := HighlightGraph[g, Table[Style[VertexList[g][[i]], ColorData["TemperatureMap"][cc[[i]] / Max[cc]]], {i, VertexCount[g]}]];g = KnightTourGraph[8, 8, VertexSize -> Large];HighlightCentrality[g, VertexDegree[g]]HighlightCentrality[g, ClosenessCentrality[g]]HighlightCentrality[g, EigenvectorCentrality[g]]特性と関係 (3)
KnightTourGraph[m,n]は m n の頂点を持つ:
VertexCount[KnightTourGraph[m, n]]KnightTourGraph[m,n]は
の辺を持つ:
EdgeCount[KnightTourGraph[m, n]]KnightTourGraph[n,n]は
ではハミルトン(Hamilton)グラフである:
HamiltonianGraphQ[KnightTourGraph[4, 4]]考えられる問題 (1)
DirectedEdges->True の設定はKnightTourGraphには適用できない:
KnightTourGraph[3, 3, DirectedEdges -> True]関連するガイド
テキスト
Wolfram Research (2010), KnightTourGraph, Wolfram言語関数, https://reference.wolfram.com/language/ref/KnightTourGraph.html.
CMS
Wolfram Language. 2010. "KnightTourGraph." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/KnightTourGraph.html.
APA
Wolfram Language. (2010). KnightTourGraph. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/KnightTourGraph.html
BibTeX
@misc{reference.wolfram_2026_knighttourgraph, author="Wolfram Research", title="{KnightTourGraph}", year="2010", howpublished="\url{https://reference.wolfram.com/language/ref/KnightTourGraph.html}", note=[Accessed: 04-December-2026]}
BibLaTeX
@online{reference.wolfram_2026_knighttourgraph, organization={Wolfram Research}, title={KnightTourGraph}, year={2010}, url={https://reference.wolfram.com/language/ref/KnightTourGraph.html}, note=[Accessed: 04-December-2026]}