0
3
0
... | ... |
@@ -57,43 +57,51 @@ |
57 | 57 |
|
58 | 58 |
\code |
59 | 59 |
@nodes |
60 | 60 |
label coordinates size title |
61 | 61 |
1 (10,20) 10 "First node" |
62 | 62 |
2 (80,80) 8 "Second node" |
63 | 63 |
3 (40,10) 10 "Third node" |
64 | 64 |
\endcode |
65 | 65 |
|
66 | 66 |
The \c \@arcs section is very similar to the \c \@nodes section, |
67 | 67 |
it again starts with a header line describing the names of the maps, |
68 | 68 |
but the \c "label" map is not obligatory here. The following lines |
69 | 69 |
describe the arcs. The first two tokens of each line are |
70 | 70 |
the source and the target node of the arc, respectively, then come the map |
71 | 71 |
values. The source and target tokens must be node labels. |
72 | 72 |
|
73 | 73 |
\code |
74 | 74 |
@arcs |
75 | 75 |
capacity |
76 | 76 |
1 2 16 |
77 | 77 |
1 3 12 |
78 | 78 |
2 3 18 |
79 | 79 |
\endcode |
80 | 80 |
|
81 |
The \c \@edges is just a synonym of \c \@arcs. |
|
81 |
The \c \@edges is just a synonym of \c \@arcs. The @arcs section can |
|
82 |
also store the edge set of an undirected graph. In such case there is |
|
83 |
a conventional method for store arc maps in the file, if two columns |
|
84 |
has the same caption with \c '+' and \c '-' prefix, then these columns |
|
85 |
can be regarded as the values of an arc map. |
|
82 | 86 |
|
83 | 87 |
The \c \@attributes section contains key-value pairs, each line |
84 |
consists of two tokens, an attribute name, and then an attribute |
|
88 |
consists of two tokens, an attribute name, and then an attribute |
|
89 |
value. The value of the attribute could be also a label value of a |
|
90 |
node or an edge, or even an edge label prefixed with \c '+' or \c '-', |
|
91 |
which regards to the forward or backward directed arc of the |
|
92 |
corresponding edge. |
|
85 | 93 |
|
86 | 94 |
\code |
87 | 95 |
@attributes |
88 | 96 |
source 1 |
89 | 97 |
target 3 |
90 | 98 |
caption "LEMON test digraph" |
91 | 99 |
\endcode |
92 | 100 |
|
93 | 101 |
The \e LGF can contain extra sections, but there is no restriction on |
94 | 102 |
the format of such sections. |
95 | 103 |
|
96 | 104 |
*/ |
97 | 105 |
} |
98 | 106 |
|
99 | 107 |
// LocalWords: whitespace whitespaces |
... | ... |
@@ -1205,48 +1205,54 @@ |
1205 | 1205 |
return tmp; |
1206 | 1206 |
} |
1207 | 1207 |
|
1208 | 1208 |
template <typename Graph> |
1209 | 1209 |
class GraphReader; |
1210 | 1210 |
|
1211 | 1211 |
template <typename Graph> |
1212 | 1212 |
GraphReader<Graph> graphReader(std::istream& is, Graph& graph); |
1213 | 1213 |
|
1214 | 1214 |
template <typename Graph> |
1215 | 1215 |
GraphReader<Graph> graphReader(const std::string& fn, Graph& graph); |
1216 | 1216 |
|
1217 | 1217 |
template <typename Graph> |
1218 | 1218 |
GraphReader<Graph> graphReader(const char *fn, Graph& graph); |
1219 | 1219 |
|
1220 | 1220 |
/// \ingroup lemon_io |
1221 | 1221 |
/// |
1222 | 1222 |
/// \brief \ref lgf-format "LGF" reader for undirected graphs |
1223 | 1223 |
/// |
1224 | 1224 |
/// This utility reads an \ref lgf-format "LGF" file. |
1225 | 1225 |
/// |
1226 | 1226 |
/// It can be used almost the same way as \c DigraphReader. |
1227 | 1227 |
/// The only difference is that this class can handle edges and |
1228 | 1228 |
/// edge maps as well as arcs and arc maps. |
1229 |
/// |
|
1230 |
/// The columns in the \c \@edges (or \c \@arcs) section are the |
|
1231 |
/// edge maps. However, if there are two maps with the same name |
|
1232 |
/// prefixed with \c '+' and \c '-', then these can be read into an |
|
1233 |
/// arc map. Similarly, an attribute can be read into an arc, if |
|
1234 |
/// it's value is an edge label prefixed with \c '+' or \c '-'. |
|
1229 | 1235 |
template <typename _Graph> |
1230 | 1236 |
class GraphReader { |
1231 | 1237 |
public: |
1232 | 1238 |
|
1233 | 1239 |
typedef _Graph Graph; |
1234 | 1240 |
TEMPLATE_GRAPH_TYPEDEFS(Graph); |
1235 | 1241 |
|
1236 | 1242 |
private: |
1237 | 1243 |
|
1238 | 1244 |
std::istream* _is; |
1239 | 1245 |
bool local_is; |
1240 | 1246 |
|
1241 | 1247 |
Graph& _graph; |
1242 | 1248 |
|
1243 | 1249 |
std::string _nodes_caption; |
1244 | 1250 |
std::string _edges_caption; |
1245 | 1251 |
std::string _attributes_caption; |
1246 | 1252 |
|
1247 | 1253 |
typedef std::map<std::string, Node> NodeIndex; |
1248 | 1254 |
NodeIndex _node_index; |
1249 | 1255 |
typedef std::map<std::string, Edge> EdgeIndex; |
1250 | 1256 |
EdgeIndex _edge_index; |
1251 | 1257 |
|
1252 | 1258 |
typedef std::vector<std::pair<std::string, |
... | ... |
@@ -893,48 +893,54 @@ |
893 | 893 |
return tmp; |
894 | 894 |
} |
895 | 895 |
|
896 | 896 |
template <typename Graph> |
897 | 897 |
class GraphWriter; |
898 | 898 |
|
899 | 899 |
template <typename Graph> |
900 | 900 |
GraphWriter<Graph> graphWriter(std::ostream& os, const Graph& graph); |
901 | 901 |
|
902 | 902 |
template <typename Graph> |
903 | 903 |
GraphWriter<Graph> graphWriter(const std::string& fn, const Graph& graph); |
904 | 904 |
|
905 | 905 |
template <typename Graph> |
906 | 906 |
GraphWriter<Graph> graphWriter(const char *fn, const Graph& graph); |
907 | 907 |
|
908 | 908 |
/// \ingroup lemon_io |
909 | 909 |
/// |
910 | 910 |
/// \brief \ref lgf-format "LGF" writer for directed graphs |
911 | 911 |
/// |
912 | 912 |
/// This utility writes an \ref lgf-format "LGF" file. |
913 | 913 |
/// |
914 | 914 |
/// It can be used almost the same way as \c DigraphWriter. |
915 | 915 |
/// The only difference is that this class can handle edges and |
916 | 916 |
/// edge maps as well as arcs and arc maps. |
917 |
/// |
|
918 |
/// The arc maps are written into the file as two columns, the |
|
919 |
/// caption of the columns are the name of the map prefixed with \c |
|
920 |
/// '+' and \c '-'. The arcs are written into the \c \@attributes |
|
921 |
/// section as a \c '+' or a \c '-' prefix (depends on the direction |
|
922 |
/// of the arc) and the label of corresponding edge. |
|
917 | 923 |
template <typename _Graph> |
918 | 924 |
class GraphWriter { |
919 | 925 |
public: |
920 | 926 |
|
921 | 927 |
typedef _Graph Graph; |
922 | 928 |
TEMPLATE_GRAPH_TYPEDEFS(Graph); |
923 | 929 |
|
924 | 930 |
private: |
925 | 931 |
|
926 | 932 |
|
927 | 933 |
std::ostream* _os; |
928 | 934 |
bool local_os; |
929 | 935 |
|
930 | 936 |
Graph& _graph; |
931 | 937 |
|
932 | 938 |
std::string _nodes_caption; |
933 | 939 |
std::string _edges_caption; |
934 | 940 |
std::string _attributes_caption; |
935 | 941 |
|
936 | 942 |
typedef std::map<Node, std::string> NodeIndex; |
937 | 943 |
NodeIndex _node_index; |
938 | 944 |
typedef std::map<Edge, std::string> EdgeIndex; |
939 | 945 |
EdgeIndex _edge_index; |
940 | 946 |
|
0 comments (0 inline)