
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 dgml, dimacs, dimacs_relaxed, combinatorica, dot, edges, gexf, graphlet, graphml, gxl, jgf, leda, pajek, tgf, and tsplib. For a file containing multiple graphs, the supported formats are digraph6, graph6, and sparse6. These formats encode the graph in ascii text and 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, dgml, dot, gexf, graphlet, graphml, gxl, jgf, leda, pajek, and tgf. For exporting multiple graphs to a file, the supported formats are digraph6, graph6, and sparse6, and these can be mixed in a file (any of these being valid to specify reading any of these 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


>

$\mathrm{with}\left(\mathrm{GraphTheory}\right)\:$

>

$\mathrm{ExportGraph}\left(\mathrm{CompleteGraph}\left(4\right)\,''K4''\,\mathrm{edges}\right)$

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
>

$G\u2254\mathrm{ImportGraph}\left(\mathrm{K4}\,\mathrm{edges}\right)$

>

$\mathrm{with}\left(\mathrm{SpecialGraphs}\right)\:$

>

$P\u2254\mathrm{PetersenGraph}\left(\right)$

${P}{\u2254}{\mathrm{Graph\; 1:\; an\; undirected\; unweighted\; graph\; with\; 10\; vertices\; and\; 15\; edge(s)}}$
 (1) 
>

$\mathrm{ExportGraph}\left(P\,''Graph1.mp''\,'\mathrm{metapost}'\right)$

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.
>

$\mathrm{HighlightSubgraph}\left(P\,\mathrm{InducedSubgraph}\left(P\,\left[6\,7\,8\,9\,10\right]\right)\right)$

>

$\mathrm{DrawGraph}\left(P\right)$

>

$\mathbf{save}\phantom{\rule[0.0ex]{0.3em}{0.0ex}}P,''petersen.txt''\:$

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.
>

$\mathbf{read}\phantom{\rule[0.0ex]{0.3em}{0.0ex}}''petersen.txt''\:$

>

$\mathrm{DrawGraph}\left(P\right)$



Compatibility


•

The GraphTheory[ImportGraph] and GraphTheory[ExportGraph] commands were updated in Maple 2018.

•

The format parameter was updated in Maple 2018.




