New in Wolfram
Mathematica
8: Graph & Network Analysis
◄
previous
|
next
►
Application Areas
Perform a Depth-First Scan
Depth-first traversal of a hypercube.
In[1]:=
X
Manipulate[ GraphicsRow[{HighlightGraph[g4, {1, stepedge4[[;; i]]}, GraphStyle -> "BasicBlue", GraphHighlightStyle -> "Thick"], HighlightGraph[tree4, {1, stepedge4[[;; i]]}, GraphStyle -> "BasicBlue", GraphHighlightStyle -> "Thick"]}, ImageSize -> 500], {{i, 0, "step"}, 0, 7, 1}, Initialization :> (g4 = \!\(\* GraphicsBox[ NamespaceBox["NetworkGraphics", DynamicModuleBox[{Typeset`graph = HoldComplete[ Graph[{1, 2, 3, 4, 5, 6, 7, 8}, { Null, {{1, 6}, {1, 8}, {2, 7}, {2, 3}, {3, 8}, {4, 7}, {5, 6}, {5, 2}, {6, 4}, {6, 8}, {7, 5}, {8, 5}}}]], Typeset`boxes = GraphicsGroupBox[{{ Directive[ Hue[0.6, 0.2, 0.8], EdgeForm[ Directive[ GrayLevel[0], Opacity[0.7]]]], TagBox[ DiskBox[{2.4236706088404016`, 1.239627956100249}, 0.026414778842631922`], "DynamicName", BoxID -> "VertexID$1"], TagBox[ DiskBox[{0.001718994768031168, 1.7590443958916122`}, 0.026414778842631922`], "DynamicName", BoxID -> "VertexID$2"], TagBox[ DiskBox[{0.7414558593956714, 2.483164793250533}, 0.026414778842631922`], "DynamicName", BoxID -> "VertexID$3"], TagBox[ DiskBox[{0.7392756891940193, 0.}, 0.026414778842631922`], "DynamicName", BoxID -> "VertexID$4"], TagBox[ DiskBox[{0.7345601729455921, 1.2408968837893677`}, 0.026414778842631922`], "DynamicName", BoxID -> "VertexID$5"], TagBox[ DiskBox[{1.5604937073399374`, 0.7673778843174758}, 0.026414778842631922`], "DynamicName", BoxID -> "VertexID$6"], TagBox[ DiskBox[{0., 0.7248569562155478}, 0.026414778842631922`], "DynamicName", BoxID -> "VertexID$7"], TagBox[ DiskBox[{1.5608736802508196`, 1.7151386554586212`}, 0.026414778842631922`], "DynamicName", BoxID -> "VertexID$8"]}, { Directive[ Opacity[0.7], Hue[0.6, 0.7, 0.5]], LineBox[{{ DynamicLocation["VertexID$1", Automatic, Center], DynamicLocation["VertexID$6", Automatic, Center]}, { DynamicLocation["VertexID$1", Automatic, Center], DynamicLocation["VertexID$8", Automatic, Center]}, { DynamicLocation["VertexID$2", Automatic, Center], DynamicLocation["VertexID$7", Automatic, Center]}, { DynamicLocation["VertexID$2", Automatic, Center], DynamicLocation["VertexID$3", Automatic, Center]}, { DynamicLocation["VertexID$2", Automatic, Center], DynamicLocation["VertexID$5", Automatic, Center]}, { DynamicLocation["VertexID$3", Automatic, Center], DynamicLocation["VertexID$8", Automatic, Center]}, { DynamicLocation["VertexID$4", Automatic, Center], DynamicLocation["VertexID$7", Automatic, Center]}, { DynamicLocation["VertexID$4", Automatic, Center], DynamicLocation["VertexID$6", Automatic, Center]}, { DynamicLocation["VertexID$5", Automatic, Center], DynamicLocation["VertexID$6", Automatic, Center]}, { DynamicLocation["VertexID$5", Automatic, Center], DynamicLocation["VertexID$7", Automatic, Center]}, { DynamicLocation["VertexID$5", Automatic, Center], DynamicLocation["VertexID$8", Automatic, Center]}, { DynamicLocation["VertexID$6", Automatic, Center], DynamicLocation["VertexID$8", Automatic, Center]}}]}}]}, DynamicBox[GraphComputation`NetworkGraphicsBox[ 1, Typeset`graph, Typeset`boxes], { CachedValue :> Typeset`boxes, SingleEvaluation -> True, SynchronousUpdating -> False, TrackedSymbols :> {}}, ImageSizeCache->{{0.5857864376269051, 88.41421356237308}, {-47.485413562373054`, 42.395580804124165`}}]]], DefaultBaseStyle->{ "NetworkGraphics", FrontEnd`GraphicsHighlightColor -> Hue[0.8, 1., 0.6]}, FrameTicks->None]\); {pred4, edges4} = Reap[DepthFirstScan[g4, 1, {"FrontierEdge" -> Sow}]]; tree4 = TreeGraph[edges4[[1]]]; stepedge4 = edges4[[1]]) ]
Out[1]=
Play Animation
»
Stop Animation
»