test/lgf_reader_writer_test.cc
changeset 1215 f7247b5c04bf
child 1270 dceba191c00d
equal deleted inserted replaced
-1:000000000000 0:3ba6ba2a6e17
       
     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 #include <string>
       
    20 
       
    21 #include <lemon/concepts/digraph.h>
       
    22 #include <lemon/concepts/graph.h>
       
    23 #include <lemon/concepts/bpgraph.h>
       
    24 
       
    25 #include <lemon/list_graph.h>
       
    26 #include <lemon/smart_graph.h>
       
    27 #include <lemon/lgf_reader.h>
       
    28 
       
    29 #include "test_tools.h"
       
    30 
       
    31 struct ReaderConverter {
       
    32   int operator()(const std::string& str) const {
       
    33     return str.length();
       
    34   }
       
    35 };
       
    36 
       
    37 struct WriterConverter {
       
    38   std::string operator()(int value) const {
       
    39     return std::string(value, '*');
       
    40   }
       
    41 };
       
    42 
       
    43 void checkDigraphReaderCompile() {
       
    44   typedef lemon::concepts::ExtendableDigraphComponent<
       
    45     lemon::concepts::Digraph> Digraph;
       
    46   Digraph digraph;
       
    47   Digraph::NodeMap<int> node_map(digraph);
       
    48   Digraph::ArcMap<int> arc_map(digraph);
       
    49   Digraph::Node node;
       
    50   Digraph::Arc arc;
       
    51   int attr;
       
    52 
       
    53   lemon::DigraphReader<Digraph> reader(digraph, "filename");
       
    54   reader.nodeMap("node_map", node_map);
       
    55   reader.nodeMap("node_map", node_map, ReaderConverter());
       
    56   reader.arcMap("arc_map", arc_map);
       
    57   reader.arcMap("arc_map", arc_map, ReaderConverter());
       
    58   reader.attribute("attr", attr);
       
    59   reader.attribute("attr", attr, ReaderConverter());
       
    60   reader.node("node", node);
       
    61   reader.arc("arc", arc);
       
    62 
       
    63   reader.nodes("alt_nodes_caption");
       
    64   reader.arcs("alt_arcs_caption");
       
    65   reader.attributes("alt_attrs_caption");
       
    66 
       
    67   reader.useNodes(node_map);
       
    68   reader.useNodes(node_map, WriterConverter());
       
    69   reader.useArcs(arc_map);
       
    70   reader.useArcs(arc_map, WriterConverter());
       
    71 
       
    72   reader.skipNodes();
       
    73   reader.skipArcs();
       
    74 
       
    75   reader.run();
       
    76 
       
    77   lemon::DigraphReader<Digraph> reader2(digraph, std::cin);
       
    78 }
       
    79 
       
    80 void checkDigraphWriterCompile() {
       
    81   typedef lemon::concepts::Digraph Digraph;
       
    82   Digraph digraph;
       
    83   Digraph::NodeMap<int> node_map(digraph);
       
    84   Digraph::ArcMap<int> arc_map(digraph);
       
    85   Digraph::Node node;
       
    86   Digraph::Arc arc;
       
    87   int attr;
       
    88 
       
    89   lemon::DigraphWriter<Digraph> writer(digraph, "filename");
       
    90   writer.nodeMap("node_map", node_map);
       
    91   writer.nodeMap("node_map", node_map, WriterConverter());
       
    92   writer.arcMap("arc_map", arc_map);
       
    93   writer.arcMap("arc_map", arc_map, WriterConverter());
       
    94   writer.attribute("attr", attr);
       
    95   writer.attribute("attr", attr, WriterConverter());
       
    96   writer.node("node", node);
       
    97   writer.arc("arc", arc);
       
    98 
       
    99   writer.nodes("alt_nodes_caption");
       
   100   writer.arcs("alt_arcs_caption");
       
   101   writer.attributes("alt_attrs_caption");
       
   102 
       
   103   writer.skipNodes();
       
   104   writer.skipArcs();
       
   105 
       
   106   writer.run();
       
   107 }
       
   108 
       
   109 void checkGraphReaderCompile() {
       
   110   typedef lemon::concepts::ExtendableGraphComponent<
       
   111     lemon::concepts::Graph> Graph;
       
   112   Graph graph;
       
   113   Graph::NodeMap<int> node_map(graph);
       
   114   Graph::ArcMap<int> arc_map(graph);
       
   115   Graph::EdgeMap<int> edge_map(graph);
       
   116   Graph::Node node;
       
   117   Graph::Arc arc;
       
   118   Graph::Edge edge;
       
   119   int attr;
       
   120 
       
   121   lemon::GraphReader<Graph> reader(graph, "filename");
       
   122   reader.nodeMap("node_map", node_map);
       
   123   reader.nodeMap("node_map", node_map, ReaderConverter());
       
   124   reader.arcMap("arc_map", arc_map);
       
   125   reader.arcMap("arc_map", arc_map, ReaderConverter());
       
   126   reader.edgeMap("edge_map", edge_map);
       
   127   reader.edgeMap("edge_map", edge_map, ReaderConverter());
       
   128   reader.attribute("attr", attr);
       
   129   reader.attribute("attr", attr, ReaderConverter());
       
   130   reader.node("node", node);
       
   131   reader.arc("arc", arc);
       
   132 
       
   133   reader.nodes("alt_nodes_caption");
       
   134   reader.edges("alt_edges_caption");
       
   135   reader.attributes("alt_attrs_caption");
       
   136 
       
   137   reader.useNodes(node_map);
       
   138   reader.useNodes(node_map, WriterConverter());
       
   139   reader.useEdges(edge_map);
       
   140   reader.useEdges(edge_map, WriterConverter());
       
   141 
       
   142   reader.skipNodes();
       
   143   reader.skipEdges();
       
   144 
       
   145   reader.run();
       
   146 
       
   147   lemon::GraphReader<Graph> reader2(graph, std::cin);
       
   148 }
       
   149 
       
   150 void checkGraphWriterCompile() {
       
   151   typedef lemon::concepts::Graph Graph;
       
   152   Graph graph;
       
   153   Graph::NodeMap<int> node_map(graph);
       
   154   Graph::ArcMap<int> arc_map(graph);
       
   155   Graph::EdgeMap<int> edge_map(graph);
       
   156   Graph::Node node;
       
   157   Graph::Arc arc;
       
   158   Graph::Edge edge;
       
   159   int attr;
       
   160 
       
   161   lemon::GraphWriter<Graph> writer(graph, "filename");
       
   162   writer.nodeMap("node_map", node_map);
       
   163   writer.nodeMap("node_map", node_map, WriterConverter());
       
   164   writer.arcMap("arc_map", arc_map);
       
   165   writer.arcMap("arc_map", arc_map, WriterConverter());
       
   166   writer.edgeMap("edge_map", edge_map);
       
   167   writer.edgeMap("edge_map", edge_map, WriterConverter());
       
   168   writer.attribute("attr", attr);
       
   169   writer.attribute("attr", attr, WriterConverter());
       
   170   writer.node("node", node);
       
   171   writer.arc("arc", arc);
       
   172   writer.edge("edge", edge);
       
   173 
       
   174   writer.nodes("alt_nodes_caption");
       
   175   writer.edges("alt_edges_caption");
       
   176   writer.attributes("alt_attrs_caption");
       
   177 
       
   178   writer.skipNodes();
       
   179   writer.skipEdges();
       
   180 
       
   181   writer.run();
       
   182 
       
   183   lemon::GraphWriter<Graph> writer2(graph, std::cout);
       
   184 }
       
   185 
       
   186 void checkBpGraphReaderCompile() {
       
   187   typedef lemon::concepts::ExtendableBpGraphComponent<
       
   188     lemon::concepts::BpGraph> BpGraph;
       
   189   BpGraph graph;
       
   190   BpGraph::NodeMap<int> node_map(graph);
       
   191   BpGraph::RedNodeMap<int> red_node_map(graph);
       
   192   BpGraph::BlueNodeMap<int> blue_node_map(graph);
       
   193   BpGraph::ArcMap<int> arc_map(graph);
       
   194   BpGraph::EdgeMap<int> edge_map(graph);
       
   195   BpGraph::Node node;
       
   196   BpGraph::RedNode red_node;
       
   197   BpGraph::BlueNode blue_node;
       
   198   BpGraph::Arc arc;
       
   199   BpGraph::Edge edge;
       
   200   int attr;
       
   201 
       
   202   lemon::BpGraphReader<BpGraph> reader(graph, "filename");
       
   203   reader.nodeMap("node_map", node_map);
       
   204   reader.nodeMap("node_map", node_map, ReaderConverter());
       
   205   reader.redNodeMap("red_node_map", red_node_map);
       
   206   reader.redNodeMap("red_node_map", red_node_map, ReaderConverter());
       
   207   reader.blueNodeMap("blue_node_map", blue_node_map);
       
   208   reader.blueNodeMap("blue_node_map", blue_node_map, ReaderConverter());
       
   209   reader.arcMap("arc_map", arc_map);
       
   210   reader.arcMap("arc_map", arc_map, ReaderConverter());
       
   211   reader.edgeMap("edge_map", edge_map);
       
   212   reader.edgeMap("edge_map", edge_map, ReaderConverter());
       
   213   reader.attribute("attr", attr);
       
   214   reader.attribute("attr", attr, ReaderConverter());
       
   215   reader.node("node", node);
       
   216   reader.redNode("red_node", red_node);
       
   217   reader.blueNode("blue_node", blue_node);
       
   218   reader.arc("arc", arc);
       
   219 
       
   220   reader.nodes("alt_nodes_caption");
       
   221   reader.edges("alt_edges_caption");
       
   222   reader.attributes("alt_attrs_caption");
       
   223 
       
   224   reader.useNodes(node_map);
       
   225   reader.useNodes(node_map, WriterConverter());
       
   226   reader.useEdges(edge_map);
       
   227   reader.useEdges(edge_map, WriterConverter());
       
   228 
       
   229   reader.skipNodes();
       
   230   reader.skipEdges();
       
   231 
       
   232   reader.run();
       
   233 
       
   234   lemon::BpGraphReader<BpGraph> reader2(graph, std::cin);
       
   235 }
       
   236 
       
   237 void checkBpGraphWriterCompile() {
       
   238   typedef lemon::concepts::BpGraph BpGraph;
       
   239   BpGraph graph;
       
   240   BpGraph::NodeMap<int> node_map(graph);
       
   241   BpGraph::RedNodeMap<int> red_node_map(graph);
       
   242   BpGraph::BlueNodeMap<int> blue_node_map(graph);
       
   243   BpGraph::ArcMap<int> arc_map(graph);
       
   244   BpGraph::EdgeMap<int> edge_map(graph);
       
   245   BpGraph::Node node;
       
   246   BpGraph::RedNode red_node;
       
   247   BpGraph::BlueNode blue_node;
       
   248   BpGraph::Arc arc;
       
   249   BpGraph::Edge edge;
       
   250   int attr;
       
   251 
       
   252   lemon::BpGraphWriter<BpGraph> writer(graph, "filename");
       
   253   writer.nodeMap("node_map", node_map);
       
   254   writer.nodeMap("node_map", node_map, WriterConverter());
       
   255   writer.redNodeMap("red_node_map", red_node_map);
       
   256   writer.redNodeMap("red_node_map", red_node_map, WriterConverter());
       
   257   writer.blueNodeMap("blue_node_map", blue_node_map);
       
   258   writer.blueNodeMap("blue_node_map", blue_node_map, WriterConverter());
       
   259   writer.arcMap("arc_map", arc_map);
       
   260   writer.arcMap("arc_map", arc_map, WriterConverter());
       
   261   writer.edgeMap("edge_map", edge_map);
       
   262   writer.edgeMap("edge_map", edge_map, WriterConverter());
       
   263   writer.attribute("attr", attr);
       
   264   writer.attribute("attr", attr, WriterConverter());
       
   265   writer.node("node", node);
       
   266   writer.redNode("red_node", red_node);
       
   267   writer.blueNode("blue_node", blue_node);
       
   268   writer.arc("arc", arc);
       
   269 
       
   270   writer.nodes("alt_nodes_caption");
       
   271   writer.edges("alt_edges_caption");
       
   272   writer.attributes("alt_attrs_caption");
       
   273 
       
   274   writer.skipNodes();
       
   275   writer.skipEdges();
       
   276 
       
   277   writer.run();
       
   278 
       
   279   lemon::BpGraphWriter<BpGraph> writer2(graph, std::cout);
       
   280 }
       
   281 
       
   282 void checkDigraphReaderWriter() {
       
   283   typedef lemon::SmartDigraph Digraph;
       
   284   Digraph digraph;
       
   285   Digraph::Node n1 = digraph.addNode();
       
   286   Digraph::Node n2 = digraph.addNode();
       
   287   Digraph::Node n3 = digraph.addNode();
       
   288 
       
   289   Digraph::Arc a1 = digraph.addArc(n1, n2);
       
   290   Digraph::Arc a2 = digraph.addArc(n2, n3);
       
   291 
       
   292   Digraph::NodeMap<int> node_map(digraph);
       
   293   node_map[n1] = 11;
       
   294   node_map[n2] = 12;
       
   295   node_map[n3] = 13;
       
   296 
       
   297   Digraph::ArcMap<int> arc_map(digraph);
       
   298   arc_map[a1] = 21;
       
   299   arc_map[a2] = 22;
       
   300 
       
   301   int attr = 100;
       
   302 
       
   303   std::ostringstream os;
       
   304   lemon::DigraphWriter<Digraph> writer(digraph, os);
       
   305 
       
   306   writer.nodeMap("node_map1", node_map);
       
   307   writer.nodeMap("node_map2", node_map, WriterConverter());
       
   308   writer.arcMap("arc_map1", arc_map);
       
   309   writer.arcMap("arc_map2", arc_map, WriterConverter());
       
   310   writer.node("node", n2);
       
   311   writer.arc("arc", a1);
       
   312   writer.attribute("attr1", attr);
       
   313   writer.attribute("attr2", attr, WriterConverter());
       
   314 
       
   315   writer.run();
       
   316 
       
   317   typedef lemon::ListDigraph ExpDigraph;
       
   318   ExpDigraph exp_digraph;
       
   319   ExpDigraph::NodeMap<int> exp_node_map1(exp_digraph);
       
   320   ExpDigraph::NodeMap<int> exp_node_map2(exp_digraph);
       
   321   ExpDigraph::ArcMap<int> exp_arc_map1(exp_digraph);
       
   322   ExpDigraph::ArcMap<int> exp_arc_map2(exp_digraph);
       
   323   ExpDigraph::Node exp_n2;
       
   324   ExpDigraph::Arc exp_a1;
       
   325   int exp_attr1;
       
   326   int exp_attr2;
       
   327 
       
   328   std::istringstream is(os.str());
       
   329   lemon::DigraphReader<ExpDigraph> reader(exp_digraph, is);
       
   330 
       
   331   reader.nodeMap("node_map1", exp_node_map1);
       
   332   reader.nodeMap("node_map2", exp_node_map2, ReaderConverter());
       
   333   reader.arcMap("arc_map1", exp_arc_map1);
       
   334   reader.arcMap("arc_map2", exp_arc_map2, ReaderConverter());
       
   335   reader.node("node", exp_n2);
       
   336   reader.arc("arc", exp_a1);
       
   337   reader.attribute("attr1", exp_attr1);
       
   338   reader.attribute("attr2", exp_attr2, ReaderConverter());
       
   339 
       
   340   reader.run();
       
   341 
       
   342   check(lemon::countNodes(exp_digraph) == 3, "Wrong number of nodes");
       
   343   check(lemon::countArcs(exp_digraph) == 2, "Wrong number of arcs");
       
   344   check(exp_node_map1[exp_n2] == 12, "Wrong map value");
       
   345   check(exp_node_map2[exp_n2] == 12, "Wrong map value");
       
   346   check(exp_arc_map1[exp_a1] == 21, "Wrong map value");
       
   347   check(exp_arc_map2[exp_a1] == 21, "Wrong map value");
       
   348   check(exp_attr1 == 100, "Wrong attr value");
       
   349   check(exp_attr2 == 100, "Wrong attr value");
       
   350 }
       
   351 
       
   352 void checkGraphReaderWriter() {
       
   353   typedef lemon::SmartGraph Graph;
       
   354   Graph graph;
       
   355   Graph::Node n1 = graph.addNode();
       
   356   Graph::Node n2 = graph.addNode();
       
   357   Graph::Node n3 = graph.addNode();
       
   358 
       
   359   Graph::Edge e1 = graph.addEdge(n1, n2);
       
   360   Graph::Edge e2 = graph.addEdge(n2, n3);
       
   361 
       
   362   Graph::NodeMap<int> node_map(graph);
       
   363   node_map[n1] = 11;
       
   364   node_map[n2] = 12;
       
   365   node_map[n3] = 13;
       
   366 
       
   367   Graph::EdgeMap<int> edge_map(graph);
       
   368   edge_map[e1] = 21;
       
   369   edge_map[e2] = 22;
       
   370 
       
   371   Graph::ArcMap<int> arc_map(graph);
       
   372   arc_map[graph.direct(e1, true)] = 211;
       
   373   arc_map[graph.direct(e1, false)] = 212;
       
   374   arc_map[graph.direct(e2, true)] = 221;
       
   375   arc_map[graph.direct(e2, false)] = 222;
       
   376 
       
   377   int attr = 100;
       
   378 
       
   379   std::ostringstream os;
       
   380   lemon::GraphWriter<Graph> writer(graph, os);
       
   381 
       
   382   writer.nodeMap("node_map1", node_map);
       
   383   writer.nodeMap("node_map2", node_map, WriterConverter());
       
   384   writer.edgeMap("edge_map1", edge_map);
       
   385   writer.edgeMap("edge_map2", edge_map, WriterConverter());
       
   386   writer.arcMap("arc_map1", arc_map);
       
   387   writer.arcMap("arc_map2", arc_map, WriterConverter());
       
   388   writer.node("node", n2); 
       
   389   writer.edge("edge", e1);
       
   390   writer.arc("arc", graph.direct(e1, false));
       
   391   writer.attribute("attr1", attr);
       
   392   writer.attribute("attr2", attr, WriterConverter());
       
   393 
       
   394   writer.run();
       
   395 
       
   396   typedef lemon::ListGraph ExpGraph;
       
   397   ExpGraph exp_graph;
       
   398   ExpGraph::NodeMap<int> exp_node_map1(exp_graph);
       
   399   ExpGraph::NodeMap<int> exp_node_map2(exp_graph);
       
   400   ExpGraph::EdgeMap<int> exp_edge_map1(exp_graph);
       
   401   ExpGraph::EdgeMap<int> exp_edge_map2(exp_graph);
       
   402   ExpGraph::ArcMap<int> exp_arc_map1(exp_graph);
       
   403   ExpGraph::ArcMap<int> exp_arc_map2(exp_graph);
       
   404   ExpGraph::Node exp_n2;
       
   405   ExpGraph::Edge exp_e1;
       
   406   ExpGraph::Arc exp_a1;
       
   407   int exp_attr1;
       
   408   int exp_attr2;
       
   409 
       
   410   std::istringstream is(os.str());
       
   411   lemon::GraphReader<ExpGraph> reader(exp_graph, is);
       
   412 
       
   413   reader.nodeMap("node_map1", exp_node_map1);
       
   414   reader.nodeMap("node_map2", exp_node_map2, ReaderConverter());
       
   415   reader.edgeMap("edge_map1", exp_edge_map1);
       
   416   reader.edgeMap("edge_map2", exp_edge_map2, ReaderConverter());
       
   417   reader.arcMap("arc_map1", exp_arc_map1);
       
   418   reader.arcMap("arc_map2", exp_arc_map2, ReaderConverter());
       
   419   reader.node("node", exp_n2);
       
   420   reader.edge("edge", exp_e1);
       
   421   reader.arc("arc", exp_a1);
       
   422   reader.attribute("attr1", exp_attr1);
       
   423   reader.attribute("attr2", exp_attr2, ReaderConverter());
       
   424 
       
   425   reader.run();
       
   426 
       
   427   check(lemon::countNodes(exp_graph) == 3, "Wrong number of nodes");
       
   428   check(lemon::countEdges(exp_graph) == 2, "Wrong number of edges");
       
   429   check(lemon::countArcs(exp_graph) == 4, "Wrong number of arcs");
       
   430   check(exp_node_map1[exp_n2] == 12, "Wrong map value");
       
   431   check(exp_node_map2[exp_n2] == 12, "Wrong map value");
       
   432   check(exp_edge_map1[exp_e1] == 21, "Wrong map value");
       
   433   check(exp_edge_map2[exp_e1] == 21, "Wrong map value");
       
   434   check(exp_arc_map1[exp_a1] == 212, "Wrong map value");
       
   435   check(exp_arc_map2[exp_a1] == 212, "Wrong map value");
       
   436   check(exp_attr1 == 100, "Wrong attr value");
       
   437   check(exp_attr2 == 100, "Wrong attr value");
       
   438 }
       
   439 
       
   440 void checkBpGraphReaderWriter() {
       
   441   typedef lemon::SmartBpGraph Graph;
       
   442   Graph graph;
       
   443   Graph::RedNode rn1 = graph.addRedNode();
       
   444   Graph::RedNode rn2 = graph.addRedNode();
       
   445   Graph::RedNode rn3 = graph.addRedNode();
       
   446   Graph::BlueNode bn1 = graph.addBlueNode();
       
   447   Graph::BlueNode bn2 = graph.addBlueNode();
       
   448   Graph::Node n = bn1;
       
   449 
       
   450   Graph::Edge e1 = graph.addEdge(rn1, bn1);
       
   451   Graph::Edge e2 = graph.addEdge(rn2, bn1);
       
   452 
       
   453   Graph::NodeMap<int> node_map(graph);
       
   454   node_map[rn1] = 11;
       
   455   node_map[rn2] = 12;
       
   456   node_map[rn3] = 13;
       
   457   node_map[bn1] = 14;
       
   458   node_map[bn2] = 15;
       
   459 
       
   460   Graph::NodeMap<int> red_node_map(graph);
       
   461   red_node_map[rn1] = 411;
       
   462   red_node_map[rn2] = 412;
       
   463   red_node_map[rn3] = 413;
       
   464 
       
   465   Graph::NodeMap<int> blue_node_map(graph);
       
   466   blue_node_map[bn1] = 414;
       
   467   blue_node_map[bn2] = 415;
       
   468 
       
   469   Graph::EdgeMap<int> edge_map(graph);
       
   470   edge_map[e1] = 21;
       
   471   edge_map[e2] = 22;
       
   472 
       
   473   Graph::ArcMap<int> arc_map(graph);
       
   474   arc_map[graph.direct(e1, true)] = 211;
       
   475   arc_map[graph.direct(e1, false)] = 212;
       
   476   arc_map[graph.direct(e2, true)] = 221;
       
   477   arc_map[graph.direct(e2, false)] = 222;
       
   478 
       
   479   int attr = 100;
       
   480 
       
   481   std::ostringstream os;
       
   482   lemon::BpGraphWriter<Graph> writer(graph, os);
       
   483 
       
   484   writer.nodeMap("node_map1", node_map);
       
   485   writer.nodeMap("node_map2", node_map, WriterConverter());
       
   486   writer.nodeMap("red_node_map1", red_node_map);
       
   487   writer.nodeMap("red_node_map2", red_node_map, WriterConverter());
       
   488   writer.nodeMap("blue_node_map1", blue_node_map);
       
   489   writer.nodeMap("blue_node_map2", blue_node_map, WriterConverter());
       
   490   writer.edgeMap("edge_map1", edge_map);
       
   491   writer.edgeMap("edge_map2", edge_map, WriterConverter());
       
   492   writer.arcMap("arc_map1", arc_map);
       
   493   writer.arcMap("arc_map2", arc_map, WriterConverter());
       
   494   writer.node("node", n);
       
   495   writer.redNode("red_node", rn1); 
       
   496   writer.blueNode("blue_node", bn2);
       
   497   writer.edge("edge", e1);
       
   498   writer.arc("arc", graph.direct(e1, false));
       
   499   writer.attribute("attr1", attr);
       
   500   writer.attribute("attr2", attr, WriterConverter());
       
   501 
       
   502   writer.run();
       
   503 
       
   504   typedef lemon::ListBpGraph ExpGraph;
       
   505   ExpGraph exp_graph;
       
   506   ExpGraph::NodeMap<int> exp_node_map1(exp_graph);
       
   507   ExpGraph::NodeMap<int> exp_node_map2(exp_graph);
       
   508   ExpGraph::RedNodeMap<int> exp_red_node_map1(exp_graph);
       
   509   ExpGraph::RedNodeMap<int> exp_red_node_map2(exp_graph);
       
   510   ExpGraph::BlueNodeMap<int> exp_blue_node_map1(exp_graph);
       
   511   ExpGraph::BlueNodeMap<int> exp_blue_node_map2(exp_graph);
       
   512   ExpGraph::EdgeMap<int> exp_edge_map1(exp_graph);
       
   513   ExpGraph::EdgeMap<int> exp_edge_map2(exp_graph);
       
   514   ExpGraph::ArcMap<int> exp_arc_map1(exp_graph);
       
   515   ExpGraph::ArcMap<int> exp_arc_map2(exp_graph);
       
   516   ExpGraph::Node exp_n;
       
   517   ExpGraph::RedNode exp_rn1;
       
   518   ExpGraph::BlueNode exp_bn2;
       
   519   ExpGraph::Edge exp_e1;
       
   520   ExpGraph::Arc exp_a1;
       
   521   int exp_attr1;
       
   522   int exp_attr2;
       
   523 
       
   524   std::istringstream is(os.str());
       
   525   lemon::BpGraphReader<ExpGraph> reader(exp_graph, is);
       
   526 
       
   527   reader.nodeMap("node_map1", exp_node_map1);
       
   528   reader.nodeMap("node_map2", exp_node_map2, ReaderConverter());
       
   529   reader.redNodeMap("red_node_map1", exp_red_node_map1);
       
   530   reader.redNodeMap("red_node_map2", exp_red_node_map2, ReaderConverter());
       
   531   reader.blueNodeMap("blue_node_map1", exp_blue_node_map1);
       
   532   reader.blueNodeMap("blue_node_map2", exp_blue_node_map2, ReaderConverter());
       
   533   reader.edgeMap("edge_map1", exp_edge_map1);
       
   534   reader.edgeMap("edge_map2", exp_edge_map2, ReaderConverter());
       
   535   reader.arcMap("arc_map1", exp_arc_map1);
       
   536   reader.arcMap("arc_map2", exp_arc_map2, ReaderConverter());
       
   537   reader.node("node", exp_n);
       
   538   reader.redNode("red_node", exp_rn1);
       
   539   reader.blueNode("blue_node", exp_bn2);
       
   540   reader.edge("edge", exp_e1);
       
   541   reader.arc("arc", exp_a1);
       
   542   reader.attribute("attr1", exp_attr1);
       
   543   reader.attribute("attr2", exp_attr2, ReaderConverter());
       
   544 
       
   545   reader.run();
       
   546 
       
   547   check(lemon::countNodes(exp_graph) == 5, "Wrong number of nodes");
       
   548   check(lemon::countRedNodes(exp_graph) == 3, "Wrong number of red nodes");
       
   549   check(lemon::countBlueNodes(exp_graph) == 2, "Wrong number of blue nodes");
       
   550   check(lemon::countEdges(exp_graph) == 2, "Wrong number of edges");
       
   551   check(lemon::countArcs(exp_graph) == 4, "Wrong number of arcs");
       
   552   check(exp_node_map1[exp_n] == 14, "Wrong map value");
       
   553   check(exp_node_map2[exp_n] == 14, "Wrong map value");
       
   554   check(exp_red_node_map1[exp_rn1] == 411, "Wrong map value");
       
   555   check(exp_red_node_map2[exp_rn1] == 411, "Wrong map value");
       
   556   check(exp_blue_node_map1[exp_bn2] == 415, "Wrong map value");
       
   557   check(exp_blue_node_map2[exp_bn2] == 415, "Wrong map value");
       
   558   check(exp_edge_map1[exp_e1] == 21, "Wrong map value");
       
   559   check(exp_edge_map2[exp_e1] == 21, "Wrong map value");
       
   560   check(exp_arc_map1[exp_a1] == 212, "Wrong map value");
       
   561   check(exp_arc_map2[exp_a1] == 212, "Wrong map value");
       
   562   check(exp_attr1 == 100, "Wrong attr value");
       
   563   check(exp_attr2 == 100, "Wrong attr value");
       
   564 }
       
   565 
       
   566 
       
   567 int main() {
       
   568   { // Check digrpah
       
   569     checkDigraphReaderWriter();
       
   570   }
       
   571   { // Check graph
       
   572     checkGraphReaderWriter();
       
   573   }
       
   574   { // Check bipartite graph
       
   575     checkBpGraphReaderWriter();
       
   576   }
       
   577   return 0;
       
   578 }