DigraphReader

Declared in lemon/lgf_reader.h, in the group LEMON Graph Format; the same class on the Doxygen site.

template< typename DGR >
class DigraphReader

LGF reader for directed graphs

This utility reads an LGF file.

The reading method does a batch processing. The user creates a reader object, then various reading rules can be added to the reader, and eventually the reading is executed with the run() member function. A map reading rule can be added to the reader with the nodeMap() or arcMap() members. An optional converter parameter can also be added as a standard functor converting from std::string to the value type of the map. If it is set, it will determine how the tokens in the file should be converted to the value type of the map. If the functor is not set, then a default conversion will be used. One map can be read into multiple map objects at the same time. The attribute(), node() and arc() functions are used to add attribute reading rules.

DigraphReader< DGR >( digraph , std::cin )
  .nodeMap( "coordinates" , coord_map )
  .arcMap( "capacity" , cap_map )
  .node( "source" , src )
  .node( "target" , trg )
  .attribute( "caption" , caption )
  .run();

By default, the reader uses the first section in the file of the proper type. If a section has an optional name, then it can be selected for reading by giving an optional name parameter to the nodes(), arcs() or attributes() functions.

The useNodes() and useArcs() functions are used to tell the reader that the nodes or arcs should not be constructed (added to the graph) during the reading, but instead the label map of the items are given as a parameter of these functions. An application of these functions is multipass reading, which is important if two @arcs sections must be read from the file. In this case the first phase would read the node set and one of the arc sets, while the second phase would read the second arc set into an ArcSet class (SmartArcSet or ListArcSet). The previously read label node map should be passed to the useNodes() functions. Another application of multipass reading when paths are given as a node map or an arc map. It is impossible to read this in a single pass, because the arcs are not constructed when the node maps are read.

Reading Rules

template< typename Map >
inline DigraphReader & nodeMap(
const std::string & caption,
Map & map
)

Node map reading rule.

Add a node map reading rule to the reader.

template< typename Map , typename Converter >
inline DigraphReader & nodeMap(
const std::string & caption,
Map & map,
const Converter & converter = Converter()
)

Node map reading rule.

Add a node map reading rule with specialized converter to the reader.

template< typename Map >
inline DigraphReader & arcMap(
const std::string & caption,
Map & map
)

Arc map reading rule.

Add an arc map reading rule to the reader.

template< typename Map , typename Converter >
inline DigraphReader & arcMap(
const std::string & caption,
Map & map,
const Converter & converter = Converter()
)

Arc map reading rule.

Add an arc map reading rule with specialized converter to the reader.

template< typename Value >
inline DigraphReader & attribute(
const std::string & caption,
Value & value
)

Attribute reading rule.

Add an attribute reading rule to the reader.

template< typename Value , typename Converter >
inline DigraphReader & attribute(
const std::string & caption,
Value & value,
const Converter & converter = Converter()
)

Attribute reading rule.

Add an attribute reading rule with specialized converter to the reader.

inline DigraphReader & node( const std::string & caption , Node & node )

Node reading rule.

Add a node reading rule to reader.

inline DigraphReader & arc( const std::string & caption , Arc & arc )

Arc reading rule.

Add an arc reading rule to reader.

Select Section by Name

inline DigraphReader & nodes( const std::string & caption )

Set @nodes section to be read

inline DigraphReader & arcs( const std::string & caption )

Set @arcs section to be read

inline DigraphReader & attributes( const std::string & caption )

Set @attributes section to be read

Using Previously Constructed Node or Arc Set

template< typename Map >
inline DigraphReader & useNodes( const Map & map )

Use previously constructed node set.

Use previously constructed node set, and specify the node label map.

template< typename Map , typename Converter >
inline DigraphReader & useNodes(
const Map & map,
const Converter & converter = Converter()
)

Use previously constructed node set.

Use previously constructed node set, and specify the node label map and a functor which converts the label map values to std::string.

template< typename Map >
inline DigraphReader & useArcs( const Map & map )

Use previously constructed arc set.

Use previously constructed arc set, and specify the arc label map.

template< typename Map , typename Converter >
inline DigraphReader & useArcs(
const Map & map,
const Converter & converter = Converter()
)

Use previously constructed arc set.

Use previously constructed arc set, and specify the arc label map and a functor which converts the label map values to std::string.

inline DigraphReader & skipNodes()

Skips the reading of node section.

Omit the reading of the node section. This implies that each node map reading rule will be abandoned, and the nodes of the graph will not be constructed, which usually cause that the arc set could not be read due to lack of node name resolving. Therefore skipArcs() function should also be used, or useNodes() should be used to specify the label of the nodes.

inline DigraphReader & skipArcs()

Skips the reading of arc section.

Omit the reading of the arc section. This implies that each arc map reading rule will be abandoned, and the arcs of the graph will not be constructed.

Execution of the Reader

inline void run()

Start the batch processing.

This function starts the batch processing

Public Types

typedef DGR Digraph

Public Functions

inline DigraphReader( DGR & digraph , std::istream & is = std::cin )

Constructor.

Construct a directed graph reader, which reads from the given input stream.

inline DigraphReader( DGR & digraph , const std::string & fn )

Constructor.

Construct a directed graph reader, which reads from the given file.

inline DigraphReader( DGR & digraph , const char * fn )

Constructor.

Construct a directed graph reader, which reads from the given file.

inline ~DigraphReader()

Destructor.

template< typename TDGR >
DigraphReader< TDGR > digraphReader(
TDGR & digraph,
const std::string & fn
)

Return a DigraphReader class.

This function just returns a DigraphReader class.

See also

digraphReader( TDGR & digraph , std::istream & is )

template< typename TDGR >
DigraphReader< TDGR > digraphReader(
TDGR & digraph,
const char * fn
)

Return a DigraphReader class.

This function just returns a DigraphReader class.

See also

digraphReader( TDGR & digraph , std::istream & is )