アップグレード情報:

DiscreteMath`GraphPlot`

GraphPlotの機能が,新しく加わった組込みの Mathematica カーネル関数GraphPlotおよびLayeredGraphPlotで利用できるようになった.
GraphPlot3Dが新しく加わった組込みの Mathematica カーネル関数GraphPlot3Dで利用できるようになった.
TreePlotが,新しく加わった組込みの Mathematica カーネル関数TreePlotで利用できるようになった.
EdgeStyleFunctionオプションが,新しく加わった組込みの Mathematica カーネルオプションEdgeShapeFunctionとして利用できるようになった.
TreeSizeFunctionオプションが新しく加わった組込みの Mathematica カーネルオプションLayerSizeFunctionとして利用できるようになった.
VertexCoordinatesオプションが新しく加わった組込みの Mathematica カーネルオプションVertexCoordinatesとして利用できるようになった.
VertexStyleFunctionオプションが新しく加わった組込みの Mathematica カーネルオプションVertexShapeFunctionとして利用できるようになった.
RootPositionオプションが組込みの Mathematica カーネル関数TreePlotの第2引数として利用できるようになった.

GraphPlot

規則のリストで指定されたグラフをプロットする:

Version 5.2 << DiscreteMath`GraphPlot`;
g = GraphPlot[{2 -> 1, 3 -> 1, 3 -> 2, 4 -> 1, 4 -> 2, 5 -> 1, 
   5 -> 2}]

GraphPlot3D

グラフを3Dでレイアウトする:

Version 5.2 << DiscreteMath`GraphPlot`;
GraphPlot3D[{2 -> 1, 3 -> 1, 3 -> 2, 4 -> 1, 4 -> 2, 5 -> 1, 5 -> 2}]

TreePlot

二分木を描画する:

Version 5.2 << DiscreteMath`GraphPlot`;
g = Flatten[Table[{i -> 2*i, i -> 2*i + 1}, {i, 2^4 - 1}]]
TreePlot[g];

EdgeStyleFunction

EdgeShapeFunctionを使って,辺の描画方法を制御する:

Version 5.2 << DiscreteMath`GraphPlot`;
GraphPlot[Table[1, {30}, {30}], EdgeStyleFunction -> ({} &)]

辺を矢印として描画する別の方法:

