1 /* -*- mode: C++; indent-tabs-mode: nil; -*-
3 * This file is a part of LEMON, a generic C++ optimization library.
5 * Copyright (C) 2003-2010
6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 * (Egervary Research Group on Combinatorial Optimization, EGRES).
9 * Permission to use, modify and distribute this software is granted
10 * provided that this copyright notice appears in all copies. For
11 * precise terms see the accompanying LICENSE file.
13 * This software is provided "AS IS" with no warranty of any kind,
14 * express or implied, and with no claim as to its suitability for any
21 [PAGE]sec_lgf[PAGE] LEMON Graph Format
23 LEMON provides a versatile file format for storing graphs and related
24 node and arc maps. Such a format should be really flexible, it should be
25 able to store arbitrary number of maps of arbitrary value types.
26 On the other hand, the file size and the ease of processing are also critical
27 to support huge graphs, which is a major goal of LEMON.
28 These requirements forbid using complicated and deeply structured formats
29 like XML. That is why a compact text file format is designed for LEMON
30 instead of using hierarchical formats (such as GraphML, GXL or GML).
32 The LEMON Graph Format (LGF) consists of several sections, for example a
33 digraph is stored in a <tt>\@nodes</tt> and an <tt>\@arcs</tt> section.
34 These parts use column oriented formats, each column belongs to a map in
35 the graph. The first line of the section associates names to these maps,
36 which can be used to refer them. Note that this simple idea makes it
37 possible to extend the files with new maps (columns) at any position
38 without having to modify the codes using these files.
39 Other data can also be added to an LGF file as individual properties
40 in an <tt>\@attributes</tt> section. This part can be used to specify
41 certain nodes or arcs, or store meta data for the file, such as copyright
44 For example, a shortest path problem, which is represented as a directed
45 graph with some node and arc maps, can be stored in LGF format as follows.
65 caption "A shortest path problem"
68 In the <tt>\@nodes</tt> section, the \c label map has special role,
69 it must store unique values, which in turn can be used to refer to the nodes
71 The first two columns of the <tt>\@arcs</tt> section are anonymous, they
72 store the source and target nodes, respectively.
74 The \ref DigraphReader and \ref DigraphWriter classes can used
75 to read and write data in LGF format.
76 For example, the above file can be read as follows.
80 ListDigraph::NodeMap<dim2::Point<int> > coord(g);
81 ListDigraph::ArcMap<int> length(g);
82 ListDigraph::Node src;
85 digraphReader(g, "digraph.lgf")
86 .nodeMap("coordinate", coord)
87 .arcMap("length", length)
89 .attribute("caption", title)
93 Note that the \ref DigraphReader class is used through the \ref digraphReader()
94 function with several named parameters.
96 \note By default, a map can be used with these classes if its value type
97 has standard I/O operators (\c operator<<(ostream&, T) and \c
98 operator>>(istream&, T&)). Otherwise, a function object can be specified
99 which converts the value type to \c std::string.
101 The following code demonstrates how the above digraph with the maps and
102 attributes can be written into the standard output in LGF Format.
105 digraphWriter(g, std::cout)
106 .nodeMap("coordinate", coord)
107 .arcMap("length", length)
109 .attribute("caption", title)
113 Apart from LGF, the library can also handle other graph
114 formats, such as the well-known DIMACS format.
116 For more information, see a more detailed \ref lgf-format
117 "description of the LGF format" and the \ref io_group module
118 in the reference manual.