COIN-OR::LEMON - Graph Library

Changeset 1901:723b2b81d900 in lemon-0.x


Ignore:
Timestamp:
01/24/06 17:07:38 (14 years ago)
Author:
Balazs Dezso
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@2476
Message:

Lemon Graph Format uses label instead of id named map.

Files:
17 edited

Legend:

Unmodified
Added
Removed
  • demo/coloring.lgf

    r1683 r1901  
    11@nodeset
    2 coords  id     
     2coords  label   
    33(162, 142)      10     
    44(169, -35)      9       
     
    1313(-282, -149)    0       
    1414@undiredgeset
    15                 id     
     15                label   
    16169       10      17     
    17171       9       15     
  • demo/dir_components.lgf

    r1802 r1901  
    11@nodeset
    2 coordinates_x   coordinates_y   id     
     2coordinates_x   coordinates_y   label   
    33218.178 27.2723 19     
    44157.79  -130.517        18     
     
    2121-389.604        -136.361        1       
    2222@edgeset
    23                 id     
     23                label   
    242417      19      23     
    252519      18      24     
  • demo/graph_orientation.cc

    r1875 r1901  
    5050
    5151  ListGraph::NodeMap<int> f(g); //in-deg requirement;
    52   ListGraph::NodeMap<int> id(g);
     52  ListGraph::NodeMap<int> label(g);
    5353  ListGraph::NodeMap<xy<double> > coords(g);
    5454 
     
    5656    GraphReader<ListGraph> reader(argv[1],g);
    5757    reader.readNodeMap("f",f);
    58     reader.readNodeMap("id",id);
     58    reader.readNodeMap("label",label);
    5959    reader.readNodeMap("coordinates_x",xMap(coords));
    6060    reader.readNodeMap("coordinates_y",yMap(coords));
     
    8181  Node act;
    8282  while((act=IterableBoolNodeMap<ListGraph>::TrueIt(active))!=INVALID) {
    83     std::cout << "Process node " << id[act]
     83    std::cout << "Process node " << label[act]
    8484              << " (def=" << def[act]
    8585              << " lev=" << level[act] << "): ";
     
    8888    if(e!=INVALID) {
    8989      std::cout << " REVERT EDGE " << g.id(e)
    90                 << " (" << id[g.source(e)] << "---"
    91                 << id[g.target(e)] << ")"
     90                << " (" << label[g.source(e)] << "---"
     91                << label[g.target(e)] << ")"
    9292                << std::endl;
    9393      if(--def[act]==0) active[act]=false;
  • demo/graph_orientation.lgf

    r1687 r1901  
    11@nodeset
    2 coordinates_x   coordinates_y   f       id     
     2coordinates_x   coordinates_y   f       label   
    33-198    -73     2       7       
    44120     30      4       6       
     
    99-131    83      3       1       
    1010@edgeset
    11                 id     
     11                label   
    12127       6       3       
    13131       6       2       
  • demo/partitions.lgf

    r1802 r1901  
    11@nodeset
    2 coordinates_x   coordinates_y   id     
     2coordinates_x   coordinates_y   label   
    33513.857         -446.322        23     
    44393.468         566.711         22     
     
    2525-274            -131            1       
    2626@undiredgeset
    27                 id     
     27                label   
    282812      23      15     
    292913      23      14     
  • demo/route.lgf

    r1530 r1901  
    11@nodeset
    2 id      coordinates_x   coordinates_y   
     2label   coordinates_x   coordinates_y   
    339       447.907 578.328
    448       79.2573 909.464
     
    12120       189.239 92.5316
    1313@edgeset
    14                 length  id     
     14                length  label   
    15152       3       901.074 0       
    16168       5       270.85  1       
  • demo/sample.lgf

    r1541 r1901  
    11@nodeset
    2 id      coordinates_x   coordinates_y
     2label      coordinates_x   coordinates_y
    335       796.398 208.035
    444       573.002 63.002
     
    880       102.239 257.532
    99@edgeset
    10                 id      capacity
     10                label      capacity
    11114       5       6       8
    12123       5       5       8
  • demo/sub_gad_input.lgf

    r1577 r1901  
    11@nodeset
    2 id
     2label
    336
    445
     
    990
    1010@edgeset
    11                 id      length
     11                label      length
    12125       6       9       4
    13134       6       8       2
  • demo/undir_components.lgf

    r1802 r1901  
    11@nodeset
    2 coordinates_x   coordinates_y   id     
     2coordinates_x   coordinates_y   label   
    33574.035 177.301 44     
    44694.579 115.483 43     
     
    4545-567.302        43.6423 33     
    4646@undiredgeset
    47                 id     
     47                label   
    484841      42      44     
    494940      42      43     
  • doc/graph_io.dox

    r1848 r1901  
    3232The next line contains the names of the nodemaps, separated by whitespaces.  Each
    3333following line describes a node in the graph: it contains the values of the
    34 maps in the right order. The map named "id" should contain unique values
    35 because it is regarded as an ID-map. These ids need not be numbers but they
     34maps in the right order. The map named "label" should contain unique values
     35because it is regarded as a label map. These labels need not be numbers but they
    3636must identify the nodes uniquely for later reference. For example:
    3737
    3838\code
    3939@nodeset
    40 id  x-coord  y-coord  color
     40label  x-coord  y-coord  color
    41413   1.0      4.0      blue
    42425   2.3      5.7      red
     
    5151The next line contains the whitespace separated list of names of the edge
    5252maps.  Each of the next lines describes one edge. The first two elements in
    53 the line are the IDs of the source and target (or tail and head) nodes of the
    54 edge as they occur in the ID node map of the nodeset section. You can also
    55 have an optional ID map on the edges for later reference (which has to be
     53the line are the labels of the source and target (or tail and head) nodes of the
     54edge as they occur in the label node map of the nodeset section. You can also
     55have an optional label map on the edges for later reference (which has to be
    5656unique in this case).
    5757
    5858\code
    5959@edgeset
    60              id    weight   label
    61 3   5        a     4.3      a-edge
    62 5   12       c     2.6      c-edge
    63 3   12       g     3.4      g-edge
     60             label      weight   note
     613   5        a          4.3      a-edge
     625   12       c          2.6      c-edge
     633   12       g          3.4      g-edge
    6464\endcode
    6565
     
    7171
    7272Each of the next lines contains a label for a node in the graph
    73 and then the ID as described in the \e nodeset section.
     73and then the label as described in the \e nodeset section.
    7474
    7575\code
     
    8181The last section describes the <em>labeled (distinguished) edges</em>
    8282(i.e. edges having a special label on them). It starts with \c \@edges
    83 and then each line contains the name of the edge and the ID.
     83and then each line contains the name of the edge and the label.
    8484
    8585\code
     
    104104\endcode
    105105
    106 <tt> \@end </tt>
    107 
    108 line.
     106Finally, the file should be closed with \c \@end line.
    109107
    110108
     
    133131\ref lemon::GraphWriter "GraphWriter".
    134132You should give a name to the map and the map
    135 object as parameters. The NodeMap writing command with name "id" should write a
    136 unique map because it will be regarded as an ID map.
     133object as parameters. The NodeMap writing command with name "label" should write a
     134unique map because it will be regarded as a label map.
    137135
    138136\see IdMap, DescriptorMap 
    139137
    140138\code
    141 IdMap<ListGraph, Node> nodeIdMap;
    142 writer.writeNodeMap("id", nodeIdMap);
     139IdMap<ListGraph, Node> nodeLabelMap;
     140writer.writeNodeMap("label", nodeLabelMap);
    143141
    144142writer.writeNodeMap("x-coord", xCoordMap);
     
    158156
    159157writer.writeEdgeMap("weight", weightMap);
    160 writer.writeEdgeMap("label", labelMap);
     158writer.writeEdgeMap("note", noteMap);
    161159\endcode
    162160
     
    315313special template parameter to the GraphReader class. By default, the
    316314template parameter is \c DefaultReaderTraits. A reader traits class
    317 should provide an inner template class Reader for each type, and a
     315should provide a nested template class Reader for each type, and a
    318316DefaultReader for skipping a value.
    319317
    320 The specialization of  writing is very similar to that of reading.
     318The specialization of writing is very similar to that of reading.
    321319
    322320\section undir Undirected graphs
     
    334332\code
    335333@undiredgeset
    336              id    capacity +flow -flow
    337 32   2       1     4.3      2.0   0.0
    338 21   21      5     2.6      0.0   2.6
    339 21   12      8     3.4      0.0   0.0
     334             label      capacity        +flow  -flow
     33532   2       1          4.3             2.0     0.0
     33621   21      5          2.6             0.0     2.6
     33721   12      8          3.4             0.0     0.0
    340338\endcode
    341339
     
    462460and the \ref lemon::UndirGraphReader "UndirGraphReader" can be converted
    463461to \ref lemon::LemonReader "LemonReader"
    464 and it can resolve the ID's of the items, the previous
     462and it can resolve the label's of the items, the previous
    465463result can be achived with the \ref lemon::UndirGraphReader "UndirGraphReader"
    466464class, too.
  • gui/graphocska.lgf

    r1581 r1901  
    11@nodeset
    2 id      coordinates_x   coordinates_y data
     2label   coordinates_x   coordinates_y data
    331       230     -80     1.123
    442       230     100     3.234
  • lemon/graph_reader.h

    r1875 r1901  
    6868  /// reader.readNodeMap("coords", coords);
    6969  ///
    70   /// reader.readNodeMap<QuotedStringReader>("label", labelMap);
    71   /// reader.skipNodeMap<QuotedStringReader>("description");
     70  /// reader.skipNodeMap("description", desc);
    7271  ///
    7372  /// reader.readNodeMap("color", colorMap);
     
    307306    }
    308307
    309     /// \brief Gives back the node by its id.
    310     ///
    311     /// It reads an id from the stream and gives back which node belongs to
    312     /// it. It is possible only if there was read an "id" named node map.
    313     Node readId(std::istream& is, Node) const {
    314       return nodeset_reader.readId(is, Node());
     308
     309    /// \brief Returns true if the reader can give back the items by its label.
     310    ///
     311    /// \brief Returns true if the reader can give back the items by its label.
     312    bool isLabelReader() const {
     313      return nodeset_reader.isLabelReader() && edgeset_reader.isLabelReader();
     314    }
     315
     316    /// \brief Gives back the node by its label.
     317    ///
     318    /// It reads an label from the stream and gives back which node belongs to
     319    /// it. It is possible only if there was read an "label" named node map.
     320    void readLabel(std::istream& is, Node& node) const {
     321      nodeset_reader.readLabel(is, node);
    315322    }
    316323
    317     /// \brief Gives back the edge by its id.
    318     ///
    319     /// It reads an id from the stream and gives back which edge belongs to
    320     /// it. It is possible only if there was read an "id" named edge map.
    321     Edge readId(std::istream& is, Edge) const {
    322       return edgeset_reader.readId(is, Edge());
     324    /// \brief Gives back the edge by its label.
     325    ///
     326    /// It reads an label from the stream and gives back which edge belongs to
     327    /// it. It is possible only if there was read an "label" named edge map.
     328    void readLabel(std::istream& is, Edge& edge) const {
     329      return edgeset_reader.readLabel(is, edge);
    323330    }
    324331
     
    405412  /// reader.readNodeMap("coords", coords);
    406413  ///
    407   /// reader.readNodeMap<QuotedStringReader>("label", labelMap);
    408   /// reader.skipNodeMap<QuotedStringReader>("description");
     414  /// reader.skipNodeMap("description", desc);
    409415  ///
    410416  /// reader.readNodeMap("color", colorMap);
     
    705711    }
    706712
    707     /// \brief Gives back the node by its id.
    708     ///
    709     /// It reads an id from the stream and gives back which node belongs to
    710     /// it. It is possible only if there was read an "id" named node map.
    711     Node readId(std::istream& is, Node) const {
    712       return nodeset_reader.readId(is, Node());
     713
     714    /// \brief Returns true if the reader can give back the items by its label.
     715    ///
     716    /// \brief Returns true if the reader can give back the items by its label.
     717    bool isLabelReader() const {
     718      return nodeset_reader.isLabelReader() &&
     719        undir_edgeset_reader.isLabelReader();
     720    }
     721
     722    /// \brief Gives back the node by its label.
     723    ///
     724    /// It reads an label from the stream and gives back which node belongs to
     725    /// it. It is possible only if there was read an "label" named node map.
     726    void readLabel(std::istream& is, Node& node) const {
     727      return nodeset_reader.readLabel(is, node);
    713728    }
    714729
    715     /// \brief Gives back the edge by its id.
    716     ///
    717     /// It reads an id from the stream and gives back which edge belongs to
    718     /// it. It is possible only if there was read an "id" named edge map.
    719     Edge readId(std::istream& is, Edge) const {
    720       return undir_edgeset_reader.readId(is, Edge());
     730    /// \brief Gives back the edge by its label.
     731    ///
     732    /// It reads an label from the stream and gives back which edge belongs to
     733    /// it. It is possible only if there was read an "label" named edge map.
     734    void readLabel(std::istream& is, Edge& edge) const {
     735      return undir_edgeset_reader.readLabel(is, edge);
    721736    }
    722737
    723     /// \brief Gives back the undirected edge by its id.
    724     ///
    725     /// It reads an id from the stream and gives back which undirected edge
    726     /// belongs to it. It is possible only if there was read an "id" named
     738    /// \brief Gives back the undirected edge by its label.
     739    ///
     740    /// It reads an label from the stream and gives back which undirected edge
     741    /// belongs to it. It is possible only if there was read an "label" named
    727742    /// edge map.
    728     UndirEdge readId(std::istream& is, UndirEdge) const {
    729       return undir_edgeset_reader.readId(is, UndirEdge());
     743    void readLabel(std::istream& is, UndirEdge& uedge) const {
     744      return undir_edgeset_reader.readLabel(is, uedge);
    730745    }
    731746   
  • lemon/graph_writer.h

    r1875 r1901  
    5555  /// command in the \c GraphWriter. You should give as parameter
    5656  /// the name of the map and the map object. The NodeMap writing
    57   /// command with name "id" should write a unique map because it
    58   /// is regarded as ID map (such a map is essential if the graph has edges).
    59   ///
    60   /// \code
    61   /// IdMap<ListGraph, Node> nodeIdMap;
    62   /// writer.writeNodeMap("id", nodeIdMap);
     57  /// command with name "label" should write a unique map because it
     58  /// is regarded as label map (such a map is essential if the graph has edges).
     59  ///
     60  /// \code
     61  /// IdMap<ListGraph, Node> nodeLabelMap;
     62  /// writer.writeNodeMap("label", nodeLabelMap);
    6363  ///
    6464  /// writer.writeNodeMap("coords", coords);
     
    254254    }
    255255
    256     /// \brief Write the id of the given node.
    257     ///
    258     /// It writes the id of the given node. If there was written an "id"
     256    /// \brief Write the label of the given node.
     257    ///
     258    /// It writes the label of the given node. If there was written an "label"
    259259    /// named node map then it will write the map value belonging to the node.
    260     void writeId(std::ostream& os, const Node& item) const {
    261       nodeset_writer.writeId(os, item);
     260    void writeLabel(std::ostream& os, const Node& item) const {
     261      nodeset_writer.writeLabel(os, item);
    262262    }
    263263
    264     /// \brief Write the id of the given edge.
    265     ///
    266     /// It writes the id of the given edge. If there was written an "id"
     264    /// \brief Write the label of the given edge.
     265    ///
     266    /// It writes the label of the given edge. If there was written an "label"
    267267    /// named edge map then it will write the map value belonging to the edge.
    268     void writeId(std::ostream& os, const Edge& item) const {
    269       edgeset_writer.writeId(os, item);
     268    void writeLabel(std::ostream& os, const Edge& item) const {
     269      edgeset_writer.writeLabel(os, item);
    270270    }
    271271
     
    328328  /// command in the \c UndirGraphWriter. You should give as parameter
    329329  /// the name of the map and the map object. The NodeMap writing
    330   /// command with name "id" should write a unique map because it
    331   /// is regarded as ID map.
    332   ///
    333   /// \code
    334   /// IdMap<UndirListGraph, Node> nodeIdMap;
    335   /// writer.writeNodeMap("id", nodeIdMap);
     330  /// command with name "label" should write a unique map because it
     331  /// is regarded as label map.
     332  ///
     333  /// \code
     334  /// IdMap<UndirListGraph, Node> nodeLabelMap;
     335  /// writer.writeNodeMap("label", nodeLabelMap);
    336336  ///
    337337  /// writer.writeNodeMap("coords", coords);
     
    562562    }
    563563
    564     /// \brief Write the id of the given node.
    565     ///
    566     /// It writes the id of the given node. If there was written an "id"
     564    /// \brief Write the label of the given node.
     565    ///
     566    /// It writes the label of the given node. If there was written an "label"
    567567    /// named node map then it will write the map value belonging to the node.
    568     void writeId(std::ostream& os, const Node& item) const {
    569       nodeset_writer.writeId(os, item);
     568    void writeLabel(std::ostream& os, const Node& item) const {
     569      nodeset_writer.writeLabel(os, item);
    570570    }
    571571
    572     /// \brief Write the id of the given edge.
    573     ///
    574     /// It writes the id of the given edge. If there was written an "id"
     572    /// \brief Write the label of the given edge.
     573    ///
     574    /// It writes the label of the given edge. If there was written an "label"
    575575    /// named edge map then it will write the map value belonging to the edge.
    576     void writeId(std::ostream& os, const Edge& item) const {
    577       undir_edgeset_writer.writeId(os, item);
     576    void writeLabel(std::ostream& os, const Edge& item) const {
     577      undir_edgeset_writer.writeLabel(os, item);
    578578    }
    579579
    580     /// \brief Write the id of the given undirected edge.
    581     ///
    582     /// It writes the id of the given undirected edge. If there was written
    583     /// an "id" named edge map then it will write the map value belonging to
     580    /// \brief Write the label of the given undirected edge.
     581    ///
     582    /// It writes the label of the given undirected edge. If there was written
     583    /// an "label" named edge map then it will write the map value belonging to
    584584    /// the edge.
    585     void writeId(std::ostream& os, const UndirEdge& item) const {
    586       undir_edgeset_writer.writeId(os, item);
     585    void writeLabel(std::ostream& os, const UndirEdge& item) const {
     586      undir_edgeset_writer.writeLabel(os, item);
    587587    }
    588588
  • lemon/lemon_reader.h

    r1875 r1901  
    4848    template <typename T>
    4949    bool operator<(T, T) {
    50       throw DataFormatError("Id is not comparable");
     50      throw DataFormatError("Label is not comparable");
    5151    }
    5252
     
    5959
    6060    template <typename Item>
    61     class ItemIdReader {
     61    class ItemLabelReader {
    6262    public:
    6363
    64       bool isIdReader() { return true; }
    65 
    66       void readId(std::istream&, Item&) {}
     64      bool isLabelReader() { return true; }
     65
     66      void readLabel(std::istream&, Item&) {}
    6767     
    68       template <class _ItemIdReader>
     68      template <class _ItemLabelReader>
    6969      struct Constraints {
    7070        void constraints() {
    71           bool b = reader.isIdReader();
     71          bool b = reader.isLabelReader();
    7272          ignore_unused_variable_warning(b);
    7373          Item item;
    74           reader.readId(is, item);
    75         }
    76         _ItemIdReader& reader;
     74          reader.readLabel(is, item);
     75        }
     76        _ItemLabelReader& reader;
    7777        std::istream& is;
    7878      };
     
    242242          inverse.insert(std::make_pair(value, item));
    243243        } else {
    244           throw DataFormatError("Multiple ID occurence");
     244          throw DataFormatError("Multiple label occurence");
    245245        }
    246246      }
     
    253253          return it->second;
    254254        } else {
    255           throw DataFormatError("Invalid ID error");
     255          throw DataFormatError("Invalid label error");
    256256        }
    257257      }     
     
    280280          inverse.insert(std::make_pair(value, item));
    281281        } else {
    282           throw DataFormatError("Multiple ID occurence error");
     282          throw DataFormatError("Multiple label occurence error");
    283283        }
    284284      }
     
    291291          return it->second;
    292292        } else {
    293           throw DataFormatError("Invalid ID error");
     293          throw DataFormatError("Invalid label error");
    294294        }
    295295      }
     
    371371
    372372    template <typename _Item>
    373     class IdReaderBase {
     373    class LabelReaderBase {
    374374    public:
    375375      typedef _Item Item;
    376       virtual ~IdReaderBase() {}
     376      virtual ~LabelReaderBase() {}
    377377      virtual Item read(std::istream& is) const = 0;
    378       virtual bool isIdReader() const = 0;
    379     };
    380 
    381     template <typename _Item, typename _BoxedIdReader>
    382     class IdReader : public IdReaderBase<_Item> {
     378      virtual bool isLabelReader() const = 0;
     379    };
     380
     381    template <typename _Item, typename _BoxedLabelReader>
     382    class LabelReader : public LabelReaderBase<_Item> {
    383383    public:
    384384      typedef _Item Item;
    385       typedef _BoxedIdReader BoxedIdReader;
     385      typedef _BoxedLabelReader BoxedLabelReader;
    386386     
    387       const BoxedIdReader& boxedIdReader;
    388 
    389       IdReader(const BoxedIdReader& _boxedIdReader)
    390         : boxedIdReader(_boxedIdReader) {}
     387      const BoxedLabelReader& boxedLabelReader;
     388
     389      LabelReader(const BoxedLabelReader& _boxedLabelReader)
     390        : boxedLabelReader(_boxedLabelReader) {}
    391391
    392392      virtual Item read(std::istream& is) const {
    393393        Item item;
    394         boxedIdReader.readId(is, item);
     394        boxedLabelReader.readLabel(is, item);
    395395        return item;
    396396      }
    397397
    398       virtual bool isIdReader() const {
    399         return boxedIdReader.isIdReader();
     398      virtual bool isLabelReader() const {
     399        return boxedLabelReader.isLabelReader();
    400400      }
    401401    };
     
    728728  ///
    729729  /// The lemon format can store multiple graph nodesets with several maps.
    730   /// The nodeset section's header line is \c \@nodeset \c nodeset_id, but the
    731   /// \c nodeset_id may be empty.
     730  /// The nodeset section's header line is \c \@nodeset \c nodeset_name, but the
     731  /// \c nodeset_name may be empty.
    732732  ///
    733733  /// The first line of the section contains the names of the maps separated
     
    735735  /// contains the mapped values for each map.
    736736  ///
    737   /// If the nodeset contains an \c "id" named map then it will be regarded
     737  /// If the nodeset contains an \c "label" named map then it will be regarded
    738738  /// as id map. This map should contain only unique values and when the
    739   /// \c readId() member will read a value from the given stream it will
     739  /// \c readLabel() member will read a value from the given stream it will
    740740  /// give back that node which is mapped to this value.
    741741  ///
     
    756756    /// attach it into the given LemonReader. The nodeset reader will
    757757    /// add the readed nodes to the given Graph. The reader will read
    758     /// the section when the \c section_id and the \c _id are the same.
     758    /// the section when the \c section_name and the \c _name are the same.
    759759    NodeSetReader(LemonReader& _reader,
    760760                  Graph& _graph,
    761                   const std::string& _id = std::string(),
     761                  const std::string& _name = std::string(),
    762762                  const DefaultSkipper& _skipper = DefaultSkipper())
    763       : Parent(_reader), graph(_graph), id(_id), skipper(_skipper) {}
     763      : Parent(_reader), graph(_graph), name(_name), skipper(_skipper) {}
    764764
    765765
     
    856856    ///
    857857    /// It gives back true when the header line starts with \c \@nodeset,
    858     /// and the header line's id and the nodeset's id are the same.
     858    /// and the header line's name and the nodeset's name are the same.
    859859    virtual bool header(const std::string& line) {
    860860      std::istringstream ls(line);
    861861      std::string command;
    862       std::string name;
     862      std::string id;
    863863      ls >> command >> name;
    864864      return command == "@nodeset" && name == id;
     
    873873
    874874      getline(is, line);
    875       std::istringstream ls(line);     
     875      std::istringstream ls(line);
     876      std::string id;
    876877      while (ls >> id) {
    877878        typename MapReaders::iterator it = readers.find(id);
     
    882883          index.push_back(&skipper);
    883884        }
    884         if (id == "id" && inverter.get() == 0) {
     885        if (id == "label" || (id =="id" && inverter.get() == 0)) {
    885886          inverter.reset(index.back()->getInverter());
    886887          index.back() = inverter.get();
     
    906907  public:
    907908
    908     /// \brief Returns true if the nodeset can give back the node by its id.
    909     ///
    910     /// Returns true if the nodeset can give back the node by its id.
    911     /// It is possible only if an "id" named map was read.
    912     bool isIdReader() const {
     909    /// \brief Returns true if the nodeset can give back the node by its label.
     910    ///
     911    /// Returns true if the nodeset can give back the node by its label.
     912    /// It is possible only if an "label" named map was read.
     913    bool isLabelReader() const {
    913914      return inverter.get() != 0;
    914915    }
    915916
    916     /// \brief Gives back the node by its id.
     917    /// \brief Gives back the node by its label.
    917918    ///
    918919    /// It reads an id from the stream and gives back which node belongs to
    919     /// it. It is possible only if there was read an "id" named map.
    920     void readId(std::istream& is, Node& node) const {
     920    /// it. It is possible only if there was read an "label" named map.
     921    void readLabel(std::istream& is, Node& node) const {
    921922      node = inverter->read(is);
    922923    }
     
    928929   
    929930    Graph& graph;   
    930     std::string id;
     931    std::string name;
    931932    _reader_bits::SkipReader<Node, DefaultSkipper> skipper;
    932933
     
    938939  ///
    939940  /// The lemon format can store multiple graph edgesets with several maps.
    940   /// The edgeset section's header line is \c \@edgeset \c edgeset_id, but the
    941   /// \c edgeset_id may be empty.
     941  /// The edgeset section's header line is \c \@edgeset \c edgeset_name, but the
     942  /// \c edgeset_name may be empty.
    942943  ///
    943944  /// The first line of the section contains the names of the maps separated
     
    946947  /// values for each map.
    947948  ///
    948   /// If the edgeset contains an \c "id" named map then it will be regarded
     949  /// If the edgeset contains an \c "label" named map then it will be regarded
    949950  /// as id map. This map should contain only unique values and when the
    950   /// \c readId() member will read a value from the given stream it will
     951  /// \c readLabel() member will read a value from the given stream it will
    951952  /// give back that edge which is mapped to this value.
    952953  ///
    953954  /// The edgeset reader needs a node id reader to identify which nodes
    954   /// have to be connected. If a NodeSetReader reads an "id" named map,
     955  /// have to be connected. If a NodeSetReader reads an "label" named map,
    955956  /// it will be able to resolve the nodes by ids.
    956957  ///
     
    973974    /// add the readed edges to the given Graph. It will use the given
    974975    /// node id reader to read the source and target nodes of the edges.
    975     /// The reader will read the section only if the \c _id and the
    976     /// \c edgset_id are the same.
    977     template <typename NodeIdReader>
     976    /// The reader will read the section only if the \c _name and the
     977    /// \c edgset_name are the same.
     978    template <typename NodeLabelReader>
    978979    EdgeSetReader(LemonReader& _reader,
    979980                  Graph& _graph,
    980                   const NodeIdReader& _nodeIdReader,
    981                   const std::string& _id = std::string(),
     981                  const NodeLabelReader& _nodeLabelReader,
     982                  const std::string& _name = std::string(),
    982983                  const DefaultSkipper& _skipper = DefaultSkipper())
    983       : Parent(_reader), graph(_graph), id(_id), skipper(_skipper) {
    984       checkConcept<_reader_bits::ItemIdReader<Node>, NodeIdReader>();
    985       nodeIdReader.reset(new _reader_bits::
    986                          IdReader<Node, NodeIdReader>(_nodeIdReader));
     984      : Parent(_reader), graph(_graph), name(_name), skipper(_skipper) {
     985      checkConcept<_reader_bits::ItemLabelReader<Node>, NodeLabelReader>();
     986      nodeLabelReader.reset(new _reader_bits::
     987                         LabelReader<Node, NodeLabelReader>(_nodeLabelReader));
    987988    }
    988989    /// \brief Destructor.
     
    10781079    ///
    10791080    /// It gives back true when the header line starts with \c \@edgeset,
    1080     /// and the header line's id and the edgeset's id are the same.
     1081    /// and the header line's name and the edgeset's name are the same.
    10811082    virtual bool header(const std::string& line) {
    10821083      std::istringstream ls(line);
    10831084      std::string command;
    1084       std::string name;
     1085      std::string id;
    10851086      ls >> command >> name;
    10861087      return command == "@edgeset" && name == id;
     
    10911092    /// It reads the content of the section.
    10921093    virtual void read(std::istream& is) {
    1093       if (!nodeIdReader->isIdReader()) {
    1094         throw DataFormatError("Cannot find nodeset or ID map");
     1094      if (!nodeLabelReader->isLabelReader()) {
     1095        throw DataFormatError("Cannot find nodeset or label map");
    10951096      }
    10961097      std::vector<_reader_bits::MapReaderBase<Edge>* > index;
     
    10991100      getline(is, line);
    11001101      std::istringstream ls(line);     
     1102      std::string id;
    11011103      while (ls >> id) {
    11021104        typename MapReaders::iterator it = readers.find(id);
     
    11071109          index.push_back(&skipper);
    11081110        }
    1109         if (id == "id" && inverter.get() == 0) {
     1111        if (id == "label" || (id =="id" && inverter.get() == 0)) {
    11101112          inverter.reset(index.back()->getInverter());
    11111113          index.back() = inverter.get();
     
    11221124      while (getline(is, line)) {       
    11231125        std::istringstream ls(line);
    1124         Node from = nodeIdReader->read(ls);
    1125         Node to = nodeIdReader->read(ls);
     1126        Node from = nodeLabelReader->read(ls);
     1127        Node to = nodeLabelReader->read(ls);
    11261128        Edge edge = graph.addEdge(from, to);
    11271129        for (int i = 0; i < (int)index.size(); ++i) {
     
    11331135  public:
    11341136
    1135     /// \brief Returns true if the edgeset can give back the edge by its id.
    1136     ///
    1137     /// Returns true if the edgeset can give back the edge by its id.
    1138     /// It is possible only if an "id" named map was read.
    1139     bool isIdReader() const {
     1137    /// \brief Returns true if the edgeset can give back the edge by its label.
     1138    ///
     1139    /// Returns true if the edgeset can give back the edge by its label.
     1140    /// It is possible only if an "label" named map was read.
     1141    bool isLabelReader() const {
    11401142      return inverter.get() != 0;
    11411143    }
    11421144
    1143     /// \brief Gives back the edge by its id.
     1145    /// \brief Gives back the edge by its label.
    11441146    ///
    11451147    /// It reads an id from the stream and gives back which edge belongs to
    1146     /// it. It is possible only if there was read an "id" named map.
    1147     void readId(std::istream& is, Edge& edge) const {
     1148    /// it. It is possible only if there was read an "label" named map.
     1149    void readLabel(std::istream& is, Edge& edge) const {
    11481150      edge = inverter->read(is);
    11491151    }
     
    11551157   
    11561158    Graph& graph;   
    1157     std::string id;
     1159    std::string name;
    11581160    _reader_bits::SkipReader<Edge, DefaultSkipper> skipper;
    11591161
    11601162    std::auto_ptr<_reader_bits::MapInverterBase<Edge> > inverter;
    1161     std::auto_ptr<_reader_bits::IdReaderBase<Node> > nodeIdReader;
     1163    std::auto_ptr<_reader_bits::LabelReaderBase<Node> > nodeLabelReader;
    11621164  };
    11631165
     
    11671169  /// The lemon format can store multiple undirected edgesets with several
    11681170  /// maps. The undirected edgeset section's header line is \c \@undiredgeset
    1169   /// \c undiredgeset_id, but the \c undiredgeset_id may be empty.
     1171  /// \c undiredgeset_name, but the \c undiredgeset_name may be empty.
    11701172  ///
    11711173  /// The first line of the section contains the names of the maps separated
     
    11791181  /// difference.
    11801182  ///
    1181   /// If the edgeset contains an \c "id" named map then it will be regarded
     1183  /// If the edgeset contains an \c "label" named map then it will be regarded
    11821184  /// as id map. This map should contain only unique values and when the
    1183   /// \c readId() member will read a value from the given stream it will
     1185  /// \c readLabel() member will read a value from the given stream it will
    11841186  /// give back that undiricted edge which is mapped to this value.
    11851187  ///
    11861188  /// The undirected edgeset reader needs a node id reader to identify which
    1187   /// nodes have to be connected. If a NodeSetReader reads an "id" named map,
     1189  /// nodes have to be connected. If a NodeSetReader reads an "label" named map,
    11881190  /// it will be able to resolve the nodes by ids.
    11891191  ///
     
    12081210    /// will use the given node id reader to read the source and target
    12091211    /// nodes of the edges. The reader will read the section only if the
    1210     /// \c _id and the \c undiredgset_id are the same.
    1211     template <typename NodeIdReader>
     1212    /// \c _name and the \c undiredgset_name are the same.
     1213    template <typename NodeLabelReader>
    12121214    UndirEdgeSetReader(LemonReader& _reader,
    12131215                       Graph& _graph,
    1214                        const NodeIdReader& _nodeIdReader,
    1215                        const std::string& _id = std::string(),
     1216                       const NodeLabelReader& _nodeLabelReader,
     1217                       const std::string& _name = std::string(),
    12161218                       const DefaultSkipper& _skipper = DefaultSkipper())
    1217       : Parent(_reader), graph(_graph), id(_id), skipper(_skipper) {
    1218       checkConcept<_reader_bits::ItemIdReader<Node>, NodeIdReader>();
    1219       nodeIdReader.reset(new _reader_bits::
    1220                          IdReader<Node, NodeIdReader>(_nodeIdReader));
     1219      : Parent(_reader), graph(_graph), name(_name), skipper(_skipper) {
     1220      checkConcept<_reader_bits::ItemLabelReader<Node>, NodeLabelReader>();
     1221      nodeLabelReader.reset(new _reader_bits::
     1222                         LabelReader<Node, NodeLabelReader>(_nodeLabelReader));
    12211223    }
    12221224    /// \brief Destructor.
     
    13731375    ///
    13741376    /// It gives back true when the header line starts with \c \@undiredgeset,
    1375     /// and the header line's id and the edgeset's id are the same.
     1377    /// and the header line's name and the edgeset's name are the same.
    13761378    virtual bool header(const std::string& line) {
    13771379      std::istringstream ls(line);
    13781380      std::string command;
    1379       std::string name;
     1381      std::string id;
    13801382      ls >> command >> name;
    13811383      return command == "@undiredgeset" && name == id;
     
    13861388    /// It reads the content of the section.
    13871389    virtual void read(std::istream& is) {
    1388       if (!nodeIdReader->isIdReader()) {
    1389         throw DataFormatError("Cannot find nodeset or ID map");
     1390      if (!nodeLabelReader->isLabelReader()) {
     1391        throw DataFormatError("Cannot find nodeset or label map");
    13901392      }
    13911393      std::vector<_reader_bits::MapReaderBase<UndirEdge>* > index;
     
    13941396      getline(is, line);
    13951397      std::istringstream ls(line);     
     1398      std::string id;
    13961399      while (ls >> id) {
    13971400        typename MapReaders::iterator it = readers.find(id);
     
    14021405          index.push_back(&skipper);
    14031406        }
    1404         if (id == "id" && inverter.get() == 0) {
     1407        if (id == "label" || (id =="id" && inverter.get() == 0)) {
    14051408          inverter.reset(index.back()->getInverter());
    14061409          index.back() = inverter.get();
     
    14171420      while (getline(is, line)) {       
    14181421        std::istringstream ls(line);
    1419         Node from = nodeIdReader->read(ls);
    1420         Node to = nodeIdReader->read(ls);
     1422        Node from = nodeLabelReader->read(ls);
     1423        Node to = nodeLabelReader->read(ls);
    14211424        UndirEdge edge = graph.addEdge(from, to);
    14221425        for (int i = 0; i < (int)index.size(); ++i) {
     
    14281431  public:
    14291432
    1430     /// \brief Returns true if the edgeset can give back the edge by its id.
     1433    /// \brief Returns true if the edgeset can give back the edge by its label.
    14311434    ///
    14321435    /// Returns true if the edgeset can give back the undirected edge by its
    1433     /// id. It is possible only if an "id" named map was read.
    1434     bool isIdReader() const {
     1436    /// id. It is possible only if an "label" named map was read.
     1437    bool isLabelReader() const {
    14351438      return inverter.get() != 0;
    14361439    }
    14371440
    1438     /// \brief Gives back the undirected edge by its id.
     1441    /// \brief Gives back the undirected edge by its label.
    14391442    ///
    14401443    /// It reads an id from the stream and gives back which undirected edge
    1441     /// belongs to it. It is possible only if there was read an "id" named map.
    1442     void readId(std::istream& is, UndirEdge& undirEdge) const {
     1444    /// belongs to it. It is possible only if there was read an "label" named map.
     1445    void readLabel(std::istream& is, UndirEdge& undirEdge) const {
    14431446      undirEdge = inverter->read(is);
    14441447    }
    14451448
    1446     /// \brief Gives back the directed edge by its id.
     1449    /// \brief Gives back the directed edge by its label.
    14471450    ///
    14481451    /// It reads an id from the stream and gives back which directed edge
    14491452    /// belongs to it. The directed edge id is the \c '+' or \c '-' character
    14501453    /// and the undirected edge id. It is possible only if there was read
    1451     /// an "id" named map.
    1452     void readId(std::istream& is, Edge& edge) const {
     1454    /// an "label" named map.
     1455    void readLabel(std::istream& is, Edge& edge) const {
    14531456      char c;
    14541457      is >> c;
     
    14711474   
    14721475    Graph& graph;   
    1473     std::string id;
     1476    std::string name;
    14741477    _reader_bits::SkipReader<UndirEdge, DefaultSkipper> skipper;
    14751478
    14761479    std::auto_ptr<_reader_bits::MapInverterBase<UndirEdge> > inverter;
    1477     std::auto_ptr<_reader_bits::IdReaderBase<Node> > nodeIdReader;
     1480    std::auto_ptr<_reader_bits::LabelReaderBase<Node> > nodeLabelReader;
    14781481  };
    14791482
     
    14811484  /// \brief SectionReader for reading labeled nodes.
    14821485  ///
    1483   /// The nodes section's header line is \c \@nodes \c nodes_id, but the
    1484   /// \c nodes_id may be empty.
     1486  /// The nodes section's header line is \c \@nodes \c nodes_name, but the
     1487  /// \c nodes_name may be empty.
    14851488  ///
    14861489  /// Each line in the section contains the name of the node
     
    15001503    /// attach it into the given LemonReader. It will use the given
    15011504    /// node id reader to give back the nodes. The reader will read the
    1502     /// section only if the \c _id and the \c nodes_id are the same.
    1503     template <typename _IdReader>
    1504     NodeReader(LemonReader& _reader, const _IdReader& _idReader,
    1505                const std::string& _id = std::string())
    1506       : Parent(_reader), id(_id) {
    1507       checkConcept<_reader_bits::ItemIdReader<Node>, _IdReader>();
    1508       nodeIdReader.reset(new _reader_bits::
    1509                          IdReader<Node, _IdReader>(_idReader));
     1505    /// section only if the \c _name and the \c nodes_name are the same.
     1506    template <typename _LabelReader>
     1507    NodeReader(LemonReader& _reader, const _LabelReader& _labelReader,
     1508               const std::string& _name = std::string())
     1509      : Parent(_reader), name(_name) {
     1510      checkConcept<_reader_bits::ItemLabelReader<Node>, _LabelReader>();
     1511      nodeLabelReader.reset(new _reader_bits::
     1512                         LabelReader<Node, _LabelReader>(_labelReader));
    15101513    }
    15111514
     
    15391542    ///
    15401543    /// It gives back true when the header line start with \c \@nodes,
    1541     /// and the header line's id and the reader's id are the same.
     1544    /// and the header line's name and the reader's name are the same.
    15421545    virtual bool header(const std::string& line) {
    15431546      std::istringstream ls(line);
    15441547      std::string command;
    1545       std::string name;
     1548      std::string id;
    15461549      ls >> command >> name;
    15471550      return command == "@nodes" && name == id;
     
    15521555    /// It reads the content of the section.
    15531556    virtual void read(std::istream& is) {
    1554       if (!nodeIdReader->isIdReader()) {
    1555         throw DataFormatError("Cannot find nodeset or ID map");
     1557      if (!nodeLabelReader->isLabelReader()) {
     1558        throw DataFormatError("Cannot find nodeset or label map");
    15561559      }
    15571560      std::string line;
     
    15621565        typename NodeReaders::iterator it = readers.find(id);
    15631566        if (it != readers.end()) {
    1564           it->second.read(nodeIdReader->read(ls));
     1567          it->second.read(nodeLabelReader->read(ls));
    15651568          it->second.touch();
    15661569        }       
     
    15781581  private:
    15791582
    1580     std::string id;
     1583    std::string name;
    15811584
    15821585    typedef std::map<std::string, _reader_bits::ItemStore<Node> > NodeReaders;
    15831586    NodeReaders readers;
    1584     std::auto_ptr<_reader_bits::IdReaderBase<Node> > nodeIdReader;
     1587    std::auto_ptr<_reader_bits::LabelReaderBase<Node> > nodeLabelReader;
    15851588  };
    15861589
     
    15881591  /// \brief SectionReader for reading labeled edges.
    15891592  ///
    1590   /// The edges section's header line is \c \@edges \c edges_id, but the
    1591   /// \c edges_id may be empty.
     1593  /// The edges section's header line is \c \@edges \c edges_name, but the
     1594  /// \c edges_name may be empty.
    15921595  ///
    15931596  /// Each line in the section contains the name of the edge
     
    16071610    /// attach it into the given LemonReader. It will use the given
    16081611    /// edge id reader to give back the edges. The reader will read the
    1609     /// section only if the \c _id and the \c edges_id are the same.
    1610     template <typename _IdReader>
    1611     EdgeReader(LemonReader& _reader, const _IdReader& _idReader,
    1612                const std::string& _id = std::string())
    1613       : Parent(_reader), id(_id) {
    1614       checkConcept<_reader_bits::ItemIdReader<Edge>, _IdReader>();
    1615       edgeIdReader.reset(new _reader_bits::
    1616                          IdReader<Edge, _IdReader>(_idReader));
     1612    /// section only if the \c _name and the \c edges_name are the same.
     1613    template <typename _LabelReader>
     1614    EdgeReader(LemonReader& _reader, const _LabelReader& _labelReader,
     1615               const std::string& _name = std::string())
     1616      : Parent(_reader), name(_name) {
     1617      checkConcept<_reader_bits::ItemLabelReader<Edge>, _LabelReader>();
     1618      edgeLabelReader.reset(new _reader_bits::
     1619                         LabelReader<Edge, _LabelReader>(_labelReader));
    16171620    }
    16181621
     
    16451648    ///
    16461649    /// It gives back true when the header line start with \c \@edges,
    1647     /// and the header line's id and the reader's id are the same.
     1650    /// and the header line's name and the reader's name are the same.
    16481651    virtual bool header(const std::string& line) {
    16491652      std::istringstream ls(line);
    16501653      std::string command;
    1651       std::string name;
     1654      std::string id;
    16521655      ls >> command >> name;
    16531656      return command == "@edges" && name == id;
     
    16581661    /// It reads the content of the section.
    16591662    virtual void read(std::istream& is) {
    1660       if (!edgeIdReader->isIdReader()) {
    1661         throw DataFormatError("Cannot find edgeset or ID map");
     1663      if (!edgeLabelReader->isLabelReader()) {
     1664        throw DataFormatError("Cannot find edgeset or label map");
    16621665      }
    16631666      std::string line;
     
    16681671        typename EdgeReaders::iterator it = readers.find(id);
    16691672        if (it != readers.end()) {
    1670           it->second.read(edgeIdReader->read(ls));
     1673          it->second.read(edgeLabelReader->read(ls));
    16711674          it->second.touch();
    16721675        }       
     
    16841687  private:
    16851688
    1686     std::string id;
     1689    std::string name;
    16871690
    16881691    typedef std::map<std::string, _reader_bits::ItemStore<Edge> > EdgeReaders;
    16891692    EdgeReaders readers;
    1690     std::auto_ptr<_reader_bits::IdReaderBase<Edge> > edgeIdReader;
     1693    std::auto_ptr<_reader_bits::LabelReaderBase<Edge> > edgeLabelReader;
    16911694  };
    16921695
     
    16951698  ///
    16961699  /// The undirected edges section's header line is \c \@undiredges
    1697   /// \c undiredges_id, but the \c undiredges_id may be empty.
     1700  /// \c undiredges_name, but the \c undiredges_name may be empty.
    16981701  ///
    16991702  /// Each line in the section contains the name of the undirected edge
     
    17141717    /// attach it into the given LemonReader. It will use the given
    17151718    /// undirected edge id reader to give back the edges. The reader will
    1716     /// read the section only if the \c _id and the \c undiredges_id are
     1719    /// read the section only if the \c _name and the \c undiredges_name are
    17171720    /// the same.
    1718     template <typename _IdReader>
    1719     UndirEdgeReader(LemonReader& _reader, const _IdReader& _idReader,
    1720                const std::string& _id = std::string())
    1721       : Parent(_reader), id(_id) {
    1722       checkConcept<_reader_bits::ItemIdReader<UndirEdge>, _IdReader>();
    1723       checkConcept<_reader_bits::ItemIdReader<Edge>, _IdReader>();
    1724       undirEdgeIdReader.reset(new _reader_bits::
    1725                               IdReader<UndirEdge, _IdReader>(_idReader));
    1726       edgeIdReader.reset(new _reader_bits::
    1727                          IdReader<Edge, _IdReader>(_idReader));
     1721    template <typename _LabelReader>
     1722    UndirEdgeReader(LemonReader& _reader, const _LabelReader& _labelReader,
     1723               const std::string& _name = std::string())
     1724      : Parent(_reader), name(_name) {
     1725      checkConcept<_reader_bits::ItemLabelReader<UndirEdge>, _LabelReader>();
     1726      checkConcept<_reader_bits::ItemLabelReader<Edge>, _LabelReader>();
     1727      undirEdgeLabelReader.reset(new _reader_bits::
     1728                              LabelReader<UndirEdge, _LabelReader>(_labelReader));
     1729      edgeLabelReader.reset(new _reader_bits::
     1730                         LabelReader<Edge, _LabelReader>(_labelReader));
    17281731    }
    17291732
     
    17691772    ///
    17701773    /// It gives back true when the header line start with \c \@edges,
    1771     /// and the header line's id and the reader's id are the same.
     1774    /// and the header line's name and the reader's name are the same.
    17721775    virtual bool header(const std::string& line) {
    17731776      std::istringstream ls(line);
    17741777      std::string command;
    1775       std::string name;
     1778      std::string id;
    17761779      ls >> command >> name;
    17771780      return command == "@undiredges" && name == id;
     
    17821785    /// It reads the content of the section.
    17831786    virtual void read(std::istream& is) {
    1784       if (!edgeIdReader->isIdReader()) {
    1785         throw DataFormatError("Cannot find undirected edgeset or ID map");
    1786       }
    1787       if (!undirEdgeIdReader->isIdReader()) {
    1788         throw DataFormatError("Cannot find undirected edgeset or ID map");
     1787      if (!edgeLabelReader->isLabelReader()) {
     1788        throw DataFormatError("Cannot find undirected edgeset or label map");
     1789      }
     1790      if (!undirEdgeLabelReader->isLabelReader()) {
     1791        throw DataFormatError("Cannot find undirected edgeset or label map");
    17891792      }
    17901793      std::string line;
     
    17961799          typename UndirEdgeReaders::iterator it = undirEdgeReaders.find(id);
    17971800          if (it != undirEdgeReaders.end()) {
    1798             it->second.read(undirEdgeIdReader->read(ls));
     1801            it->second.read(undirEdgeLabelReader->read(ls));
    17991802            it->second.touch();
    18001803            continue;
     
    18031806          typename EdgeReaders::iterator it = edgeReaders.find(id);
    18041807          if (it != edgeReaders.end()) {
    1805             it->second.read(edgeIdReader->read(ls));
     1808            it->second.read(edgeLabelReader->read(ls));
    18061809            it->second.touch();
    18071810            continue;
     
    18291832  private:
    18301833
    1831     std::string id;
     1834    std::string name;
    18321835
    18331836    typedef std::map<std::string,
    18341837                     _reader_bits::ItemStore<UndirEdge> > UndirEdgeReaders;
    18351838    UndirEdgeReaders undirEdgeReaders;
    1836     std::auto_ptr<_reader_bits::IdReaderBase<UndirEdge> > undirEdgeIdReader;
     1839    std::auto_ptr<_reader_bits::LabelReaderBase<UndirEdge> > undirEdgeLabelReader;
    18371840
    18381841    typedef std::map<std::string, _reader_bits::ItemStore<Edge> > EdgeReaders;
    18391842    EdgeReaders edgeReaders;
    1840     std::auto_ptr<_reader_bits::IdReaderBase<Edge> > edgeIdReader;
     1843    std::auto_ptr<_reader_bits::LabelReaderBase<Edge> > edgeLabelReader;
    18411844  };
    18421845
     
    18451848  ///
    18461849  /// The lemon format can store multiple attribute set. Each set has
    1847   /// the header line \c \@attributes \c attributeset_id, but the
    1848   /// attributeset_id may be empty.
     1850  /// the header line \c \@attributes \c attributeset_name, but the
     1851  /// attributeset_name may be empty.
    18491852  ///
    18501853  /// The attributeset section contains several lines. Each of them starts
     
    18611864    /// Constructor for AttributeReader. It creates the AttributeReader and
    18621865    /// attach it into the given LemonReader. The reader process a section
    1863     /// only if the \c section_id and the \c _id are the same.
     1866    /// only if the \c section_name and the \c _name are the same.
    18641867    AttributeReader(LemonReader& _reader,
    1865                     const std::string& _id = std::string())
    1866       : Parent(_reader), id(_id) {}
     1868                    const std::string& _name = std::string())
     1869      : Parent(_reader), name(_name) {}
    18671870
    18681871    /// \brief Destructor.
     
    19171920      std::istringstream ls(line);
    19181921      std::string command;
    1919       std::string name;
     1922      std::string id;
    19201923      ls >> command >> name;
    19211924      return command == "@attributes" && name == id;
     
    19341937        if (it != readers.end()) {
    19351938          it->second->read(ls);
    1936           it->second->touch();
     1939          it->second->touch();
    19371940        }
    19381941      }
     
    19481951
    19491952  private:
    1950     std::string id;
     1953    std::string name;
    19511954
    19521955    typedef std::map<std::string, _reader_bits::ValueReaderBase*> Readers;
     
    22042207
    22052208    void readMapNames(std::istream& is, std::vector<std::string>& maps) {
    2206       std::string line, id;
     2209      std::string line, name;
    22072210      std::getline(is, line);
    22082211      std::istringstream ls(line);
    2209       while (ls >> id) {
    2210         maps.push_back(id);
     2212      while (ls >> name) {
     2213        maps.push_back(name);
    22112214      }
    22122215      while (getline(is, line));
     
    22142217
    22152218    void readItemNames(std::istream& is, std::vector<std::string>& maps) {
    2216       std::string line, id;
     2219      std::string line, name;
    22172220      while (std::getline(is, line)) {
    22182221        std::istringstream ls(line);
    2219         ls >> id;
    2220         maps.push_back(id);
     2222        ls >> name;
     2223        maps.push_back(name);
    22212224      }
    22222225    }
  • lemon/lemon_writer.h

    r1875 r1901  
    4747   
    4848    template <typename Item>
    49     class ItemIdWriter {
     49    class ItemLabelWriter {
    5050    public:
    5151
    52       bool isIdWriter() { return true; }
    53 
    54       void writeId(std::ostream&, const Item&) {}
     52      bool isLabelWriter() { return true; }
     53
     54      void writeLabel(std::ostream&, const Item&) {}
    5555     
    56       template <class _ItemIdWriter>
     56      template <class _ItemLabelWriter>
    5757      struct Constraints {
    5858        void constraints() {
    59           bool b = writer.isIdWriter();
     59          bool b = writer.isLabelWriter();
    6060          ignore_unused_variable_warning(b);
    61           writer.writeId(os, item);
     61          writer.writeLabel(os, item);
    6262        }
    63         _ItemIdWriter& writer;
     63        _ItemLabelWriter& writer;
    6464        std::ostream& os;
    6565        const Item& item;
     
    226226
    227227    template <typename _Item>
    228     class IdWriterBase {
     228    class LabelWriterBase {
    229229    public:
    230230      typedef _Item Item;
    231       virtual ~IdWriterBase() {}
     231      virtual ~LabelWriterBase() {}
    232232      virtual void write(std::ostream&, const Item&) const = 0;
    233       virtual bool isIdWriter() const = 0;
    234     };
    235 
    236     template <typename _Item, typename _BoxedIdWriter>
    237     class IdWriter : public IdWriterBase<_Item> {
     233      virtual bool isLabelWriter() const = 0;
     234    };
     235
     236    template <typename _Item, typename _BoxedLabelWriter>
     237    class LabelWriter : public LabelWriterBase<_Item> {
    238238    public:
    239239      typedef _Item Item;
    240       typedef _BoxedIdWriter BoxedIdWriter;
    241 
    242       const BoxedIdWriter& idWriter;
    243 
    244       IdWriter(const BoxedIdWriter& _idWriter)
    245         : idWriter(_idWriter) {}
     240      typedef _BoxedLabelWriter BoxedLabelWriter;
     241
     242      const BoxedLabelWriter& labelWriter;
     243
     244      LabelWriter(const BoxedLabelWriter& _labelWriter)
     245        : labelWriter(_labelWriter) {}
    246246
    247247      virtual void write(std::ostream& os, const Item& item) const {
    248         idWriter.writeId(os, item);
    249       }
    250 
    251       virtual bool isIdWriter() const {
    252         return idWriter.isIdWriter();
     248        labelWriter.writeLabel(os, item);
     249      }
     250
     251      virtual bool isLabelWriter() const {
     252        return labelWriter.isLabelWriter();
    253253      }
    254254    };
     
    375375  ///
    376376  /// The lemon format can store multiple graph nodesets with several maps.
    377   /// The nodeset section's header line is \c \@nodeset \c nodeset_id, but the
    378   /// \c nodeset_id may be empty.
     377  /// The nodeset section's header line is \c \@nodeset \c nodeset_name, but
     378  /// the \c nodeset_name may be empty.
    379379  ///
    380380  /// The first line of the section contains the names of the maps separated
     
    382382  /// contains the mapped values for each map.
    383383  ///
    384   /// If the nodeset contains an \c "id" named map then it will be regarded
    385   /// as id map. This map should contain only unique values and when the
    386   /// \c writeId() member will be called with a node it will write it's id.
    387   /// Otherwise if the \c _forceIdMap constructor parameter is true then
    388   /// the id map will be the id in the graph.
     384  /// If the nodeset contains an \c "label" named map then it will be regarded
     385  /// as label map. This map should contain only unique values and when the
     386  /// \c writeLabel() member will be called with a node it will write it's
     387  /// label. Otherwise if the \c _forceLabelMap constructor parameter is true
     388  /// then the label map will be the id in the graph.
    389389  ///
    390390  /// \relates LemonWriter
     
    401401    ///
    402402    /// Constructor for NodeSetWriter. It creates the NodeSetWriter and
    403     /// attach it into the given LemonWriter. If the \c _forceIdMap
    404     /// parameter is true then the writer will write own id map when
    405     /// the user does not give "id" named map.
     403    /// attach it into the given LemonWriter. If the \c _forceLabelMap
     404    /// parameter is true then the writer will write own label map when
     405    /// the user does not give "label" named map.
    406406    NodeSetWriter(LemonWriter& _writer, const Graph& _graph,
    407                   const std::string& _id = std::string(),
    408                   bool _forceIdMap = true)
    409       : Parent(_writer), idMap(0), forceIdMap(_forceIdMap),
    410         graph(_graph), id(_id) {}
     407                  const std::string& _name = std::string(),
     408                  bool _forceLabelMap = true)
     409      : Parent(_writer), labelMap(0), forceLabelMap(_forceLabelMap),
     410        graph(_graph), name(_name) {}
    411411
    412412    /// \brief Destructor.
     
    455455    /// It gives back the header of the section.
    456456    virtual std::string header() {
    457       return "@nodeset " + id;
     457      return "@nodeset " + name;
    458458    }
    459459
     
    463463    virtual void write(std::ostream& os) {
    464464      for (int i = 0; i < (int)writers.size(); ++i) {
    465         if (writers[i].first == "id") {
    466           idMap = writers[i].second;
    467           forceIdMap = false;
     465        if (writers[i].first == "label" || (writers[i].first == "id" && labelMap == 0)) {
     466          labelMap = writers[i].second;
     467          forceLabelMap = false;
    468468          break;
    469469        }
    470470      }
    471       if (forceIdMap) {
    472         os << "id\t";
     471      if (forceLabelMap) {
     472        os << "label\t";
    473473      }
    474474      for (int i = 0; i < (int)writers.size(); ++i) {
     
    477477      os << std::endl;
    478478      for (typename Graph::NodeIt it(graph); it != INVALID; ++it) {
    479         if (forceIdMap) {
     479        if (forceLabelMap) {
    480480          os << graph.id(it) << '\t';
    481481        }
     
    490490  public:
    491491
    492     /// \brief Returns true if the nodeset can write the ids of the nodes.
    493     ///
    494     /// Returns true if the nodeset can write the ids of the nodes.
    495     /// It is possible only if an "id" named map was written or the
    496     /// \c _forceIdMap constructor parameter was true.
    497     bool isIdWriter() const {
    498       return idMap != 0 || forceIdMap;
    499     }
    500 
    501     /// \brief Write the id of the given node.
    502     ///
    503     /// It writes the id of the given node. If there was written an "id"
     492    /// \brief Returns true if the nodeset can write the labels of the nodes.
     493    ///
     494    /// Returns true if the nodeset can write the labels of the nodes.
     495    /// It is possible only if an "label" named map was written or the
     496    /// \c _forceLabelMap constructor parameter was true.
     497    bool isLabelWriter() const {
     498      return labelMap != 0 || forceLabelMap;
     499    }
     500
     501    /// \brief Write the label of the given node.
     502    ///
     503    /// It writes the label of the given node. If there was written an "label"
    504504    /// named map then it will write the map value belongs to the node.
    505     /// Otherwise if the \c forceId parameter was true it will write
    506     /// its id in the graph.
    507     void writeId(std::ostream& os, const Node& item) const {
    508       if (forceIdMap) {
     505    /// Otherwise if the \c forceLabel parameter was true it will write
     506    /// its label in the graph.
     507    void writeLabel(std::ostream& os, const Node& item) const {
     508      if (forceLabelMap) {
    509509        os << graph.id(item);
    510510      } else {
    511         idMap->write(os, item);
     511        labelMap->write(os, item);
    512512      }
    513513    }
     
    519519    MapWriters writers;
    520520
    521     _writer_bits::MapWriterBase<Node>* idMap;
    522     bool forceIdMap;
     521    _writer_bits::MapWriterBase<Node>* labelMap;
     522    bool forceLabelMap;
    523523   
    524524    const Graph& graph;   
    525     std::string id;
     525    std::string name;
    526526
    527527  };
     
    531531  ///
    532532  /// The lemon format can store multiple graph edgesets with several maps.
    533   /// The edgeset section's header line is \c \@edgeset \c edgeset_id, but the
    534   /// \c edgeset_id may be empty.
     533  /// The edgeset section's header line is \c \@edgeset \c edgeset_name, but
     534  /// the \c edgeset_name may be empty.
    535535  ///
    536536  /// The first line of the section contains the names of the maps separated
    537537  /// with white spaces. Each next lines describes a edge in the edgeset. The
    538   /// line contains the source and the target nodes' id and the mapped
     538  /// line contains the source and the target nodes' label and the mapped
    539539  /// values for each map.
    540540  ///
    541   /// If the edgeset contains an \c "id" named map then it will be regarded
    542   /// as id map. This map should contain only unique values and when the
    543   /// \c writeId() member will be called with an edge it will write it's id.
    544   /// Otherwise if the \c _forceIdMap constructor parameter is true then
    545   /// the id map will be the id in the graph.
    546   ///
    547   /// The edgeset writer needs a node id writer to identify which nodes
    548   /// have to be connected. If a NodeSetWriter can write the nodes' id,
     541  /// If the edgeset contains an \c "label" named map then it will be regarded
     542  /// as label map. This map should contain only unique values and when the
     543  /// \c writeLabel() member will be called with an edge it will write it's
     544  /// label. Otherwise if the \c _forceLabelMap constructor parameter is true
     545  /// then the label map will be the id in the graph.
     546  ///
     547  /// The edgeset writer needs a node label writer to identify which nodes
     548  /// have to be connected. If a NodeSetWriter can write the nodes' label,
    549549  /// it will be able to use with this class.
    550550  ///
     
    563563    ///
    564564    /// Constructor for EdgeSetWriter. It creates the EdgeSetWriter and
    565     /// attach it into the given LemonWriter. It will write node ids by
    566     /// the \c _nodeIdWriter. If the \c _forceIdMap parameter is true
    567     /// then the writer will write own id map if the user does not give
    568     /// "id" named map.
    569     template <typename NodeIdWriter>
     565    /// attach it into the given LemonWriter. It will write node labels by
     566    /// the \c _nodeLabelWriter. If the \c _forceLabelMap parameter is true
     567    /// then the writer will write own label map if the user does not give
     568    /// "label" named map.
     569    template <typename NodeLabelWriter>
    570570    EdgeSetWriter(LemonWriter& _writer, const Graph& _graph,
    571                   const NodeIdWriter& _nodeIdWriter,
    572                   const std::string& _id = std::string(),
    573                   bool _forceIdMap = true)
    574       : Parent(_writer), idMap(0), forceIdMap(_forceIdMap),
    575         graph(_graph), id(_id) {
    576       checkConcept<_writer_bits::ItemIdWriter<Node>, NodeIdWriter>();
    577       nodeIdWriter.reset(new _writer_bits::
    578                          IdWriter<Node, NodeIdWriter>(_nodeIdWriter));
     571                  const NodeLabelWriter& _nodeLabelWriter,
     572                  const std::string& _name = std::string(),
     573                  bool _forceLabelMap = true)
     574      : Parent(_writer), labelMap(0), forceLabelMap(_forceLabelMap),
     575        graph(_graph), name(_name) {
     576      checkConcept<_writer_bits::ItemLabelWriter<Node>, NodeLabelWriter>();
     577      nodeLabelWriter.reset(new _writer_bits::
     578                         LabelWriter<Node, NodeLabelWriter>(_nodeLabelWriter));
    579579    }
    580580
     
    624624    /// It gives back the header of the section.
    625625    virtual std::string header() {
    626       return "@edgeset " + id;
     626      return "@edgeset " + name;
    627627    }
    628628
     
    631631    /// Write the content of the section.
    632632    virtual void write(std::ostream& os) {
    633       if (!nodeIdWriter->isIdWriter()) {
    634         throw DataFormatError("Cannot find nodeset or ID map");
     633      if (!nodeLabelWriter->isLabelWriter()) {
     634        throw DataFormatError("Cannot find nodeset or label map");
    635635      }
    636636      for (int i = 0; i < (int)writers.size(); ++i) {
    637         if (writers[i].first == "id") {
    638           idMap = writers[i].second;
    639           forceIdMap = false;
     637        if (writers[i].first == "label" || (writers[i].first == "id" && labelMap == 0)) {
     638          labelMap = writers[i].second;
     639          forceLabelMap = false;
    640640          break;
    641641        }
    642642      }
    643643      os << "\t\t";
    644       if (forceIdMap) {
    645         os << "id\t";
     644      if (forceLabelMap) {
     645        os << "label\t";
    646646      }
    647647      for (int i = 0; i < (int)writers.size(); ++i) {
     
    650650      os << std::endl;
    651651      for (typename Graph::EdgeIt it(graph); it != INVALID; ++it) {
    652         nodeIdWriter->write(os, graph.source(it));
     652        nodeLabelWriter->write(os, graph.source(it));
    653653        os << '\t';
    654         nodeIdWriter->write(os, graph.target(it));
     654        nodeLabelWriter->write(os, graph.target(it));
    655655        os << '\t';
    656         if (forceIdMap) {
     656        if (forceLabelMap) {
    657657          os << graph.id(it) << '\t';
    658658        }
     
    667667  public:
    668668
    669     /// \brief Returns true if the edgeset can write the ids of the edges.
    670     ///
    671     /// Returns true if the edgeset can write the ids of the edges.
    672     /// It is possible only if an "id" named map was written or the
    673     /// \c _forceIdMap constructor parameter was true.
    674     bool isIdWriter() const {
    675       return forceIdMap || idMap != 0;
    676     }
    677 
    678     /// \brief Write the id of the given edge.
    679     ///
    680     /// It writes the id of the given edge. If there was written an "id"
     669    /// \brief Returns true if the edgeset can write the labels of the edges.
     670    ///
     671    /// Returns true if the edgeset can write the labels of the edges.
     672    /// It is possible only if an "label" named map was written or the
     673    /// \c _forceLabelMap constructor parameter was true.
     674    bool isLabelWriter() const {
     675      return forceLabelMap || labelMap != 0;
     676    }
     677
     678    /// \brief Write the label of the given edge.
     679    ///
     680    /// It writes the label of the given edge. If there was written an "label"
    681681    /// named map then it will write the map value belongs to the edge.
    682     /// Otherwise if the \c forceId parameter was true it will write
    683     /// its id in the graph.
    684     void writeId(std::ostream& os, const Edge& item) const {
    685       if (forceIdMap) {
     682    /// Otherwise if the \c forceLabel parameter was true it will write
     683    /// its label in the graph.
     684    void writeLabel(std::ostream& os, const Edge& item) const {
     685      if (forceLabelMap) {
    686686        os << graph.id(item);
    687687      } else {
    688         idMap->write(os, item);
     688        labelMap->write(os, item);
    689689      }
    690690    }
     
    696696    MapWriters writers;
    697697
    698     _writer_bits::MapWriterBase<Edge>* idMap;
    699     bool forceIdMap;
     698    _writer_bits::MapWriterBase<Edge>* labelMap;
     699    bool forceLabelMap;
    700700   
    701701    const Graph& graph;   
    702     std::string id;
    703 
    704     std::auto_ptr<_writer_bits::IdWriterBase<Node> > nodeIdWriter;
     702    std::string name;
     703
     704    std::auto_ptr<_writer_bits::LabelWriterBase<Node> > nodeLabelWriter;
    705705  };
    706706
     
    710710  /// The lemon format can store multiple undirected edgesets with several
    711711  /// maps. The undirected edgeset section's header line is \c \@undiredgeset
    712   /// \c undiredgeset_id, but the \c undiredgeset_id may be empty.
     712  /// \c undiredgeset_name, but the \c undiredgeset_name may be empty.
    713713  ///
    714714  /// The first line of the section contains the names of the maps separated
    715715  /// with white spaces. Each next lines describes an undirected edge in the
    716   /// edgeset. The line contains the two connected nodes' id and the mapped
     716  /// edgeset. The line contains the two connected nodes' label and the mapped
    717717  /// values for each undirected map.
    718718  ///
     
    723723  /// difference.
    724724  ///
    725   /// If the edgeset contains an \c "id" named map then it will be regarded
    726   /// as id map. This map should contain only unique values and when the
    727   /// \c writeId() member will be called with an undirected edge it will
    728   /// write it's id. Otherwise if the \c _forceIdMap constructor parameter
    729   /// is true then the id map will be the id in the graph.
    730   ///
    731   /// The undirected edgeset writer needs a node id writer to identify
     725  /// If the edgeset contains an \c "label" named map then it will be regarded
     726  /// as label map. This map should contain only unique values and when the
     727  /// \c writeLabel() member will be called with an undirected edge it will
     728  /// write it's label. Otherwise if the \c _forceLabelMap constructor
     729  /// parameter is true then the label map will be the id in the graph.
     730  ///
     731  /// The undirected edgeset writer needs a node label writer to identify
    732732  /// which nodes have to be connected. If a NodeSetWriter can write the
    733   /// nodes' id, it will be able to use with this class.
     733  /// nodes' label, it will be able to use with this class.
    734734  ///
    735735  /// \relates LemonWriter
     
    748748    ///
    749749    /// Constructor for UndirEdgeSetWriter. It creates the UndirEdgeSetWriter
    750     /// and attach it into the given LemonWriter. It will write node ids by
    751     /// the \c _nodeIdWriter. If the \c _forceIdMap parameter is true
    752     /// then the writer will write own id map if the user does not give
    753     /// "id" named map.
    754     template <typename NodeIdWriter>
     750    /// and attach it into the given LemonWriter. It will write node labels by
     751    /// the \c _nodeLabelWriter. If the \c _forceLabelMap parameter is true
     752    /// then the writer will write own label map if the user does not give
     753    /// "label" named map.
     754    template <typename NodeLabelWriter>
    755755    UndirEdgeSetWriter(LemonWriter& _writer, const Graph& _graph,
    756                        const NodeIdWriter& _nodeIdWriter,
    757                        const std::string& _id = std::string(),
    758                        bool _forceIdMap = true)
    759       : Parent(_writer), idMap(0), forceIdMap(_forceIdMap),
    760         graph(_graph), id(_id) {
    761       checkConcept<_writer_bits::ItemIdWriter<Node>, NodeIdWriter>();
    762       nodeIdWriter.reset(new _writer_bits::
    763                          IdWriter<Node, NodeIdWriter>(_nodeIdWriter));
     756                       const NodeLabelWriter& _nodeLabelWriter,
     757                       const std::string& _name = std::string(),
     758                       bool _forceLabelMap = true)
     759      : Parent(_writer), labelMap(0), forceLabelMap(_forceLabelMap),
     760        graph(_graph), name(_name) {
     761      checkConcept<_writer_bits::ItemLabelWriter<Node>, NodeLabelWriter>();
     762      nodeLabelWriter.reset(new _writer_bits::
     763                         LabelWriter<Node, NodeLabelWriter>(_nodeLabelWriter));
    764764    }
    765765
     
    833833    /// It gives back the header of the section.
    834834    virtual std::string header() {
    835       return "@undiredgeset " + id;
     835      return "@undiredgeset " + name;
    836836    }
    837837
     
    840840    /// Write the content of the section.
    841841    virtual void write(std::ostream& os) {
    842       if (!nodeIdWriter->isIdWriter()) {
    843         throw DataFormatError("Cannot find nodeset or ID map");
     842      if (!nodeLabelWriter->isLabelWriter()) {
     843        throw DataFormatError("Cannot find nodeset or label map");
    844844      }
    845845      for (int i = 0; i < (int)writers.size(); ++i) {
    846         if (writers[i].first == "id") {
    847           idMap = writers[i].second;
    848           forceIdMap = false;
     846        if (writers[i].first == "label") {
     847          labelMap = writers[i].second;
     848          forceLabelMap = false;
    849849          break;
    850850        }
    851851      }
    852852      os << "\t\t";
    853       if (forceIdMap) {
    854         os << "id\t";
     853      if (forceLabelMap) {
     854        os << "label\t";
    855855      }
    856856      for (int i = 0; i < (int)writers.size(); ++i) {
     
    859859      os << std::endl;
    860860      for (typename Graph::UndirEdgeIt it(graph); it != INVALID; ++it) {
    861         nodeIdWriter->write(os, graph.source(it));
     861        nodeLabelWriter->write(os, graph.source(it));
    862862        os << '\t';
    863         nodeIdWriter->write(os, graph.target(it));
     863        nodeLabelWriter->write(os, graph.target(it));
    864864        os << '\t';
    865         if (forceIdMap) {
     865        if (forceLabelMap) {
    866866          os << graph.id(it) << '\t';
    867867        }
     
    876876  public:
    877877
    878     /// \brief Returns true if the undirected edgeset can write the ids of
     878    /// \brief Returns true if the undirected edgeset can write the labels of
    879879    /// the edges.
    880880    ///
    881     /// Returns true if the undirected edgeset can write the ids of the
    882     /// undirected edges. It is possible only if an "id" named map was
    883     /// written or the \c _forceIdMap constructor parameter was true.
    884     bool isIdWriter() const {
    885       return forceIdMap || idMap != 0;
    886     }
    887 
    888     /// \brief Write the id of the given undirected edge.
    889     ///
    890     /// It writes the id of the given undirected edge. If there was written
    891     /// an "id" named map then it will write the map value belongs to the
    892     /// undirected edge. Otherwise if the \c forceId parameter was true it
     881    /// Returns true if the undirected edgeset can write the labels of the
     882    /// undirected edges. It is possible only if an "label" named map was
     883    /// written or the \c _forceLabelMap constructor parameter was true.
     884    bool isLabelWriter() const {
     885      return forceLabelMap || labelMap != 0;
     886    }
     887
     888    /// \brief Write the label of the given undirected edge.
     889    ///
     890    /// It writes the label of the given undirected edge. If there was written
     891    /// an "label" named map then it will write the map value belongs to the
     892    /// undirected edge. Otherwise if the \c forceLabel parameter was true it
    893893    /// will write its id in the graph.
    894     void writeId(std::ostream& os, const UndirEdge& item) const {
    895       if (forceIdMap) {
     894    void writeLabel(std::ostream& os, const UndirEdge& item) const {
     895      if (forceLabelMap) {
    896896        os << graph.id(item);
    897897      } else {
    898         idMap->write(os, item);
     898        labelMap->write(os, item);
    899899      }
    900900    }
    901901
    902     /// \brief Write the id of the given edge.
    903     ///
    904     /// It writes the id of the given edge. If there was written
    905     /// an "id" named map then it will write the map value belongs to the
    906     /// edge. Otherwise if the \c forceId parameter was true it
     902    /// \brief Write the label of the given edge.
     903    ///
     904    /// It writes the label of the given edge. If there was written
     905    /// an "label" named map then it will write the map value belongs to the
     906    /// edge. Otherwise if the \c forceLabel parameter was true it
    907907    /// will write its id in the graph. If the edge is forward map
    908908    /// then its prefix character is \c '+' elsewhere \c '-'.
    909     void writeId(std::ostream& os, const Edge& item) const {
     909    void writeLabel(std::ostream& os, const Edge& item) const {
    910910      if (graph.direction(item)) {
    911911        os << "+ ";
     
    913913        os << "- ";
    914914      }
    915       if (forceIdMap) {
     915      if (forceLabelMap) {
    916916        os << graph.id(item);
    917917      } else {
    918         idMap->write(os, item);
     918        labelMap->write(os, item);
    919919      }
    920920    }
     
    926926    MapWriters writers;
    927927
    928     _writer_bits::MapWriterBase<UndirEdge>* idMap;
    929     bool forceIdMap;
     928    _writer_bits::MapWriterBase<UndirEdge>* labelMap;
     929    bool forceLabelMap;
    930930   
    931931    const Graph& graph;   
    932     std::string id;
    933 
    934     std::auto_ptr<_writer_bits::IdWriterBase<Node> > nodeIdWriter;
     932    std::string name;
     933
     934    std::auto_ptr<_writer_bits::LabelWriterBase<Node> > nodeLabelWriter;
    935935  };
    936936
    937937  /// \ingroup io_group
    938   /// \brief SectionWriter for writing labeled nodes.
    939   ///
    940   /// The nodes section's header line is \c \@nodes \c nodes_id, but the
    941   /// \c nodes_id may be empty.
    942   ///
    943   /// Each line in the section contains the label of the node and
    944   /// then the node id.
     938  /// \brief SectionWriter for writing named nodes.
     939  ///
     940  /// The nodes section's header line is \c \@nodes \c nodes_name, but the
     941  /// \c nodes_name may be empty.
     942  ///
     943  /// Each line in the section contains the name of the node and
     944  /// then the node label.
    945945  ///
    946946  /// \relates LemonWriter
     
    955955    ///
    956956    /// Constructor for NodeWriter. It creates the NodeWriter and
    957     /// attach it into the given LemonWriter. The given \c _IdWriter
    958     /// will write the nodes' id what can be a nodeset writer.
    959     template <typename _IdWriter>
    960     NodeWriter(LemonWriter& _writer, const _IdWriter& _idWriter,
    961                const std::string& _id = std::string())
    962       : Parent(_writer), id(_id) {
    963       checkConcept<_writer_bits::ItemIdWriter<Node>, _IdWriter>();
    964       idWriter.reset(new _writer_bits::IdWriter<Node, _IdWriter>(_idWriter));
     957    /// attach it into the given LemonWriter. The given \c _LabelWriter
     958    /// will write the nodes' label what can be a nodeset writer.
     959    template <typename _LabelWriter>
     960    NodeWriter(LemonWriter& _writer, const _LabelWriter& _labelWriter,
     961               const std::string& _name = std::string())
     962      : Parent(_writer), name(_name) {
     963      checkConcept<_writer_bits::ItemLabelWriter<Node>, _LabelWriter>();
     964      labelWriter.reset(new _writer_bits::LabelWriter<Node, _LabelWriter>
     965                        (_labelWriter));
    965966    }
    966967
     
    986987  protected:
    987988
    988     /// \brief Header checking function.
    989     ///
    990     /// It gives back true when the header line start with \c \@nodes,
    991     /// and the header line's id and the writer's id are the same.
     989    /// \brief The header of the section.
     990    ///
     991    /// It gives back the header of the section.
    992992    virtual std::string header() {
    993       return "@nodes " + id;
     993      return "@nodes " + name;
    994994    }
    995995
     
    998998    /// Write the content of the section.
    999999    virtual void write(std::ostream& os) {
    1000       if (!idWriter->isIdWriter()) {
    1001         throw DataFormatError("Cannot find nodeset or ID map");
     1000      if (!labelWriter->isLabelWriter()) {
     1001        throw DataFormatError("Cannot find nodeset or label map");
    10021002      }
    10031003      for (int i = 0; i < (int)writers.size(); ++i) {
    10041004        os << writers[i].first << ' ';
    1005         idWriter->write(os, *(writers[i].second));
     1005        labelWriter->write(os, *(writers[i].second));
    10061006        os << std::endl;
    10071007      }
     
    10101010  private:
    10111011
    1012     std::string id;
     1012    std::string name;
    10131013
    10141014    typedef std::vector<std::pair<std::string, const Node*> > NodeWriters;
    10151015    NodeWriters writers;
    1016     std::auto_ptr<_writer_bits::IdWriterBase<Node> > idWriter;
     1016    std::auto_ptr<_writer_bits::LabelWriterBase<Node> > labelWriter;
    10171017  };
    10181018
    10191019  /// \ingroup io_group
    1020   /// \brief SectionWriter for writing labeled edges.
    1021   ///
    1022   /// The edges section's header line is \c \@edges \c edges_id, but the
    1023   /// \c edges_id may be empty.
    1024   ///
    1025   /// Each line in the section contains the label of the edge and
    1026   /// then the edge id.
     1020  /// \brief SectionWriter for writing named edges.
     1021  ///
     1022  /// The edges section's header line is \c \@edges \c edges_name, but the
     1023  /// \c edges_name may be empty.
     1024  ///
     1025  /// Each line in the section contains the name of the edge and
     1026  /// then the edge label.
    10271027  ///
    10281028  /// \relates LemonWriter
     
    10371037    ///
    10381038    /// Constructor for EdgeWriter. It creates the EdgeWriter and
    1039     /// attach it into the given LemonWriter. The given \c _IdWriter
    1040     /// will write the edges' id what can be a edgeset writer.
    1041     template <typename _IdWriter>
    1042     EdgeWriter(LemonWriter& _writer, const _IdWriter& _idWriter,
    1043                const std::string& _id = std::string())
    1044       : Parent(_writer), id(_id) {
    1045       checkConcept<_writer_bits::ItemIdWriter<Edge>, _IdWriter>();
    1046       idWriter.reset(new _writer_bits::IdWriter<Edge, _IdWriter>(_idWriter));
     1039    /// attach it into the given LemonWriter. The given \c _LabelWriter
     1040    /// will write the edges' label what can be a edgeset writer.
     1041    template <typename _LabelWriter>
     1042    EdgeWriter(LemonWriter& _writer, const _LabelWriter& _labelWriter,
     1043               const std::string& _name = std::string())
     1044      : Parent(_writer), name(_name) {
     1045      checkConcept<_writer_bits::ItemLabelWriter<Edge>, _LabelWriter>();
     1046      labelWriter.reset(new _writer_bits::LabelWriter<Edge, _LabelWriter>(_labelWriter));
    10471047    }
    10481048
     
    10661066  protected:
    10671067
    1068     /// \brief Header checking function.
    1069     ///
    1070     /// It gives back true when the header line start with \c \@edges,
    1071     /// and the header line's id and the writer's id are the same.
     1068    /// \brief The header of the section.
     1069    ///
     1070    /// It gives back the header of the section.
    10721071    virtual std::string header() {
    1073       return "@edges " + id;
     1072      return "@edges " + name;
    10741073    }
    10751074
     
    10781077    /// Write the content of the section.
    10791078    virtual void write(std::ostream& os) {
    1080       if (!idWriter->isIdWriter()) {
    1081         throw DataFormatError("Cannot find edgeset or ID map");
     1079      if (!labelWriter->isLabelWriter()) {
     1080        throw DataFormatError("Cannot find edgeset or label map");
    10821081      }
    10831082      for (int i = 0; i < (int)writers.size(); ++i) {
    10841083        os << writers[i].first << ' ';
    1085         idWriter->write(os, *(writers[i].second));
     1084        labelWriter->write(os, *(writers[i].second));
    10861085        os << std::endl;
    10871086      }
     
    10901089  private:
    10911090
    1092     std::string id;
     1091    std::string name;
    10931092
    10941093    typedef std::vector<std::pair<std::string, const Edge*> > EdgeWriters;
    10951094    EdgeWriters writers;
    10961095
    1097     std::auto_ptr<_writer_bits::IdWriterBase<Edge> > idWriter;
     1096    std::auto_ptr<_writer_bits::LabelWriterBase<Edge> > labelWriter;
    10981097  };
    10991098
    11001099  /// \ingroup io_group
    1101   /// \brief SectionWriter for writing labeled undirected edges.
     1100  /// \brief SectionWriter for writing named undirected edges.
    11021101  ///
    11031102  /// The undirected edges section's header line is \c \@undiredges
    1104   /// \c undiredges_id, but the \c undiredges_id may be empty.
    1105   ///
    1106   /// Each line in the section contains the label of the undirected edge and
    1107   /// then the undirected edge id.
     1103  /// \c undiredges_name, but the \c undiredges_name may be empty.
     1104  ///
     1105  /// Each line in the section contains the name of the undirected edge and
     1106  /// then the undirected edge label.
    11081107  ///
    11091108  /// \relates LemonWriter
     
    11201119    ///
    11211120    /// Constructor for UndirEdgeWriter. It creates the UndirEdgeWriter and
    1122     /// attach it into the given LemonWriter. The given \c _IdWriter
    1123     /// will write the undirected edges' id what can be an undirected
     1121    /// attach it into the given LemonWriter. The given \c _LabelWriter
     1122    /// will write the undirected edges' label what can be an undirected
    11241123    /// edgeset writer.
    1125     template <typename _IdWriter>
    1126     UndirEdgeWriter(LemonWriter& _writer, const _IdWriter& _idWriter,
    1127                const std::string& _id = std::string())
    1128       : Parent(_writer), id(_id) {
    1129       checkConcept<_writer_bits::ItemIdWriter<Edge>, _IdWriter>();
    1130       checkConcept<_writer_bits::ItemIdWriter<UndirEdge>, _IdWriter>();
    1131       undirEdgeIdWriter.reset(new _writer_bits::
    1132                               IdWriter<UndirEdge, _IdWriter>(_idWriter));
    1133       edgeIdWriter.reset(new _writer_bits::
    1134                          IdWriter<Edge, _IdWriter>(_idWriter));
     1124    template <typename _LabelWriter>
     1125    UndirEdgeWriter(LemonWriter& _writer, const _LabelWriter& _labelWriter,
     1126               const std::string& _name = std::string())
     1127      : Parent(_writer), name(_name) {
     1128      checkConcept<_writer_bits::ItemLabelWriter<Edge>, _LabelWriter>();
     1129      checkConcept<_writer_bits::ItemLabelWriter<UndirEdge>, _LabelWriter>();
     1130      undirEdgeLabelWriter.reset(new _writer_bits::
     1131                              LabelWriter<UndirEdge, _LabelWriter>(_labelWriter));
     1132      edgeLabelWriter.reset(new _writer_bits::
     1133                         LabelWriter<Edge, _LabelWriter>(_labelWriter));
    11351134    }
    11361135
     
    11611160  protected:
    11621161
    1163     /// \brief Header checking function.
    1164     ///
    1165     /// It gives back true when the header line start with \c \@undiredges,
    1166     /// and the header line's id and the writer's id are the same.
     1162    /// \brief The header of the section.
     1163    ///
     1164    /// It gives back the header of the section.
    11671165    virtual std::string header() {
    1168       return "@undiredges " + id;
     1166      return "@undiredges " + name;
    11691167    }
    11701168
     
    11731171    /// Write the content of the section.
    11741172    virtual void write(std::ostream& os) {
    1175       if (!edgeIdWriter->isIdWriter()) {
    1176         throw DataFormatError("Cannot find undirected edgeset or ID map");
    1177       }
    1178       if (!undirEdgeIdWriter->isIdWriter()) {
    1179         throw DataFormatError("Cannot find undirected edgeset or ID map");
     1173      if (!edgeLabelWriter->isLabelWriter()) {
     1174        throw DataFormatError("Cannot find undirected edgeset or label map");
     1175      }
     1176      if (!undirEdgeLabelWriter->isLabelWriter()) {
     1177        throw DataFormatError("Cannot find undirected edgeset or label map");
    11801178      }
    11811179      for (int i = 0; i < (int)undirEdgeWriters.size(); ++i) {
    11821180        os << undirEdgeWriters[i].first << ' ';
    1183         undirEdgeIdWriter->write(os, *(undirEdgeWriters[i].second));
     1181        undirEdgeLabelWriter->write(os, *(undirEdgeWriters[i].second));
    11841182        os << std::endl;
    11851183      }
    11861184      for (int i = 0; i < (int)edgeWriters.size(); ++i) {
    11871185        os << edgeWriters[i].first << ' ';
    1188         edgeIdWriter->write(os, *(edgeWriters[i].second));
     1186        edgeLabelWriter->write(os, *(edgeWriters[i].second));
    11891187        os << std::endl;
    11901188      }
     
    11931191  private:
    11941192
    1195     std::string id;
     1193    std::string name;
    11961194
    11971195    typedef std::vector<std::pair<std::string,
    11981196                                  const UndirEdge*> > UndirEdgeWriters;
    11991197    UndirEdgeWriters undirEdgeWriters;
    1200     std::auto_ptr<_writer_bits::IdWriterBase<UndirEdge> > undirEdgeIdWriter;
     1198    std::auto_ptr<_writer_bits::LabelWriterBase<UndirEdge> > undirEdgeLabelWriter;
    12011199
    12021200    typedef std::vector<std::pair<std::string, const Edge*> > EdgeWriters;
    12031201    EdgeWriters edgeWriters;
    1204     std::auto_ptr<_writer_bits::IdWriterBase<Edge> > edgeIdWriter;
     1202    std::auto_ptr<_writer_bits::LabelWriterBase<Edge> > edgeLabelWriter;
    12051203
    12061204  };
     
    12101208  ///
    12111209  /// The lemon format can store multiple attribute set. Each set has
    1212   /// the header line \c \@attributes \c attributeset_id, but the
    1213   /// attributeset_id may be empty.
     1210  /// the header line \c \@attributes \c attributes_name, but the
     1211  /// attributeset_name may be empty.
    12141212  ///
    12151213  /// The attributeset section contains several lines. Each of them starts
     
    12271225    /// attach it into the given LemonWriter.
    12281226    AttributeWriter(LemonWriter& _writer,
    1229                     const std::string& _id = std::string())
    1230       : Parent(_writer), id(_id) {}
     1227                    const std::string& _name = std::string())
     1228      : Parent(_writer), name(_name) {}
    12311229
    12321230    /// \brief Destructor.
     
    12491247    /// Add an attribute writer command for the writer.
    12501248    template <typename Value>
    1251     AttributeWriter& writeAttribute(const std::string& id,
     1249    AttributeWriter& writeAttribute(const std::string& name,
    12521250                                    const Value& value) {
    12531251      return
    1254         writeAttribute<typename Traits::template Writer<Value> >(id, value);
     1252        writeAttribute<typename Traits::template Writer<Value> >(name, value);
    12551253    }
    12561254
     
    12741272    /// It gives back the header of the section.
    12751273    std::string header() {
    1276       return "@attributes " + id;
     1274      return "@attributes " + name;
    12771275    }
    12781276
     
    12901288
    12911289  private:
    1292     std::string id;
     1290    std::string name;
    12931291
    12941292    typedef std::vector<std::pair<std::string,
  • test/Makefile.am

    r1847 r1901  
    1111        heap_test.h
    1212
     13
    1314check_PROGRAMS = \
    1415        all_pairs_shortest_path_test \
     
    2122        graph_utils_test \
    2223        kruskal_test \
    23         max_matching_test \
    2424        maps_test \
    2525        matrix_maps_test \
     26        max_matching_test \
    2627        min_cost_flow_test \
    2728        suurballe_test \
  • test/dijkstra_test.lgf

    r1435 r1901  
    11@nodeset
    2 id     
     2label   
    33999     
    44998     
     
    100210020       
    10031003@edgeset
    1004                 id      capacity       
     1004                label   capacity       
    1005100575      377     6906    27     
    10061006417     515     6905    69     
Note: See TracChangeset for help on using the changeset viewer.