Wolfram Demonstrations Project
7717

Constructing and Manipulating Graphs

This Demonstration lets you create and manipulate any undirected and directed graphs (including even bidirectional arrows and loops).
This is facilitated by a range of edit and display options that you can select, such as "distance" (i.e., degree of separation).
You can drag the vertices and the connecting edges will follow. You can add and delete, even split and join vertices!
You can also let the system find the shortest path between two points or the shortest closed path containing a given edge.
Each vertex and edge can have its own color. Vertices are numbered automatically and can carry text labels.
As an application, you are asked to find nice embeddings of five cubic graphs.

SNAPSHOTS

  • [Snapshot]
  • [Snapshot]
  • [Snapshot]
  • [Snapshot]

DETAILS

Motivation
While there are already many other Demonstrations about two-dimensional graphs, none of them allows you to freely create, color, and manipulate graphs.
Basic options
The options "store" and "restore" allow you to keep a backup version of your graph in memory. Note that the default setup is already stored in the backup (hit "clear" and then "restore" to test it).
Hitting "clear" leaves only one vertex.
The options "N","S","E","W" shift the whole graph to the North, South, East or West, one unit at a time.
The option "<" decreases the size of the graph by ten percent; the option ">" enlarges it.
You can add a new vertex at any time with Command+Click (Alt+Click on Windows or Option+Click on the Mac). You can also delete an existing vertex with Command+Click.
Warning: Do not create new vertices too quickly, since this can lead to system errors.
The option "X" switches the display of the axes on and off.
The drop-down menu "rotate" lets you rotate the graph around the "from" vertex.
The "grid" drop-down menu options let you choose between a rectangular grid and an isometric grid (the latter allows regular triangles and hexagons to be drawn since snap points are distanced accordingly).
The "directed" option
Select "yes" to show arrows. (See "edges" below to find out how to create bidirectional arrows).
Select "highlight bidir" to additionally display all bidirectional arrows in red color.
Notation (the "show" option)
Here you can select several types of notation or labels for the vertices and edges.
The option "vertex labels" displays text for each vertex; this text can be edited with the "label" feature (see below).
You can show the "degrees" of the vertices; the degree of a vertex is the number of edges connected to it.
With "distance (vertex)" you can show the graph distance (degree of separation) of each vertex in relation to the selected "from" vertex. Note that the degree of separation on a directed graph is different from the one on an undirected graph (click "directed" to switch between these cases).
The option "edge numbers" will show the edge numbers at the centre of the edges.
The option "distance (edge)" shows how far an edge is from the "from" vertex. (The distance of an edge is calculated as the minimum of the distances of its endpoints).
The option "number offset" lets you choose where the notation should be in relation to the vertices and edges (North, South, etc).
Editing vertex labels
Select the option "show vertex labels" first. Select the vertex whose label you want to edit ("from" parameter).
Now selecting the label option "-" deletes the vertices' label. The option "=" deletes all labels. The option "+" copies the label of the "from" vertex to all vertices without a label. Selecting a letter will cause the letter to be joined to the end of the label word, as a typewriter would.
Color code drop-down menu
The option "degree (vertex)" color-codes all vertices according to their degree, that is, by the number of edges converging to the vertex (the degrees 0, 1, 2, 3, 4, 5, 6, >6, correspond to the colors red, orange, green, cyan, blue, purple, gray, black).
The option "distance (vertex)" color-codes all vertices according to their graph-distance from the "from" vertex (the distances 0, 1, 2, 3, 4, 5, >5, ∞ correspond to the colors red, orange, cyan, green, blue, purple, gray, black).
The degree of separation on a directed graph is different from the one on an undirected graph (click "directed" to switch between these cases).
The special case ∞ (color-coded black) denotes all parts of the graph that cannot be reached at all from the "from" vertex.
The option "distance (v,e)" color-codes all vertices and edges according to their graph-distance from the "from" vertex.
The option "shortest path" finds the shortest path (if there is one) from "from" vertex to "to" vertex.
The option "short path tree" displays a tree of shortest paths from the "from" vertex to all the other vertices. The "to" parameter is ignored here.
The option "shortest loop" finds the shortest closed path (if there is one) that contains the line from the "from" vertex to the "to" vertex.
Vertices
Select the correct "from" vertex number to select a vertex.
Color the vertex with the "col" option. The option "c e" re-colors all edges (!) connected to the selected vertex. The option "c r" recolors all vertices with numbers in the range between "from" and "to". You might have to switch off the automatic color coding (described above) first.
The option "s" splits a vertex into two vertices, with the new vertex having the same connections to other vertices.
The option "u" unites the two vertices selected in "from" and "to", with the new vertex having the sum of the connections.
"del" deletes the selected vertex. The option "d r" deletes all vertices with numbers in the range between "from" and "to".
If you delete a vertex, the remaining vertices are renumbered. For technical reasons you cannot delete the last remaining vertex. Therefore the "clear" option leaves a single vertex at the bottom-left corner.
Edges
Select the correct "from" and "to" vertex numbers to add an edge ("+").
If "from" is the same as "to", a little loop will be created. The small loop will be created using the opposite of the "number offset". Hence if "number offset" is S (South), then the loop will be to the North of the vertex. This keeps numbers and loops separate for better readability.
To reverse the direction of an arrow click "r"; to delete an edge click "d".
Clicking "+" for an EXISTING edge switches an arrow from unidirectional to bidirectional and vice versa. (By the way: in directional graphs the edges are called "arcs".)
The option "rf" deletes all edges connected to the "from" vertex.
The option "r*" reverses all edge directions. The direction of an edge is only visible when you select the "directed" option. In this Demonstration either all edges of a graph have directions or none have. A graph with directions is called a directed graph.
The option "c" re-colors the selected edge. You might have to switch off the automatic color coding (described above) first.
Coloring of all edges connected to the "from" vertex is covered above in the paragraph "Vertices".
The option "c*" recolors all edges with the given edge color.
The option "d" deletes the selected edge.
The option "df" deletes all edges connected to the "from" vertex.
The option "dr" deletes all edges converging at any vertex of the selected range 'from', …, 'to'.
Add a formation
Often graphs in science are presented as a linear or circular arrangement of vertices. For this reason this Demonstration offers a convenient tool to create such arrangements with a single mouse click:
The "circles of dots" option creates a circular arrangement of vertices around the "from" vertex.
The "circles with lines" option creates a ring of vertices and edges around the "from" vertex.
The option "complete circle" creates a circular arrangement of vertices around the "from" vertex, where all additional vertices are connected with each other (but not with the center; use the "connect to" option for this, see further down).
The variables "amount" and "radius" define the number of new vertices and their distance from the "from" vertex.
There are many more formations available; try them out!
The special option "complete graph" does not add any vertices, it rather adds all missing edges between any existing vertices.
The options "midpoints from-to" adds one or more ("amount") equidistant vertices to the existing edge given by the "from" and "to" parameters. The parameter "radius" is not used for the midpoints.
If the option "connect to" is selected, then all new vertices of the added formation will be additionally connected to the selected vertex. However, the option "complete graph" does not use this parameter; all other formations can use it.
Add a new vertex
You can add a new vertex at any time with Command+Click (Alt+Click on Windows or Option+Click on the Mac).
(You can also delete an existing vertex with Command+Click.)
Several options let you connect this new vertex automatically to existing vertices:
In the "connect to" drop-down menu you can choose "last" to automatically connect the new vertex to the "last" vertex created (the one with the highest number), or choose "from" to automatically connect to the "from" vertex or choose "from,to" to connect to both the "from" and "to" vertex. You can also choose to connect to a range of vertices or to all vertices.
Given examples
Graph 1 shows a nice embedding of a cubic graph with six crossings found by Ed Pegg Jr.
Graphs 2 to 6 show various graphs where you can try to find a nice representation similar to the one given in graph 1. The graph should be very symmetric or with minimum crossings (or both).
Graph 7 is a special default setup (with vertices arranged in two straight lines) that you can use to develop your own graphs. You can create similar setups with the special formation "rectangle".

RELATED LINKS

Use this code to add a screen shot with a link to this Demonstration to your site.
Interactive embeds coming soon!

Files require Wolfram CDF Player or Mathematica.









 
RELATED RESOURCES
Mathematica »
The #1 tool for creating Demonstrations
and anything technical.
Wolfram|Alpha »
Explore anything with the first
computational knowledge engine.
MathWorld »
The web's most extensive
mathematics resource.
Course Assistant Apps »
An app for every course—
right in the palm of your hand.
Wolfram Blog »
Read our views on math,
science, and technology.
Computable Document Format »
The format that makes Demonstrations
(and any information) easy to share and interact with.
STEM Initiative »
Programs & resources for
educators, schools & students.
Computerbasedmath.org »
Join the initiative for modernizing
math education.
Powered by Wolfram Mathematica © 2012 Wolfram Demonstrations Project & Contributors  |  Terms of Use  |  Privacy Policy  |  RSS Give us your feedback
Note: To run this Demonstration you need Mathematica 7+ or the free Mathematica Player 7EX
Download or upgrade to Mathematica Player 7EX
I already have Mathematica Player or Mathematica 7+