Index: lemon/full_graph.h
===================================================================
--- lemon/full_graph.h	(revision 1188)
+++ lemon/full_graph.h	(revision 1192)
@@ -992,4 +992,7 @@
     }
 
+    using Parent::redNode;
+    using Parent::blueNode;
+
     /// \brief Returns the red node with the given index.
     ///
Index: lemon/lgf_reader.h
===================================================================
--- lemon/lgf_reader.h	(revision 1110)
+++ lemon/lgf_reader.h	(revision 1192)
@@ -2129,4 +2129,1044 @@
   }
 
+  template <typename BGR>
+  class BpGraphReader;
+
+  template <typename TBGR>
+  BpGraphReader<TBGR> bpGraphReader(TBGR& graph, std::istream& is = std::cin);
+  template <typename TBGR>
+  BpGraphReader<TBGR> bpGraphReader(TBGR& graph, const std::string& fn);
+  template <typename TBGR>
+  BpGraphReader<TBGR> bpGraphReader(TBGR& graph, const char *fn);
+
+  /// \ingroup lemon_io
+  ///
+  /// \brief \ref lgf-format "LGF" reader for bipartite graphs
+  ///
+  /// This utility reads an \ref lgf-format "LGF" file.
+  ///
+  /// It can be used almost the same way as \c GraphReader, but it
+  /// reads the red and blue nodes from separate sections, and these
+  /// sections can contain different set of maps.
+  ///
+  /// The red and blue maps are read from the corresponding
+  /// sections. If a map is defined with the same name in both of
+  /// these sections, then it can be read as a node map.
+  template <typename BGR>
+  class BpGraphReader {
+  public:
+
+    typedef BGR Graph;
+
+  private:
+
+    TEMPLATE_BPGRAPH_TYPEDEFS(BGR);
+
+    std::istream* _is;
+    bool local_is;
+    std::string _filename;
+
+    BGR& _graph;
+
+    std::string _nodes_caption;
+    std::string _edges_caption;
+    std::string _attributes_caption;
+
+    typedef std::map<std::string, Node> NodeIndex;
+    NodeIndex _node_index;
+    typedef std::map<std::string, Edge> EdgeIndex;
+    EdgeIndex _edge_index;
+
+    typedef std::vector<std::pair<std::string,
+      _reader_bits::MapStorageBase<Node>*> > NodeMaps;
+    NodeMaps _red_maps;
+    NodeMaps _blue_maps;
+
+    typedef std::vector<std::pair<std::string,
+      _reader_bits::MapStorageBase<Edge>*> > EdgeMaps;
+    EdgeMaps _edge_maps;
+
+    typedef std::multimap<std::string, _reader_bits::ValueStorageBase*>
+      Attributes;
+    Attributes _attributes;
+
+    bool _use_nodes;
+    bool _use_edges;
+
+    bool _skip_nodes;
+    bool _skip_edges;
+
+    int line_num;
+    std::istringstream line;
+
+  public:
+
+    /// \brief Constructor
+    ///
+    /// Construct an undirected graph reader, which reads from the given
+    /// input stream.
+    BpGraphReader(BGR& graph, std::istream& is = std::cin)
+      : _is(&is), local_is(false), _graph(graph),
+        _use_nodes(false), _use_edges(false),
+        _skip_nodes(false), _skip_edges(false) {}
+
+    /// \brief Constructor
+    ///
+    /// Construct an undirected graph reader, which reads from the given
+    /// file.
+    BpGraphReader(BGR& graph, const std::string& fn)
+      : _is(new std::ifstream(fn.c_str())), local_is(true),
+        _filename(fn), _graph(graph),
+        _use_nodes(false), _use_edges(false),
+        _skip_nodes(false), _skip_edges(false) {
+      if (!(*_is)) {
+        delete _is;
+        throw IoError("Cannot open file", fn);
+      }
+    }
+
+    /// \brief Constructor
+    ///
+    /// Construct an undirected graph reader, which reads from the given
+    /// file.
+    BpGraphReader(BGR& graph, const char* fn)
+      : _is(new std::ifstream(fn)), local_is(true),
+        _filename(fn), _graph(graph),
+        _use_nodes(false), _use_edges(false),
+        _skip_nodes(false), _skip_edges(false) {
+      if (!(*_is)) {
+        delete _is;
+        throw IoError("Cannot open file", fn);
+      }
+    }
+
+    /// \brief Destructor
+    ~BpGraphReader() {
+      for (typename NodeMaps::iterator it = _red_maps.begin();
+           it != _red_maps.end(); ++it) {
+        delete it->second;
+      }
+
+      for (typename NodeMaps::iterator it = _blue_maps.begin();
+           it != _blue_maps.end(); ++it) {
+        delete it->second;
+      }
+
+      for (typename EdgeMaps::iterator it = _edge_maps.begin();
+           it != _edge_maps.end(); ++it) {
+        delete it->second;
+      }
+
+      for (typename Attributes::iterator it = _attributes.begin();
+           it != _attributes.end(); ++it) {
+        delete it->second;
+      }
+
+      if (local_is) {
+        delete _is;
+      }
+
+    }
+
+  private:
+    template <typename TBGR>
+    friend BpGraphReader<TBGR> bpGraphReader(TBGR& graph, std::istream& is);
+    template <typename TBGR>
+    friend BpGraphReader<TBGR> bpGraphReader(TBGR& graph,
+                                             const std::string& fn);
+    template <typename TBGR>
+    friend BpGraphReader<TBGR> bpGraphReader(TBGR& graph, const char *fn);
+
+    BpGraphReader(BpGraphReader& other)
+      : _is(other._is), local_is(other.local_is), _graph(other._graph),
+        _use_nodes(other._use_nodes), _use_edges(other._use_edges),
+        _skip_nodes(other._skip_nodes), _skip_edges(other._skip_edges) {
+
+      other._is = 0;
+      other.local_is = false;
+
+      _node_index.swap(other._node_index);
+      _edge_index.swap(other._edge_index);
+
+      _red_maps.swap(other._red_maps);
+      _blue_maps.swap(other._blue_maps);
+      _edge_maps.swap(other._edge_maps);
+      _attributes.swap(other._attributes);
+
+      _nodes_caption = other._nodes_caption;
+      _edges_caption = other._edges_caption;
+      _attributes_caption = other._attributes_caption;
+
+    }
+
+    BpGraphReader& operator=(const BpGraphReader&);
+
+  public:
+
+    /// \name Reading Rules
+    /// @{
+
+    /// \brief Node map reading rule
+    ///
+    /// Add a node map reading rule to the reader.
+    template <typename Map>
+    BpGraphReader& nodeMap(const std::string& caption, Map& map) {
+      checkConcept<concepts::WriteMap<Node, typename Map::Value>, Map>();
+      _reader_bits::MapStorageBase<Node>* red_storage =
+        new _reader_bits::MapStorage<Node, Map>(map);
+      _red_maps.push_back(std::make_pair(caption, red_storage));
+      _reader_bits::MapStorageBase<Node>* blue_storage =
+        new _reader_bits::MapStorage<Node, Map>(map);
+      _blue_maps.push_back(std::make_pair(caption, blue_storage));
+      return *this;
+    }
+
+    /// \brief Node map reading rule
+    ///
+    /// Add a node map reading rule with specialized converter to the
+    /// reader.
+    template <typename Map, typename Converter>
+    BpGraphReader& nodeMap(const std::string& caption, Map& map,
+                           const Converter& converter = Converter()) {
+      checkConcept<concepts::WriteMap<Node, typename Map::Value>, Map>();
+      _reader_bits::MapStorageBase<Node>* red_storage =
+        new _reader_bits::MapStorage<Node, Map, Converter>(map, converter);
+      _red_maps.push_back(std::make_pair(caption, red_storage));
+      _reader_bits::MapStorageBase<Node>* blue_storage =
+        new _reader_bits::MapStorage<Node, Map, Converter>(map, converter);
+      _blue_maps.push_back(std::make_pair(caption, blue_storage));
+      return *this;
+    }
+
+    /// Add a red map reading rule to the reader.
+    template <typename Map>
+    BpGraphReader& redMap(const std::string& caption, Map& map) {
+      checkConcept<concepts::WriteMap<Node, typename Map::Value>, Map>();
+      _reader_bits::MapStorageBase<Node>* storage =
+        new _reader_bits::MapStorage<Node, Map>(map);
+      _red_maps.push_back(std::make_pair(caption, storage));
+      return *this;
+    }
+
+    /// \brief Red map reading rule
+    ///
+    /// Add a red map reading rule with specialized converter to the
+    /// reader.
+    template <typename Map, typename Converter>
+    BpGraphReader& redMap(const std::string& caption, Map& map,
+                          const Converter& converter = Converter()) {
+      checkConcept<concepts::WriteMap<Node, typename Map::Value>, Map>();
+      _reader_bits::MapStorageBase<Node>* storage =
+        new _reader_bits::MapStorage<Node, Map, Converter>(map, converter);
+      _red_maps.push_back(std::make_pair(caption, storage));
+      return *this;
+    }
+
+    /// Add a blue map reading rule to the reader.
+    template <typename Map>
+    BpGraphReader& blueMap(const std::string& caption, Map& map) {
+      checkConcept<concepts::WriteMap<Node, typename Map::Value>, Map>();
+      _reader_bits::MapStorageBase<Node>* storage =
+        new _reader_bits::MapStorage<Node, Map>(map);
+      _blue_maps.push_back(std::make_pair(caption, storage));
+      return *this;
+    }
+
+    /// \brief Blue map reading rule
+    ///
+    /// Add a blue map reading rule with specialized converter to the
+    /// reader.
+    template <typename Map, typename Converter>
+    BpGraphReader& blueMap(const std::string& caption, Map& map,
+                           const Converter& converter = Converter()) {
+      checkConcept<concepts::WriteMap<Node, typename Map::Value>, Map>();
+      _reader_bits::MapStorageBase<Node>* storage =
+        new _reader_bits::MapStorage<Node, Map, Converter>(map, converter);
+      _blue_maps.push_back(std::make_pair(caption, storage));
+      return *this;
+    }
+
+    /// \brief Edge map reading rule
+    ///
+    /// Add an edge map reading rule to the reader.
+    template <typename Map>
+    BpGraphReader& edgeMap(const std::string& caption, Map& map) {
+      checkConcept<concepts::WriteMap<Edge, typename Map::Value>, Map>();
+      _reader_bits::MapStorageBase<Edge>* storage =
+        new _reader_bits::MapStorage<Edge, Map>(map);
+      _edge_maps.push_back(std::make_pair(caption, storage));
+      return *this;
+    }
+
+    /// \brief Edge map reading rule
+    ///
+    /// Add an edge map reading rule with specialized converter to the
+    /// reader.
+    template <typename Map, typename Converter>
+    BpGraphReader& edgeMap(const std::string& caption, Map& map,
+                          const Converter& converter = Converter()) {
+      checkConcept<concepts::WriteMap<Edge, typename Map::Value>, Map>();
+      _reader_bits::MapStorageBase<Edge>* storage =
+        new _reader_bits::MapStorage<Edge, Map, Converter>(map, converter);
+      _edge_maps.push_back(std::make_pair(caption, storage));
+      return *this;
+    }
+
+    /// \brief Arc map reading rule
+    ///
+    /// Add an arc map reading rule to the reader.
+    template <typename Map>
+    BpGraphReader& arcMap(const std::string& caption, Map& map) {
+      checkConcept<concepts::WriteMap<Arc, typename Map::Value>, Map>();
+      _reader_bits::MapStorageBase<Edge>* forward_storage =
+        new _reader_bits::GraphArcMapStorage<Graph, true, Map>(_graph, map);
+      _edge_maps.push_back(std::make_pair('+' + caption, forward_storage));
+      _reader_bits::MapStorageBase<Edge>* backward_storage =
+        new _reader_bits::GraphArcMapStorage<BGR, false, Map>(_graph, map);
+      _edge_maps.push_back(std::make_pair('-' + caption, backward_storage));
+      return *this;
+    }
+
+    /// \brief Arc map reading rule
+    ///
+    /// Add an arc map reading rule with specialized converter to the
+    /// reader.
+    template <typename Map, typename Converter>
+    BpGraphReader& arcMap(const std::string& caption, Map& map,
+                          const Converter& converter = Converter()) {
+      checkConcept<concepts::WriteMap<Arc, typename Map::Value>, Map>();
+      _reader_bits::MapStorageBase<Edge>* forward_storage =
+        new _reader_bits::GraphArcMapStorage<BGR, true, Map, Converter>
+        (_graph, map, converter);
+      _edge_maps.push_back(std::make_pair('+' + caption, forward_storage));
+      _reader_bits::MapStorageBase<Edge>* backward_storage =
+        new _reader_bits::GraphArcMapStorage<BGR, false, Map, Converter>
+        (_graph, map, converter);
+      _edge_maps.push_back(std::make_pair('-' + caption, backward_storage));
+      return *this;
+    }
+
+    /// \brief Attribute reading rule
+    ///
+    /// Add an attribute reading rule to the reader.
+    template <typename Value>
+    BpGraphReader& attribute(const std::string& caption, Value& value) {
+      _reader_bits::ValueStorageBase* storage =
+        new _reader_bits::ValueStorage<Value>(value);
+      _attributes.insert(std::make_pair(caption, storage));
+      return *this;
+    }
+
+    /// \brief Attribute reading rule
+    ///
+    /// Add an attribute reading rule with specialized converter to the
+    /// reader.
+    template <typename Value, typename Converter>
+    BpGraphReader& attribute(const std::string& caption, Value& value,
+                             const Converter& converter = Converter()) {
+      _reader_bits::ValueStorageBase* storage =
+        new _reader_bits::ValueStorage<Value, Converter>(value, converter);
+      _attributes.insert(std::make_pair(caption, storage));
+      return *this;
+    }
+
+    /// \brief Node reading rule
+    ///
+    /// Add a node reading rule to reader.
+    BpGraphReader& node(const std::string& caption, Node& node) {
+      typedef _reader_bits::MapLookUpConverter<Node> Converter;
+      Converter converter(_node_index);
+      _reader_bits::ValueStorageBase* storage =
+        new _reader_bits::ValueStorage<Node, Converter>(node, converter);
+      _attributes.insert(std::make_pair(caption, storage));
+      return *this;
+    }
+
+    /// \brief Edge reading rule
+    ///
+    /// Add an edge reading rule to reader.
+    BpGraphReader& edge(const std::string& caption, Edge& edge) {
+      typedef _reader_bits::MapLookUpConverter<Edge> Converter;
+      Converter converter(_edge_index);
+      _reader_bits::ValueStorageBase* storage =
+        new _reader_bits::ValueStorage<Edge, Converter>(edge, converter);
+      _attributes.insert(std::make_pair(caption, storage));
+      return *this;
+    }
+
+    /// \brief Arc reading rule
+    ///
+    /// Add an arc reading rule to reader.
+    BpGraphReader& arc(const std::string& caption, Arc& arc) {
+      typedef _reader_bits::GraphArcLookUpConverter<BGR> Converter;
+      Converter converter(_graph, _edge_index);
+      _reader_bits::ValueStorageBase* storage =
+        new _reader_bits::ValueStorage<Arc, Converter>(arc, converter);
+      _attributes.insert(std::make_pair(caption, storage));
+      return *this;
+    }
+
+    /// @}
+
+    /// \name Select Section by Name
+    /// @{
+
+    /// \brief Set \c \@nodes section to be read
+    ///
+    /// Set \c \@nodes section to be read.
+    BpGraphReader& nodes(const std::string& caption) {
+      _nodes_caption = caption;
+      return *this;
+    }
+
+    /// \brief Set \c \@edges section to be read
+    ///
+    /// Set \c \@edges section to be read.
+    BpGraphReader& edges(const std::string& caption) {
+      _edges_caption = caption;
+      return *this;
+    }
+
+    /// \brief Set \c \@attributes section to be read
+    ///
+    /// Set \c \@attributes section to be read.
+    BpGraphReader& attributes(const std::string& caption) {
+      _attributes_caption = caption;
+      return *this;
+    }
+
+    /// @}
+
+    /// \name Using Previously Constructed Node or Edge Set
+    /// @{
+
+    /// \brief Use previously constructed node set
+    ///
+    /// Use previously constructed node set, and specify the node
+    /// label map.
+    template <typename Map>
+    BpGraphReader& useNodes(const Map& map) {
+      checkConcept<concepts::ReadMap<Node, typename Map::Value>, Map>();
+      LEMON_ASSERT(!_use_nodes, "Multiple usage of useNodes() member");
+      _use_nodes = true;
+      _writer_bits::DefaultConverter<typename Map::Value> converter;
+      for (NodeIt n(_graph); n != INVALID; ++n) {
+        _node_index.insert(std::make_pair(converter(map[n]), n));
+      }
+      return *this;
+    }
+
+    /// \brief 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
+    /// \c std::string.
+    template <typename Map, typename Converter>
+    BpGraphReader& useNodes(const Map& map,
+                            const Converter& converter = Converter()) {
+      checkConcept<concepts::ReadMap<Node, typename Map::Value>, Map>();
+      LEMON_ASSERT(!_use_nodes, "Multiple usage of useNodes() member");
+      _use_nodes = true;
+      for (NodeIt n(_graph); n != INVALID; ++n) {
+        _node_index.insert(std::make_pair(converter(map[n]), n));
+      }
+      return *this;
+    }
+
+    /// \brief Use previously constructed edge set
+    ///
+    /// Use previously constructed edge set, and specify the edge
+    /// label map.
+    template <typename Map>
+    BpGraphReader& useEdges(const Map& map) {
+      checkConcept<concepts::ReadMap<Edge, typename Map::Value>, Map>();
+      LEMON_ASSERT(!_use_edges, "Multiple usage of useEdges() member");
+      _use_edges = true;
+      _writer_bits::DefaultConverter<typename Map::Value> converter;
+      for (EdgeIt a(_graph); a != INVALID; ++a) {
+        _edge_index.insert(std::make_pair(converter(map[a]), a));
+      }
+      return *this;
+    }
+
+    /// \brief Use previously constructed edge set
+    ///
+    /// Use previously constructed edge set, and specify the edge
+    /// label map and a functor which converts the label map values to
+    /// \c std::string.
+    template <typename Map, typename Converter>
+    BpGraphReader& useEdges(const Map& map,
+                            const Converter& converter = Converter()) {
+      checkConcept<concepts::ReadMap<Edge, typename Map::Value>, Map>();
+      LEMON_ASSERT(!_use_edges, "Multiple usage of useEdges() member");
+      _use_edges = true;
+      for (EdgeIt a(_graph); a != INVALID; ++a) {
+        _edge_index.insert(std::make_pair(converter(map[a]), a));
+      }
+      return *this;
+    }
+
+    /// \brief Skip 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 edge set
+    /// could not be read due to lack of node name
+    /// could not be read due to lack of node name resolving.
+    /// Therefore \c skipEdges() function should also be used, or
+    /// \c useNodes() should be used to specify the label of the nodes.
+    BpGraphReader& skipNodes() {
+      LEMON_ASSERT(!_skip_nodes, "Skip nodes already set");
+      _skip_nodes = true;
+      return *this;
+    }
+
+    /// \brief Skip the reading of edge section
+    ///
+    /// Omit the reading of the edge section. This implies that each edge
+    /// map reading rule will be abandoned, and the edges of the graph
+    /// will not be constructed.
+    BpGraphReader& skipEdges() {
+      LEMON_ASSERT(!_skip_edges, "Skip edges already set");
+      _skip_edges = true;
+      return *this;
+    }
+
+    /// @}
+
+  private:
+
+    bool readLine() {
+      std::string str;
+      while(++line_num, std::getline(*_is, str)) {
+        line.clear(); line.str(str);
+        char c;
+        if (line >> std::ws >> c && c != '#') {
+          line.putback(c);
+          return true;
+        }
+      }
+      return false;
+    }
+
+    bool readSuccess() {
+      return static_cast<bool>(*_is);
+    }
+
+    void skipSection() {
+      char c;
+      while (readSuccess() && line >> c && c != '@') {
+        readLine();
+      }
+      if (readSuccess()) {
+        line.putback(c);
+      }
+    }
+
+    void readRedNodes() {
+
+      std::vector<int> map_index(_red_maps.size());
+      int map_num, label_index;
+
+      char c;
+      if (!readLine() || !(line >> c) || c == '@') {
+        if (readSuccess() && line) line.putback(c);
+        if (!_red_maps.empty())
+          throw FormatError("Cannot find map names");
+        return;
+      }
+      line.putback(c);
+
+      {
+        std::map<std::string, int> maps;
+
+        std::string map;
+        int index = 0;
+        while (_reader_bits::readToken(line, map)) {
+          if (maps.find(map) != maps.end()) {
+            std::ostringstream msg;
+            msg << "Multiple occurence of red map: " << map;
+            throw FormatError(msg.str());
+          }
+          maps.insert(std::make_pair(map, index));
+          ++index;
+        }
+
+        for (int i = 0; i < static_cast<int>(_red_maps.size()); ++i) {
+          std::map<std::string, int>::iterator jt =
+            maps.find(_red_maps[i].first);
+          if (jt == maps.end()) {
+            std::ostringstream msg;
+            msg << "Map not found: " << _red_maps[i].first;
+            throw FormatError(msg.str());
+          }
+          map_index[i] = jt->second;
+        }
+
+        {
+          std::map<std::string, int>::iterator jt = maps.find("label");
+          if (jt != maps.end()) {
+            label_index = jt->second;
+          } else {
+            label_index = -1;
+          }
+        }
+        map_num = maps.size();
+      }
+
+      while (readLine() && line >> c && c != '@') {
+        line.putback(c);
+
+        std::vector<std::string> tokens(map_num);
+        for (int i = 0; i < map_num; ++i) {
+          if (!_reader_bits::readToken(line, tokens[i])) {
+            std::ostringstream msg;
+            msg << "Column not found (" << i + 1 << ")";
+            throw FormatError(msg.str());
+          }
+        }
+        if (line >> std::ws >> c)
+          throw FormatError("Extra character at the end of line");
+
+        Node n;
+        if (!_use_nodes) {
+          n = _graph.addRedNode();
+          if (label_index != -1)
+            _node_index.insert(std::make_pair(tokens[label_index], n));
+        } else {
+          if (label_index == -1)
+            throw FormatError("Label map not found");
+          typename std::map<std::string, Node>::iterator it =
+            _node_index.find(tokens[label_index]);
+          if (it == _node_index.end()) {
+            std::ostringstream msg;
+            msg << "Node with label not found: " << tokens[label_index];
+            throw FormatError(msg.str());
+          }
+          n = it->second;
+        }
+
+        for (int i = 0; i < static_cast<int>(_red_maps.size()); ++i) {
+          _red_maps[i].second->set(n, tokens[map_index[i]]);
+        }
+
+      }
+      if (readSuccess()) {
+        line.putback(c);
+      }
+    }
+
+    void readBlueNodes() {
+
+      std::vector<int> map_index(_blue_maps.size());
+      int map_num, label_index;
+
+      char c;
+      if (!readLine() || !(line >> c) || c == '@') {
+        if (readSuccess() && line) line.putback(c);
+        if (!_blue_maps.empty())
+          throw FormatError("Cannot find map names");
+        return;
+      }
+      line.putback(c);
+
+      {
+        std::map<std::string, int> maps;
+
+        std::string map;
+        int index = 0;
+        while (_reader_bits::readToken(line, map)) {
+          if (maps.find(map) != maps.end()) {
+            std::ostringstream msg;
+            msg << "Multiple occurence of blue map: " << map;
+            throw FormatError(msg.str());
+          }
+          maps.insert(std::make_pair(map, index));
+          ++index;
+        }
+
+        for (int i = 0; i < static_cast<int>(_blue_maps.size()); ++i) {
+          std::map<std::string, int>::iterator jt =
+            maps.find(_blue_maps[i].first);
+          if (jt == maps.end()) {
+            std::ostringstream msg;
+            msg << "Map not found: " << _blue_maps[i].first;
+            throw FormatError(msg.str());
+          }
+          map_index[i] = jt->second;
+        }
+
+        {
+          std::map<std::string, int>::iterator jt = maps.find("label");
+          if (jt != maps.end()) {
+            label_index = jt->second;
+          } else {
+            label_index = -1;
+          }
+        }
+        map_num = maps.size();
+      }
+
+      while (readLine() && line >> c && c != '@') {
+        line.putback(c);
+
+        std::vector<std::string> tokens(map_num);
+        for (int i = 0; i < map_num; ++i) {
+          if (!_reader_bits::readToken(line, tokens[i])) {
+            std::ostringstream msg;
+            msg << "Column not found (" << i + 1 << ")";
+            throw FormatError(msg.str());
+          }
+        }
+        if (line >> std::ws >> c)
+          throw FormatError("Extra character at the end of line");
+
+        Node n;
+        if (!_use_nodes) {
+          n = _graph.addBlueNode();
+          if (label_index != -1)
+            _node_index.insert(std::make_pair(tokens[label_index], n));
+        } else {
+          if (label_index == -1)
+            throw FormatError("Label map not found");
+          typename std::map<std::string, Node>::iterator it =
+            _node_index.find(tokens[label_index]);
+          if (it == _node_index.end()) {
+            std::ostringstream msg;
+            msg << "Node with label not found: " << tokens[label_index];
+            throw FormatError(msg.str());
+          }
+          n = it->second;
+        }
+
+        for (int i = 0; i < static_cast<int>(_blue_maps.size()); ++i) {
+          _blue_maps[i].second->set(n, tokens[map_index[i]]);
+        }
+
+      }
+      if (readSuccess()) {
+        line.putback(c);
+      }
+    }
+
+    void readEdges() {
+
+      std::vector<int> map_index(_edge_maps.size());
+      int map_num, label_index;
+
+      char c;
+      if (!readLine() || !(line >> c) || c == '@') {
+        if (readSuccess() && line) line.putback(c);
+        if (!_edge_maps.empty())
+          throw FormatError("Cannot find map names");
+        return;
+      }
+      line.putback(c);
+
+      {
+        std::map<std::string, int> maps;
+
+        std::string map;
+        int index = 0;
+        while (_reader_bits::readToken(line, map)) {
+          if (maps.find(map) != maps.end()) {
+            std::ostringstream msg;
+            msg << "Multiple occurence of edge map: " << map;
+            throw FormatError(msg.str());
+          }
+          maps.insert(std::make_pair(map, index));
+          ++index;
+        }
+
+        for (int i = 0; i < static_cast<int>(_edge_maps.size()); ++i) {
+          std::map<std::string, int>::iterator jt =
+            maps.find(_edge_maps[i].first);
+          if (jt == maps.end()) {
+            std::ostringstream msg;
+            msg << "Map not found: " << _edge_maps[i].first;
+            throw FormatError(msg.str());
+          }
+          map_index[i] = jt->second;
+        }
+
+        {
+          std::map<std::string, int>::iterator jt = maps.find("label");
+          if (jt != maps.end()) {
+            label_index = jt->second;
+          } else {
+            label_index = -1;
+          }
+        }
+        map_num = maps.size();
+      }
+
+      while (readLine() && line >> c && c != '@') {
+        line.putback(c);
+
+        std::string source_token;
+        std::string target_token;
+
+        if (!_reader_bits::readToken(line, source_token))
+          throw FormatError("Red node not found");
+
+        if (!_reader_bits::readToken(line, target_token))
+          throw FormatError("Blue node not found");
+
+        std::vector<std::string> tokens(map_num);
+        for (int i = 0; i < map_num; ++i) {
+          if (!_reader_bits::readToken(line, tokens[i])) {
+            std::ostringstream msg;
+            msg << "Column not found (" << i + 1 << ")";
+            throw FormatError(msg.str());
+          }
+        }
+        if (line >> std::ws >> c)
+          throw FormatError("Extra character at the end of line");
+
+        Edge e;
+        if (!_use_edges) {
+
+          typename NodeIndex::iterator it;
+
+          it = _node_index.find(source_token);
+          if (it == _node_index.end()) {
+            std::ostringstream msg;
+            msg << "Item not found: " << source_token;
+            throw FormatError(msg.str());
+          }
+          Node source = it->second;
+          if (!_graph.red(source)) {
+            std::ostringstream msg;
+            msg << "Item is not red node: " << source_token;
+            throw FormatError(msg.str());
+          }
+
+          it = _node_index.find(target_token);
+          if (it == _node_index.end()) {
+            std::ostringstream msg;
+            msg << "Item not found: " << target_token;
+            throw FormatError(msg.str());
+          }
+          Node target = it->second;
+          if (!_graph.blue(target)) {
+            std::ostringstream msg;
+            msg << "Item is not red node: " << source_token;
+            throw FormatError(msg.str());
+          }
+
+          e = _graph.addEdge(source, target);
+          if (label_index != -1)
+            _edge_index.insert(std::make_pair(tokens[label_index], e));
+        } else {
+          if (label_index == -1)
+            throw FormatError("Label map not found");
+          typename std::map<std::string, Edge>::iterator it =
+            _edge_index.find(tokens[label_index]);
+          if (it == _edge_index.end()) {
+            std::ostringstream msg;
+            msg << "Edge with label not found: " << tokens[label_index];
+            throw FormatError(msg.str());
+          }
+          e = it->second;
+        }
+
+        for (int i = 0; i < static_cast<int>(_edge_maps.size()); ++i) {
+          _edge_maps[i].second->set(e, tokens[map_index[i]]);
+        }
+
+      }
+      if (readSuccess()) {
+        line.putback(c);
+      }
+    }
+
+    void readAttributes() {
+
+      std::set<std::string> read_attr;
+
+      char c;
+      while (readLine() && line >> c && c != '@') {
+        line.putback(c);
+
+        std::string attr, token;
+        if (!_reader_bits::readToken(line, attr))
+          throw FormatError("Attribute name not found");
+        if (!_reader_bits::readToken(line, token))
+          throw FormatError("Attribute value not found");
+        if (line >> c)
+          throw FormatError("Extra character at the end of line");
+
+        {
+          std::set<std::string>::iterator it = read_attr.find(attr);
+          if (it != read_attr.end()) {
+            std::ostringstream msg;
+            msg << "Multiple occurence of attribute: " << attr;
+            throw FormatError(msg.str());
+          }
+          read_attr.insert(attr);
+        }
+
+        {
+          typename Attributes::iterator it = _attributes.lower_bound(attr);
+          while (it != _attributes.end() && it->first == attr) {
+            it->second->set(token);
+            ++it;
+          }
+        }
+
+      }
+      if (readSuccess()) {
+        line.putback(c);
+      }
+      for (typename Attributes::iterator it = _attributes.begin();
+           it != _attributes.end(); ++it) {
+        if (read_attr.find(it->first) == read_attr.end()) {
+          std::ostringstream msg;
+          msg << "Attribute not found: " << it->first;
+          throw FormatError(msg.str());
+        }
+      }
+    }
+
+  public:
+
+    /// \name Execution of the Reader
+    /// @{
+
+    /// \brief Start the batch processing
+    ///
+    /// This function starts the batch processing
+    void run() {
+
+      LEMON_ASSERT(_is != 0, "This reader assigned to an other reader");
+
+      bool red_nodes_done = _skip_nodes;
+      bool blue_nodes_done = _skip_nodes;
+      bool edges_done = _skip_edges;
+      bool attributes_done = false;
+
+      line_num = 0;
+      readLine();
+      skipSection();
+
+      while (readSuccess()) {
+        try {
+          char c;
+          std::string section, caption;
+          line >> c;
+          _reader_bits::readToken(line, section);
+          _reader_bits::readToken(line, caption);
+
+          if (line >> c)
+            throw FormatError("Extra character at the end of line");
+
+          if (section == "red_nodes" && !red_nodes_done) {
+            if (_nodes_caption.empty() || _nodes_caption == caption) {
+              readRedNodes();
+              red_nodes_done = true;
+            }
+          } else if (section == "blue_nodes" && !blue_nodes_done) {
+            if (_nodes_caption.empty() || _nodes_caption == caption) {
+              readBlueNodes();
+              blue_nodes_done = true;
+            }
+          } else if ((section == "edges" || section == "arcs") &&
+                     !edges_done) {
+            if (_edges_caption.empty() || _edges_caption == caption) {
+              readEdges();
+              edges_done = true;
+            }
+          } else if (section == "attributes" && !attributes_done) {
+            if (_attributes_caption.empty() || _attributes_caption == caption) {
+              readAttributes();
+              attributes_done = true;
+            }
+          } else {
+            readLine();
+            skipSection();
+          }
+        } catch (FormatError& error) {
+          error.line(line_num);
+          error.file(_filename);
+          throw;
+        }
+      }
+
+      if (!red_nodes_done) {
+        throw FormatError("Section @red_nodes not found");
+      }
+
+      if (!blue_nodes_done) {
+        throw FormatError("Section @blue_nodes not found");
+      }
+
+      if (!edges_done) {
+        throw FormatError("Section @edges not found");
+      }
+
+      if (!attributes_done && !_attributes.empty()) {
+        throw FormatError("Section @attributes not found");
+      }
+
+    }
+
+    /// @}
+
+  };
+
+  /// \ingroup lemon_io
+  ///
+  /// \brief Return a \ref BpGraphReader class
+  ///
+  /// This function just returns a \ref BpGraphReader class.
+  ///
+  /// With this function a graph can be read from an
+  /// \ref lgf-format "LGF" file or input stream with several maps and
+  /// attributes. For example, there is bipartite weighted matching problem
+  /// on a graph, i.e. a graph with a \e weight map on the edges. This
+  /// graph can be read with the following code:
+  ///
+  ///\code
+  ///ListBpGraph graph;
+  ///ListBpGraph::EdgeMap<int> weight(graph);
+  ///bpGraphReader(graph, std::cin).
+  ///  edgeMap("weight", weight).
+  ///  run();
+  ///\endcode
+  ///
+  /// For a complete documentation, please see the \ref BpGraphReader
+  /// class documentation.
+  /// \warning Don't forget to put the \ref BpGraphReader::run() "run()"
+  /// to the end of the parameter list.
+  /// \relates BpGraphReader
+  /// \sa bpGraphReader(TBGR& graph, const std::string& fn)
+  /// \sa bpGraphReader(TBGR& graph, const char* fn)
+  template <typename TBGR>
+  BpGraphReader<TBGR> bpGraphReader(TBGR& graph, std::istream& is) {
+    BpGraphReader<TBGR> tmp(graph, is);
+    return tmp;
+  }
+
+  /// \brief Return a \ref BpGraphReader class
+  ///
+  /// This function just returns a \ref BpGraphReader class.
+  /// \relates BpGraphReader
+  /// \sa bpGraphReader(TBGR& graph, std::istream& is)
+  template <typename TBGR>
+  BpGraphReader<TBGR> bpGraphReader(TBGR& graph, const std::string& fn) {
+    BpGraphReader<TBGR> tmp(graph, fn);
+    return tmp;
+  }
+
+  /// \brief Return a \ref BpGraphReader class
+  ///
+  /// This function just returns a \ref BpGraphReader class.
+  /// \relates BpGraphReader
+  /// \sa bpGraphReader(TBGR& graph, std::istream& is)
+  template <typename TBGR>
+  BpGraphReader<TBGR> bpGraphReader(TBGR& graph, const char* fn) {
+    BpGraphReader<TBGR> tmp(graph, fn);
+    return tmp;
+  }
+
   class SectionReader;
 
