(*********************************************************************** This file was generated automatically by the Mathematica front end. It contains Initialization cells from a Notebook file, which typically will have the same name as this file except ending in ".nb" instead of ".m". This file is intended to be loaded into the Mathematica kernel using the package loading commands Get or Needs. Doing so is equivalent to using the Evaluate Initialization Cells menu command in the front end. DO NOT EDIT THIS FILE. This entire file is regenerated automatically each time the parent Notebook file is saved in the Mathematica front end. Any changes you make to this file will be overwritten. ***********************************************************************) (* :Title: CombinatoricaPlots *) (* :Context: DiscreteMath`CombinatoricaPlots` *) (* :Author: David J. M. Park Jr. djmp@earthlink.net *) (* :Summary: This package adds more generalized plot routines to the Combinatorica \ package. It corrects an error that cuts off some of the labels. It allows plots to be both labeled and directed. *) (* :Copyright: \[Copyright] 1999, 2000 by David J. M. Park Jr. *) (* :Package Version: 2.0 *) (* :Mathematica Version: 4.0 *) (* :Keywords: Combinatorica, Graphics *) (* :Requirements: DiscreteMath`Combinatorica, Graphics`Arrow` *) BeginPackage["DiscreteMath`CombinatoricaPlots`",{"DiscreteMath`Combinatorica`\ ","Graphics`Arrow`"}] DiscreteMath`CombinatoricaPlots::usage=" CombinatoricaPlots adds more \ generalized plot routines to the Combinatorica package. PlotGraph replaces \ the old ShowGraph. It corrects an error that cuts off some of the labels. It \ allows plots to be both labeled and directed. It is possible to label edges \ as well as vertices. Graphics directives may be specified for the vertices, \ edges and labels. Directed edges may have the arrows at any point along the \ edge. Self-loops may be included in the plot." ArrowheadPosition::usage= "ArrowPosition gives the position of the tip of the arrowhead on directed \ edges as a fraction of the length of the edge. It should be a number between \ 0.13 and 1. The default value is 1."; $NewMessage[Directed,"usage"]; Directed::usage= Directed::usage<> " For PlotGraph, Directed may take the values False|True|{Arrow options}. \ False is the default. If True, standard Arrows are drawn for the branches of \ the graph. Or a list of Arrow options can be given, which implies True."; DrawGraph::usage="DrawGraph[g_Graph, options...] extracts the graphic \ primitives from the corresponding PlotGraph routine."; EdgeDirectives::usage="EdgeDirectives is an option for PlotGraph which \ specifies a list of graphics directives which will be executed before the \ graph edges are drawn. Its default is {GrayLevel[0], AbsoluteThickness[1]}."; EdgeLabels::usage= "EdgeLabels is an option for PlotGraph which specifies labels for edges. \ Only edges which are specifically listed are labeled. The general format is \ {edge1, edge2,...}. Each edgei can take the form {{from, to}, label, offset} \ where from and to give the starting and ending vertex numbers and label is \ the actual label value. The third item, offset, is optional and specifies the \ label offset for that particular edge. Otherwise the global edge label offset \ is used."; EdgeLabelOffset::usage= "EdgeLabelOffset is an option for PlotGraph which specifies the offset to \ be used in printing edge labels. The default is {-1.1, 0}. The label position \ is the midpoint of the edge. See the Mathematica Text statement for the use \ of offset."; EdgeLabelTextOptions::usage= "EdgeLabelTextOptions is an option for PlotGraph which can be used to \ specify a list of options to be inserted in the Text statement when printing \ the edge labels."; GraphPlottingOptions::usage="GraphPlottingOptions is an option for PlotGraph \ which can be used to specify a list of graphics options for the plot. The \ default value is {}. The actual options used are {supplied \ options}~Join~{AspectRatio \[Rule] Automatic, PlotRange \[Rule] All}"; PlotGraph::usage="PlotGraph[g_Graph, options...] will plot a graph. The \ options allow the graph plot to be directed or undirected, labeled or \ unlabeled, and in addition graphics directives can be given for the points, \ labels, lines or arrows. The graphics directives are: Directed, VertexLabels, \ VertexDirectives, VertexLabelOffset, VertexLabelTextOptions, EdgeDirectives \ and GraphPlottingOptions. See their associated usage messages."; SelfLoops::usage= "SelfLoops is an option for PlotGraph. Its default value is False. If set \ to True self-loop circles will be drawn through any vertex which has a \ nonzero value in the corresponding diagonal position of the graph adjacency \ matrix. The absolute radius of the circles can be specified by setting \ SelfLoop to a numerical value, otherwise the radii will be 15 percent of the \ distance of the farthest vertex from the center of the graph."; VertexDirectives::usage="VertexDirectives is an option for PlotGraph which \ specifies a list of graphics directives which will be executed before the \ vertex points are drawn. Its default is {GrayLevel[0], \ AbsolutePointSize[4]}."; VertexLabelOffset::usage="VertexLabelOffset is an option for PlotGraph which \ specifies the offset to be used in printing vertex labels. The default is {2, \ 2}. See the Mathematica Text statement for the use of offset."; VertexLabels::usage= "VertexLabels is an option for PlotGraph which specifies that labels will \ be attached to the vertices. VertexLabels may take the values \ False|True|{vertex labels}. The default value is False. If True the vertices \ are numbered in order. A list of vertex labels implies True and uses the \ given list for labeling. If a list of vertex labels is supplied, the i'th \ item will be the label for vertex i, or be of the form {label,offset} for the \ i'th vertex. See also VertexLabelOffset and VertexLabelTextOptions."; VertexLabelTextOptions::usage="VertexLabelTextOptions is an option for \ PlotGraph which can be used to specify a list of options to be inserted in \ the Text statement when printing the vertex labels."; Begin["`Private`"] DrawGraph[g_Graph,opts___?OptionQ]:= Module[{opts2={opts}}, If[MemberQ[opts2,GraphPlottingOptions\[Rule]a_], opts2=opts2/.(GraphPlottingOptions\[Rule] a_)\[RuleDelayed](GraphPlottingOptions\[Rule] Join[{DisplayFunction\[Rule]Identity},a]), opts2=Join[ opts2,{GraphPlottingOptions\[Rule]{DisplayFunction\[Rule] Identity}}]]; First[PlotGraph[g,Sequence@@opts2]] ] \!\(\(Options[ PlotGraph] = {\[IndentingNewLine]Directed \[Rule] False, \[IndentingNewLine]VertexLabels \[Rule] False, \[IndentingNewLine]VertexDirectives \[Rule] {GrayLevel[0], AbsolutePointSize[4]}, VertexLabelOffset \[Rule] {2, 2}, \[IndentingNewLine]VertexLabelTextOptions \[Rule] {}, \ \[IndentingNewLine]EdgeDirectives \[Rule] {GrayLevel[0], AbsoluteThickness[ 1]}, \[IndentingNewLine]ArrowheadPosition \[Rule] 1, \[IndentingNewLine]EdgeLabels \[Rule] False, \[IndentingNewLine]EdgeLabelOffset \[Rule] {\(-1.1\), 0}, \[IndentingNewLine]EdgeLabelTextOptions \[Rule] {}, \ \[IndentingNewLine]SelfLoops \[Rule] False, \[IndentingNewLine]GraphPlottingOptions \[Rule] {}};\)\n\ \[IndentingNewLine] PlotGraph[g_Graph, opts___?OptionQ] := Module[\[IndentingNewLine]{pairs = ToOrderedPairs[g], directed, vertexlabels, vertexdirectives, labeloffset, vertextext, edgedirectives, arrowoptions, plotoptions, arrowposition, edgelabels, edgelabeloffset, edgetext, elabvalue, elabpos, elaboffset, edges, selfloops, drawloops, rloop, gc, v, numv, vlabels, vlabvalue, vlaboffset, i}, \[IndentingNewLine]\[IndentingNewLine]directed = \(Directed \ /. \[InvisibleSpace]{opts}\) /. \[InvisibleSpace]Options[PlotGraph]; vertexlabels = \(VertexLabels /. \[InvisibleSpace]{opts}\) \ /. \[InvisibleSpace]Options[PlotGraph]; vertexdirectives = \(VertexDirectives /. \[InvisibleSpace]{opts}\) \ /. \[InvisibleSpace]Options[PlotGraph]; labeloffset = \(VertexLabelOffset /. \[InvisibleSpace]{opts}\) \ /. \[InvisibleSpace]Options[PlotGraph]; vertextext = \(VertexLabelTextOptions /. \[InvisibleSpace]{opts}\) \ /. \[InvisibleSpace]Options[PlotGraph]; edgedirectives = \(EdgeDirectives /. \[InvisibleSpace]{opts}\) \ /. \[InvisibleSpace]Options[PlotGraph]; arrowposition = \(ArrowheadPosition /. \[InvisibleSpace]{opts}\) \ /. \[InvisibleSpace]Options[ PlotGraph]; \[IndentingNewLine]edgelabels = \(EdgeLabels /. \ {opts}\) /. Options[ PlotGraph2]; \[IndentingNewLine]edgelabeloffset = \ \(EdgeLabelOffset /. {opts}\) /. Options[PlotGraph]; \[IndentingNewLine]edgetext = \ \(EdgeLabelTextOptions /. {opts}\) /. Options[PlotGraph]; \[IndentingNewLine]selfloops = \(SelfLoops /. \ {opts}\) /. Options[PlotGraph]; \[IndentingNewLine]plotoptions = \ \(GraphPlottingOptions /. \[InvisibleSpace]{opts}\) \ /. \[InvisibleSpace]Options[ PlotGraph]; \[IndentingNewLine]\[IndentingNewLine]arrowposition = Max[0.13, Min[1, arrowposition]]; \[IndentingNewLine]v = Vertices[g]; \[IndentingNewLine]numv = Length[v]; \[IndentingNewLine]edges = Edges[g]; \[IndentingNewLine]\[IndentingNewLine]Which[\ \[IndentingNewLine]directed === True, arrowoptions = {}, \[IndentingNewLine]directed === False, arrowoptions = {}, True, arrowoptions = directed; directed = True]; \[IndentingNewLine]\[IndentingNewLine]drawloops = True; \[IndentingNewLine]gc = \((Plus @@ v)\)/Length[v] // Chop; \[IndentingNewLine]Which[\[IndentingNewLine]selfloops === False \[Or] Tr[Edges[g]] == 0, drawloops = False, \[IndentingNewLine]MatchQ[selfloops, _?NumberQ], rloop = selfloops, \[IndentingNewLine]selfloops === True, \[IndentingNewLine]rloop = 0.15 Max[\(\@\(# . #\) &\) /@ Table[v\[LeftDoubleBracket]i\[RightDoubleBracket] - gc, {i, 1, numv}]], \[IndentingNewLine]True, drawloops = False]; \[IndentingNewLine]\[IndentingNewLine]Show[ Graphics[{\[IndentingNewLine]Sequence @@ edgedirectives, \[IndentingNewLine]\[IndentingNewLine]Which[\ \[IndentingNewLine]directed === False, \((Line[ v\[LeftDoubleBracket]#1\[RightDoubleBracket]] &)\) /@ pairs, \[IndentingNewLine]True, {\((Arrow[Sequence @@ #1, Sequence @@ arrowoptions] &)\) /@ \(\(({#1\[LeftDoubleBracket]1\ \[RightDoubleBracket], #1\[LeftDoubleBracket]1\[RightDoubleBracket] + arrowposition\ \((#1\[LeftDoubleBracket]2\ \[RightDoubleBracket] - #1\[LeftDoubleBracket]1\[RightDoubleBracket])\)} &)\) \ /@ \(\((v\[LeftDoubleBracket]#1\[RightDoubleBracket] &)\) /@ pairs\)\), \((Line[#1] &)\) /@ \(\(({#1\ \[LeftDoubleBracket]1\[RightDoubleBracket] + arrowposition\ \((#1\[LeftDoubleBracket]2\ \[RightDoubleBracket] - #1\[LeftDoubleBracket]1\[RightDoubleBracket])\), #1\ \[LeftDoubleBracket]2\[RightDoubleBracket]} &)\) /@ \ \(\((v\[LeftDoubleBracket]#1\[RightDoubleBracket] &)\) /@ pairs\)\)}], \[IndentingNewLine]\[IndentingNewLine]If[ drawloops, \[IndentingNewLine]\(Circle[ If[# \[NotEqual] gc, \((\@\(\((# - gc)\) . \((# - gc)\)\) + rloop)\) \((# - gc)\), gc + {rloop, rloop}/\@2], rloop] &\) /@ \((Table[ If[edges\[LeftDoubleBracket]i, i\[RightDoubleBracket] \[NotEqual] 0, v\[LeftDoubleBracket]i\[RightDoubleBracket], Null], {i, 1, numv}] /. Null \[Rule] Sequence[])\), {}], \[IndentingNewLine]\ \[IndentingNewLine]Sequence @@ vertexdirectives, Point /@ v, \[IndentingNewLine]\[IndentingNewLine]GrayLevel[ 0], \[IndentingNewLine]vlabels = If[vertexlabels === True, Range[V[g]], vertexlabels]; If[\[InvisibleSpace]\(! \((vlabels === False)\)\), \[IndentingNewLine]Table[{vlabvalue, vlaboffset} = If[MatchQ[ vlabels\[LeftDoubleBracket] i\[RightDoubleBracket], {a_, {_?NumberQ, _? NumberQ}}], {vlabels\[LeftDoubleBracket]i, 1\[RightDoubleBracket], vlabels\[LeftDoubleBracket]i, 2\[RightDoubleBracket]}, {vlabels\[LeftDoubleBracket] i\[RightDoubleBracket], labeloffset}]; Text[vlabvalue, v\[LeftDoubleBracket]i\[RightDoubleBracket], vlaboffset, Sequence @@ vertextext], {i, Length[v]}], {}], \[IndentingNewLine]\[IndentingNewLine]If[ edgelabels =!= False, \[IndentingNewLine]Table[\[IndentingNewLine]elabpos = \ \(\((#\_\(\(\[LeftDoubleBracket]\)\(1\)\(\[RightDoubleBracket]\)\) + #\_\(\(\ \[LeftDoubleBracket]\)\(2\)\(\[RightDoubleBracket]\)\))\)/ 2 &\)[\(v\[LeftDoubleBracket]#\[RightDoubleBracket] &\ \) /@ edgelabels\[LeftDoubleBracket]i, 1\[RightDoubleBracket]]; \[IndentingNewLine]elabvalue \ = edgelabels\[LeftDoubleBracket]i, 2\[RightDoubleBracket]; \[IndentingNewLine]elaboffset = If[Length[ edgelabels\[LeftDoubleBracket] i\[RightDoubleBracket]] > 2, edgelabels\[LeftDoubleBracket]i, 3\[RightDoubleBracket], edgelabeloffset]; \[IndentingNewLine]Text[elabvalue, elabpos, elaboffset, Sequence @@ edgetext], {i, 1, Length[edgelabels]}], {}]\[IndentingNewLine]}], \ \[IndentingNewLine]\[IndentingNewLine]Sequence @@ plotoptions, AspectRatio \[Rule] Automatic, PlotRange \[Rule] All]]\) End[] Protect[PlotGraph,DrawGraph] EndPackage[]