1 | /* -*- mode: C++; indent-tabs-mode: nil; -*- |
---|
2 | * |
---|
3 | * This file is a part of LEMON, a generic C++ optimization library. |
---|
4 | * |
---|
5 | * Copyright (C) 2003-2010 |
---|
6 | * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
---|
7 | * (Egervary Research Group on Combinatorial Optimization, EGRES). |
---|
8 | * |
---|
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. |
---|
12 | * |
---|
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 |
---|
15 | * purpose. |
---|
16 | * |
---|
17 | */ |
---|
18 | |
---|
19 | namespace lemon { |
---|
20 | /** |
---|
21 | [PAGE]sec_lgf[PAGE] LEMON Graph Format |
---|
22 | |
---|
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). |
---|
31 | |
---|
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 |
---|
42 | notice. |
---|
43 | |
---|
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. |
---|
46 | |
---|
47 | \code |
---|
48 | @nodes |
---|
49 | label coordinate |
---|
50 | 0 (20,100) |
---|
51 | 1 (40,120) |
---|
52 | ... |
---|
53 | 41 (600,100) |
---|
54 | |
---|
55 | @arcs |
---|
56 | label length |
---|
57 | 0 1 0 16 |
---|
58 | 0 2 1 12 |
---|
59 | 2 12 2 20 |
---|
60 | ... |
---|
61 | 36 41 123 21 |
---|
62 | |
---|
63 | @attributes |
---|
64 | source 0 |
---|
65 | caption "A shortest path problem" |
---|
66 | \endcode |
---|
67 | |
---|
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 |
---|
70 | in the file. |
---|
71 | The first two columns of the <tt>\@arcs</tt> section are anonymous, they |
---|
72 | store the source and target nodes, respectively. |
---|
73 | |
---|
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. |
---|
77 | |
---|
78 | \code |
---|
79 | ListDigraph g; |
---|
80 | ListDigraph::NodeMap<dim2::Point<int> > coord(g); |
---|
81 | ListDigraph::ArcMap<int> length(g); |
---|
82 | ListDigraph::Node src; |
---|
83 | std::string title; |
---|
84 | |
---|
85 | digraphReader(g, "digraph.lgf") |
---|
86 | .nodeMap("coordinate", coord) |
---|
87 | .arcMap("length", length) |
---|
88 | .node("source", src) |
---|
89 | .attribute("caption", title) |
---|
90 | .run(); |
---|
91 | \endcode |
---|
92 | |
---|
93 | Note that the \ref DigraphReader class is used through the \ref digraphReader() |
---|
94 | function with several named parameters. |
---|
95 | |
---|
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. |
---|
100 | |
---|
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. |
---|
103 | |
---|
104 | \code |
---|
105 | digraphWriter(g, std::cout) |
---|
106 | .nodeMap("coordinate", coord) |
---|
107 | .arcMap("length", length) |
---|
108 | .node("source", src) |
---|
109 | .attribute("caption", title) |
---|
110 | .run(); |
---|
111 | \endcode |
---|
112 | |
---|
113 | Apart from LGF, the library can also handle other graph |
---|
114 | formats, such as the well-known DIMACS format. |
---|
115 | |
---|
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. |
---|
119 | |
---|
120 | [TRAILER] |
---|
121 | */ |
---|
122 | } |
---|