Index: lemon/lgf_writer.h
===================================================================
--- lemon/lgf_writer.h	(revision 956)
+++ lemon/lgf_writer.h	(revision 1192)
@@ -987,5 +987,5 @@
   /// \ingroup lemon_io
   ///
-  /// \brief \ref lgf-format "LGF" writer for directed graphs
+  /// \brief \ref lgf-format "LGF" writer for undirected graphs
   ///
   /// This utility writes an \ref lgf-format "LGF" file.
@@ -1043,6 +1043,6 @@
     /// \brief Constructor
     ///
-    /// Construct a directed graph writer, which writes to the given
-    /// output stream.
+    /// Construct an undirected graph writer, which writes to the
+    /// given output stream.
     GraphWriter(const GR& graph, std::ostream& os = std::cout)
       : _os(&os), local_os(false), _graph(graph),
@@ -1051,5 +1051,5 @@
     /// \brief Constructor
     ///
-    /// Construct a directed graph writer, which writes to the given
+    /// Construct a undirected graph writer, which writes to the given
     /// output file.
     GraphWriter(const GR& graph, const std::string& fn)
@@ -1064,5 +1064,5 @@
     /// \brief Constructor
     ///
-    /// Construct a directed graph writer, which writes to the given
+    /// Construct a undirected graph writer, which writes to the given
     /// output file.
     GraphWriter(const GR& graph, const char* fn)
