n 個の頂点を持つ完全グラフ
を与える.
CompleteGraph[{n1,n2,…,nk}]
頂点数が n1+n2+⋯+nk の完全 k 部グラフ
を与える.
CompleteGraph
n 個の頂点を持つ完全グラフ
を与える.
CompleteGraph[{n1,n2,…,nk}]
頂点数が n1+n2+⋯+nk の完全 k 部グラフ
を与える.
詳細とオプション
- CompleteGraphはユニバーサルグラフあるいは完全なグラフとしても知られている.
- CompleteGraphはGraphオブジェクトを生成する.
- CompleteGraph[n]は頂点数が n ですべての点と点の間に辺があるグラフを与える.
- CompleteGraph[{n1,n2,…,nk}]は頂点数が n1+⋯+nkの連結されていない複数の集合 Viに分割されたグラフを与える.この集合はそれぞれ ni個の頂点を持ち,異なる集合 Viと Vjの間では頂点がすべてが繋がれているが同一集合 Vi内の頂点は繋がれていない.
- CompleteGraph[…,DirectedEdges->True]は有向完全グラフを与える.
- CompleteGraphにはGraphと同じオプションが使える.
全オプションのリスト
例題
すべて開く すべて閉じる例 (4)
Table[CompleteGraph[i, PlotLabel -> Subscript[K, ``i``]], {i, 3, 6}]Table[CompleteGraph[{i, i}, PlotLabel -> Subscript[K, i, i]], {i, 2, 4}]Table[CompleteGraph[n, DirectedEdges -> True, PlotLabel -> Subscript[K, n]], {n, 3, 5}]有向完全
部グラフは1つのグループから他のグループへ有向辺を使う:
Table[CompleteGraph[{i, i, i}, DirectedEdges -> True, PlotLabel -> Subscript[K, i, i, i]], {i, 2, 4}]オプション (81)
AnnotationRules (2)
DirectedEdges (2)
CompleteGraph[4]DirectedEdges->Trueを使って有向グラフを生成する:
CompleteGraph[4, DirectedEdges -> True]Row[Table[CompleteGraph[Range[n], DirectedEdges -> True], {n, 2, 4}]]EdgeLabels (7)
CompleteGraph[4, EdgeLabels -> {12 -> "Hello"}]el = EdgeList[CompleteGraph[4]]CompleteGraph[4, EdgeLabels -> Table[el[[i]] -> Subscript["e", i], {i, Length[el]}]]CompleteGraph[4, EdgeLabels -> {24 -> [image], 34 -> [image], 13 -> [image]}]Placedを記号位置と一緒に使って辺に沿ったラベル位置を制御する:
Table[CompleteGraph[4, EdgeLabels -> {34 -> Placed["■■■", p]}, PlotLabel -> p], {p, {"Start", "Middle", "End"}}]Table[CompleteGraph[4, EdgeLabels -> {23 -> Placed["■■■", p]}, PlotLabel -> p, BaselinePosition -> Bottom], {p, {0, 1 / 4, 1 / 3}}]Table[CompleteGraph[4, EdgeLabels -> {23 -> Placed["■■■", {1 / 2, p}]}, PlotLabel -> p, BaselinePosition -> Bottom], {p, {{0, 0}, {1 / 2, 1 / 2}, {1, 1}}}]CompleteGraph[5, EdgeLabels -> {31 -> Placed[{"lbl1", "lbl2"}, {"Start", "End"}]}]CompleteGraph[5, EdgeLabels -> {31 -> Placed[{"lbl1", "lbl2", "lbl3"}, {"Start", "Middle", "End"}]}]TooltipとStatusAreaの値から自動でラベル付けを行う:
CompleteGraph[5, EdgeLabels -> Placed["Name", Tooltip]]CompleteGraph[5, EdgeLabels -> Placed["Name", StatusArea]]EdgeShapeFunction (6)
EdgeShapeFunctionの組込み設定のリストを得る:
ResourceData["EdgeShapeFunction"]CompleteGraph[4, EdgeShapeFunction -> "Line"]Table[CompleteGraph[4, EdgeShapeFunction -> {{ef, "ArrowSize" -> 0.1}}, PlotLabel -> ef], {ef, {"BoxLine", "DiamondLine", "DotLine"}}]Table[CompleteGraph[4, EdgeShapeFunction -> {{ef, "ArrowSize" -> 0.1}}, PlotLabel -> ef], {ef, ResourceData["EdgeShapeFunction", "FilledArrow"]}]Table[CompleteGraph[4, EdgeShapeFunction -> {{ef, "ArrowSize" -> 0.1}}, PlotLabel -> ef], {ef, ResourceData["EdgeShapeFunction", "UnfilledArrow"]}]Table[CompleteGraph[4, EdgeShapeFunction -> {{ef, "ArrowSize" -> 0.1}}, PlotLabel -> ef], {ef, ResourceData["EdgeShapeFunction", "CarvedArrow"]}]CompleteGraph[4, EdgeShapeFunction -> {12 -> "DotLine"}]CompleteGraph[5, EdgeShapeFunction -> {12 -> "BoxLine", "DotLine"}]ef[pts_List, e_] :=
Block[{s = 0.015, g = [image]}, {Arrowheads[{{s, 0.33, g}, {s, 0.67, g}}], Arrow[pts]}]CompleteGraph[4, EdgeShapeFunction -> ef]EdgeShapeFunctionはEdgeStyleと組み合せることができる:
CompleteGraph[4, EdgeStyle -> Blue, EdgeShapeFunction -> (Line[#1]&)]EdgeShapeFunctionはEdgeStyleより優先順位が高い:
CompleteGraph[4, EdgeStyle -> Blue, EdgeShapeFunction -> ({Red, Line[#1]}&)]EdgeStyle (2)
EdgeWeight (2)
CompleteGraph[4, EdgeWeight -> RandomInteger[5, 6]]WeightedAdjacencyMatrix[%]//MatrixFormCompleteGraph[4, EdgeWeight -> {a, b, c, d, e, f}]WeightedAdjacencyMatrix[%]//MatrixFormGraphHighlight (3)
CompleteGraph[4, VertexSize -> Tiny, GraphHighlight -> {1}]CompleteGraph[4, VertexSize -> Tiny, GraphHighlight -> {23}]CompleteGraph[4, VertexSize -> Tiny, GraphHighlight -> {1, 2, 13, 23}]GraphHighlightStyle (2)
GraphHighlightStyleの組込み設定のリストを得る:
ResourceData["GraphHighlightStyle"]GraphHighlightStyleの組込み設定を使う:
CompleteGraph[3, GraphHighlight -> {1, 23}, VertexSize -> Small, GraphHighlightStyle -> #, PlotLabel -> #]& /@ Select[ResourceData["GraphHighlightStyle"], # =!= Automatic&]GraphLayout (5)
CompleteGraph[5, GraphLayout -> Automatic]Table[CompleteGraph[20, GraphLayout -> l, PlotLabel -> l], {l, {"CircularEmbedding", "SpiralEmbedding"}}]Table[CompleteGraph[20, GraphLayout -> l, PlotLabel -> l], {l, {"SpringEmbedding", "SpringElectricalEmbedding", "HighDimensionalEmbedding"}}]VertexCoordinatesはGraphLayoutの座標を無効にする:
{CompleteGraph[5, GraphLayout -> "SpringElectricalEmbedding"],
CompleteGraph[5, GraphLayout -> "SpringElectricalEmbedding", VertexCoordinates -> Table[{i, i}, {i, 0, 4}]]}AbsoluteOptionsを使って,レイアウトアルゴリズムで計算されたVertexCoordinatesを抽出する:
CompleteGraph[5]AbsoluteOptions[%, VertexCoordinates]PlotTheme (4)
基本テーマ (2)
VertexCoordinates (3)
CompleteGraph[4]AbsoluteOptionsを使って結果の頂点座標を抽出する:
AbsoluteOptions[%, VertexCoordinates]ellipseLayout[n_, {a_, b_}] := Table[{a Cos[2Pi / n u], b Sin[2Pi / n u]}, {u, 1, n}]Graphics[Point[ellipseLayout[10, {2, 1}]]]CompleteGraph[10, VertexCoordinates -> ellipseLayout[10, {2, 1}]]VertexCoordinatesはGraphLayoutより優先順位が高い:
CompleteGraph[4, VertexCoordinates -> Table[{i, i}, {i, 4}], GraphLayout -> "CircularEmbedding"]VertexLabels (13)
CompleteGraph[3, VertexLabels -> "Name"]CompleteGraph[3, VertexLabels -> {1 -> "one"}]CompleteGraph[3, VertexLabels -> Table[i -> Subscript[v, i], {i, 3}]]CompleteGraph[3, VertexLabels -> {1 -> [image], 2 -> [image], 3 -> [image]}, ImagePadding -> 20]Placedを記号位置と一緒に使って外側の位置を含むラベルの置き方を制御する:
Table[CompleteGraph[3, VertexSize -> 0.1, VertexShapeFunction -> "Square", VertexLabels -> Table[i -> Placed["■■■", p], {i, 3}], PlotLabel -> p, ImagePadding -> 20], {p, {Before, After, Below, Above}}]pl = {{Before, Below}, {After, Below}, {Before, Above}, {After, Above}};Table[CompleteGraph[3, VertexSize -> 0.1, VertexShapeFunction -> "Square", ImagePadding -> 20, VertexLabels -> Table[i -> Placed["■■■", p], {i, 3}], PlotLabel -> p], {p, pl}]Table[CompleteGraph[3, VertexSize -> 0.25, VertexLabels -> Table[i -> Placed["■■■", p], {i, 3}], VertexShapeFunction -> "Square", PlotLabel -> p], {p, {Left, Top, Right, Bottom}}]pl = {{Left, Bottom}, {Right, Bottom}, {Left, Top}, {Right, Top}};Table[CompleteGraph[3, VertexSize -> 0.25, VertexShapeFunction -> "Square", VertexLabels -> Table[i -> Placed["■■■", p], {i, 3}], PlotLabel -> p], {p, pl}]Table[CompleteGraph[3, VertexSize -> 0.25, VertexShapeFunction -> "Square", VertexLabels -> Table[i -> Placed[[image], p], {i, 3}], PlotLabel -> p, BaselinePosition -> Bottom], {p, {{0, 0}, {1 / 2, 1 / 2}, {1, 1}}}]すべてのラベルを頂点の右上コーナーに置き,ラベル内の座標を変える:
Table[CompleteGraph[3, VertexSize -> 0.35, VertexShapeFunction -> "Square", VertexLabels -> Table[i -> Placed[[image], {{1, 1}, p}], {i, 3}], PlotLabel -> p, BaselinePosition -> Bottom], {p, {{0, 0}, {1 / 2, 1 / 2}, {1, 1}}}]CompleteGraph[3, VertexLabels -> {1 -> Placed[{"lbl1", "lbl2"}, {Above, Below}]}]CompleteGraph[3, VertexLabels -> {1 -> Placed[{"lbl1", "lbl2", "lbl3", "lbl4"}, {Above, After, Below, Before}]}]Placedの引数を使ってTooltipを含むフォーマットを制御する:
CompleteGraph[3, VertexLabels -> Placed["Name", Tooltip]]あるいはStatusAreaを含むフォーマットを制御する:
CompleteGraph[3, VertexLabels -> Placed["Name", StatusArea]]rotateLabel[lab_] := Rotate[lab, 45Degree]CompleteGraph[3, VertexLabels -> Table[i -> Placed["xxx", Below, rotateLabel], {i, 3}]]panelLabel[lab_] := Panel[lab, FrameMargins -> 0, Background -> StandardBlue]CompleteGraph[3, VertexLabels -> Table[i -> Placed["xxx", Center, panelLabel], {i, 3}]]hyperlinkLabel[lab_] := Hyperlink[lab, "http://www.wolfram.com"]CompleteGraph[3, VertexLabels -> Table[i -> Placed["xxx", Center, hyperlinkLabel], {i, 3}]]VertexShape (5)
Graphics,Image,Graphics3Dの任意のものを頂点の形として使う:
Table[CompleteGraph[5, VertexShape -> s, VertexSize -> Medium], {s, {[image], [image], [image]}}]CompleteGraph[5, VertexShape -> {2 -> [image]}, VertexSize -> Medium]VertexShapeはVertexSizeと組み合せることができる:
Table[CompleteGraph[5, VertexSize -> s, VertexShape -> [image], PlotLabel -> s], {s, {Small, Large}}]VertexShapeはVertexStyleの影響を受けない:
CompleteGraph[5, VertexSize -> 0.2, VertexShape -> [image], VertexStyle -> Blue]VertexShapeFunctionはVertexShapeよりも優先順位が高い:
CompleteGraph[5, VertexSize -> 0.1, VertexShapeFunction -> "Square", VertexShape -> [image]]VertexShapeFunction (10)
組込みのVertexShapeFunctionコレクションのリストを得る:
ResourceData["VertexShapeFunction"]"Basic"コレクションのVertexShapeFunctionの組込み設定を使う:
ResourceData["VertexShapeFunction", "Basic"]Table[CompleteGraph[4, VertexShapeFunction -> vf, VertexSize -> 0.2, PlotLabel -> vf], {vf, {"Triangle", "Square", "Rectangle", "Pentagon", "Hexagon", "Octagon"}}]Table[CompleteGraph[4, VertexShapeFunction -> vf, VertexSize -> 0.2, PlotLabel -> vf], {vf, {"DownTrapezoid", "UpTrapezoid", "Parallelogram", "FiveDown", "Circle", "Diamond", "Star", "Capsule"}}]"Rounded"コレクションのVertexShapeFunctionの組込み設定を使う:
ResourceData["VertexShapeFunction", "Rounded"]Table[CompleteGraph[4, VertexShapeFunction -> vf, VertexSize -> 0.2, PlotLabel -> vf], {vf, ResourceData["VertexShapeFunction", "Rounded"]}]"Concave"コレクションのVertexShapeFunctionの組込み設定を使う:
ResourceData["VertexShapeFunction", "Concave"]Table[CompleteGraph[4, VertexShapeFunction -> vf, VertexSize -> 0.2, PlotLabel -> vf], {vf, ResourceData["VertexShapeFunction", "Concave"]}]CompleteGraph[4, VertexShapeFunction -> { 1 -> "Square"}, VertexSize -> 0.2]CompleteGraph[4, VertexShapeFunction -> { 1 -> "Square", "Triangle"}, VertexSize -> 0.2]CompleteGraph[4, 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}}]
];CompleteGraph[4, VertexShapeFunction -> vf, VertexSize -> 0.2]VertexShapeFunctionはVertexStyleと組み合せることができる:
vf1[{xc_, yc_}, name_, {w_, h_}] := Rectangle[{xc - w, yc - h}, {xc + w, yc + h}]CompleteGraph[4, 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}]}CompleteGraph[4, VertexSize -> 0.2, VertexStyle -> Blue, VertexShapeFunction -> vf2]VertexShapeFunctionはVertexShapeと組み合せることができる:
CompleteGraph[4, VertexShapeFunction -> "Star", VertexSize -> {1 -> Small, Medium}]VertexShapeFunctionはVertexShapeより優先順位が高い:
CompleteGraph[4, VertexSize -> 0.3, VertexShapeFunction -> "Star", VertexShape -> [image]]VertexSize (8)
CompleteGraph[5, VertexSize -> Automatic]Table[CompleteGraph[5, VertexSize -> s, PlotLabel -> s], {s, {Tiny, Small, Medium, Large}}]Table[CompleteGraph[5, VertexSize -> s, PlotLabel -> s], {s, 0.1, 1, 0.3}]Table[CompleteGraph[5, VertexSize -> {"Scaled", s}, PlotLabel -> {"Scaled", s}], {s, 0.1, 1, 0.3}]Table[CompleteGraph[5, VertexSize -> s, PlotLabel -> s], {s, {{0.1, 0.2}, {0.2, 0.1}}}]CompleteGraph[4, VertexSize -> {1 -> 0.2, 2 -> 0.3}]VertexSizeはVertexShapeFunctionと組み合せることができる:
Table[CompleteGraph[5, VertexSize -> s, VertexShapeFunction -> "Square", PlotLabel -> s], {s, {0.05, 0.1, 0.2}}]VertexSizeはVertexShapeと組み合せることができる:
Table[CompleteGraph[5, VertexSize -> s, VertexShape -> [image], PlotLabel -> s], {s, {0.1, 0.2, 0.4}}]VetexStyle (5)
Table[CompleteGraph[4, VertexStyle -> style, VertexSize -> 0.3, PlotLabel -> style], {style, {Yellow, EdgeForm[Dashed]}}]CompleteGraph[4, 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}]CompleteGraph[4, 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}]}CompleteGraph[4, VertexSize -> 0.2, VertexStyle -> Blue, VertexShapeFunction -> vf2]VertexStyleはBaseStyleと組み合せることができる:
CompleteGraph[4, VertexStyle -> LightBlue, BaseStyle -> EdgeForm[Dotted], VertexSize -> 0.2]VertexStyleはBaseStyleより優先順位が高い:
CompleteGraph[4, VertexStyle -> LightBlue, BaseStyle -> Gray, VertexSize -> 0.2]VertexShapeはVertexStyleの影響を受けない:
CompleteGraph[5, VertexSize -> 0.2, VertexShape -> [image], VertexStyle -> Blue]VertexWeight (2)
アプリケーション (7)
完全グラフのGraphCenterにはすべての頂点が含まれる:
Table[HighlightGraph[#, GraphCenter[#]]&[CompleteGraph[i, VertexSize -> Small]], {i, 3, 6}]GraphPeripheryはすべての頂点を含む:
Table[HighlightGraph[#, GraphPeriphery[#]]&[CompleteGraph[i, VertexSize -> Small]], {i, 3, 6}]VertexEccentricityはすべての頂点について1である:
VertexEccentricity[CompleteGraph[5], #]& /@ VertexList[CompleteGraph[5]]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 = CompleteGraph[4], FindVertexEccentricityPath[g, u]], {u, Range[4]}]GraphRadiusは1である:
Table[GraphRadius[CompleteGraph[i]], {i, 3, 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[#]]&[CompleteGraph[i, VertexSize -> Small]], {i, 3, 6}]GraphDiameterは1である:
Table[GraphDiameter[CompleteGraph[i]], {i, 3, 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[#]]&[CompleteGraph[i, VertexSize -> Small]], {i, 3, 6}]
から
までの頂点連結性は
から
までの頂点独立経路の数である:
g = CompleteGraph[4, VertexLabels -> "Name"]{HighlightGraph[g, 12],
HighlightGraph[g, PathGraph[{1, 3, 2}]],
HighlightGraph[g, PathGraph[{1, 4, 2}]]}CompleteGraph[n]の頂点連結性は
である:
g = CompleteGraph[5, VertexLabels -> "Name"];{HighlightGraph[g, PathGraph[{1, 2}]],
HighlightGraph[g, PathGraph[{1, 3, 2}]],
HighlightGraph[g, PathGraph[{1, 4, 2}]],
HighlightGraph[g, PathGraph[{1, 5, 2}]]
}CompleteGraphの頂点次数をハイライトする:
HighlightCentrality[g_, cc_] := HighlightGraph[g, Table[Style[VertexList[g][[i]], ColorData["TemperatureMap"][cc[[i]] / Max[cc]]], {i, VertexCount[g]}]];g = CompleteGraph[8, VertexSize -> Large];HighlightCentrality[g, VertexDegree[g]]HighlightCentrality[g, ClosenessCentrality[g]]HighlightCentrality[g, EigenvectorCentrality[g]]特性と関係 (12)
CompleteGraph[n]の頂点の数:
VertexCount[CompleteGraph[n]]CompleteGraph[n]の辺の数:
EdgeCount[CompleteGraph[n]]CompleteGraph[6]VertexDegree[%]g = CompleteGraph[8]HighlightGraph[g, h = Subgraph[g, Range[5]]]CompleteGraphQ[h]CompleteGraph[8, VertexSize -> {1 -> 0.2}]HighlightGraph[%, NeighborhoodGraph[%, 1]]CompleteGraph[5]Subgraph[%, First[FindClique[%]]]辺のない完全グラフのGraphComplement:
GraphComplement[CompleteGraph[5]]完全グラフでは,AdjacencyMatrixの対角の外側のすべての項は1である:
AdjacencyMatrix[CompleteGraph[25]]//MatrixPlot完全
部グラフでは,対角ブロックの外側の項はすべて1である:
AdjacencyMatrix[CompleteGraph[{1, 2, 3, 4, 5}]]//MatrixPlot{CompleteGraph[3], CycleGraph[3]}{CompleteGraph[4], WheelGraph[4]}{CompleteGraph[6], LineGraph[StarGraph[7]]}おもしろい例題 (2)
Graphics[Table[Inset[CompleteGraph[RandomInteger[{4, 8}]], RandomReal[{0, 10}, 2], Automatic, 1], {75}]]ColoringCycles[n_] := Block[{i, e},
e = Table[Mod[#, n, 1]Mod[# + i, n, 1]& /@ Range[n], {i, (n - 1) / 2}];
HighlightGraph[CompleteGraph[n], Table[Style[e[[i]], ColorData[1][i]], {i, Length[e]}]]
]Table[ColoringCycles[i], {i, {3, 5, 7, 9, 11, 13}}]関連するガイド
-
▪
- グラフの構築と表現 ▪
- グラフとネットワーク
テキスト
Wolfram Research (2010), CompleteGraph, Wolfram言語関数, https://reference.wolfram.com/language/ref/CompleteGraph.html (2020年に更新).
CMS
Wolfram Language. 2010. "CompleteGraph." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2020. https://reference.wolfram.com/language/ref/CompleteGraph.html.
APA
Wolfram Language. (2010). CompleteGraph. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/CompleteGraph.html
BibTeX
@misc{reference.wolfram_2026_completegraph, author="Wolfram Research", title="{CompleteGraph}", year="2020", howpublished="\url{https://reference.wolfram.com/language/ref/CompleteGraph.html}", note=[Accessed: 13-September-2026]}
BibLaTeX
@online{reference.wolfram_2026_completegraph, organization={Wolfram Research}, title={CompleteGraph}, year={2020}, url={https://reference.wolfram.com/language/ref/CompleteGraph.html}, note=[Accessed: 13-September-2026]}