COIN-OR::LEMON - Graph Library

Changeset 599:f63e87b9748e in lemon-1.2 for lemon/lgf_writer.h


Ignore:
Timestamp:
04/21/09 11:34:49 (10 years ago)
Author:
Alpar Juttner <alpar@…>
Branch:
default
Parents:
598:a3402913cffe (diff), 597:2ca0cdb5f366 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Phase:
public
Message:

Merge

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • lemon/lgf_writer.h

    r584 r599  
    348348  }
    349349
    350   template <typename Digraph>
     350  template <typename DGR>
    351351  class DigraphWriter;
    352352
    353   template <typename Digraph>
    354   DigraphWriter<Digraph> digraphWriter(const Digraph& digraph,
    355                                        std::ostream& os = std::cout);
    356   template <typename Digraph>
    357   DigraphWriter<Digraph> digraphWriter(const Digraph& digraph,
    358                                        const std::string& fn);
    359 
    360   template <typename Digraph>
    361   DigraphWriter<Digraph> digraphWriter(const Digraph& digraph,
    362                                        const char* fn);
     353  template <typename TDGR>
     354  DigraphWriter<TDGR> digraphWriter(const TDGR& digraph,
     355                                   std::ostream& os = std::cout);
     356  template <typename TDGR>
     357  DigraphWriter<TDGR> digraphWriter(const TDGR& digraph, const std::string& fn);
     358
     359  template <typename TDGR>
     360  DigraphWriter<TDGR> digraphWriter(const TDGR& digraph, const char* fn);
    363361
    364362
     
    382380  ///
    383381  ///\code
    384   /// DigraphWriter<Digraph>(digraph, std::cout).
     382  /// DigraphWriter<DGR>(digraph, std::cout).
    385383  ///   nodeMap("coordinates", coord_map).
    386384  ///   nodeMap("size", size).
     
    407405  /// the \c ostream() function, hence the second pass can append its
    408406  /// output to the output of the first pass.
    409   template <typename GR>
     407  template <typename DGR>
    410408  class DigraphWriter {
    411409  public:
    412410
    413     typedef GR Digraph;
    414     TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
     411    typedef DGR Digraph;
     412    TEMPLATE_DIGRAPH_TYPEDEFS(DGR);
    415413
    416414  private:
     
    420418    bool local_os;
    421419
    422     const Digraph& _digraph;
     420    const DGR& _digraph;
    423421
    424422    std::string _nodes_caption;
     
    452450    /// Construct a directed graph writer, which writes to the given
    453451    /// output stream.
    454     DigraphWriter(const Digraph& digraph, std::ostream& os = std::cout)
     452    DigraphWriter(const DGR& digraph, std::ostream& os = std::cout)
    455453      : _os(&os), local_os(false), _digraph(digraph),
    456454        _skip_nodes(false), _skip_arcs(false) {}
     
    460458    /// Construct a directed graph writer, which writes to the given
    461459    /// output file.
    462     DigraphWriter(const Digraph& digraph, const std::string& fn)
     460    DigraphWriter(const DGR& digraph, const std::string& fn)
    463461      : _os(new std::ofstream(fn.c_str())), local_os(true), _digraph(digraph),
    464462        _skip_nodes(false), _skip_arcs(false) {
     
    473471    /// Construct a directed graph writer, which writes to the given
    474472    /// output file.
    475     DigraphWriter(const Digraph& digraph, const char* fn)
     473    DigraphWriter(const DGR& digraph, const char* fn)
    476474      : _os(new std::ofstream(fn)), local_os(true), _digraph(digraph),
    477475        _skip_nodes(false), _skip_arcs(false) {
     
    506504  private:
    507505
    508     template <typename DGR>
    509     friend DigraphWriter<DGR> digraphWriter(const DGR& digraph,
    510                                             std::ostream& os);
    511     template <typename DGR>
    512     friend DigraphWriter<DGR> digraphWriter(const DGR& digraph,
    513                                             const std::string& fn);
    514     template <typename DGR>
    515     friend DigraphWriter<DGR> digraphWriter(const DGR& digraph,
    516                                             const char *fn);
     506    template <typename TDGR>
     507    friend DigraphWriter<TDGR> digraphWriter(const TDGR& digraph,
     508                                             std::ostream& os);
     509    template <typename TDGR>
     510    friend DigraphWriter<TDGR> digraphWriter(const TDGR& digraph,
     511                                             const std::string& fn);
     512    template <typename TDGR>
     513    friend DigraphWriter<TDGR> digraphWriter(const TDGR& digraph,
     514                                             const char *fn);
    517515
    518516    DigraphWriter(DigraphWriter& other)
     
    725723
    726724      if (label == 0) {
    727         IdMap<Digraph, Node> id_map(_digraph);
    728         _writer_bits::MapLess<IdMap<Digraph, Node> > id_less(id_map);
     725        IdMap<DGR, Node> id_map(_digraph);
     726        _writer_bits::MapLess<IdMap<DGR, Node> > id_less(id_map);
    729727        std::sort(nodes.begin(), nodes.end(), id_less);
    730728      } else {
     
    810808
    811809      if (label == 0) {
    812         IdMap<Digraph, Arc> id_map(_digraph);
    813         _writer_bits::MapLess<IdMap<Digraph, Arc> > id_less(id_map);
     810        IdMap<DGR, Arc> id_map(_digraph);
     811        _writer_bits::MapLess<IdMap<DGR, Arc> > id_less(id_map);
    814812        std::sort(arcs.begin(), arcs.end(), id_less);
    815813      } else {
     
    916914  };
    917915
     916  /// \ingroup lemon_io
     917  ///
     918  /// \brief Return a \ref DigraphWriter class
     919  ///
     920  /// This function just returns a \ref DigraphWriter class.
     921  ///
     922  /// With this function a digraph can be write to a file or output
     923  /// stream in \ref lgf-format "LGF" format with several maps and
     924  /// attributes. For example, with the following code a network flow
     925  /// problem can be written to the standard output, i.e. a digraph
     926  /// with a \e capacity map on the arcs and \e source and \e target
     927  /// nodes:
     928  ///
     929  ///\code
     930  ///ListDigraph digraph;
     931  ///ListDigraph::ArcMap<int> cap(digraph);
     932  ///ListDigraph::Node src, trg;
     933  ///  // Setting the capacity map and source and target nodes
     934  ///digraphWriter(digraph, std::cout).
     935  ///  arcMap("capacity", cap).
     936  ///  node("source", src).
     937  ///  node("target", trg).
     938  ///  run();
     939  ///\endcode
     940  ///
     941  /// For a complete documentation, please see the \ref DigraphWriter
     942  /// class documentation.
     943  /// \warning Don't forget to put the \ref DigraphWriter::run() "run()"
     944  /// to the end of the parameter list.
     945  /// \relates DigraphWriter
     946  /// \sa digraphWriter(const TDGR& digraph, const std::string& fn)
     947  /// \sa digraphWriter(const TDGR& digraph, const char* fn)
     948  template <typename TDGR>
     949  DigraphWriter<TDGR> digraphWriter(const TDGR& digraph, std::ostream& os) {
     950    DigraphWriter<TDGR> tmp(digraph, os);
     951    return tmp;
     952  }
     953
    918954  /// \brief Return a \ref DigraphWriter class
    919955  ///
    920956  /// This function just returns a \ref DigraphWriter class.
    921957  /// \relates DigraphWriter
    922   template <typename Digraph>
    923   DigraphWriter<Digraph> digraphWriter(const Digraph& digraph,
    924                                        std::ostream& os) {
    925     DigraphWriter<Digraph> tmp(digraph, os);
     958  /// \sa digraphWriter(const TDGR& digraph, std::ostream& os)
     959  template <typename TDGR>
     960  DigraphWriter<TDGR> digraphWriter(const TDGR& digraph,
     961                                    const std::string& fn) {
     962    DigraphWriter<TDGR> tmp(digraph, fn);
    926963    return tmp;
    927964  }
     
    931968  /// This function just returns a \ref DigraphWriter class.
    932969  /// \relates DigraphWriter
    933   template <typename Digraph>
    934   DigraphWriter<Digraph> digraphWriter(const Digraph& digraph,
    935                                        const std::string& fn) {
    936     DigraphWriter<Digraph> tmp(digraph, fn);
     970  /// \sa digraphWriter(const TDGR& digraph, std::ostream& os)
     971  template <typename TDGR>
     972  DigraphWriter<TDGR> digraphWriter(const TDGR& digraph, const char* fn) {
     973    DigraphWriter<TDGR> tmp(digraph, fn);
    937974    return tmp;
    938975  }
    939976
    940   /// \brief Return a \ref DigraphWriter class
    941   ///
    942   /// This function just returns a \ref DigraphWriter class.
    943   /// \relates DigraphWriter
    944   template <typename Digraph>
    945   DigraphWriter<Digraph> digraphWriter(const Digraph& digraph,
    946                                        const char* fn) {
    947     DigraphWriter<Digraph> tmp(digraph, fn);
    948     return tmp;
    949   }
    950 
    951   template <typename Graph>
     977  template <typename GR>
    952978  class GraphWriter;
    953979
    954   template <typename Graph>
    955   GraphWriter<Graph> graphWriter(const Graph& graph,
    956                                  std::ostream& os = std::cout);
    957   template <typename Graph>
    958   GraphWriter<Graph> graphWriter(const Graph& graph, const std::string& fn);
    959   template <typename Graph>
    960   GraphWriter<Graph> graphWriter(const Graph& graph, const char* fn);
     980  template <typename TGR>
     981  GraphWriter<TGR> graphWriter(const TGR& graph, std::ostream& os = std::cout);
     982  template <typename TGR>
     983  GraphWriter<TGR> graphWriter(const TGR& graph, const std::string& fn);
     984  template <typename TGR>
     985  GraphWriter<TGR> graphWriter(const TGR& graph, const char* fn);
    961986
    962987  /// \ingroup lemon_io
     
    9801005
    9811006    typedef GR Graph;
    982     TEMPLATE_GRAPH_TYPEDEFS(Graph);
     1007    TEMPLATE_GRAPH_TYPEDEFS(GR);
    9831008
    9841009  private:
     
    9881013    bool local_os;
    9891014
    990     const Graph& _graph;
     1015    const GR& _graph;
    9911016
    9921017    std::string _nodes_caption;
     
    10201045    /// Construct a directed graph writer, which writes to the given
    10211046    /// output stream.
    1022     GraphWriter(const Graph& graph, std::ostream& os = std::cout)
     1047    GraphWriter(const GR& graph, std::ostream& os = std::cout)
    10231048      : _os(&os), local_os(false), _graph(graph),
    10241049        _skip_nodes(false), _skip_edges(false) {}
     
    10281053    /// Construct a directed graph writer, which writes to the given
    10291054    /// output file.
    1030     GraphWriter(const Graph& graph, const std::string& fn)
     1055    GraphWriter(const GR& graph, const std::string& fn)
    10311056      : _os(new std::ofstream(fn.c_str())), local_os(true), _graph(graph),
    10321057        _skip_nodes(false), _skip_edges(false) {
     
    10411066    /// Construct a directed graph writer, which writes to the given
    10421067    /// output file.
    1043     GraphWriter(const Graph& graph, const char* fn)
     1068    GraphWriter(const GR& graph, const char* fn)
    10441069      : _os(new std::ofstream(fn)), local_os(true), _graph(graph),
    10451070        _skip_nodes(false), _skip_edges(false) {
     
    10741099  private:
    10751100
    1076     template <typename Graph>
    1077     friend GraphWriter<Graph> graphWriter(const Graph& graph,
    1078                                           std::ostream& os);
    1079     template <typename Graph>
    1080     friend GraphWriter<Graph> graphWriter(const Graph& graph,
    1081                                           const std::string& fn);
    1082     template <typename Graph>
    1083     friend GraphWriter<Graph> graphWriter(const Graph& graph,
    1084                                           const char *fn);
     1101    template <typename TGR>
     1102    friend GraphWriter<TGR> graphWriter(const TGR& graph, std::ostream& os);
     1103    template <typename TGR>
     1104    friend GraphWriter<TGR> graphWriter(const TGR& graph,
     1105                                        const std::string& fn);
     1106    template <typename TGR>
     1107    friend GraphWriter<TGR> graphWriter(const TGR& graph, const char *fn);
    10851108   
    10861109    GraphWriter(GraphWriter& other)
     
    11691192      checkConcept<concepts::ReadMap<Arc, typename Map::Value>, Map>();
    11701193      _writer_bits::MapStorageBase<Edge>* forward_storage =
    1171         new _writer_bits::GraphArcMapStorage<Graph, true, Map>(_graph, map);
     1194        new _writer_bits::GraphArcMapStorage<GR, true, Map>(_graph, map);
    11721195      _edge_maps.push_back(std::make_pair('+' + caption, forward_storage));
    11731196      _writer_bits::MapStorageBase<Edge>* backward_storage =
    1174         new _writer_bits::GraphArcMapStorage<Graph, false, Map>(_graph, map);
     1197        new _writer_bits::GraphArcMapStorage<GR, false, Map>(_graph, map);
    11751198      _edge_maps.push_back(std::make_pair('-' + caption, backward_storage));
    11761199      return *this;
     
    11861209      checkConcept<concepts::ReadMap<Arc, typename Map::Value>, Map>();
    11871210      _writer_bits::MapStorageBase<Edge>* forward_storage =
    1188         new _writer_bits::GraphArcMapStorage<Graph, true, Map, Converter>
     1211        new _writer_bits::GraphArcMapStorage<GR, true, Map, Converter>
    11891212        (_graph, map, converter);
    11901213      _edge_maps.push_back(std::make_pair('+' + caption, forward_storage));
    11911214      _writer_bits::MapStorageBase<Edge>* backward_storage =
    1192         new _writer_bits::GraphArcMapStorage<Graph, false, Map, Converter>
     1215        new _writer_bits::GraphArcMapStorage<GR, false, Map, Converter>
    11931216        (_graph, map, converter);
    11941217      _edge_maps.push_back(std::make_pair('-' + caption, backward_storage));
     
    12481271    /// Add an arc writing rule to writer.
    12491272    GraphWriter& arc(const std::string& caption, const Arc& arc) {
    1250       typedef _writer_bits::GraphArcLookUpConverter<Graph> Converter;
     1273      typedef _writer_bits::GraphArcLookUpConverter<GR> Converter;
    12511274      Converter converter(_graph, _edge_index);
    12521275      _writer_bits::ValueStorageBase* storage =
     
    13391362
    13401363      if (label == 0) {
    1341         IdMap<Graph, Node> id_map(_graph);
    1342         _writer_bits::MapLess<IdMap<Graph, Node> > id_less(id_map);
     1364        IdMap<GR, Node> id_map(_graph);
     1365        _writer_bits::MapLess<IdMap<GR, Node> > id_less(id_map);
    13431366        std::sort(nodes.begin(), nodes.end(), id_less);
    13441367      } else {
     
    14241447
    14251448      if (label == 0) {
    1426         IdMap<Graph, Edge> id_map(_graph);
    1427         _writer_bits::MapLess<IdMap<Graph, Edge> > id_less(id_map);
     1449        IdMap<GR, Edge> id_map(_graph);
     1450        _writer_bits::MapLess<IdMap<GR, Edge> > id_less(id_map);
    14281451        std::sort(edges.begin(), edges.end(), id_less);
    14291452      } else {
     
    15301553  };
    15311554
     1555  /// \ingroup lemon_io
     1556  ///
     1557  /// \brief Return a \ref GraphWriter class
     1558  ///
     1559  /// This function just returns a \ref GraphWriter class.
     1560  ///
     1561  /// With this function a graph can be write to a file or output
     1562  /// stream in \ref lgf-format "LGF" format with several maps and
     1563  /// attributes. For example, with the following code a weighted
     1564  /// matching problem can be written to the standard output, i.e. a
     1565  /// graph with a \e weight map on the edges:
     1566  ///
     1567  ///\code
     1568  ///ListGraph graph;
     1569  ///ListGraph::EdgeMap<int> weight(graph);
     1570  ///  // Setting the weight map
     1571  ///graphWriter(graph, std::cout).
     1572  ///  edgeMap("weight", weight).
     1573  ///  run();
     1574  ///\endcode
     1575  ///
     1576  /// For a complete documentation, please see the \ref GraphWriter
     1577  /// class documentation.
     1578  /// \warning Don't forget to put the \ref GraphWriter::run() "run()"
     1579  /// to the end of the parameter list.
     1580  /// \relates GraphWriter
     1581  /// \sa graphWriter(const TGR& graph, const std::string& fn)
     1582  /// \sa graphWriter(const TGR& graph, const char* fn)
     1583  template <typename TGR>
     1584  GraphWriter<TGR> graphWriter(const TGR& graph, std::ostream& os) {
     1585    GraphWriter<TGR> tmp(graph, os);
     1586    return tmp;
     1587  }
     1588
    15321589  /// \brief Return a \ref GraphWriter class
    15331590  ///
    15341591  /// This function just returns a \ref GraphWriter class.
    15351592  /// \relates GraphWriter
    1536   template <typename Graph>
    1537   GraphWriter<Graph> graphWriter(const Graph& graph,
    1538                                  std::ostream& os) {
    1539     GraphWriter<Graph> tmp(graph, os);
     1593  /// \sa graphWriter(const TGR& graph, std::ostream& os)
     1594  template <typename TGR>
     1595  GraphWriter<TGR> graphWriter(const TGR& graph, const std::string& fn) {
     1596    GraphWriter<TGR> tmp(graph, fn);
    15401597    return tmp;
    15411598  }
     
    15451602  /// This function just returns a \ref GraphWriter class.
    15461603  /// \relates GraphWriter
    1547   template <typename Graph>
    1548   GraphWriter<Graph> graphWriter(const Graph& graph, const std::string& fn) {
    1549     GraphWriter<Graph> tmp(graph, fn);
    1550     return tmp;
    1551   }
    1552 
    1553   /// \brief Return a \ref GraphWriter class
    1554   ///
    1555   /// This function just returns a \ref GraphWriter class.
    1556   /// \relates GraphWriter
    1557   template <typename Graph>
    1558   GraphWriter<Graph> graphWriter(const Graph& graph, const char* fn) {
    1559     GraphWriter<Graph> tmp(graph, fn);
     1604  /// \sa graphWriter(const TGR& graph, std::ostream& os)
     1605  template <typename TGR>
     1606  GraphWriter<TGR> graphWriter(const TGR& graph, const char* fn) {
     1607    GraphWriter<TGR> tmp(graph, fn);
    15601608    return tmp;
    15611609  }
     
    17471795  };
    17481796
     1797  /// \ingroup lemon_io
     1798  ///
    17491799  /// \brief Return a \ref SectionWriter class
    17501800  ///
    17511801  /// This function just returns a \ref SectionWriter class.
     1802  ///
     1803  /// Please see SectionWriter documentation about the custom section
     1804  /// output.
     1805  ///
    17521806  /// \relates SectionWriter
     1807  /// \sa sectionWriter(const std::string& fn)
     1808  /// \sa sectionWriter(const char *fn)
    17531809  inline SectionWriter sectionWriter(std::ostream& os) {
    17541810    SectionWriter tmp(os);
     
    17601816  /// This function just returns a \ref SectionWriter class.
    17611817  /// \relates SectionWriter
     1818  /// \sa sectionWriter(std::ostream& os)
    17621819  inline SectionWriter sectionWriter(const std::string& fn) {
    17631820    SectionWriter tmp(fn);
     
    17691826  /// This function just returns a \ref SectionWriter class.
    17701827  /// \relates SectionWriter
     1828  /// \sa sectionWriter(std::ostream& os)
    17711829  inline SectionWriter sectionWriter(const char* fn) {
    17721830    SectionWriter tmp(fn);
  • lemon/lgf_writer.h

    r598 r599  
    537537  public:
    538538
    539     /// \name Writing rules
     539    /// \name Writing Rules
    540540    /// @{
    541541
     
    640640    }
    641641
    642     /// \name Section captions
     642    /// \name Section Captions
    643643    /// @{
    644644
     
    667667    }
    668668
    669     /// \name Skipping section
     669    /// \name Skipping Section
    670670    /// @{
    671671
     
    884884  public:
    885885
    886     /// \name Execution of the writer
     886    /// \name Execution of the Writer
    887887    /// @{
    888888
     
    11301130  public:
    11311131
    1132     /// \name Writing rules
     1132    /// \name Writing Rules
    11331133    /// @{
    11341134
     
    12791279    }
    12801280
    1281     /// \name Section captions
     1281    /// \name Section Captions
    12821282    /// @{
    12831283
     
    13061306    }
    13071307
    1308     /// \name Skipping section
     1308    /// \name Skipping Section
    13091309    /// @{
    13101310
     
    15231523  public:
    15241524
    1525     /// \name Execution of the writer
     1525    /// \name Execution of the Writer
    15261526    /// @{
    15271527
     
    17001700  public:
    17011701
    1702     /// \name Section writers
     1702    /// \name Section Writers
    17031703    /// @{
    17041704
     
    17671767
    17681768
    1769     /// \name Execution of the writer
     1769    /// \name Execution of the Writer
    17701770    /// @{
    17711771
Note: See TracChangeset for help on using the changeset viewer.