3

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]}
 ]
Jagra
  • 14,343
  • 1
  • 39
  • 81
Sultan of Swing
  • 913
  • 1
  • 6
  • 19
  • 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. – mfvonh Oct 22 '14 at 00:21
  • If the code is the same as last night, have you shut down the kernel? You may have forgotten to save a definition. – mfvonh Oct 22 '14 at 00:22
  • 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. – Sultan of Swing Oct 22 '14 at 00:37
  • if you can't format your code here, post it on Github or similar. Perhaps some tender soul will give it a try. – Dr. belisarius Oct 22 '14 at 00:57
  • Well I'm not expecting anyone to go through the code and find exactly what's wrong. If that is in fact required, then I'm basically screwed and will have to start again. I was hoping for some insight...basically I'm hopeful that the problem is not too complicated as it was working just fine not too long ago. – Sultan of Swing Oct 22 '14 at 01:04
  • I can replicate the problem. Unfortunately the code it not written in a well-modularized way that would ease debugging. Nevertheless I will see what I can do. – Mr.Wizard Oct 22 '14 at 02:21
  • This is not the only problem but near the bottom of the code you have GraphData[;; 6] twice; I don't think this is syntactically valid. – Mr.Wizard Oct 22 '14 at 02:28
  • I went on a computer with Mathematica 8.0 and it worked just fine. Pretty pathetic how on a lower end computer, with a version of Mathematica that is years old, the notebook (that was created on version 10) runs instantly. On a better-spec.ed computer, it hangs indefinitely. This is why I am happy I didn't have to pay for Mathematica. – Sultan of Swing Oct 22 '14 at 02:41
  • 1
    @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.

    – Sultan of Swing Oct 22 '14 at 02:42
  • 1
    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. – Mr.Wizard Oct 22 '14 at 06:15
  • I have been able to narrow the problem to the use of GraphData in the sense that removing those expressions prevents the hang/crash though of course it also breaks the program. This jogged a memory of another question about loading data inside a Dynamic expression causing a hang as the result of curated data being repeatedly (erroneously) loaded. I can't seem to find that now but I think it may be the same problem. I suggest you search for it. – Mr.Wizard Oct 22 '14 at 06:25
  • No problem I'm very grateful you've helped me as much as you have so far. I would agree with you about the loading of the curated data. Over the duration of today I noticed my SSD lose 10 GB of space. All this time I've been constantly running this notebook on and off. If I check the AppData folder in my user, under roaming>Mathematica>Paclets>Temporary, I have 10 GB of these little files that say GraphData in the name. I suspect the problem was basically somewhere in loading all this data. Just wanted to mention that here. – Sultan of Swing Oct 22 '14 at 11:27
  • FWIW it works ok with v9/windows. (I just copied the code from the post). – george2079 Oct 22 '14 at 18:55
  • Still an issue in V9.0.1 and V10.2....In V10.2, the FE simply hangs (no CPU activity, low memory use, but "Formatting notebook..." just stays there). – Michael E2 Aug 08 '15 at 20:03

0 Answers0