Version 5.2 << DiscreteMath`GraphPlot`;
GraphPlot[{1 -> 2, 2 -> 3, 3 -> 4, 4 -> 5, 5 -> 6, 6 -> 7, 7 -> 8, 
   8 -> 1, 1 -> 9, 2 -> 9, 3 -> 10, 4 -> 10, 6 -> 11, 5 -> 11, 
   7 -> 12, 8 -> 12}, EdgeStyleFunction -> (Arrow[{#1, #2}] &)];

LayerSizeFunction

二分木を描画する:

Version 5.2 << DiscreteMath`GraphPlot`;
g = Flatten[Table[{i -> 2*i, i -> 2*i + 1}, {i, 2^4 - 1}]]
TreePlot[g];

以下でも同じグラフを描画するが.各レベルの高さ i1/i2に比例するようにする:

Version 5.2 << DiscreteMath`GraphPlot`;
g = Flatten[Table[{i -> 2*i, i -> 2*i + 1}, {i, 2^4 - 1}]]
TreePlot[g, TreeSizeFunction -> (1/#^2 &)];

VertexCoordinates

VertexCoordinatesを使うと,頂点の座標を明示的に指定することができる:

Version 5.2 << DiscreteMath`GraphPlot`;
GraphPlot[{1 -> 3, 1 -> 4, 2 -> 4, 2 -> 5, 3 -> 5, 6 -> 7, 7 -> 8, 
  8 -> 9, 9 -> 10, 6 -> 10, 1 -> 6, 2 -> 7, 3 -> 8, 4 -> 9, 5 -> 10}, 
 VertexCoordinates -> {{0.309017, 
    0.951057}, {-0.809017, -0.587785}, {0.309017, -0.951057}, \
{-0.809017, 0.587785}, {1., 0}, {0.618034, 1.90211}, {-1.61803, 
    1.17557}, {-1.61803, -1.17557}, {0.618034, -1.90211}, {2., 0}}

VertexStyleFunction

VertexShapeFunctionを使うと頂点の描画方法が制御できる.以下では頂点を描画しない:

Version 5.2 << DiscreteMath`GraphPlot`;
GraphPlot[{1 -> 2, 2 -> 3, 3 -> 4, 4 -> 5, 5 -> 6, 6 -> 1}, 
 VertexStyleFunction -> ({} &)]

ここでは青い大きい頂点を描画する:

Version 5.2 << DiscreteMath`GraphPlot`;
GraphPlot[{1 -> 2, 1 -> 3, 1 -> 4, 2 -> 3, 2 -> 4, 3 -> 5, 4 -> 6, 
   5 -> 7, 5 -> 8, 6 -> 7, 6 -> 8, 7 -> 8}, 
  VertexStyleFunction -> ({Hue[0], Disk[#, 0.03]} &)];

RootPosition (TreePlotの引数)

根を左側に置いて木をプロットする:

Version 5.2 << DiscreteMath`GraphPlot`;
TreePlot[{1 -> 2, 2 -> 4, 3 -> 6, 4 -> 8, 5 -> 10, 6 -> 12, 1 -> 3, 
  2 -> 5, 3 -> 7, 4 -> 9, 5 -> 11, 6 -> 13}, RootPosition -> Left]
DiscreteMath`GraphPlot`関数

DiscreteMath`GraphPlot`の関数の多くが組込みの Mathematica カーネル関数として利用できるようになった..

以下では37個の頂点を持つグラフをプロットする:

Version 5.2 << DiscreteMath`GraphPlot`;
GraphPlot[\!\(\*
TagBox[
RowBox[{"g", "=", 
RowBox[{"{", 
RowBox[{
RowBox[{"1", "->", "2"}], ",", 
RowBox[{"1", "->", "6"}], ",", 
RowBox[{"1", "->", "7"}], ",", 
RowBox[{"2", "->", "3"}], ",", 
RowBox[{"2", "->", "7"}], ",", 
RowBox[{"3", "->", "30"}], ",", 
RowBox[{"3", "->", "26"}], ",", 
RowBox[{"3", "->", "4"}], ",", 
RowBox[{"3", "->", "32"}], ",", 
RowBox[{"4", "->", "5"}], ",", 
RowBox[{"4", "->", "9"}], ",", 
RowBox[{"5", "->", "9"}], ",", 
RowBox[{"5", "->", "10"}], ",", 
RowBox[{"6", "->", "7"}], ",", 
RowBox[{"6", "->", "11"}], ",", 
RowBox[{"7", "->", "8"}], ",", 
RowBox[{"7", "->", "30"}], ",", 
RowBox[{"7", "->", "12"}], ",", 
RowBox[{"8", "->", "9"}], ",", 
RowBox[{"8", "->", "26"}], ",", 
RowBox[{"8", "->", "13"}], ",", 
RowBox[{"9", "->", "10"}], ",", 
RowBox[{"9", "->", "32"}], ",", 
RowBox[{"9", "->", "14"}], ",", 
RowBox[{"10", "->", "15"}], ",", 
RowBox[{"11", "->", "16"}], ",", 
RowBox[{"11", "->", "27"}], ",", 
RowBox[{"11", "->", "30"}], ",", 
RowBox[{"11", "->", "35"}], ",", 
RowBox[{"12", "->", "13"}], ",", 
RowBox[{"12", "->", "17"}], ",", 
RowBox[{"12", "->", "27"}], ",", 
RowBox[{"13", "->", "31"}], ",", 
RowBox[{"13", "->", "33"}], ",", 
RowBox[{"13", "->", "14"}], ",", 
RowBox[{"13", "->", "36"}], ",", 
RowBox[{"13", "->", "18"}], ",", 
RowBox[{"13", "->", "34"}], ",", 
RowBox[{"14", "->", "28"}], ",", 
RowBox[{"14", "->", "19"}], ",", 
RowBox[{"15", "->", "32"}], ",", 
RowBox[{"15", "->", "28"}], ",", 
RowBox[{"15", "->", "37"}], ",", 
RowBox[{"15", "->", "20"}], ",", 
RowBox[{"16", "->", "17"}], ",", 
RowBox[{"16", "->", "21"}], ",", 
RowBox[{"17", "->", "21"}], ",", 
RowBox[{"17", "->", "22"}], ",", 
RowBox[{"17", "->", "35"}], ",", 
RowBox[{"17", "->", "18"}], ",", 
RowBox[{"18", "->", "19"}], ",", 
RowBox[{"18", "->", "29"}], ",", 
RowBox[{"19", "->", "37"}], ",", 
RowBox[{"19", "->", "20"}], ",", 
RowBox[{"19", "->", "24"}], ",", 
RowBox[{"19", "->", "25"}], ",", 
RowBox[{"20", "->", "25"}], ",", 
RowBox[{"21", "->", "22"}], ",", 
RowBox[{"22", "->", "23"}], ",", 
RowBox[{"23", "->", "24"}], ",", 
RowBox[{"23", "->", "29"}], ",", 
RowBox[{"23", "->", "35"}], ",", 
RowBox[{"23", "->", "37"}], ",", 
RowBox[{"24", "->", "25"}], ",", 
RowBox[{"30", "->", "31"}], ",", 
RowBox[{"32", "->", "33"}], ",", 
RowBox[{"34", "->", "35"}], ",", 
RowBox[{"36", "->", "37"}]}], "}"}]}],
Short[#, 1000]& ]\), VertexStyleFunction -> Automatic];

グラフの直径を計算する:

Version 5.2 << DiscreteMath`GraphPlot`;
ug = Join[g, Reverse /@ g];
PseudoDiameter[ug]

頂点1と頂点25の間の距離を計算する:

Version 5.2 << DiscreteMath`GraphPlot`;
GraphDistance[ug, 1, 25]