COIN-OR::LEMON - Graph Library

Ignore:
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • lemon/gomory_hu.h

    r643 r628  
    4343  /// between these nodes. Moreover the components obtained by removing
    4444  /// this edge from the tree determine the corresponding minimum cut.
     45  ///
    4546  /// Therefore once this tree is computed, the minimum cut between any pair
    4647  /// of nodes can easily be obtained.
    4748  ///
    4849  /// The algorithm calculates \e n-1 distinct minimum cuts (currently with
    49   /// the \ref Preflow algorithm), thus it has \f$O(n^3\sqrt{e})\f$ overall
    50   /// time complexity. It calculates a rooted Gomory-Hu tree.
    51   /// The structure of the tree and the edge weights can be
    52   /// obtained using \c predNode(), \c predValue() and \c rootDist().
    53   /// The functions \c minCutMap() and \c minCutValue() calculate
     50  /// the \ref Preflow algorithm), therefore the algorithm has
     51  /// \f$(O(n^3\sqrt{e})\f$ overall time complexity. It calculates a
     52  /// rooted Gomory-Hu tree, its structure and the weights can be obtained
     53  /// by \c predNode(), \c predValue() and \c rootDist().
     54  ///
     55  /// The members \c minCutMap() and \c minCutValue() calculate
    5456  /// the minimum cut and the minimum cut value between any two nodes
    5557  /// in the graph. You can also list (iterate on) the nodes and the
     
    5759  ///
    5860  /// \tparam GR The type of the undirected graph the algorithm runs on.
    59   /// \tparam CAP The type of the edge map containing the capacities.
    60   /// The default map type is \ref concepts::Graph::EdgeMap "GR::EdgeMap<int>".
     61  /// \tparam CAP The type of the edge map describing the edge capacities.
     62  /// It is \ref concepts::Graph::EdgeMap "GR::EdgeMap<int>" by default.
    6163#ifdef DOXYGEN
    6264  template <typename GR,
     
    6971  public:
    7072
    71     /// The graph type of the algorithm
     73    /// The graph type
    7274    typedef GR Graph;
    73     /// The capacity map type of the algorithm
     75    /// The type of the edge capacity map
    7476    typedef CAP Capacity;
    7577    /// The value type of capacities
     
    116118    /// \brief Constructor
    117119    ///
    118     /// Constructor.
     120    /// Constructor
    119121    /// \param graph The undirected graph the algorithm runs on.
    120122    /// \param capacity The edge capacity map.
     
    129131    /// \brief Destructor
    130132    ///
    131     /// Destructor.
     133    /// Destructor
    132134    ~GomoryHu() {
    133135      destroyStructures();
     
    214216    ///The results of the algorithm can be obtained using these
    215217    ///functions.\n
    216     ///\ref run() should be called before using them.\n
     218    ///\ref run() "run()" should be called before using them.\n
    217219    ///See also \ref MinCutNodeIt and \ref MinCutEdgeIt.
    218220
     
    221223    /// \brief Return the predecessor node in the Gomory-Hu tree.
    222224    ///
    223     /// This function returns the predecessor node of the given node
     225    /// This function returns the predecessor node in the Gomory-Hu tree.
     226    /// If the node is
     227    /// the root of the Gomory-Hu tree, then it returns \c INVALID.
     228    Node predNode(const Node& node) {
     229      return (*_pred)[node];
     230    }
     231
     232    /// \brief Return the distance from the root node in the Gomory-Hu tree.
     233    ///
     234    /// This function returns the distance of \c node from the root node
    224235    /// in the Gomory-Hu tree.
    225     /// If \c node is the root of the tree, then it returns \c INVALID.
    226     ///
    227     /// \pre \ref run() must be called before using this function.
    228     Node predNode(const Node& node) const {
    229       return (*_pred)[node];
     236    int rootDist(const Node& node) {
     237      return (*_order)[node];
    230238    }
    231239
     
    233241    /// Gomory-Hu tree.
    234242    ///
    235     /// This function returns the weight of the predecessor edge of the
    236     /// given node in the Gomory-Hu tree.
    237     /// If \c node is the root of the tree, the result is undefined.
    238     ///
    239     /// \pre \ref run() must be called before using this function.
    240     Value predValue(const Node& node) const {
     243    /// This function returns the weight of the predecessor edge in the
     244    /// Gomory-Hu tree.  If the node is the root, the result is undefined.
     245    Value predValue(const Node& node) {
    241246      return (*_weight)[node];
    242247    }
    243248
    244     /// \brief Return the distance from the root node in the Gomory-Hu tree.
    245     ///
    246     /// This function returns the distance of the given node from the root
    247     /// node in the Gomory-Hu tree.
    248     ///
    249     /// \pre \ref run() must be called before using this function.
    250     int rootDist(const Node& node) const {
    251       return (*_order)[node];
    252     }
    253 
    254249    /// \brief Return the minimum cut value between two nodes
    255250    ///
    256     /// This function returns the minimum cut value between the nodes
    257     /// \c s and \c t.
    258     /// It finds the nearest common ancestor of the given nodes in the
    259     /// Gomory-Hu tree and calculates the minimum weight edge on the
    260     /// paths to the ancestor.
    261     ///
    262     /// \pre \ref run() must be called before using this function.
     251    /// This function returns the minimum cut value between two nodes. The
     252    /// algorithm finds the nearest common ancestor in the Gomory-Hu
     253    /// tree and calculates the minimum weight edge on the paths to
     254    /// the ancestor.
    263255    Value minCutValue(const Node& s, const Node& t) const {
    264256      Node sn = s, tn = t;
     
    283275    /// \c s to \c true and the other nodes to \c false.
    284276    ///
    285     /// For higher level interfaces see MinCutNodeIt and MinCutEdgeIt.
    286     ///
    287     /// \param s The base node.
    288     /// \param t The node you want to separate from node \c s.
    289     /// \param cutMap The cut will be returned in this map.
    290     /// It must be a \c bool (or convertible) \ref concepts::ReadWriteMap
    291     /// "ReadWriteMap" on the graph nodes.
    292     ///
    293     /// \return The value of the minimum cut between \c s and \c t.
    294     ///
    295     /// \pre \ref run() must be called before using this function.
     277    /// For higher level interfaces, see MinCutNodeIt and MinCutEdgeIt.
    296278    template <typename CutMap>
    297     Value minCutMap(const Node& s, ///<
     279    Value minCutMap(const Node& s, ///< The base node.
    298280                    const Node& t,
    299                     ///<
     281                    ///< The node you want to separate from node \c s.
    300282                    CutMap& cutMap
    301                     ///<
     283                    ///< The cut will be returned in this map.
     284                    /// It must be a \c bool (or convertible)
     285                    /// \ref concepts::ReadWriteMap "ReadWriteMap"
     286                    /// on the graph nodes.
    302287                    ) const {
    303288      Node sn = s, tn = t;
     
    354339   
    355340    /// This iterator class lists the nodes of a minimum cut found by
    356     /// GomoryHu. Before using it, you must allocate a GomoryHu class
     341    /// GomoryHu. Before using it, you must allocate a GomoryHu class,
    357342    /// and call its \ref GomoryHu::run() "run()" method.
    358343    ///
     
    451436   
    452437    /// This iterator class lists the edges of a minimum cut found by
    453     /// GomoryHu. Before using it, you must allocate a GomoryHu class
     438    /// GomoryHu. Before using it, you must allocate a GomoryHu class,
    454439    /// and call its \ref GomoryHu::run() "run()" method.
    455440    ///
     
    463448    ///   value+=capacities[e];
    464449    /// \endcode
    465     /// The result will be the same as the value returned by
    466     /// \ref GomoryHu::minCutValue() "gom.minCutValue(s,t)".
     450    /// the result will be the same as it is returned by
     451    /// \ref GomoryHu::minCutValue() "gom.minCutValue(s,t)"
    467452    class MinCutEdgeIt
    468453    {
     
    484469     
    485470    public:
    486       /// Constructor
    487 
    488       /// Constructor.
    489       ///
    490471      MinCutEdgeIt(GomoryHu const &gomory,
    491472                   ///< The GomoryHu class. You must call its
     
    498479                   ///< If it is \c true (default) then the listed arcs
    499480                   ///  will be oriented from the
    500                    ///  nodes of the component containing \c s,
     481                   ///  the nodes of the component containing \c s,
    501482                   ///  otherwise they will be oriented in the opposite
    502483                   ///  direction.
  • lemon/hao_orlin.h

    r644 r628  
    3232/// \brief Implementation of the Hao-Orlin algorithm.
    3333///
    34 /// Implementation of the Hao-Orlin algorithm for finding a minimum cut
    35 /// in a digraph.
     34/// Implementation of the Hao-Orlin algorithm class for testing network
     35/// reliability.
    3636
    3737namespace lemon {
     
    3939  /// \ingroup min_cut
    4040  ///
    41   /// \brief Hao-Orlin algorithm for finding a minimum cut in a digraph.
     41  /// \brief %Hao-Orlin algorithm to find a minimum cut in directed graphs.
    4242  ///
    43   /// This class implements the Hao-Orlin algorithm for finding a minimum
    44   /// value cut in a directed graph \f$D=(V,A)\f$.
    45   /// It takes a fixed node \f$ source \in V \f$ and
     43  /// Hao-Orlin calculates a minimum cut in a directed graph
     44  /// \f$D=(V,A)\f$. It takes a fixed node \f$ source \in V \f$ and
    4645  /// consists of two phases: in the first phase it determines a
    4746  /// minimum cut with \f$ source \f$ on the source-side (i.e. a set
    48   /// \f$ X\subsetneq V \f$ with \f$ source \in X \f$ and minimal outgoing
    49   /// capacity) and in the second phase it determines a minimum cut
     47  /// \f$ X\subsetneq V \f$ with \f$ source \in X \f$ and minimal
     48  /// out-degree) and in the second phase it determines a minimum cut
    5049  /// with \f$ source \f$ on the sink-side (i.e. a set
    51   /// \f$ X\subsetneq V \f$ with \f$ source \notin X \f$ and minimal outgoing
    52   /// capacity). Obviously, the smaller of these two cuts will be a
     50  /// \f$ X\subsetneq V \f$ with \f$ source \notin X \f$ and minimal
     51  /// out-degree). Obviously, the smaller of these two cuts will be a
    5352  /// minimum cut of \f$ D \f$. The algorithm is a modified
    54   /// preflow push-relabel algorithm. Our implementation calculates
     53  /// push-relabel preflow algorithm and our implementation calculates
    5554  /// the minimum cut in \f$ O(n^2\sqrt{m}) \f$ time (we use the
    5655  /// highest-label rule), or in \f$O(nm)\f$ for unit capacities. The
    57   /// purpose of such algorithm is e.g. testing network reliability.
     56  /// purpose of such algorithm is testing network reliability. For an
     57  /// undirected graph you can run just the first phase of the
     58  /// algorithm or you can use the algorithm of Nagamochi and Ibaraki
     59  /// which solves the undirected problem in
     60  /// \f$ O(nm + n^2 \log n) \f$ time: it is implemented in the
     61  /// NagamochiIbaraki algorithm class.
    5862  ///
    59   /// For an undirected graph you can run just the first phase of the
    60   /// algorithm or you can use the algorithm of Nagamochi and Ibaraki,
    61   /// which solves the undirected problem in \f$ O(nm + n^2 \log n) \f$
    62   /// time. It is implemented in the NagamochiIbaraki algorithm class.
    63   ///
    64   /// \tparam GR The type of the digraph the algorithm runs on.
    65   /// \tparam CAP The type of the arc map containing the capacities,
    66   /// which can be any numreric type. The default map type is
    67   /// \ref concepts::Digraph::ArcMap "GR::ArcMap<int>".
    68   /// \tparam TOL Tolerance class for handling inexact computations. The
     63  /// \param GR The digraph class the algorithm runs on.
     64  /// \param CAP An arc map of capacities which can be any numreric type.
     65  /// The default type is \ref concepts::Digraph::ArcMap "GR::ArcMap<int>".
     66  /// \param TOL Tolerance class for handling inexact computations. The
    6967  /// default tolerance type is \ref Tolerance "Tolerance<CAP::Value>".
    7068#ifdef DOXYGEN
     
    7674#endif
    7775  class HaoOrlin {
    78   public:
    79    
    80     /// The digraph type of the algorithm
     76  private:
     77
    8178    typedef GR Digraph;
    82     /// The capacity map type of the algorithm
    8379    typedef CAP CapacityMap;
    84     /// The tolerance type of the algorithm
    8580    typedef TOL Tolerance;
    8681
    87   private:
    88 
    8982    typedef typename CapacityMap::Value Value;
    9083
    91     TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
     84    TEMPLATE_GRAPH_TYPEDEFS(Digraph);
    9285
    9386    const Digraph& _graph;
     
    227220      for (NodeIt n(_graph); n != INVALID; ++n) {
    228221        (*_excess)[n] = 0;
    229         (*_source_set)[n] = false;
    230222      }
    231223
     
    527519      for (NodeIt n(_graph); n != INVALID; ++n) {
    528520        (*_excess)[n] = 0;
    529         (*_source_set)[n] = false;
    530521      }
    531522
     
    825816  public:
    826817
    827     /// \name Execution Control
     818    /// \name Execution control
    828819    /// The simplest way to execute the algorithm is to use
    829820    /// one of the member functions called \ref run().
    830821    /// \n
    831     /// If you need better control on the execution,
    832     /// you have to call one of the \ref init() functions first, then
    833     /// \ref calculateOut() and/or \ref calculateIn().
     822    /// If you need more control on the execution,
     823    /// first you must call \ref init(), then the \ref calculateIn() or
     824    /// \ref calculateOut() functions.
    834825
    835826    /// @{
    836827
    837     /// \brief Initialize the internal data structures.
     828    /// \brief Initializes the internal data structures.
    838829    ///
    839     /// This function initializes the internal data structures. It creates
    840     /// the maps and some bucket structures for the algorithm.
    841     /// The first node is used as the source node for the push-relabel
    842     /// algorithm.
     830    /// Initializes the internal data structures. It creates
     831    /// the maps, residual graph adaptors and some bucket structures
     832    /// for the algorithm.
    843833    void init() {
    844834      init(NodeIt(_graph));
    845835    }
    846836
    847     /// \brief Initialize the internal data structures.
     837    /// \brief Initializes the internal data structures.
    848838    ///
    849     /// This function initializes the internal data structures. It creates
    850     /// the maps and some bucket structures for the algorithm.
    851     /// The given node is used as the source node for the push-relabel
    852     /// algorithm.
     839    /// Initializes the internal data structures. It creates
     840    /// the maps, residual graph adaptor and some bucket structures
     841    /// for the algorithm. Node \c source  is used as the push-relabel
     842    /// algorithm's source.
    853843    void init(const Node& source) {
    854844      _source = source;
     
    890880
    891881
    892     /// \brief Calculate a minimum cut with \f$ source \f$ on the
     882    /// \brief Calculates a minimum cut with \f$ source \f$ on the
    893883    /// source-side.
    894884    ///
    895     /// This function calculates a minimum cut with \f$ source \f$ on the
     885    /// Calculates a minimum cut with \f$ source \f$ on the
    896886    /// source-side (i.e. a set \f$ X\subsetneq V \f$ with
    897     /// \f$ source \in X \f$ and minimal outgoing capacity).
    898     ///
    899     /// \pre \ref init() must be called before using this function.
     887    /// \f$ source \in X \f$ and minimal out-degree).
    900888    void calculateOut() {
    901889      findMinCutOut();
    902890    }
    903891
    904     /// \brief Calculate a minimum cut with \f$ source \f$ on the
    905     /// sink-side.
     892    /// \brief Calculates a minimum cut with \f$ source \f$ on the
     893    /// target-side.
    906894    ///
    907     /// This function calculates a minimum cut with \f$ source \f$ on the
    908     /// sink-side (i.e. a set \f$ X\subsetneq V \f$ with
    909     /// \f$ source \notin X \f$ and minimal outgoing capacity).
    910     ///
    911     /// \pre \ref init() must be called before using this function.
     895    /// Calculates a minimum cut with \f$ source \f$ on the
     896    /// target-side (i.e. a set \f$ X\subsetneq V \f$ with
     897    /// \f$ source \in X \f$ and minimal out-degree).
    912898    void calculateIn() {
    913899      findMinCutIn();
     
    915901
    916902
    917     /// \brief Run the algorithm.
     903    /// \brief Runs the algorithm.
    918904    ///
    919     /// This function runs the algorithm. It finds nodes \c source and
    920     /// \c target arbitrarily and then calls \ref init(), \ref calculateOut()
     905    /// Runs the algorithm. It finds nodes \c source and \c target
     906    /// arbitrarily and then calls \ref init(), \ref calculateOut()
    921907    /// and \ref calculateIn().
    922908    void run() {
     
    926912    }
    927913
    928     /// \brief Run the algorithm.
     914    /// \brief Runs the algorithm.
    929915    ///
    930     /// This function runs the algorithm. It uses the given \c source node,
    931     /// finds a proper \c target node and then calls the \ref init(),
    932     /// \ref calculateOut() and \ref calculateIn().
     916    /// Runs the algorithm. It uses the given \c source node, finds a
     917    /// proper \c target and then calls the \ref init(), \ref
     918    /// calculateOut() and \ref calculateIn().
    933919    void run(const Node& s) {
    934920      init(s);
     
    941927    /// \name Query Functions
    942928    /// The result of the %HaoOrlin algorithm
    943     /// can be obtained using these functions.\n
    944     /// \ref run(), \ref calculateOut() or \ref calculateIn()
    945     /// should be called before using them.
     929    /// can be obtained using these functions.
     930    /// \n
     931    /// Before using these functions, either \ref run(), \ref
     932    /// calculateOut() or \ref calculateIn() must be called.
    946933
    947934    /// @{
    948935
    949     /// \brief Return the value of the minimum cut.
     936    /// \brief Returns the value of the minimum value cut.
    950937    ///
    951     /// This function returns the value of the minimum cut.
    952     ///
    953     /// \pre \ref run(), \ref calculateOut() or \ref calculateIn()
    954     /// must be called before using this function.
     938    /// Returns the value of the minimum value cut.
    955939    Value minCutValue() const {
    956940      return _min_cut;
     
    958942
    959943
    960     /// \brief Return a minimum cut.
     944    /// \brief Returns a minimum cut.
    961945    ///
    962     /// This function sets \c cutMap to the characteristic vector of a
    963     /// minimum value cut: it will give a non-empty set \f$ X\subsetneq V \f$
    964     /// with minimal outgoing capacity (i.e. \c cutMap will be \c true exactly
    965     /// for the nodes of \f$ X \f$).
    966     ///
    967     /// \param cutMap A \ref concepts::WriteMap "writable" node map with
    968     /// \c bool (or convertible) value type.
    969     ///
    970     /// \return The value of the minimum cut.
    971     ///
    972     /// \pre \ref run(), \ref calculateOut() or \ref calculateIn()
    973     /// must be called before using this function.
    974     template <typename CutMap>
    975     Value minCutMap(CutMap& cutMap) const {
     946    /// Sets \c nodeMap to the characteristic vector of a minimum
     947    /// value cut: it will give a nonempty set \f$ X\subsetneq V \f$
     948    /// with minimal out-degree (i.e. \c nodeMap will be true exactly
     949    /// for the nodes of \f$ X \f$).  \pre nodeMap should be a
     950    /// bool-valued node-map.
     951    template <typename NodeMap>
     952    Value minCutMap(NodeMap& nodeMap) const {
    976953      for (NodeIt it(_graph); it != INVALID; ++it) {
    977         cutMap.set(it, (*_min_cut_map)[it]);
     954        nodeMap.set(it, (*_min_cut_map)[it]);
    978955      }
    979956      return _min_cut;
     
    984961  }; //class HaoOrlin
    985962
     963
    986964} //namespace lemon
    987965
  • lemon/lgf_reader.h

    r646 r631  
    102102    };
    103103
    104     template <typename _GR, bool _dir, typename _Map,
     104    template <typename _Graph, bool _dir, typename _Map,
    105105              typename _Converter = DefaultConverter<typename _Map::Value> >
    106     class GraphArcMapStorage : public MapStorageBase<typename _GR::Edge> {
     106    class GraphArcMapStorage : public MapStorageBase<typename _Graph::Edge> {
    107107    public:
    108108      typedef _Map Map;
    109109      typedef _Converter Converter;
    110       typedef _GR GR;
    111       typedef typename GR::Edge Item;
     110      typedef _Graph Graph;
     111      typedef typename Graph::Edge Item;
    112112      static const bool dir = _dir;
    113113
    114114    private:
    115       const GR& _graph;
     115      const Graph& _graph;
    116116      Map& _map;
    117117      Converter _converter;
    118118
    119119    public:
    120       GraphArcMapStorage(const GR& graph, Map& map,
     120      GraphArcMapStorage(const Graph& graph, Map& map,
    121121                         const Converter& converter = Converter())
    122122        : _graph(graph), _map(map), _converter(converter) {}
     
    174174    };
    175175
    176     template <typename GR>
     176    template <typename Graph>
    177177    struct GraphArcLookUpConverter {
    178       const GR& _graph;
    179       const std::map<std::string, typename GR::Edge>& _map;
    180 
    181       GraphArcLookUpConverter(const GR& graph,
     178      const Graph& _graph;
     179      const std::map<std::string, typename Graph::Edge>& _map;
     180
     181      GraphArcLookUpConverter(const Graph& graph,
    182182                              const std::map<std::string,
    183                                              typename GR::Edge>& map)
     183                                             typename Graph::Edge>& map)
    184184        : _graph(graph), _map(map) {}
    185185
    186       typename GR::Arc operator()(const std::string& str) {
     186      typename Graph::Arc operator()(const std::string& str) {
    187187        if (str.empty() || (str[0] != '+' && str[0] != '-')) {
    188188          throw FormatError("Item must start with '+' or '-'");
    189189        }
    190         typename std::map<std::string, typename GR::Edge>
     190        typename std::map<std::string, typename Graph::Edge>
    191191          ::const_iterator it = _map.find(str.substr(1));
    192192        if (it == _map.end()) {
     
    388388  }
    389389
    390   template <typename DGR>
     390  template <typename Digraph>
    391391  class DigraphReader;
    392392
    393   template <typename TDGR>
    394   DigraphReader<TDGR> digraphReader(TDGR& digraph, std::istream& is = std::cin);
    395   template <typename TDGR>
    396   DigraphReader<TDGR> digraphReader(TDGR& digraph, const std::string& fn);
    397   template <typename TDGR>
    398   DigraphReader<TDGR> digraphReader(TDGR& digraph, const char *fn);
     393  template <typename Digraph>
     394  DigraphReader<Digraph> digraphReader(Digraph& digraph,
     395                                       std::istream& is = std::cin);
     396  template <typename Digraph>
     397  DigraphReader<Digraph> digraphReader(Digraph& digraph, const std::string& fn);
     398  template <typename Digraph>
     399  DigraphReader<Digraph> digraphReader(Digraph& digraph, const char *fn);
    399400
    400401  /// \ingroup lemon_io
     
    419420  ///
    420421  ///\code
    421   /// DigraphReader<DGR>(digraph, std::cin).
     422  /// DigraphReader<Digraph>(digraph, std::cin).
    422423  ///   nodeMap("coordinates", coord_map).
    423424  ///   arcMap("capacity", cap_map).
     
    448449  /// a single pass, because the arcs are not constructed when the node
    449450  /// maps are read.
    450   template <typename DGR>
     451  template <typename GR>
    451452  class DigraphReader {
    452453  public:
    453454
    454     typedef DGR Digraph;
     455    typedef GR Digraph;
    455456
    456457  private:
    457458
    458     TEMPLATE_DIGRAPH_TYPEDEFS(DGR);
     459    TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
    459460
    460461    std::istream* _is;
     
    462463    std::string _filename;
    463464
    464     DGR& _digraph;
     465    Digraph& _digraph;
    465466
    466467    std::string _nodes_caption;
     
    500501    /// Construct a directed graph reader, which reads from the given
    501502    /// input stream.
    502     DigraphReader(DGR& digraph, std::istream& is = std::cin)
     503    DigraphReader(Digraph& digraph, std::istream& is = std::cin)
    503504      : _is(&is), local_is(false), _digraph(digraph),
    504505        _use_nodes(false), _use_arcs(false),
     
    509510    /// Construct a directed graph reader, which reads from the given
    510511    /// file.
    511     DigraphReader(DGR& digraph, const std::string& fn)
     512    DigraphReader(Digraph& digraph, const std::string& fn)
    512513      : _is(new std::ifstream(fn.c_str())), local_is(true),
    513514        _filename(fn), _digraph(digraph),
     
    524525    /// Construct a directed graph reader, which reads from the given
    525526    /// file.
    526     DigraphReader(DGR& digraph, const char* fn)
     527    DigraphReader(Digraph& digraph, const char* fn)
    527528      : _is(new std::ifstream(fn)), local_is(true),
    528529        _filename(fn), _digraph(digraph),
     
    560561  private:
    561562
    562     template <typename TDGR>
    563     friend DigraphReader<TDGR> digraphReader(TDGR& digraph, std::istream& is);
    564     template <typename TDGR>
    565     friend DigraphReader<TDGR> digraphReader(TDGR& digraph,
    566                                              const std::string& fn);
    567     template <typename TDGR>
    568     friend DigraphReader<TDGR> digraphReader(TDGR& digraph, const char *fn);
     563    template <typename DGR>
     564    friend DigraphReader<DGR> digraphReader(DGR& digraph, std::istream& is);
     565    template <typename DGR>
     566    friend DigraphReader<DGR> digraphReader(DGR& digraph,
     567                                            const std::string& fn);
     568    template <typename DGR>
     569    friend DigraphReader<DGR> digraphReader(DGR& digraph, const char *fn);
    569570
    570571    DigraphReader(DigraphReader& other)
     
    11881189
    11891190  };
    1190  
    1191   /// \ingroup lemon_io
    1192   ///
    1193   /// \brief Return a \ref DigraphReader class
    1194   ///
    1195   /// This function just returns a \ref DigraphReader class.
    1196   ///
    1197   /// With this function a digraph can be read from an
    1198   /// \ref lgf-format "LGF" file or input stream with several maps and
    1199   /// attributes. For example, there is network flow problem on a
    1200   /// digraph, i.e. a digraph with a \e capacity map on the arcs and
    1201   /// \e source and \e target nodes. This digraph can be read with the
    1202   /// following code:
    1203   ///
    1204   ///\code
    1205   ///ListDigraph digraph;
    1206   ///ListDigraph::ArcMap<int> cm(digraph);
    1207   ///ListDigraph::Node src, trg;
    1208   ///digraphReader(digraph, std::cin).
    1209   ///  arcMap("capacity", cap).
    1210   ///  node("source", src).
    1211   ///  node("target", trg).
    1212   ///  run();
    1213   ///\endcode
    1214   ///
    1215   /// For a complete documentation, please see the \ref DigraphReader
    1216   /// class documentation.
    1217   /// \warning Don't forget to put the \ref DigraphReader::run() "run()"
    1218   /// to the end of the parameter list.
    1219   /// \relates DigraphReader
    1220   /// \sa digraphReader(TDGR& digraph, const std::string& fn)
    1221   /// \sa digraphReader(TDGR& digraph, const char* fn)
    1222   template <typename TDGR>
    1223   DigraphReader<TDGR> digraphReader(TDGR& digraph, std::istream& is) {
    1224     DigraphReader<TDGR> tmp(digraph, is);
    1225     return tmp;
    1226   }
    12271191
    12281192  /// \brief Return a \ref DigraphReader class
     
    12301194  /// This function just returns a \ref DigraphReader class.
    12311195  /// \relates DigraphReader
    1232   /// \sa digraphReader(TDGR& digraph, std::istream& is)
    1233   template <typename TDGR>
    1234   DigraphReader<TDGR> digraphReader(TDGR& digraph, const std::string& fn) {
    1235     DigraphReader<TDGR> tmp(digraph, fn);
     1196  template <typename Digraph>
     1197  DigraphReader<Digraph> digraphReader(Digraph& digraph, std::istream& is) {
     1198    DigraphReader<Digraph> tmp(digraph, is);
    12361199    return tmp;
    12371200  }
     
    12411204  /// This function just returns a \ref DigraphReader class.
    12421205  /// \relates DigraphReader
    1243   /// \sa digraphReader(TDGR& digraph, std::istream& is)
    1244   template <typename TDGR>
    1245   DigraphReader<TDGR> digraphReader(TDGR& digraph, const char* fn) {
    1246     DigraphReader<TDGR> tmp(digraph, fn);
     1206  template <typename Digraph>
     1207  DigraphReader<Digraph> digraphReader(Digraph& digraph,
     1208                                       const std::string& fn) {
     1209    DigraphReader<Digraph> tmp(digraph, fn);
    12471210    return tmp;
    12481211  }
    12491212
    1250   template <typename GR>
     1213  /// \brief Return a \ref DigraphReader class
     1214  ///
     1215  /// This function just returns a \ref DigraphReader class.
     1216  /// \relates DigraphReader
     1217  template <typename Digraph>
     1218  DigraphReader<Digraph> digraphReader(Digraph& digraph, const char* fn) {
     1219    DigraphReader<Digraph> tmp(digraph, fn);
     1220    return tmp;
     1221  }
     1222
     1223  template <typename Graph>
    12511224  class GraphReader;
    12521225 
    1253   template <typename TGR>
    1254   GraphReader<TGR> graphReader(TGR& graph, std::istream& is = std::cin);
    1255   template <typename TGR>
    1256   GraphReader<TGR> graphReader(TGR& graph, const std::string& fn);
    1257   template <typename TGR>
    1258   GraphReader<TGR> graphReader(TGR& graph, const char *fn);
     1226  template <typename Graph>
     1227  GraphReader<Graph> graphReader(Graph& graph,
     1228                                 std::istream& is = std::cin);
     1229  template <typename Graph>
     1230  GraphReader<Graph> graphReader(Graph& graph, const std::string& fn);
     1231  template <typename Graph>
     1232  GraphReader<Graph> graphReader(Graph& graph, const char *fn);
    12591233
    12601234  /// \ingroup lemon_io
     
    12811255  private:
    12821256
    1283     TEMPLATE_GRAPH_TYPEDEFS(GR);
     1257    TEMPLATE_GRAPH_TYPEDEFS(Graph);
    12841258
    12851259    std::istream* _is;
     
    12871261    std::string _filename;
    12881262
    1289     GR& _graph;
     1263    Graph& _graph;
    12901264
    12911265    std::string _nodes_caption;
     
    13251299    /// Construct an undirected graph reader, which reads from the given
    13261300    /// input stream.
    1327     GraphReader(GR& graph, std::istream& is = std::cin)
     1301    GraphReader(Graph& graph, std::istream& is = std::cin)
    13281302      : _is(&is), local_is(false), _graph(graph),
    13291303        _use_nodes(false), _use_edges(false),
     
    13341308    /// Construct an undirected graph reader, which reads from the given
    13351309    /// file.
    1336     GraphReader(GR& graph, const std::string& fn)
     1310    GraphReader(Graph& graph, const std::string& fn)
    13371311      : _is(new std::ifstream(fn.c_str())), local_is(true),
    13381312        _filename(fn), _graph(graph),
     
    13491323    /// Construct an undirected graph reader, which reads from the given
    13501324    /// file.
    1351     GraphReader(GR& graph, const char* fn)
     1325    GraphReader(Graph& graph, const char* fn)
    13521326      : _is(new std::ifstream(fn)), local_is(true),
    13531327        _filename(fn), _graph(graph),
     
    13841358
    13851359  private:
    1386     template <typename TGR>
    1387     friend GraphReader<TGR> graphReader(TGR& graph, std::istream& is);
    1388     template <typename TGR>
    1389     friend GraphReader<TGR> graphReader(TGR& graph, const std::string& fn);
    1390     template <typename TGR>
    1391     friend GraphReader<TGR> graphReader(TGR& graph, const char *fn);
     1360    template <typename Graph>
     1361    friend GraphReader<Graph> graphReader(Graph& graph, std::istream& is);
     1362    template <typename Graph>
     1363    friend GraphReader<Graph> graphReader(Graph& graph, const std::string& fn);
     1364    template <typename Graph>
     1365    friend GraphReader<Graph> graphReader(Graph& graph, const char *fn);
    13921366
    13931367    GraphReader(GraphReader& other)
     
    14811455      _edge_maps.push_back(std::make_pair('+' + caption, forward_storage));
    14821456      _reader_bits::MapStorageBase<Edge>* backward_storage =
    1483         new _reader_bits::GraphArcMapStorage<GR, false, Map>(_graph, map);
     1457        new _reader_bits::GraphArcMapStorage<Graph, false, Map>(_graph, map);
    14841458      _edge_maps.push_back(std::make_pair('-' + caption, backward_storage));
    14851459      return *this;
     
    14951469      checkConcept<concepts::WriteMap<Arc, typename Map::Value>, Map>();
    14961470      _reader_bits::MapStorageBase<Edge>* forward_storage =
    1497         new _reader_bits::GraphArcMapStorage<GR, true, Map, Converter>
     1471        new _reader_bits::GraphArcMapStorage<Graph, true, Map, Converter>
    14981472        (_graph, map, converter);
    14991473      _edge_maps.push_back(std::make_pair('+' + caption, forward_storage));
    15001474      _reader_bits::MapStorageBase<Edge>* backward_storage =
    1501         new _reader_bits::GraphArcMapStorage<GR, false, Map, Converter>
     1475        new _reader_bits::GraphArcMapStorage<Graph, false, Map, Converter>
    15021476        (_graph, map, converter);
    15031477      _edge_maps.push_back(std::make_pair('-' + caption, backward_storage));
     
    15571531    /// Add an arc reading rule to reader.
    15581532    GraphReader& arc(const std::string& caption, Arc& arc) {
    1559       typedef _reader_bits::GraphArcLookUpConverter<GR> Converter;
     1533      typedef _reader_bits::GraphArcLookUpConverter<Graph> Converter;
    15601534      Converter converter(_graph, _edge_index);
    15611535      _reader_bits::ValueStorageBase* storage =
     
    20602034  };
    20612035
    2062   /// \ingroup lemon_io
    2063   ///
    2064   /// \brief Return a \ref GraphReader class
    2065   ///
    2066   /// This function just returns a \ref GraphReader class.
    2067   ///
    2068   /// With this function a graph can be read from an
    2069   /// \ref lgf-format "LGF" file or input stream with several maps and
    2070   /// attributes. For example, there is weighted matching problem on a
    2071   /// graph, i.e. a graph with a \e weight map on the edges. This
    2072   /// graph can be read with the following code:
    2073   ///
    2074   ///\code
    2075   ///ListGraph graph;
    2076   ///ListGraph::EdgeMap<int> weight(graph);
    2077   ///graphReader(graph, std::cin).
    2078   ///  edgeMap("weight", weight).
    2079   ///  run();
    2080   ///\endcode
    2081   ///
    2082   /// For a complete documentation, please see the \ref GraphReader
    2083   /// class documentation.
    2084   /// \warning Don't forget to put the \ref GraphReader::run() "run()"
    2085   /// to the end of the parameter list.
    2086   /// \relates GraphReader
    2087   /// \sa graphReader(TGR& graph, const std::string& fn)
    2088   /// \sa graphReader(TGR& graph, const char* fn)
    2089   template <typename TGR>
    2090   GraphReader<TGR> graphReader(TGR& graph, std::istream& is) {
    2091     GraphReader<TGR> tmp(graph, is);
    2092     return tmp;
    2093   }
    2094 
    20952036  /// \brief Return a \ref GraphReader class
    20962037  ///
    20972038  /// This function just returns a \ref GraphReader class.
    20982039  /// \relates GraphReader
    2099   /// \sa graphReader(TGR& graph, std::istream& is)
    2100   template <typename TGR>
    2101   GraphReader<TGR> graphReader(TGR& graph, const std::string& fn) {
    2102     GraphReader<TGR> tmp(graph, fn);
     2040  template <typename Graph>
     2041  GraphReader<Graph> graphReader(Graph& graph, std::istream& is) {
     2042    GraphReader<Graph> tmp(graph, is);
    21032043    return tmp;
    21042044  }
     
    21082048  /// This function just returns a \ref GraphReader class.
    21092049  /// \relates GraphReader
    2110   /// \sa graphReader(TGR& graph, std::istream& is)
    2111   template <typename TGR>
    2112   GraphReader<TGR> graphReader(TGR& graph, const char* fn) {
    2113     GraphReader<TGR> tmp(graph, fn);
     2050  template <typename Graph>
     2051  GraphReader<Graph> graphReader(Graph& graph, const std::string& fn) {
     2052    GraphReader<Graph> tmp(graph, fn);
     2053    return tmp;
     2054  }
     2055
     2056  /// \brief Return a \ref GraphReader class
     2057  ///
     2058  /// This function just returns a \ref GraphReader class.
     2059  /// \relates GraphReader
     2060  template <typename Graph>
     2061  GraphReader<Graph> graphReader(Graph& graph, const char* fn) {
     2062    GraphReader<Graph> tmp(graph, fn);
    21142063    return tmp;
    21152064  }
     
    23682317  };
    23692318
    2370   /// \ingroup lemon_io
    2371   ///
    23722319  /// \brief Return a \ref SectionReader class
    23732320  ///
    23742321  /// This function just returns a \ref SectionReader class.
    2375   ///
    2376   /// Please see SectionReader documentation about the custom section
    2377   /// input.
    2378   ///
    23792322  /// \relates SectionReader
    2380   /// \sa sectionReader(const std::string& fn)
    2381   /// \sa sectionReader(const char *fn)
    23822323  inline SectionReader sectionReader(std::istream& is) {
    23832324    SectionReader tmp(is);
     
    23892330  /// This function just returns a \ref SectionReader class.
    23902331  /// \relates SectionReader
    2391   /// \sa sectionReader(std::istream& is)
    23922332  inline SectionReader sectionReader(const std::string& fn) {
    23932333    SectionReader tmp(fn);
     
    23992339  /// This function just returns a \ref SectionReader class.
    24002340  /// \relates SectionReader
    2401   /// \sa sectionReader(std::istream& is)
    24022341  inline SectionReader sectionReader(const char* fn) {
    24032342    SectionReader tmp(fn);
  • lemon/lgf_writer.h

    r646 r631  
    348348  }
    349349
    350   template <typename DGR>
     350  template <typename Digraph>
    351351  class DigraphWriter;
    352352
    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);
     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);
    361363
    362364
     
    380382  ///
    381383  ///\code
    382   /// DigraphWriter<DGR>(digraph, std::cout).
     384  /// DigraphWriter<Digraph>(digraph, std::cout).
    383385  ///   nodeMap("coordinates", coord_map).
    384386  ///   nodeMap("size", size).
     
    405407  /// the \c ostream() function, hence the second pass can append its
    406408  /// output to the output of the first pass.
    407   template <typename DGR>
     409  template <typename GR>
    408410  class DigraphWriter {
    409411  public:
    410412
    411     typedef DGR Digraph;
    412     TEMPLATE_DIGRAPH_TYPEDEFS(DGR);
     413    typedef GR Digraph;
     414    TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
    413415
    414416  private:
     
    418420    bool local_os;
    419421
    420     const DGR& _digraph;
     422    const Digraph& _digraph;
    421423
    422424    std::string _nodes_caption;
     
    450452    /// Construct a directed graph writer, which writes to the given
    451453    /// output stream.
    452     DigraphWriter(const DGR& digraph, std::ostream& os = std::cout)
     454    DigraphWriter(const Digraph& digraph, std::ostream& os = std::cout)
    453455      : _os(&os), local_os(false), _digraph(digraph),
    454456        _skip_nodes(false), _skip_arcs(false) {}
     
    458460    /// Construct a directed graph writer, which writes to the given
    459461    /// output file.
    460     DigraphWriter(const DGR& digraph, const std::string& fn)
     462    DigraphWriter(const Digraph& digraph, const std::string& fn)
    461463      : _os(new std::ofstream(fn.c_str())), local_os(true), _digraph(digraph),
    462464        _skip_nodes(false), _skip_arcs(false) {
     
    471473    /// Construct a directed graph writer, which writes to the given
    472474    /// output file.
    473     DigraphWriter(const DGR& digraph, const char* fn)
     475    DigraphWriter(const Digraph& digraph, const char* fn)
    474476      : _os(new std::ofstream(fn)), local_os(true), _digraph(digraph),
    475477        _skip_nodes(false), _skip_arcs(false) {
     
    504506  private:
    505507
    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);
     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);
    515517
    516518    DigraphWriter(DigraphWriter& other)
     
    723725
    724726      if (label == 0) {
    725         IdMap<DGR, Node> id_map(_digraph);
    726         _writer_bits::MapLess<IdMap<DGR, Node> > id_less(id_map);
     727        IdMap<Digraph, Node> id_map(_digraph);
     728        _writer_bits::MapLess<IdMap<Digraph, Node> > id_less(id_map);
    727729        std::sort(nodes.begin(), nodes.end(), id_less);
    728730      } else {
     
    808810
    809811      if (label == 0) {
    810         IdMap<DGR, Arc> id_map(_digraph);
    811         _writer_bits::MapLess<IdMap<DGR, Arc> > id_less(id_map);
     812        IdMap<Digraph, Arc> id_map(_digraph);
     813        _writer_bits::MapLess<IdMap<Digraph, Arc> > id_less(id_map);
    812814        std::sort(arcs.begin(), arcs.end(), id_less);
    813815      } else {
     
    914916  };
    915917
    916   /// \ingroup lemon_io
    917   ///
    918918  /// \brief Return a \ref DigraphWriter class
    919919  ///
    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.
     920  /// This function just returns a \ref DigraphWriter class.
    945921  /// \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);
     922  template <typename Digraph>
     923  DigraphWriter<Digraph> digraphWriter(const Digraph& digraph,
     924                                       std::ostream& os) {
     925    DigraphWriter<Digraph> tmp(digraph, os);
    951926    return tmp;
    952927  }
     
    956931  /// This function just returns a \ref DigraphWriter class.
    957932  /// \relates DigraphWriter
    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);
     933  template <typename Digraph>
     934  DigraphWriter<Digraph> digraphWriter(const Digraph& digraph,
     935                                       const std::string& fn) {
     936    DigraphWriter<Digraph> tmp(digraph, fn);
    963937    return tmp;
    964938  }
     
    968942  /// This function just returns a \ref DigraphWriter class.
    969943  /// \relates DigraphWriter
    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);
     944  template <typename Digraph>
     945  DigraphWriter<Digraph> digraphWriter(const Digraph& digraph,
     946                                      const char* fn) {
     947    DigraphWriter<Digraph> tmp(digraph, fn);
    974948    return tmp;
    975949  }
    976950
    977   template <typename GR>
     951  template <typename Graph>
    978952  class GraphWriter;
    979953
    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);
     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);
    986961
    987962  /// \ingroup lemon_io
     
    1005980
    1006981    typedef GR Graph;
    1007     TEMPLATE_GRAPH_TYPEDEFS(GR);
     982    TEMPLATE_GRAPH_TYPEDEFS(Graph);
    1008983
    1009984  private:
     
    1013988    bool local_os;
    1014989
    1015     const GR& _graph;
     990    const Graph& _graph;
    1016991
    1017992    std::string _nodes_caption;
     
    10451020    /// Construct a directed graph writer, which writes to the given
    10461021    /// output stream.
    1047     GraphWriter(const GR& graph, std::ostream& os = std::cout)
     1022    GraphWriter(const Graph& graph, std::ostream& os = std::cout)
    10481023      : _os(&os), local_os(false), _graph(graph),
    10491024        _skip_nodes(false), _skip_edges(false) {}
     
    10531028    /// Construct a directed graph writer, which writes to the given
    10541029    /// output file.
    1055     GraphWriter(const GR& graph, const std::string& fn)
     1030    GraphWriter(const Graph& graph, const std::string& fn)
    10561031      : _os(new std::ofstream(fn.c_str())), local_os(true), _graph(graph),
    10571032        _skip_nodes(false), _skip_edges(false) {
     
    10661041    /// Construct a directed graph writer, which writes to the given
    10671042    /// output file.
    1068     GraphWriter(const GR& graph, const char* fn)
     1043    GraphWriter(const Graph& graph, const char* fn)
    10691044      : _os(new std::ofstream(fn)), local_os(true), _graph(graph),
    10701045        _skip_nodes(false), _skip_edges(false) {
     
    10991074  private:
    11001075
    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);
     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);
    11081085   
    11091086    GraphWriter(GraphWriter& other)
     
    11921169      checkConcept<concepts::ReadMap<Arc, typename Map::Value>, Map>();
    11931170      _writer_bits::MapStorageBase<Edge>* forward_storage =
    1194         new _writer_bits::GraphArcMapStorage<GR, true, Map>(_graph, map);
     1171        new _writer_bits::GraphArcMapStorage<Graph, true, Map>(_graph, map);
    11951172      _edge_maps.push_back(std::make_pair('+' + caption, forward_storage));
    11961173      _writer_bits::MapStorageBase<Edge>* backward_storage =
    1197         new _writer_bits::GraphArcMapStorage<GR, false, Map>(_graph, map);
     1174        new _writer_bits::GraphArcMapStorage<Graph, false, Map>(_graph, map);
    11981175      _edge_maps.push_back(std::make_pair('-' + caption, backward_storage));
    11991176      return *this;
     
    12091186      checkConcept<concepts::ReadMap<Arc, typename Map::Value>, Map>();
    12101187      _writer_bits::MapStorageBase<Edge>* forward_storage =
    1211         new _writer_bits::GraphArcMapStorage<GR, true, Map, Converter>
     1188        new _writer_bits::GraphArcMapStorage<Graph, true, Map, Converter>
    12121189        (_graph, map, converter);
    12131190      _edge_maps.push_back(std::make_pair('+' + caption, forward_storage));
    12141191      _writer_bits::MapStorageBase<Edge>* backward_storage =
    1215         new _writer_bits::GraphArcMapStorage<GR, false, Map, Converter>
     1192        new _writer_bits::GraphArcMapStorage<Graph, false, Map, Converter>
    12161193        (_graph, map, converter);
    12171194      _edge_maps.push_back(std::make_pair('-' + caption, backward_storage));
     
    12711248    /// Add an arc writing rule to writer.
    12721249    GraphWriter& arc(const std::string& caption, const Arc& arc) {
    1273       typedef _writer_bits::GraphArcLookUpConverter<GR> Converter;
     1250      typedef _writer_bits::GraphArcLookUpConverter<Graph> Converter;
    12741251      Converter converter(_graph, _edge_index);
    12751252      _writer_bits::ValueStorageBase* storage =
     
    13621339
    13631340      if (label == 0) {
    1364         IdMap<GR, Node> id_map(_graph);
    1365         _writer_bits::MapLess<IdMap<GR, Node> > id_less(id_map);
     1341        IdMap<Graph, Node> id_map(_graph);
     1342        _writer_bits::MapLess<IdMap<Graph, Node> > id_less(id_map);
    13661343        std::sort(nodes.begin(), nodes.end(), id_less);
    13671344      } else {
     
    14471424
    14481425      if (label == 0) {
    1449         IdMap<GR, Edge> id_map(_graph);
    1450         _writer_bits::MapLess<IdMap<GR, Edge> > id_less(id_map);
     1426        IdMap<Graph, Edge> id_map(_graph);
     1427        _writer_bits::MapLess<IdMap<Graph, Edge> > id_less(id_map);
    14511428        std::sort(edges.begin(), edges.end(), id_less);
    14521429      } else {
     
    15531530  };
    15541531
    1555   /// \ingroup lemon_io
    1556   ///
    15571532  /// \brief Return a \ref GraphWriter class
    15581533  ///
    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.
     1534  /// This function just returns a \ref GraphWriter class.
    15801535  /// \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);
     1536  template <typename Graph>
     1537  GraphWriter<Graph> graphWriter(const Graph& graph,
     1538                                 std::ostream& os) {
     1539    GraphWriter<Graph> tmp(graph, os);
    15861540    return tmp;
    15871541  }
     
    15911545  /// This function just returns a \ref GraphWriter class.
    15921546  /// \relates GraphWriter
    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);
     1547  template <typename Graph>
     1548  GraphWriter<Graph> graphWriter(const Graph& graph, const std::string& fn) {
     1549    GraphWriter<Graph> tmp(graph, fn);
    15971550    return tmp;
    15981551  }
     
    16021555  /// This function just returns a \ref GraphWriter class.
    16031556  /// \relates GraphWriter
    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);
     1557  template <typename Graph>
     1558  GraphWriter<Graph> graphWriter(const Graph& graph, const char* fn) {
     1559    GraphWriter<Graph> tmp(graph, fn);
    16081560    return tmp;
    16091561  }
     
    17951747  };
    17961748
    1797   /// \ingroup lemon_io
    1798   ///
    17991749  /// \brief Return a \ref SectionWriter class
    18001750  ///
    18011751  /// This function just returns a \ref SectionWriter class.
    1802   ///
    1803   /// Please see SectionWriter documentation about the custom section
    1804   /// output.
    1805   ///
    18061752  /// \relates SectionWriter
    1807   /// \sa sectionWriter(const std::string& fn)
    1808   /// \sa sectionWriter(const char *fn)
    18091753  inline SectionWriter sectionWriter(std::ostream& os) {
    18101754    SectionWriter tmp(os);
     
    18161760  /// This function just returns a \ref SectionWriter class.
    18171761  /// \relates SectionWriter
    1818   /// \sa sectionWriter(std::ostream& os)
    18191762  inline SectionWriter sectionWriter(const std::string& fn) {
    18201763    SectionWriter tmp(fn);
     
    18261769  /// This function just returns a \ref SectionWriter class.
    18271770  /// \relates SectionWriter
    1828   /// \sa sectionWriter(std::ostream& os)
    18291771  inline SectionWriter sectionWriter(const char* fn) {
    18301772    SectionWriter tmp(fn);
  • test/gomory_hu_test.cc

    r643 r593  
    33#include "test_tools.h"
    44#include <lemon/smart_graph.h>
    5 #include <lemon/concepts/graph.h>
    6 #include <lemon/concepts/maps.h>
    75#include <lemon/lgf_reader.h>
    86#include <lemon/gomory_hu.h>
     
    3533  "target 3\n";
    3634 
    37 void checkGomoryHuCompile()
    38 {
    39   typedef int Value;
    40   typedef concepts::Graph Graph;
    41 
    42   typedef Graph::Node Node;
    43   typedef Graph::Edge Edge;
    44   typedef concepts::ReadMap<Edge, Value> CapMap;
    45   typedef concepts::ReadWriteMap<Node, bool> CutMap;
    46 
    47   Graph g;
    48   Node n;
    49   CapMap cap;
    50   CutMap cut;
    51   Value v;
    52   int d;
    53 
    54   GomoryHu<Graph, CapMap> gh_test(g, cap);
    55   const GomoryHu<Graph, CapMap>&
    56     const_gh_test = gh_test;
    57 
    58   gh_test.run();
    59 
    60   n = const_gh_test.predNode(n);
    61   v = const_gh_test.predValue(n);
    62   d = const_gh_test.rootDist(n);
    63   v = const_gh_test.minCutValue(n, n);
    64   v = const_gh_test.minCutMap(n, n, cut);
    65 }
    66 
    6735GRAPH_TYPEDEFS(Graph);
    6836typedef Graph::EdgeMap<int> IntEdgeMap;
     
    10371      ght.minCutMap(u, v, cm);
    10472      check(pf.flowValue() == ght.minCutValue(u, v), "Wrong cut 1");
    105       check(cm[u] != cm[v], "Wrong cut 2");
    106       check(pf.flowValue() == cutValue(graph, cm, capacity), "Wrong cut 3");
     73      check(cm[u] != cm[v], "Wrong cut 3");
     74      check(pf.flowValue() == cutValue(graph, cm, capacity), "Wrong cut 2");
    10775
    10876      int sum=0;
     
    11785        sum++;
    11886      check(sum == countNodes(graph), "Problem with MinCutNodeIt");
     87     
    11988    }
    12089  }
  • test/hao_orlin_test.cc

    r644 r463  
    2020
    2121#include <lemon/smart_graph.h>
    22 #include <lemon/adaptors.h>
    23 #include <lemon/concepts/digraph.h>
    24 #include <lemon/concepts/maps.h>
    25 #include <lemon/lgf_reader.h>
    2622#include <lemon/hao_orlin.h>
    2723
     24#include <lemon/lgf_reader.h>
    2825#include "test_tools.h"
    2926
     
    4138  "5\n"
    4239  "@edges\n"
    43   "     cap1 cap2 cap3\n"
    44   "0 1  1    1    1   \n"
    45   "0 2  2    2    4   \n"
    46   "1 2  4    4    4   \n"
    47   "3 4  1    1    1   \n"
    48   "3 5  2    2    4   \n"
    49   "4 5  4    4    4   \n"
    50   "5 4  4    4    4   \n"
    51   "2 3  1    6    6   \n"
    52   "4 0  1    6    6   \n";
    53 
    54 void checkHaoOrlinCompile()
    55 {
    56   typedef int Value;
    57   typedef concepts::Digraph Digraph;
    58 
    59   typedef Digraph::Node Node;
    60   typedef Digraph::Arc Arc;
    61   typedef concepts::ReadMap<Arc, Value> CapMap;
    62   typedef concepts::WriteMap<Node, bool> CutMap;
    63 
    64   Digraph g;
    65   Node n;
    66   CapMap cap;
    67   CutMap cut;
    68   Value v;
    69 
    70   HaoOrlin<Digraph, CapMap> ho_test(g, cap);
    71   const HaoOrlin<Digraph, CapMap>&
    72     const_ho_test = ho_test;
    73 
    74   ho_test.init();
    75   ho_test.init(n);
    76   ho_test.calculateOut();
    77   ho_test.calculateIn();
    78   ho_test.run();
    79   ho_test.run(n);
    80 
    81   v = const_ho_test.minCutValue();
    82   v = const_ho_test.minCutMap(cut);
    83 }
    84 
    85 template <typename Graph, typename CapMap, typename CutMap>
    86 typename CapMap::Value
    87   cutValue(const Graph& graph, const CapMap& cap, const CutMap& cut)
    88 {
    89   typename CapMap::Value sum = 0;
    90   for (typename Graph::ArcIt a(graph); a != INVALID; ++a) {
    91     if (cut[graph.source(a)] && !cut[graph.target(a)])
    92       sum += cap[a];
    93   }
    94   return sum;
    95 }
     40  "     label  capacity\n"
     41  "0 1  0      2\n"
     42  "1 2  1      2\n"
     43  "2 0  2      2\n"
     44  "3 4  3      2\n"
     45  "4 5  4      2\n"
     46  "5 3  5      2\n"
     47  "2 3  6      3\n";
    9648
    9749int main() {
    98   SmartDigraph graph;
    99   SmartDigraph::ArcMap<int> cap1(graph), cap2(graph), cap3(graph);
    100   SmartDigraph::NodeMap<bool> cut(graph);
     50  SmartGraph graph;
     51  SmartGraph::EdgeMap<int> capacity(graph);
    10152
    102   istringstream input(lgf);
    103   digraphReader(graph, input)
    104     .arcMap("cap1", cap1)
    105     .arcMap("cap2", cap2)
    106     .arcMap("cap3", cap3)
    107     .run();
     53  istringstream lgfs(lgf);
     54  graphReader(graph, lgfs).
     55    edgeMap("capacity", capacity).run();
    10856
    109   {
    110     HaoOrlin<SmartDigraph> ho(graph, cap1);
    111     ho.run();
    112     ho.minCutMap(cut);
    113    
    114     check(ho.minCutValue() == 1, "Wrong cut value");
    115     check(ho.minCutValue() == cutValue(graph, cap1, cut), "Wrong cut value");
    116   }
    117   {
    118     HaoOrlin<SmartDigraph> ho(graph, cap2);
    119     ho.run();
    120     ho.minCutMap(cut);
     57  HaoOrlin<SmartGraph, SmartGraph::EdgeMap<int> > ho(graph, capacity);
     58  ho.run();
    12159
    122     check(ho.minCutValue() == 1, "Wrong cut value");
    123     check(ho.minCutValue() == cutValue(graph, cap2, cut), "Wrong cut value");
    124   }
    125   {
    126     HaoOrlin<SmartDigraph> ho(graph, cap3);
    127     ho.run();
    128     ho.minCutMap(cut);
    129    
    130     check(ho.minCutValue() == 1, "Wrong cut value");
    131     check(ho.minCutValue() == cutValue(graph, cap3, cut), "Wrong cut value");
    132   }
    133  
    134   typedef Undirector<SmartDigraph> UGraph;
    135   UGraph ugraph(graph);
    136  
    137   {
    138     HaoOrlin<UGraph, SmartDigraph::ArcMap<int> > ho(ugraph, cap1);
    139     ho.run();
    140     ho.minCutMap(cut);
    141    
    142     check(ho.minCutValue() == 2, "Wrong cut value");
    143     check(ho.minCutValue() == cutValue(ugraph, cap1, cut), "Wrong cut value");
    144   }
    145   {
    146     HaoOrlin<UGraph, SmartDigraph::ArcMap<int> > ho(ugraph, cap2);
    147     ho.run();
    148     ho.minCutMap(cut);
    149    
    150     check(ho.minCutValue() == 5, "Wrong cut value");
    151     check(ho.minCutValue() == cutValue(ugraph, cap2, cut), "Wrong cut value");
    152   }
    153   {
    154     HaoOrlin<UGraph, SmartDigraph::ArcMap<int> > ho(ugraph, cap3);
    155     ho.run();
    156     ho.minCutMap(cut);
    157    
    158     check(ho.minCutValue() == 5, "Wrong cut value");
    159     check(ho.minCutValue() == cutValue(ugraph, cap3, cut), "Wrong cut value");
    160   }
     60  check(ho.minCutValue() == 3, "Wrong cut value");
    16161
    16262  return 0;
Note: See TracChangeset for help on using the changeset viewer.