Algorithmic Solutions > LEDA > LEDA Guide > Graphs and Related Data Types > Example GML Format and Native File Format

Example GML Format and Native File Format

The following example shows how the GML format and the native file format for graphs can be used.

First a random Parameterized Graph with 1000 nodes and 10000 edges is generated and (dummy) values are assigned to the nodes and edges. The resulting graph is written once in GML format and once in LEDA native format and the time is measured. Afterwards both files are read again and the time is measured again. On the authors machine, writing in GML format is about two times slower than writing in native format. For reading that factor is about 25.

#include <LEDA/graph/graph.h>
#include <LEDA/graph/graph_gen.h>

using namespace leda;

int main()
  GRAPH<string,string> G;


  node v;forall_nodes(v,G) G[v]="node";
  edge e;forall_edges(e,G) G[e]="edge";

  float t_write_gml=used_time();

  float t_write_gw=used_time();


  float t_read_gml=used_time();


  float t_read_gw=used_time();""); 

  std::cout << "t_write_gml =" << t_write_gml << std::endl;
  std::cout << "t_read_gml  =" << t_read_gml  << std::endl; 
  std::cout << "t_write_gw  =" << t_write_gw  << std::endl;
  std::cout << "t_read_gw   =" << t_read_gw   << std::endl;

  return 0;

See also:

Native File Format for Graphs

GML Parser for Graphs

Graphs and Related Data Types

Manual Entries:

GML parser for Graphs

Please send any suggestions, comments or questions to
© Copyright 2001-2003, Algorithmic Solutions Software GmbH