Application Center - Maplesoft

App Preview:

Graph Theory Editor

You can switch back to the summary page by clicking here.

Learn about Maple
Download Application




 

 

GraphTheory Editor

 

 

Maple's GraphTheory package is a powerful tool for both Graph Theory research and for instruction and demonstration in Graph Theory Courses.  This worksheet augments the GraphTheory package with a Graph Editor that allows a "point and click" approach to be used to modify and/or define graphs.  

 

In addition, the worksheet defines commands for importing and exporting graphs from graphml format, and files in graphml format can be imported and exported from Cytoscape 3.0.  Also, there are commands for alternative visualizations based on grouping vertices and their neighborhoods independently of the remainder of the graph.   Most important, much of this was created to support collaborative activities (e.g., undergraduate research) in computational biology, especially protein-protein interactions.  Consequently, it is a work in progress and I invite any and all to add to and improve on what is a "rough around the edges" creation.  

 

The section below loads the module necessary for the GraphEditor to run and the new commands described above.  

GraphEditor Module

``

Instructions:  You can either Reset and start a new graph, or you can enter the name of an existing graph and hit Edit.  Either way, once you have the graph you want, the Save button will save it with the name entered after "Name of Graph."  Once saved, the graph can be referenced throughout the remainder of that worksheet (or in the edit) using that name.  

 

NOTE: You may need to right-click on the component and set the manipulator to be "click and drag".  (the cursor will then change to the icon    )

 

Graph Editor

Name/Command:   

  

Inserts into "Name/Command" field -- Modify (if necessary) and then Edit

 

   |  

Click  

Drag

A Click on an Edge Deletes the Edge

 

Vertex:   

  as   

 

Edge:

 

 

 

Further Intructions:  Clicking on an edge deletes that edge.  Further click actions can be toggled between selecting a vertex or deleting a vertex.  Drag actions can be toggled between moving a vertex and adding an edge.  Graphs can also be toggled between directed and undirected, weighted and unweighted.  

 

Clicking on a vertex selects that vertex, allowing it to be highlighted or renamed. Dragging to create an edge selects that edge, or alternatively, the edge can be selected by selecting its initial vertex and then selecting itse final vertex.  The edge can then be highlighted or its weight can be modified.  Feel free to experiment, as the editor included an unlimited undo/redo capability.  

 

Working with GraphEditor results in Maple Itself:   

Once you have created a graph and saved it with a name (such as "MyGraph"), then commands from the GraphTheory package can be used to explore or further modify the graph.  At any point, the name of a graph can be entered into the "Name of Graph" field of the editor and modified using its point-and-click capabilities.  

 

The following command group loads the GraphTheory package (select and execute):           

with(GraphTheory);

 

 

The Next command loads special types of graphs -- the Peterson graph, for example.

with(SpecialGraphs);

 

 

Once you've entered your graph, there are a host of GraphTheory commands that you could apply to it, such as below (click italicized commands below (a box will be drawn around the command)  and then hit enter):

 

DrawGraph(MyGraph)

 

Vertices(MyGraph)

   

Diameter(MyGraph)

 

Alternatively, you can create a graph using GraphTheory graph creation commands and then load it into the editor.  For example, select and execute the commands to the right:   NewGraph := CycleGraph(5)

 

Entering NewGraph in the Graph Name text box and pushing the Edit button loads the graph into the editor for modification.  The modifications are saved only once the Save button is selected.  

 

Alternately, you can execute the command

 

After you have loaded the GraphTheory package, you can also enter a graph creation command into the "Name of Graph" field and then click Edit to create and edit that graph.  For example, if you enter

 

CycleGraph(5)

 

into the "Name of Graph" field and press Edit, then the CycleGraph(5) command will be executed and the resulting 5-cycle graph will be available for editing.  But only after the GraphTheory package is loaded -- and the command will have to be removed before the graph can be saved! 

 

 

Extra Visualization Commands:   

In addition to the commands in the GraphTheory package, this worksheet also defines some additional visualization commands.  First, the Isolate command is of the form

 

Isolate( G, VertexSubset)

 

where G is a graph and were VertexSubset is a list or set of vertices to isolate.  This command creates a visualization with the VertexSubset as the top layer, the neighborhoods of the VertexSubset vertices as a second layer, and the remaining vertices left in the visualization currently defined for them.  Execute the following to see examples of the Isolate command.  

G := GraphTheory:-SpecialGraphs:-FosterGraph();
DrawGraph(G);

G_Isolated := Isolate( G, { 1 } );
DrawGraph(G_Isolated);

G_Isolated2 := Isolate( G, [1,2] );;
DrawGraph(G_Isolated2);

G_IsolatedMulti := Isolate(G, {1,2,3,4,5,6,7} );
DrawGraph(G_IsolatedMulti);

 

 

A related command is the GraphGroups command, which is of the form

 

GraphGroups( G, SetsOfVertexSets, opts)

 

where G is a graph, SetsOfVertexSets is a list or set of subsets of vertices, and opts is a valid option (currently, only orientation = horizontal is defined).  The GraphGroups commands visualizes a graph via groups of vertices connected to each other and to other groups.  Execute the commands below to see examples of the GraphGroups command.  

G := GraphTheory:-SpecialGraphs:-FosterGraph();
DrawGraph(G);

G_Grouped1 := GraphGroups( G, { [1,2,3,4,5],[86,87,88,89,90] } ):
DrawGraph(G_Grouped1);

G_Grouped1 := GraphGroups( G, { [seq(i,i=1..15)],[seq(i,i=15..30)],[seq(i,i=31..45)],[seq(i,i=46..60)] }, orientation=horizontal ):
DrawGraph(G_Grouped1);

 

 

 

Importing and Exporting from GraphML:   

In order to work with Cytoscape and other Graph Visualization packages, there is also a module called GraphML which exports graphs into GraphML format, and which imports graphs in GraphML format into GraphML.  By default, GraphML takes one optional argument, and if the argument is a Maple graph, then it presents a file dialogue box which allows the Maple graph to be saved as a GraphML file.  If there is no argument, then the file dialogue box opens and allows the user to choose a graphml file to import.  

 

To illustrate, we create a graph Z5 which is then made into a weighted, directed graph with different vertex and edge colors.   We then map it to a GraphML structure using GraphML:-ToGraphML, and then map the GraphML structure back to a Maple Graph using the GraphML:-FromGraphML command.

Z5 := CycleGraph(5):
Z5 := MakeDirected( Z5):
DeleteArc(Z5,{[1,2],[4,3],[5,4],[3,2]}):
Z5 := MakeWeighted( Z5 ):
SetEdgeWeight(Z5,[3,4],2.3):
SetVertexAttribute(Z5, 1, "draw-pos-fixed" = [0,0] ):
HighlightVertex(Z5,2,COLOR(RGB,1,1/2,1/3)):
HighlightVertex(Z5,1,COLOR(RGB,0.8,0.9,0.4)):
HighlightEdges(Z5,[2,3],green):
DrawGraph(Z5);
GetVertexAttribute(Z5,1);

Z5asGraphML := GraphML:-ToGraphML(Z5):
XMLTools:-Print(Z5asGraphML);

Z5FromGraphML := GraphML:-FromGraphML(Z5asGraphML);
DrawGraph(Z5FromGraphML);

 

Graphs can also be exported to GraphML files and imported from GraphML files.  Execute below to see an example.  

GraphML:-ExportGraph(Z5,"Z5.graphml");

ImportedZ5 := GraphML:-ImportGraph("Z5.graphml");
DrawGraph(ImportedZ5);

 

 

 

As mentioned above, we can accomplish the same thing by simply executing GraphML( ), either with the appropriate arguments or with no arguments (which opens a dialogue box).  

GraphML(Z5,"Z5.graphml");

 

Now execute the line below and choose the file named Z5.graphml.

GraphML();

DrawGraph(%);

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  

 

 

 

 

 

 

 

 

 

 

 

 

NULL