GraphTheory - Maple Programming Help

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : Mathematics : Discrete Mathematics : Graph Theory : GraphTheory Package : GraphTheory/ImportGraph

GraphTheory

  

ImportGraph

  

ExportGraph

 

Calling Sequence

Parameters

Description

Examples

Calling Sequence

ImportGraph(filename, format, out)

ExportGraph(G, filename, format)

ExportGraph(G, filename, format, append)

Parameters

G

-

graph, list of graphs, or graph generating function

filename

-

string, symbol, or function

format

-

symbol or string

out

-

equation of the form output = graph or list, or iterator

Description

• 

ImportGraph reads one or more graphs from a file. For a file containing a single graph, the supported formats are `dimacs`, `dimacs_relaxed`, `combinatorica`, `dot`, `edges`, `graphlet`, `graphml`, `gxl`, `leda`, `pajek`, and `tgf`. For a file containing multiple graphs, the supported formats are `sparse6` and `graph6`.  The `sparse6` and `graph6` formats encode the graph in ascii text.  These two formats are much more compact than the other formats.

• 

The list and iterator output forms only apply to the case of a file with multiple graphs. The list output form returns a list of all graphs in the file, and the iterator output form returns a procedure that generates all the graphs in the file one at a time. For the iterator, the returned procedure called with no arguments simply outputs the next graph, returning FAIL after the final graph in the file has been output.

  

Note: The list of graphs and graph generating function forms for G only apply to the multiple graph per file formats.

• 

ExportGraph writes one or more graphs to a file using the specified format. For exporting a single graph to a file, the supported formats are `dimacs` (only for undirected unweighted graphs), `combinatorica` (only for undirected unweighted graphs), edges (only for undirected unweighted graphs), `metapost`, `dot`, `graphlet`, `graphml`, `gxl`, `leda`, `pajek`, and `tgf`. For exporting multiple graphs to a file, the supported formats are `sparse6` and `graph6`, and these can be mixed in a file (either being valid to specify reading both formats).  

• 

The literal `append` specifies that the graph(s) should be appended to the specified file, while by default the file is simply overwritten.

• 

To export a graph in Maple's format, use the save command. This saves the entire Maple data structure to a file, including vertex positions (used for drawing) and highlighted vertices. To read it back in later, use the read command.

Examples

 

 

File "K4" created in edges format

This creates the file "K4" in the current working directory (see currentdir). The file looks like this

4

6

1 2   1 3   1 4   2 3   2 4   3 4

3 4

The first integer 4 is the number of vertices.  The second integer 6 is the number of edges. This is followed by the edges on multiple lines with more than one edge per line. To read the graph back into Maple you would do

 

 

 

PGraph 1: an undirected unweighted graph with 10 vertices and 15 edge(s)

(1)

 

File "Graph1.mp" created in metapost format

This creates the file "Graph1.mp" in the current working directory (see currentdir).  In Unix, the "mpost" command can then be used to convert a metapost file to PostScript, for inclusion in a LaTeX document.

 

 

 

We have highlighted the star in the Petersen graph and saved it to a file "petersen.txt" in the current working directory.  When the file is read, the graph will be reloaded (in the variable P) with the highlighting intact.

 

 

 

See Also

Graph

read

save