The nodeset section describes the nodes of your graph: it identifies the nodes and gives the maps defined on them, if any. It starts with the following line:
@nodeset
The next line contains the names of the nodemaps, separated by whitespaces. Each following line describes a node in the graph: it contains the values of the maps in the right order. The map named "label" should contain unique values because it is regarded as a label map. These labels need not be numbers but they must identify the nodes uniquely for later reference. For example:
@nodeset label x-coord y-coord color 3 1.0 4.0 blue 5 2.3 5.7 red 12 7.8 2.3 green
The edgeset section is very similar to the nodeset section, it has the same coloumn oriented structure. It starts with the line
@edgeset
The next line contains the whitespace separated list of names of the edge maps. Each of the next lines describes one edge. The first two elements in the line are the labels of the source and target (or tail and head) nodes of the edge as they occur in the label node map of the nodeset section. You can also have an optional label map on the edges for later reference (which has to be unique in this case).
@edgeset label weight note 3 5 a 4.3 a-edge 5 12 c 2.6 c-edge 3 12 g 3.4 g-edge
The nodes section contains labeled (distinguished) nodes (i.e. nodes having a special label on them). The section starts with
@nodes
Each of the next lines contains a label for a node in the graph and then the label as described in the nodeset section.
@nodes source 3 target 12
The last section describes the labeled (distinguished) edges (i.e. edges having a special label on them). It starts with @edges
and then each line contains the name of the edge and the label.
@edges observed c
The file may contain empty lines and comment lines. The comment lines start with an #
character.
The attributes section can handle some information about the graph. It contains key-value pairs in each line (a key and the mapped value to key). The key should be a string without whitespaces, the value can be of various types.
@attributes title "Four colored planar graph" author "Balazs DEZSO" copyright "Lemon Library" version 12
Finally, the file should be closed with @end
line.
run()
method that executes all the given commands.NodeMap
or EdgeMap
writing and labeled Node and Edge writing.
GraphWriter<ListGraph> writer(std::cout, graph);
The writeNodeMap() function declares a NodeMap
writing command in the GraphWriter. You should give a name to the map and the map object as parameters. The NodeMap writing command with name "label" should write a unique map because it will be regarded as a label map.
IdMap<ListGraph, Node> nodeLabelMap; writer.writeNodeMap("label", nodeLabelMap); writer.writeNodeMap("x-coord", xCoordMap); writer.writeNodeMap("y-coord", yCoordMap); writer.writeNodeMap("color", colorMap);
With the writeEdgeMap() member function you can give an edge map writing command similar to the NodeMaps.
DescriptorMap<ListGraph, Edge, ListGraph::EdgeMap<int> > edgeDescMap(graph); writer.writeEdgeMap("descriptor", edgeDescMap); writer.writeEdgeMap("weight", weightMap); writer.writeEdgeMap("note", noteMap);
With writeNode() and writeEdge() functions you can designate Nodes and Edges in the graph. For example, you can write out the source and target node of a maximum flow instance.
writer.writeNode("source", sourceNode); writer.writeNode("target", targetNode); writer.writeEdge("observed", edge);
With writeAttribute() function you can write an attribute to the file.
writer.writeAttribute("author", "Balazs DEZSO"); writer.writeAttribute("version", 12);
After you give all write commands you must call the run() member function, which executes all the writing commands.
writer.run();
The reader object assumes that each not read value does not contain whitespaces, therefore it has some extra possibilities to control how it should skip the values when the string representation contains spaces.
GraphReader<ListGraph> reader(std::cin, graph);
The readNodeMap() function reads a map from the nodeset
section. If there is a map that you do not want to read from the file and there are whitespaces in the string represenation of the values then you should call the skipNodeMap() template member function with proper parameters.
reader.readNodeMap("x-coord", xCoordMap); reader.readNodeMap("y-coord", yCoordMap); reader.readNodeMap<QuotedStringReader>("label", labelMap); reader.skipNodeMap<QuotedStringReader>("description"); reader.readNodeMap("color", colorMap);
With the readEdgeMap() member function you can give an edge map reading command similar to the NodeMaps.
reader.readEdgeMap("weight", weightMap); reader.readEdgeMap("label", labelMap);
With readNode() and readEdge() functions you can read labeled Nodes and Edges.
reader.readNode("source", sourceNode); reader.readNode("target", targetNode); reader.readEdge("observed", edge);
With readAttribute() function you can read an attribute from the file.
std::string author; writer.readAttribute("author", author); int version; writer.writeAttribute("version", version);
After you give all read commands you must call the run() member function, which executes all the commands.
reader.run();
If you want to lear more, read the background technics.