3
$\begingroup$

I'm using Manipulate to play around with some graphs (up to 6 vertices). Users can work with one graph or find the union/intersection/difference between two graphs. The user can display the graph regularly, in 3D, layered form, or its complement. Lastly, the user can also choose to view the graph's properties, such as order, size, number of 2-cuts, and adjacency matrix. Graphs are selected from a dropdown list. The data comes from GraphData. There are about 70 graphs or so to choose from.

The code is one block and is 442 lines. Last night I was working on it in my kitchen (wireless internet and unplugged from power). The app was executing just fine. I'm trying to do some finishing touches to it (same as yesterday, wifi and unplugged--it is due in 7 hours) but when I try to open and execute the notebook, it hangs FOREVER and constantly says "Formatting notebook contents".

I left it for about 20 minutes and then the Mathematica program was just BLACK (though it had stopped its "formatting" garbage").

I've looked it up and I figure it might be just too much code. Is that really the case? Can software this expensive not run my code?

My machine is decent (i5-4200U, 8GB RAM, SSD), and like I said, it ran just fine last night. What gives? I'm really desperate here as it's due soon and I still have to do a couple of small things. Even still, I do want to check to make sure everything runs fine before I submit it. Thanks in advance.

Edit: Here is my code (sorry about not indenting each line--hope it is still copyable for you guys).

https://gist.github.com/anonymous/83f9064a2e6c243b24cb (hope this works, never used that site before)

Framed[Manipulate[

  If[showGraph === 0,

   Which[
    disp === reg,
    Which[
     addGraph == 0,
     GraphPlot[GraphData[name], PlotStyle -> color, 
      VertexLabeling -> True],
     addGraph == 1,
     GraphPlot[
      Operation[GraphData[name], GraphData[name2]], PlotStyle -> color,
      VertexLabeling -> True]
     ],
    disp === graphComp,
    Which[
     addGraph == 0,
     GraphPlot[GraphComplement[GraphData[name]], PlotStyle -> color, 
      VertexLabeling -> True],
     addGraph == 1,
     GraphPlot[GraphComplement[
       Operation[GraphData[name], GraphData[name2]]], 
      PlotStyle -> color,
      VertexLabeling -> True]
     ],
    disp === threeD,
    Which[
     addGraph == 0,
     GraphPlot3D[GraphData[name], PlotStyle -> color, 
      VertexLabeling -> True],
     addGraph == 1,
     GraphPlot3D[
      Operation[GraphData[name], GraphData[name2]], PlotStyle -> color,
      VertexLabeling -> True]
     ],
    disp === layered,
    Which[
     addGraph == 0,
     LayeredGraphPlot[GraphData[name], PlotStyle -> color, 
      VertexLabeling -> True],
     addGraph == 1,
     LayeredGraphPlot[
      Operation[GraphData[name], GraphData[name2]], PlotStyle -> color,
      VertexLabeling -> True]
     ]
    ],






   (*Which[
   disp===reg||disp===threeD||disp===layered,
   Which[
   addGraph\[Equal]0,
   MatrixForm[AdjacencyMatrix[GraphData[name]]],
   addGraph\[Equal]1,
   MatrixForm[AdjacencyMatrix[
   Operation[GraphData[name],GraphData[name2]]]]
   ],
   disp===graphComp,


   Which[
   addGraph\[Equal]0,
   MatrixForm[AdjacencyMatrix[GraphComplement[GraphData[name]]]],
   addGraph\[Equal]1,
   MatrixForm[AdjacencyMatrix[GraphComplement[
   Operation[GraphData[name],GraphData[name2]]]]]
   ]

   ]*)



   Which[
    disp === reg || disp === threeD || disp === layered,
    Which[
     addGraph == 0,


     Grid[{{Graphics[
         Table[Text[Style["Adjacency matrix", 15], {1, 1}, 
           Automatic, {1, 0}], {1}], ImageSize -> {120, 30}],

        Graphics[Table[Text[Style[

            Text[
             MatrixForm[AdjacencyMatrix[GraphData[name]]]
             ]

            , Bold, 15], {1, 1}, Automatic, {1, 0}], {1}]]

        }, {Graphics[
         Table[Text[Style["Graph order", 15], {1, 1}, 
           Automatic, {1, 0}], {1}], ImageSize -> {120, 30}],

        Graphics[Table[Text[Style[ 

            VertexCount[GraphData[name]]

            , Bold, 20], {1, 1}, Automatic, {1, 0}], {1}], 
         ImageSize -> 30]

        }, {Graphics[
         Table[Text[Style["Graph size", 15], {1, 1}, 
           Automatic, {1, 0}], {1}], ImageSize -> {120, 30}],

        Graphics[Table[Text[Style[

            EdgeCount[GraphData[name]]

            , Bold, 20], {1, 1}, Automatic, {1, 0}], {1}], 
         ImageSize -> 30]

        }, {Graphics[
         Table[Text[Style["Connected components", 15], {1, 1}, 
           Automatic, {1, 0}], {1}], ImageSize -> {170, 30}],

        Graphics[Table[Text[Style[ 


            HighlightGraph[GraphData[name], 
             ConnectedComponents[GraphData[name]]]

            , Bold, 20], {1, 1}, Automatic, {1, 0}], {1}]]

        }, {Graphics[
         Table[Text[Style["2-Cuts", 15], {1, 1}, 
           Automatic, {1, 0}], {1}], ImageSize -> {120, 30}],

        Graphics[Table[Text[Style[ 


            HighlightGraph[GraphData[name], 
             Map[Subgraph[GraphData[name], #] &, 
              Last[FindMinimumCut[GraphData[name]]]]]

            , Bold, 20], {1, 1}, Automatic, {1, 0}], {1}]]

        }}, Frame -> All]





     ,







     addGraph == 1,



     Grid[{{Graphics[
         Table[Text[Style["Adjacency matrix", 15], {1, 1}, 
           Automatic, {1, 0}], {1}], ImageSize -> {120, 30}],

        Graphics[Table[Text[Style[

            Text[

             MatrixForm[
              AdjacencyMatrix[
               Operation[GraphData[name], GraphData[name2]]]]
             ]

            , Bold, 15], {1, 1}, Automatic, {1, 0}], {1}]]

        }, {Graphics[
         Table[Text[Style["Graph order", 15], {1, 1}, 
           Automatic, {1, 0}], {1}], ImageSize -> {120, 30}],

        Graphics[Table[Text[Style[ 

            VertexCount[Operation[GraphData[name], GraphData[name2]]]

            , Bold, 20], {1, 1}, Automatic, {1, 0}], {1}], 
         ImageSize -> 30]

        }, {Graphics[
         Table[Text[Style["Graph size", 15], {1, 1}, 
           Automatic, {1, 0}], {1}], ImageSize -> {120, 30}],

        Graphics[Table[Text[Style[

            EdgeCount[Operation[GraphData[name], GraphData[name2]]]

            , Bold, 20], {1, 1}, Automatic, {1, 0}], {1}], 
         ImageSize -> 30]

        }, {Graphics[
         Table[Text[Style["Connected components", 15], {1, 1}, 
           Automatic, {1, 0}], {1}], ImageSize -> {170, 30}],

        Graphics[Table[Text[Style[ 


            HighlightGraph[
             Operation[GraphData[name], GraphData[name2]], 
             ConnectedComponents[
              Operation[GraphData[name], GraphData[name2]]]]

            , Bold, 20], {1, 1}, Automatic, {1, 0}], {1}]]

        }, {Graphics[
         Table[Text[Style["2-Cuts", 15], {1, 1}, 
           Automatic, {1, 0}], {1}], ImageSize -> {120, 30}],

        Graphics[Table[Text[Style[ 


            HighlightGraph[
             Operation[GraphData[name], GraphData[name2]], 
             Map[Subgraph[
                Operation[GraphData[name], GraphData[name2]], #] &, 
              Last[FindMinimumCut[
                Operation[GraphData[name], GraphData[name2]]]]]]

            , Bold, 20], {1, 1}, Automatic, {1, 0}], {1}]]

        }}, Frame -> All]






     ],
    disp === graphComp,


    Which[
     addGraph == 0,



     Grid[{{Graphics[
         Table[Text[Style["Adjacency matrix", 15], {1, 1}, 
           Automatic, {1, 0}], {1}], ImageSize -> {120, 30}],

        Graphics[Table[Text[Style[

            Text[

             MatrixForm[
              AdjacencyMatrix[GraphComplement[GraphData[name]]]]
             ]

            , Bold, 15], {1, 1}, Automatic, {1, 0}], {1}]]

        }, {Graphics[
         Table[
          Text[Style["Graph order", 15], {1, 1}, 
           Automatic, {1, 0}], {1}], ImageSize -> {120, 30}],

        Graphics[Table[Text[Style[ 

            VertexCount[GraphComplement[GraphData[name]]]

            , Bold, 20], {1, 1}, Automatic, {1, 0}], {1}], 
         ImageSize -> 30]

        }, {Graphics[
         Table[Text[Style["Graph size", 15], {1, 1}, 
           Automatic, {1, 0}], {1}], ImageSize -> {120, 30}],

        Graphics[Table[Text[Style[

            EdgeCount[GraphComplement[GraphData[name]]]

            , Bold, 20], {1, 1}, Automatic, {1, 0}], {1}], 
         ImageSize -> 30]

        }, {Graphics[
         Table[Text[Style["Connected components", 15], {1, 1}, 
           Automatic, {1, 0}], {1}], ImageSize -> {170, 30}],

        Graphics[Table[Text[Style[ 


            HighlightGraph[GraphComplement[GraphData[name]], 
             ConnectedComponents[GraphComplement[GraphData[name]]]]

            , Bold, 20], {1, 1}, Automatic, {1, 0}], {1}]]

        }, {Graphics[
         Table[Text[Style["2-Cuts", 15], {1, 1}, 
           Automatic, {1, 0}], {1}], ImageSize -> {120, 30}],

        Graphics[Table[Text[Style[ 


            HighlightGraph[GraphComplement[GraphData[name]], 
             Map[Subgraph[GraphComplement[GraphData[name]], #] &, 
              Last[FindMinimumCut[GraphComplement[GraphData[name]]]]]]

            , Bold, 20], {1, 1}, Automatic, {1, 0}], {1}]]

        }}, Frame -> All],




     addGraph == 1,



     Grid[{{Graphics[
         Table[Text[Style["Adjacency matrix", 15], {1, 1}, 
           Automatic, {1, 0}], {1}], ImageSize -> {120, 30}],

        Graphics[Table[Text[Style[

            Text[

             MatrixForm[

              AdjacencyMatrix[
               GraphComplement[
                Operation[GraphData[name], GraphData[name2]]]]]
             ]

            , Bold, 15], {1, 1}, Automatic, {1, 0}], {1}]]

        }, {Graphics[
         Table[Text[Style["Graph order", 15], {1, 1}, 
           Automatic, {1, 0}], {1}], ImageSize -> {120, 30}],

        Graphics[Table[Text[Style[ 


            VertexCount[
             GraphComplement[
              Operation[GraphData[name], GraphData[name2]]]]

            , Bold, 20], {1, 1}, Automatic, {1, 0}], {1}], 
         ImageSize -> 30]

        }, {Graphics[
         Table[Text[Style["Graph size", 15], {1, 1}, 
           Automatic, {1, 0}], {1}], ImageSize -> {120, 30}],

        Graphics[Table[Text[Style[


            EdgeCount[
             GraphComplement[
              Operation[GraphData[name], GraphData[name2]]]]

            , Bold, 20], {1, 1}, Automatic, {1, 0}], {1}], 
         ImageSize -> 30]

        }, {Graphics[
         Table[Text[Style["Connected components", 15], {1, 1}, 
           Automatic, {1, 0}], {1}], ImageSize -> {170, 30}],

        Graphics[Table[Text[Style[ 


            HighlightGraph[
             GraphComplement[
              Operation[GraphData[name], GraphData[name2]]], 
             ConnectedComponents[
              GraphComplement[
               Operation[GraphData[name], GraphData[name2]]]]]

            , Bold, 20], {1, 1}, Automatic, {1, 0}], {1}]]

        }, {Graphics[
         Table[Text[Style["2-Cuts", 15], {1, 1}, 
           Automatic, {1, 0}], {1}], ImageSize -> {120, 30}],

        Graphics[Table[Text[Style[ 


            HighlightGraph[
             GraphComplement[
              Operation[GraphData[name], GraphData[name2]]], 
             Map[Subgraph[
                GraphComplement[
                 Operation[GraphData[name], GraphData[name2]]], #] &, 
              Last[FindMinimumCut[
                GraphComplement[
                 Operation[GraphData[name], GraphData[name2]]]]]]]

            , Bold, 20], {1, 1}, Automatic, {1, 0}], {1}]]

        }}, Frame -> All]




     ]

    ]



   ],


  Style["Basic Graph Manipulations", 25],



  Style["Graphs", 16, Bold],
  {{name, {4, 2}, "Graph 1"}, GraphData[;; 6]},
  {{addGraph, 0, "Add another graph?"}, {0, 1}, Checkbox},
  {{name2, {4, 3}, "Graph 2"}, GraphData[;; 6]},
  "",
  Delimiter,
  "",
  Style["Operations and Display", 16, Bold],
  {{Operation, GraphUnion, "Graph Operation"}, {GraphUnion, 
    GraphIntersection, GraphDifference}, RadioButton},
  {{disp, reg, "Graph Display"}, {reg, graphComp, threeD, layered}, 
   RadioButton},
  {{color, Black, "Edge colour"}, ColorSetter},
  "",
  Delimiter,
  "",
  Style["Paths and Other", 16, Bold],
  {{vertex1, 1, "Vertex 1"}, 
   VertexList[Operation[GraphData[name], GraphData[name2]]], 
   PopupMenu}, {{vertex2, 1, "Vertex 2"}, 
   VertexList[Operation[GraphData[name], GraphData[name2]]], 
   PopupMenu},
  {{showGraph, 0, "Display graph information"}, {0, 1}, Checkbox},
  Paneled -> False
  ],
 FrameMargins -> 50,
 Background -> White,
 BaseStyle -> {FontColor -> GrayLevel[0]}
 ]
$\endgroup$
  • $\begingroup$ Share your code with us? You could just throw it in a github gist or whatever rather than pasting it in the post. Most likely there is something wrong in your code and it is not evaluating properly. When this happens the kernel can spew out a lot of text output and the frontend gets overwhelmed formatting it. $\endgroup$ – mfvonh Oct 22 '14 at 0:21
  • $\begingroup$ If the code is the same as last night, have you shut down the kernel? You may have forgotten to save a definition. $\endgroup$ – mfvonh Oct 22 '14 at 0:22
  • $\begingroup$ Added code but it's messy. Sorry about that. I'm new to all this. The kernel was shut down last night. Going an an hour here and it continues to show "Formatting Notebook Contents" over and over. $\endgroup$ – Sultan of Swing Oct 22 '14 at 0:37
  • 1
    $\begingroup$ @Mr.Wizard it is correct: GraphData[;;n] gives a list of standard named graphs with ≤n vertices. From GraphData documentation. Also, I apologize for the poorly-formatted code. I'm quite beside myself here as it just doesn't make sense. Thanks so far. $\endgroup$ – Sultan of Swing Oct 22 '14 at 2:42
  • 1
    $\begingroup$ Sorry for the earlier ignorant comment. On one attempt to run your code I got a message about Part failing and I thought I'd found the cause. If the code runs as intended in Mathematica 8 it seems you have run into a bug. If you report this to Wolfram support please let us know the outcome. $\endgroup$ – Mr.Wizard Oct 22 '14 at 6:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.