@@ -1290,7 +1290,7 @@
     }
 
-    /// \brief Add an additional caption to the \c \@arcs section
-    ///
-    /// Add an additional caption to the \c \@arcs section.
+    /// \brief Add an additional caption to the \c \@edges section
+    ///
+    /// Add an additional caption to the \c \@edges section.
     GraphWriter& edges(const std::string& caption) {
       _edges_caption = caption;
@@ -1606,4 +1606,792 @@
   GraphWriter<TGR> graphWriter(const TGR& graph, const char* fn) {
     GraphWriter<TGR> tmp(graph, fn);
+    return tmp;
+  }
+
+  template <typename BGR>
+  class BpGraphWriter;
+
+  template <typename TBGR>
+  BpGraphWriter<TBGR> bpGraphWriter(const TBGR& graph,
+                                    std::ostream& os = std::cout);
+  template <typename TBGR>
+  BpGraphWriter<TBGR> bpGraphWriter(const TBGR& graph, const std::string& fn);
+  template <typename TBGR>
+  BpGraphWriter<TBGR> bpGraphWriter(const TBGR& graph, const char* fn);
+
+  /// \ingroup lemon_io
+  ///
+  /// \brief \ref lgf-format "LGF" writer for undirected bipartite graphs
+  ///
+  /// This utility writes an \ref lgf-format "LGF" file.
+  ///
+  /// It can be used almost the same way as \c GraphWriter, but it
+  /// reads the red and blue nodes from separate sections, and these
+  /// sections can contain different set of maps.
+  ///
+  /// The red and blue maps are written to the corresponding
+  /// sections. The node maps are written to both of these sections
+  /// with the same map name.
+  template <typename BGR>
+  class BpGraphWriter {
+  public:
+
+    typedef BGR BpGraph;
+    TEMPLATE_BPGRAPH_TYPEDEFS(BGR);
+
+  private:
+
+
+    std::ostream* _os;
+    bool local_os;
+
+    const BGR& _graph;
+
+    std::string _nodes_caption;
+    std::string _edges_caption;
+    std::string _attributes_caption;
+
+    typedef std::map<Node, std::string> NodeIndex;
+    NodeIndex _node_index;
+    typedef std::map<Edge, std::string> EdgeIndex;
+    EdgeIndex _edge_index;
+
+    typedef std::vector<std::pair<std::string,
+      _writer_bits::MapStorageBase<Node>* > > NodeMaps;
+    NodeMaps _red_maps;
+    NodeMaps _blue_maps;
+
+    typedef std::vector<std::pair<std::string,
+      _writer_bits::MapStorageBase<Edge>* > >EdgeMaps;
+    EdgeMaps _edge_maps;
+
+    typedef std::vector<std::pair<std::string,
+      _writer_bits::ValueStorageBase*> > Attributes;
+    Attributes _attributes;
+
+    bool _skip_nodes;
+    bool _skip_edges;
+
+  public:
+
+    /// \brief Constructor
+    ///
+    /// Construct a bipartite graph writer, which writes to the given
+    /// output stream.
+    BpGraphWriter(const BGR& graph, std::ostream& os = std::cout)
+      : _os(&os), local_os(false), _graph(graph),
+        _skip_nodes(false), _skip_edges(false) {}
+
+    /// \brief Constructor
+    ///
+    /// Construct a bipartite graph writer, which writes to the given
+    /// output file.
+    BpGraphWriter(const BGR& graph, const std::string& fn)
+      : _os(new std::ofstream(fn.c_str())), local_os(true), _graph(graph),
+        _skip_nodes(false), _skip_edges(false) {
+      if (!(*_os)) {
+        delete _os;
+        throw IoError("Cannot write file", fn);
+      }
+    }
+
+    /// \brief Constructor
+    ///
+    /// Construct a bipartite graph writer, which writes to the given
+    /// output file.
+    BpGraphWriter(const BGR& graph, const char* fn)
+      : _os(new std::ofstream(fn)), local_os(true), _graph(graph),
+        _skip_nodes(false), _skip_edges(false) {
+      if (!(*_os)) {
+        delete _os;
+        throw IoError("Cannot write file", fn);
+      }
+    }
+
+    /// \brief Destructor
+    ~BpGraphWriter() {
+      for (typename NodeMaps::iterator it = _red_maps.begin();
+           it != _red_maps.end(); ++it) {
+        delete it->second;
+      }
+
+      for (typename NodeMaps::iterator it = _blue_maps.begin();
+           it != _blue_maps.end(); ++it) {
+        delete it->second;
+      }
+
+      for (typename EdgeMaps::iterator it = _edge_maps.begin();
+           it != _edge_maps.end(); ++it) {
+        delete it->second;
+      }
+
+      for (typename Attributes::iterator it = _attributes.begin();
+           it != _attributes.end(); ++it) {
+        delete it->second;
+      }
+
+      if (local_os) {
+        delete _os;
+      }
+    }
+
+  private:
+
+    template <typename TBGR>
+    friend BpGraphWriter<TBGR> bpGraphWriter(const TBGR& graph,
+                                             std::ostream& os);
+    template <typename TBGR>
+    friend BpGraphWriter<TBGR> bpGraphWriter(const TBGR& graph,
+                                             const std::string& fn);
+    template <typename TBGR>
+    friend BpGraphWriter<TBGR> bpGraphWriter(const TBGR& graph, const char *fn);
+
+    BpGraphWriter(BpGraphWriter& other)
+      : _os(other._os), local_os(other.local_os), _graph(other._graph),
+        _skip_nodes(other._skip_nodes), _skip_edges(other._skip_edges) {
+
+      other._os = 0;
+      other.local_os = false;
+
+      _node_index.swap(other._node_index);
+      _edge_index.swap(other._edge_index);
+
+      _red_maps.swap(other._red_maps);
+      _blue_maps.swap(other._blue_maps);
+      _edge_maps.swap(other._edge_maps);
+      _attributes.swap(other._attributes);
+
+      _nodes_caption = other._nodes_caption;
+      _edges_caption = other._edges_caption;
+      _attributes_caption = other._attributes_caption;
+    }
+
+    BpGraphWriter& operator=(const BpGraphWriter&);
+
+  public:
+
+    /// \name Writing Rules
+    /// @{
+
+    /// \brief Node map writing rule
+    ///
+    /// Add a node map writing rule to the writer.
+    template <typename Map>
+    BpGraphWriter& nodeMap(const std::string& caption, const Map& map) {
+      checkConcept<concepts::ReadMap<Node, typename Map::Value>, Map>();
+      _writer_bits::MapStorageBase<Node>* red_storage =
+        new _writer_bits::MapStorage<Node, Map>(map);
+      _red_maps.push_back(std::make_pair(caption, red_storage));
+      _writer_bits::MapStorageBase<Node>* blue_storage =
+        new _writer_bits::MapStorage<Node, Map>(map);
+      _blue_maps.push_back(std::make_pair(caption, blue_storage));
+      return *this;
+    }
+
+    /// \brief Node map writing rule
+    ///
+    /// Add a node map writing rule with specialized converter to the
+    /// writer.
+    template <typename Map, typename Converter>
+    BpGraphWriter& nodeMap(const std::string& caption, const Map& map,
+                           const Converter& converter = Converter()) {
+      checkConcept<concepts::ReadMap<Node, typename Map::Value>, Map>();
+      _writer_bits::MapStorageBase<Node>* red_storage =
+        new _writer_bits::MapStorage<Node, Map, Converter>(map, converter);
+      _red_maps.push_back(std::make_pair(caption, red_storage));
+      _writer_bits::MapStorageBase<Node>* blue_storage =
+        new _writer_bits::MapStorage<Node, Map, Converter>(map, converter);
+      _blue_maps.push_back(std::make_pair(caption, blue_storage));
+      return *this;
+    }
+
+    /// \brief Red map writing rule
+    ///
+    /// Add a red map writing rule to the writer.
+    template <typename Map>
+    BpGraphWriter& redMap(const std::string& caption, const Map& map) {
+      checkConcept<concepts::ReadMap<Node, typename Map::Value>, Map>();
+      _writer_bits::MapStorageBase<Node>* storage =
+        new _writer_bits::MapStorage<Node, Map>(map);
+      _red_maps.push_back(std::make_pair(caption, storage));
+      return *this;
+    }
+
+    /// \brief Red map writing rule
+    ///
+    /// Add a red map writing rule with specialized converter to the
+    /// writer.
+    template <typename Map, typename Converter>
+    BpGraphWriter& redMap(const std::string& caption, const Map& map,
+                          const Converter& converter = Converter()) {
+      checkConcept<concepts::ReadMap<Node, typename Map::Value>, Map>();
+      _writer_bits::MapStorageBase<Node>* storage =
+        new _writer_bits::MapStorage<Node, Map, Converter>(map, converter);
+      _red_maps.push_back(std::make_pair(caption, storage));
+      return *this;
+    }
+
+    /// \brief Blue map writing rule
+    ///
+    /// Add a blue map writing rule to the writer.
+    template <typename Map>
+    BpGraphWriter& blueMap(const std::string& caption, const Map& map) {
+      checkConcept<concepts::ReadMap<Node, typename Map::Value>, Map>();
+      _writer_bits::MapStorageBase<Node>* storage =
+        new _writer_bits::MapStorage<Node, Map>(map);
+      _blue_maps.push_back(std::make_pair(caption, storage));
+      return *this;
+    }
+
+    /// \brief Blue map writing rule
+    ///
+    /// Add a blue map writing rule with specialized converter to the
+    /// writer.
+    template <typename Map, typename Converter>
+    BpGraphWriter& blueMap(const std::string& caption, const Map& map,
+                           const Converter& converter = Converter()) {
+      checkConcept<concepts::ReadMap<Node, typename Map::Value>, Map>();
+      _writer_bits::MapStorageBase<Node>* storage =
+        new _writer_bits::MapStorage<Node, Map, Converter>(map, converter);
+      _blue_maps.push_back(std::make_pair(caption, storage));
+      return *this;
+    }
+
+    /// \brief Edge map writing rule
+    ///
+    /// Add an edge map writing rule to the writer.
+    template <typename Map>
+    BpGraphWriter& edgeMap(const std::string& caption, const Map& map) {
+      checkConcept<concepts::ReadMap<Edge, typename Map::Value>, Map>();
+      _writer_bits::MapStorageBase<Edge>* storage =
+        new _writer_bits::MapStorage<Edge, Map>(map);
+      _edge_maps.push_back(std::make_pair(caption, storage));
+      return *this;
+    }
+
+    /// \brief Edge map writing rule
+    ///
+    /// Add an edge map writing rule with specialized converter to the
+    /// writer.
+    template <typename Map, typename Converter>
+    BpGraphWriter& edgeMap(const std::string& caption, const Map& map,
+                          const Converter& converter = Converter()) {
+      checkConcept<concepts::ReadMap<Edge, typename Map::Value>, Map>();
+      _writer_bits::MapStorageBase<Edge>* storage =
+        new _writer_bits::MapStorage<Edge, Map, Converter>(map, converter);
+      _edge_maps.push_back(std::make_pair(caption, storage));
+      return *this;
+    }
+
+    /// \brief Arc map writing rule
+    ///
+    /// Add an arc map writing rule to the writer.
+    template <typename Map>
+    BpGraphWriter& arcMap(const std::string& caption, const Map& map) {
+      checkConcept<concepts::ReadMap<Arc, typename Map::Value>, Map>();
+      _writer_bits::MapStorageBase<Edge>* forward_storage =
+        new _writer_bits::GraphArcMapStorage<BGR, true, Map>(_graph, map);
+      _edge_maps.push_back(std::make_pair('+' + caption, forward_storage));
+      _writer_bits::MapStorageBase<Edge>* backward_storage =
+        new _writer_bits::GraphArcMapStorage<BGR, false, Map>(_graph, map);
+      _edge_maps.push_back(std::make_pair('-' + caption, backward_storage));
+      return *this;
+    }
+
+    /// \brief Arc map writing rule
+    ///
+    /// Add an arc map writing rule with specialized converter to the
+    /// writer.
+    template <typename Map, typename Converter>
+    BpGraphWriter& arcMap(const std::string& caption, const Map& map,
+                          const Converter& converter = Converter()) {
+      checkConcept<concepts::ReadMap<Arc, typename Map::Value>, Map>();
+      _writer_bits::MapStorageBase<Edge>* forward_storage =
+        new _writer_bits::GraphArcMapStorage<BGR, true, Map, Converter>
+        (_graph, map, converter);
+      _edge_maps.push_back(std::make_pair('+' + caption, forward_storage));
+      _writer_bits::MapStorageBase<Edge>* backward_storage =
+        new _writer_bits::GraphArcMapStorage<BGR, false, Map, Converter>
+        (_graph, map, converter);
+      _edge_maps.push_back(std::make_pair('-' + caption, backward_storage));
+      return *this;
+    }
+
+    /// \brief Attribute writing rule
+    ///
+    /// Add an attribute writing rule to the writer.
+    template <typename Value>
+    BpGraphWriter& attribute(const std::string& caption, const Value& value) {
+      _writer_bits::ValueStorageBase* storage =
+        new _writer_bits::ValueStorage<Value>(value);
+      _attributes.push_back(std::make_pair(caption, storage));
+      return *this;
+    }
+
+    /// \brief Attribute writing rule
+    ///
+    /// Add an attribute writing rule with specialized converter to the
+    /// writer.
+    template <typename Value, typename Converter>
+    BpGraphWriter& attribute(const std::string& caption, const Value& value,
+                             const Converter& converter = Converter()) {
+      _writer_bits::ValueStorageBase* storage =
+        new _writer_bits::ValueStorage<Value, Converter>(value, converter);
+      _attributes.push_back(std::make_pair(caption, storage));
+      return *this;
+    }
+
+    /// \brief Node writing rule
+    ///
+    /// Add a node writing rule to the writer.
+    BpGraphWriter& node(const std::string& caption, const Node& node) {
+      typedef _writer_bits::MapLookUpConverter<Node> Converter;
+      Converter converter(_node_index);
+      _writer_bits::ValueStorageBase* storage =
+        new _writer_bits::ValueStorage<Node, Converter>(node, converter);
+      _attributes.push_back(std::make_pair(caption, storage));
+      return *this;
+    }
+
+    /// \brief Edge writing rule
+    ///
+    /// Add an edge writing rule to writer.
+    BpGraphWriter& edge(const std::string& caption, const Edge& edge) {
+      typedef _writer_bits::MapLookUpConverter<Edge> Converter;
+      Converter converter(_edge_index);
+      _writer_bits::ValueStorageBase* storage =
+        new _writer_bits::ValueStorage<Edge, Converter>(edge, converter);
+      _attributes.push_back(std::make_pair(caption, storage));
+      return *this;
+    }
+
+    /// \brief Arc writing rule
+    ///
+    /// Add an arc writing rule to writer.
+    BpGraphWriter& arc(const std::string& caption, const Arc& arc) {
+      typedef _writer_bits::GraphArcLookUpConverter<BGR> Converter;
+      Converter converter(_graph, _edge_index);
+      _writer_bits::ValueStorageBase* storage =
+        new _writer_bits::ValueStorage<Arc, Converter>(arc, converter);
+      _attributes.push_back(std::make_pair(caption, storage));
+      return *this;
+    }
+
+    /// \name Section Captions
+    /// @{
+
+    /// \brief Add an additional caption to the \c \@red_nodes and
+    /// \c \@blue_nodes section
+    ///
+    /// Add an additional caption to the \c \@red_nodes and \c
+    /// \@blue_nodes section.
+    BpGraphWriter& nodes(const std::string& caption) {
+      _nodes_caption = caption;
+      return *this;
+    }
+
+    /// \brief Add an additional caption to the \c \@edges section
+    ///
+    /// Add an additional caption to the \c \@edges section.
+    BpGraphWriter& edges(const std::string& caption) {
+      _edges_caption = caption;
+      return *this;
+    }
+
+    /// \brief Add an additional caption to the \c \@attributes section
+    ///
+    /// Add an additional caption to the \c \@attributes section.
+    BpGraphWriter& attributes(const std::string& caption) {
+      _attributes_caption = caption;
+      return *this;
+    }
+
+    /// \name Skipping Section
+    /// @{
+
+    /// \brief Skip writing the node set
+    ///
+    /// The \c \@red_nodes and \c \@blue_nodes section will not be
+    /// written to the stream.
+    BpGraphWriter& skipNodes() {
+      LEMON_ASSERT(!_skip_nodes, "Multiple usage of skipNodes() member");
+      _skip_nodes = true;
+      return *this;
+    }
+
+    /// \brief Skip writing edge set
+    ///
+    /// The \c \@edges section will not be written to the stream.
+    BpGraphWriter& skipEdges() {
+      LEMON_ASSERT(!_skip_edges, "Multiple usage of skipEdges() member");
+      _skip_edges = true;
+      return *this;
+    }
+
+    /// @}
+
+  private:
+
+    void writeRedNodes() {
+      _writer_bits::MapStorageBase<Node>* label = 0;
+      for (typename NodeMaps::iterator it = _red_maps.begin();
+           it != _red_maps.end(); ++it) {
+        if (it->first == "label") {
+          label = it->second;
+          break;
+        }
+      }
+
+      *_os << "@red_nodes";
+      if (!_nodes_caption.empty()) {
+        _writer_bits::writeToken(*_os << ' ', _nodes_caption);
+      }
+      *_os << std::endl;
+
+      if (label == 0) {
+        *_os << "label" << '\t';
+      }
+      for (typename NodeMaps::iterator it = _red_maps.begin();
+           it != _red_maps.end(); ++it) {
+        _writer_bits::writeToken(*_os, it->first) << '\t';
+      }
+      *_os << std::endl;
+
+      std::vector<Node> nodes;
+      for (RedIt n(_graph); n != INVALID; ++n) {
+        nodes.push_back(n);
+      }
+
+      if (label == 0) {
+        IdMap<BGR, Node> id_map(_graph);
+        _writer_bits::MapLess<IdMap<BGR, Node> > id_less(id_map);
+        std::sort(nodes.begin(), nodes.end(), id_less);
+      } else {
+        label->sort(nodes);
+      }
+
+      for (int i = 0; i < static_cast<int>(nodes.size()); ++i) {
+        Node n = nodes[i];
+        if (label == 0) {
+          std::ostringstream os;
+          os << _graph.id(n);
+          _writer_bits::writeToken(*_os, os.str());
+          *_os << '\t';
+          _node_index.insert(std::make_pair(n, os.str()));
+        }
+        for (typename NodeMaps::iterator it = _red_maps.begin();
+             it != _red_maps.end(); ++it) {
+          std::string value = it->second->get(n);
+          _writer_bits::writeToken(*_os, value);
+          if (it->first == "label") {
+            _node_index.insert(std::make_pair(n, value));
+          }
+          *_os << '\t';
+        }
+        *_os << std::endl;
+      }
+    }
+
+    void writeBlueNodes() {
+      _writer_bits::MapStorageBase<Node>* label = 0;
+      for (typename NodeMaps::iterator it = _blue_maps.begin();
+           it != _blue_maps.end(); ++it) {
+        if (it->first == "label") {
+          label = it->second;
+          break;
+        }
+      }
+
+      *_os << "@blue_nodes";
+      if (!_nodes_caption.empty()) {
+        _writer_bits::writeToken(*_os << ' ', _nodes_caption);
+      }
+      *_os << std::endl;
+
+      if (label == 0) {
+        *_os << "label" << '\t';
+      }
+      for (typename NodeMaps::iterator it = _blue_maps.begin();
+           it != _blue_maps.end(); ++it) {
+        _writer_bits::writeToken(*_os, it->first) << '\t';
+      }
+      *_os << std::endl;
+
+      std::vector<Node> nodes;
+      for (BlueIt n(_graph); n != INVALID; ++n) {
+        nodes.push_back(n);
+      }
+
+      if (label == 0) {
+        IdMap<BGR, Node> id_map(_graph);
+        _writer_bits::MapLess<IdMap<BGR, Node> > id_less(id_map);
+        std::sort(nodes.begin(), nodes.end(), id_less);
+      } else {
+        label->sort(nodes);
+      }
+
+      for (int i = 0; i < static_cast<int>(nodes.size()); ++i) {
+        Node n = nodes[i];
+        if (label == 0) {
+          std::ostringstream os;
+          os << _graph.id(n);
+          _writer_bits::writeToken(*_os, os.str());
+          *_os << '\t';
+          _node_index.insert(std::make_pair(n, os.str()));
+        }
+        for (typename NodeMaps::iterator it = _blue_maps.begin();
+             it != _blue_maps.end(); ++it) {
+          std::string value = it->second->get(n);
+          _writer_bits::writeToken(*_os, value);
+          if (it->first == "label") {
+            _node_index.insert(std::make_pair(n, value));
+          }
+          *_os << '\t';
+        }
+        *_os << std::endl;
+      }
+    }
+
+    void createRedNodeIndex() {
+      _writer_bits::MapStorageBase<Node>* label = 0;
+      for (typename NodeMaps::iterator it = _red_maps.begin();
+           it != _red_maps.end(); ++it) {
+        if (it->first == "label") {
+          label = it->second;
+          break;
+        }
+      }
+
+      if (label == 0) {
+        for (NodeIt n(_graph); n != INVALID; ++n) {
+          std::ostringstream os;
+          os << _graph.id(n);
+          _node_index.insert(std::make_pair(n, os.str()));
+        }
+      } else {
+        for (NodeIt n(_graph); n != INVALID; ++n) {
+          std::string value = label->get(n);
+          _node_index.insert(std::make_pair(n, value));
+        }
+      }
+    }
+
+    void createBlueNodeIndex() {
+      _writer_bits::MapStorageBase<Node>* label = 0;
+      for (typename NodeMaps::iterator it = _blue_maps.begin();
+           it != _blue_maps.end(); ++it) {
+        if (it->first == "label") {
+          label = it->second;
+          break;
+        }
+      }
+
+      if (label == 0) {
+        for (NodeIt n(_graph); n != INVALID; ++n) {
+          std::ostringstream os;
+          os << _graph.id(n);
+          _node_index.insert(std::make_pair(n, os.str()));
+        }
+      } else {
+        for (NodeIt n(_graph); n != INVALID; ++n) {
+          std::string value = label->get(n);
+          _node_index.insert(std::make_pair(n, value));
+        }
+      }
+    }
+
+    void writeEdges() {
+      _writer_bits::MapStorageBase<Edge>* label = 0;
+      for (typename EdgeMaps::iterator it = _edge_maps.begin();
+           it != _edge_maps.end(); ++it) {
+        if (it->first == "label") {
+          label = it->second;
+          break;
+        }
+      }
+
+      *_os << "@edges";
+      if (!_edges_caption.empty()) {
+        _writer_bits::writeToken(*_os << ' ', _edges_caption);
+      }
+      *_os << std::endl;
+
+      *_os << '\t' << '\t';
+      if (label == 0) {
+        *_os << "label" << '\t';
+      }
+      for (typename EdgeMaps::iterator it = _edge_maps.begin();
+           it != _edge_maps.end(); ++it) {
+        _writer_bits::writeToken(*_os, it->first) << '\t';
+      }
+      *_os << std::endl;
+
+      std::vector<Edge> edges;
+      for (EdgeIt n(_graph); n != INVALID; ++n) {
+        edges.push_back(n);
+      }
+
+      if (label == 0) {
+        IdMap<BGR, Edge> id_map(_graph);
+        _writer_bits::MapLess<IdMap<BGR, Edge> > id_less(id_map);
+        std::sort(edges.begin(), edges.end(), id_less);
+      } else {
+        label->sort(edges);
+      }
+
+      for (int i = 0; i < static_cast<int>(edges.size()); ++i) {
+        Edge e = edges[i];
+        _writer_bits::writeToken(*_os, _node_index.
+                                 find(_graph.redNode(e))->second);
+        *_os << '\t';
+        _writer_bits::writeToken(*_os, _node_index.
+                                 find(_graph.blueNode(e))->second);
+        *_os << '\t';
+        if (label == 0) {
+          std::ostringstream os;
+          os << _graph.id(e);
+          _writer_bits::writeToken(*_os, os.str());
+          *_os << '\t';
+          _edge_index.insert(std::make_pair(e, os.str()));
+        }
+        for (typename EdgeMaps::iterator it = _edge_maps.begin();
+             it != _edge_maps.end(); ++it) {
+          std::string value = it->second->get(e);
+          _writer_bits::writeToken(*_os, value);
+          if (it->first == "label") {
+            _edge_index.insert(std::make_pair(e, value));
+          }
+          *_os << '\t';
+        }
+        *_os << std::endl;
+      }
+    }
+
+    void createEdgeIndex() {
+      _writer_bits::MapStorageBase<Edge>* label = 0;
+      for (typename EdgeMaps::iterator it = _edge_maps.begin();
+           it != _edge_maps.end(); ++it) {
+        if (it->first == "label") {
+          label = it->second;
+          break;
+        }
+      }
+
+      if (label == 0) {
+        for (EdgeIt e(_graph); e != INVALID; ++e) {
+          std::ostringstream os;
+          os << _graph.id(e);
+          _edge_index.insert(std::make_pair(e, os.str()));
+        }
+      } else {
+        for (EdgeIt e(_graph); e != INVALID; ++e) {
+          std::string value = label->get(e);
+          _edge_index.insert(std::make_pair(e, value));
+        }
+      }
+    }
+
+    void writeAttributes() {
+      if (_attributes.empty()) return;
+      *_os << "@attributes";
+      if (!_attributes_caption.empty()) {
+        _writer_bits::writeToken(*_os << ' ', _attributes_caption);
+      }
+      *_os << std::endl;
+      for (typename Attributes::iterator it = _attributes.begin();
+           it != _attributes.end(); ++it) {
+        _writer_bits::writeToken(*_os, it->first) << ' ';
+        _writer_bits::writeToken(*_os, it->second->get());
+        *_os << std::endl;
+      }
+    }
+
+  public:
+
+    /// \name Execution of the Writer
+    /// @{
+
+    /// \brief Start the batch processing
+    ///
+    /// This function starts the batch processing.
+    void run() {
+      if (!_skip_nodes) {
+        writeRedNodes();
+        writeBlueNodes();
+      } else {
+        createRedNodeIndex();
+        createBlueNodeIndex();
+      }
+      if (!_skip_edges) {
+        writeEdges();
+      } else {
+        createEdgeIndex();
+      }
+      writeAttributes();
+    }
+
+    /// \brief Give back the stream of the writer
+    ///
+    /// Give back the stream of the writer
+    std::ostream& ostream() {
+      return *_os;
+    }
+
+    /// @}
+  };
+
+  /// \ingroup lemon_io
+  ///
+  /// \brief Return a \ref BpGraphWriter class
+  ///
+  /// This function just returns a \ref BpGraphWriter class.
+  ///
+  /// With this function a bipartite graph can be write to a file or output
+  /// stream in \ref lgf-format "LGF" format with several maps and
+  /// attributes. For example, with the following code a bipartite
+  /// weighted matching problem can be written to the standard output,
+  /// i.e. a graph with a \e weight map on the edges:
+  ///
+  ///\code
+  ///ListBpGraph graph;
+  ///ListBpGraph::EdgeMap<int> weight(graph);
+  ///  // Setting the weight map
+  ///bpGraphWriter(graph, std::cout).
+  ///  edgeMap("weight", weight).
+  ///  run();
+  ///\endcode
+  ///
+  /// For a complete documentation, please see the \ref BpGraphWriter
+  /// class documentation.
+  /// \warning Don't forget to put the \ref BpGraphWriter::run() "run()"
+  /// to the end of the parameter list.
+  /// \relates BpGraphWriter
+  /// \sa bpGraphWriter(const TBGR& graph, const std::string& fn)
+  /// \sa bpGraphWriter(const TBGR& graph, const char* fn)
+  template <typename TBGR>
+  BpGraphWriter<TBGR> bpGraphWriter(const TBGR& graph, std::ostream& os) {
+    BpGraphWriter<TBGR> tmp(graph, os);
+    return tmp;
+  }
+
+  /// \brief Return a \ref BpGraphWriter class
+  ///
+  /// This function just returns a \ref BpGraphWriter class.
+  /// \relates BpGraphWriter
+  /// \sa graphWriter(const TBGR& graph, std::ostream& os)
+  template <typename TBGR>
+  BpGraphWriter<TBGR> bpGraphWriter(const TBGR& graph, const std::string& fn) {
+    BpGraphWriter<TBGR> tmp(graph, fn);
+    return tmp;
+  }
+
+  /// \brief Return a \ref BpGraphWriter class
+  ///
+  /// This function just returns a \ref BpGraphWriter class.
+  /// \relates BpGraphWriter
+  /// \sa graphWriter(const TBGR& graph, std::ostream& os)
+  template <typename TBGR>
+  BpGraphWriter<TBGR> bpGraphWriter(const TBGR& graph, const char* fn) {
+    BpGraphWriter<TBGR> tmp(graph, fn);
     return tmp;
   }
