TGF (.tgf)

Background & Context

    • TGF graph data format.
    • Used for the storage and exchange of graphs.
    • TGF is an acronym for Trivial Graph Format.
    • Stores directed graphs.
    • Stores at most one label per vertex and edge.
    • ASCII format.

Import & Export

  • Import["file.tgf"] imports the graph stored in the specified file, given as a single Graph object.
  • Export["file.tgf",expr] exports an adjacency matrix or edge information for one graph to the TGF format.
  • Import["file.tgf",elem] imports the specified element from a TGF file.
  • Import["file.tgf",{elem,suba,subb,}] imports a subelement.
  • Import["file.tgf",{{elem1,elem2,}}] imports multiple elements.
  • The import format can be specified with Import["file","TGF"] or Import["file",{"TGF",elem,}].
  • Export["file.tgf",expr,elem] creates a TGF file by treating expr as specifying element elem.
  • Export["file.tgf",{expr1,expr2,},{{elem1,elem2,}}] treats each expri as specifying the corresponding elemi.
  • Export["file.tgf",expr,opt1->val1,] exports expr with the specified option elements taken to have the specified values.
  • Export["file.tgf",{elem1->expr1,elem2->expr2,},"Rules"] uses rules to specify the elements to be exported.
  • See the following reference pages for full general information:
  • Import, Exportimport from or export to a file
    CloudImport, CloudExportimport from or export to a cloud object
    ImportString, ExportStringimport from or export to a string
    ImportByteArray, ExportByteArrayimport from or export to a byte array

Import Elements

  • General Import elements:
  • "Elements" list of elements and options available in this file
    "Summary"summary of the file
    "Rules"list of rules for all available elements
  • Data representation elements:
  • "AdjacencyMatrix"edge information, given as a matrix
    "EdgeAttributes"edge attributes, represented as a list of rules
    "EdgeRules"connectivity data for the graph, given as a list of rules
    "Graph"graph stored in the file, rendered as a Graph object
    "Graphics"graph stored in the file, rendered as a graph plot
    "VertexAttributes"vertex attributes, represented as a list of rules
    "VertexCount"number of vertices in the graph
    "VertexList"vertices, given as a list of strings
  • Import by default uses the "Graph" element when importing from TGF.

Options

Examples

open allclose all

Basic Examples  (5)

Import a graph from TGF, giving a visual representation:

Export a Graph object to the TGF format:

Export a list of edge rules representing a directed graph to TGF:

Export an asymmetric adjacency matrix to TGF:

Render an adjacency matrix representation of a TGF graph as a MatrixPlot:

Scope  (2)

Export a list of edge rules and attributes to TGF:

Export an adjacency matrix together with vertex labels and attributes: