COIN-OR::LEMON - Graph Library

Ticket #57: full_a598f74ea87e.patch

File full_a598f74ea87e.patch, 9.5 KB (added by Peter Kovacs, 16 years ago)

Small improvements for full graphs

  • lemon/full_graph.h

    # HG changeset patch
    # User Peter Kovacs <kpeter@inf.elte.hu>
    # Date 1225561910 -3600
    # Node ID a598f74ea87ec18aec51a5352114625a961bcaa7
    # Parent  37557a46e29874bd50b7c0e54c5595dc6bde36a2
    Improvements related to full graphs (#57)
    
    diff --git a/lemon/full_graph.h b/lemon/full_graph.h
    a b  
    1919#ifndef LEMON_FULL_GRAPH_H
    2020#define LEMON_FULL_GRAPH_H
    2121
    22 #include <lemon/math.h>
    23 
    2422#include <lemon/core.h>
    2523#include <lemon/bits/graph_extender.h>
    2624
    2725///\ingroup graphs
    2826///\file
    29 ///\brief FullDigraph and FullGraph classes.
     27///\brief FullGraph and FullDigraph classes.
     28
    3029namespace lemon {
    3130
    3231  class FullDigraphBase {
     
    6766    Node source(Arc arc) const { return arc._id / _node_num; }
    6867    Node target(Arc arc) const { return arc._id % _node_num; }
    6968
    70 
    7169    static int id(Node node) { return node._id; }
    7270    static int id(Arc arc) { return arc._id; }
    7371
    7472    static Node nodeFromId(int id) { return Node(id);}
    75 
    7673    static Arc arcFromId(int id) { return Arc(id);}
    7774
    7875    typedef True FindArcTag;
     
    8077    Arc findArc(Node s, Node t, Arc prev = INVALID) const {
    8178      return prev != INVALID ? arc(s, t) : INVALID;
    8279    }
    83 
    8480
    8581    class Node {
    8682      friend class FullDigraphBase;
     
    157153  /// This is a simple and fast directed full graph implementation.
    158154  /// From each node go arcs to each node (including the source node),
    159155  /// therefore the number of the arcs in the digraph is the square of
    160   /// the node number. The digraph is completely static, so you can
    161   /// neither add nor delete either arcs or nodes, and it needs just
     156  /// the node number. This digraph type is completely static, so you
     157  /// can neither add nor delete either arcs or nodes, and it needs just
    162158  /// constant space in memory.
    163159  ///
    164   /// Thus it conforms to the \ref concepts::Digraph "Digraph" concept
     160  /// This class conforms to the \ref concepts::Digraph "Digraph" concept
    165161  /// and it also has an important extra feature that its maps are
    166162  /// real \ref concepts::ReferenceMap "reference map"s.
    167   /// \sa concepts::Digraph.
    168163  ///
    169164  /// \sa FullGraph
    170165  class FullDigraph : public ExtendedFullDigraphBase {
     
    177172
    178173    /// \brief Constructor
    179174    ///
     175    /// Constructor.
    180176    /// \param n The number of the nodes.
    181177    FullDigraph(int n) { construct(n); }
    182178
    183     /// \brief Resize the digraph
     179    /// \brief Resizes the digraph
    184180    ///
    185     /// Resize the digraph. The function will fully destroy and
    186     /// rebuild the digraph.  This cause that the maps of the digraph
    187     /// will reallocated automatically and the previous values will be
    188     /// lost.
     181    /// Resizes the digraph. The function will fully destroy and
     182    /// rebuild the digraph. This cause that the maps of the digraph will
     183    /// reallocated automatically and the previous values will be lost.
    189184    void resize(int n) {
    190185      Parent::notifier(Arc()).clear();
    191186      Parent::notifier(Node()).clear();
     
    196191
    197192    /// \brief Returns the node with the given index.
    198193    ///
    199     /// Returns the node with the given index. Because it is a
    200     /// static size digraph the node's of the digraph can be indexed
    201     /// in the range <tt>[0..nodeNum()-1]</tt> and the index of
    202     /// the node can accessed by the \e index() member.
     194    /// Returns the node with the given index. Since it is a static
     195    /// digraph its nodes can be indexed with integers from the range
     196    /// <tt>[0..nodeNum()-1]</tt>.
     197    /// \sa index()
    203198    Node operator()(int ix) const { return Parent::operator()(ix); }
    204199
    205     /// \brief Returns the index of the node.
     200    /// \brief Returns the index of the given node.
    206201    ///
    207     /// Returns the index of the node. Because it is a
    208     /// static size digraph the node's of the digraph can be indexed
    209     /// in the range <tt>[0..nodeNum()-1]</tt> and the index of
    210     /// the node can accessed by the \e index() member.
     202    /// Returns the index of the given node. Since it is a static
     203    /// digraph its nodes can be indexed with integers from the range
     204    /// <tt>[0..nodeNum()-1]</tt>.
     205    /// \sa operator()
    211206    int index(const Node& node) const { return Parent::index(node); }
    212207
    213     /// \brief Returns the arc connects the given nodes.
     208    /// \brief Returns the arc connecting the given nodes.
    214209    ///
    215     /// Returns the arc connects the given nodes.
     210    /// Returns the arc connecting the given nodes.
    216211    Arc arc(const Node& u, const Node& v) const {
    217212      return Parent::arc(u, v);
    218213    }
     
    279274    }
    280275
    281276  public:
    282 
    283277
    284278    Node operator()(int ix) const { return Node(ix); }
    285279    int index(const Node& node) const { return node._id; }
     
    367361
    368362    class Edge {
    369363      friend class FullGraphBase;
     364      friend class Arc;
    370365
    371366    protected:
    372367      int _id;
     
    518513  ///
    519514  /// This is a simple and fast undirected full graph
    520515  /// implementation. From each node go edge to each other node,
    521   /// therefore the number of edges in the graph is
    522   /// <tt>n(n-1)/2</tt>. It is completely static, so you can neither
     516  /// therefore the number of edges in the graph is <tt>n(n-1)/2</tt>,
     517  /// \f$n(n-1)/2\f$, \f$\frec{n(n-1)}{2}\f$.
     518  /// This graph type is completely static, so you can neither
    523519  /// add nor delete either edges or nodes, and it needs just constant
    524520  /// space in memory.
    525521  ///
    526   /// The \e FullDigraph and \e FullGraph classes are very similar,
    527   /// but there are two differences. While the \e FullDigraph class is
    528   /// conform just to the \ref concepts::Digraph "Digraph" concept,
    529   /// this class is conform to the \ref concepts::Graph "Graph"
    530   /// concept. In addition, the \e FullGraph class does not contain a
     522  /// The \e FullGraph and \e FullDigraph classes are very similar,
     523  /// but there are two differences. While the \e FullDigraph class
     524  /// conforms only to the \ref concepts::Digraph "Digraph" concept,
     525  /// this class conforms to the \ref concepts::Graph "Graph"
     526  /// concept. In addition, the \e FullGraph class does not contain the
    531527  /// loop arc from each node as the \e FullDigraph does.
    532528  ///
    533529  /// It also has an important extra feature that its maps are real
     
    544540
    545541    /// \brief Constructor
    546542    ///
     543    /// Constructor.
    547544    /// \param n The number of the nodes.
    548545    FullGraph(int n) { construct(n); }
    549546
    550     /// \brief Resize the graph
     547    /// \brief Resizes the graph
    551548    ///
    552     /// Resize the graph. The function will fully destroy and rebuild
    553     /// the graph.  This cause that the maps of the graph will
    554     /// reallocated automatically and the previous values will be
    555     /// lost.
     549    /// Resizes the graph. The function will fully destroy and
     550    /// rebuild the graph. This cause that the maps of the graph will
     551    /// reallocated automatically and the previous values will be lost.
    556552    void resize(int n) {
    557553      Parent::notifier(Arc()).clear();
    558554      Parent::notifier(Edge()).clear();
     
    565561
    566562    /// \brief Returns the node with the given index.
    567563    ///
    568     /// Returns the node with the given index. Because it is a static
    569     /// size graph the node's of the graph can be indexed in the range
    570     /// <tt>[0..nodeNum()-1]</tt> and the index of the node can
    571     /// accessed by the \e index() member.
     564    /// Returns the node with the given index. Since it is a static
     565    /// graph its nodes can be indexed with integers from the range
     566    /// <tt>[0..nodeNum()-1]</tt>.
     567    /// \sa index()
    572568    Node operator()(int ix) const { return Parent::operator()(ix); }
    573569
    574     /// \brief Returns the index of the node.
     570    /// \brief Returns the index of the given node.
    575571    ///
    576     /// Returns the index of the node. Because it is a static size
    577     /// graph the node's of the graph can be indexed in the range
    578     /// <tt>[0..nodeNum()-1]</tt> and the index of the node can
    579     /// accessed by the \e index() member.
     572    /// Returns the index of the given node. Since it is a static
     573    /// graph its nodes can be indexed with integers from the range
     574    /// <tt>[0..nodeNum()-1]</tt>.
     575    /// \sa operator()
    580576    int index(const Node& node) const { return Parent::index(node); }
    581577
    582     /// \brief Number of nodes.
    583     int nodeNum() const { return Parent::nodeNum(); }
    584     /// \brief Number of arcs.
    585     int arcNum() const { return Parent::arcNum(); }
    586     /// \brief Number of edges.
    587     int edgeNum() const { return Parent::edgeNum(); }
    588 
    589     /// \brief Returns the arc connects the given nodes.
     578    /// \brief Returns the arc connecting the given nodes.
    590579    ///
    591     /// Returns the arc connects the given nodes.
     580    /// Returns the arc connecting the given nodes.
    592581    Arc arc(const Node& s, const Node& t) const {
    593582      return Parent::arc(s, t);
    594583    }
     
    599588    Edge edge(const Node& u, const Node& v) const {
    600589      return Parent::edge(u, v);
    601590    }
     591
     592    /// \brief Number of nodes.
     593    int nodeNum() const { return Parent::nodeNum(); }
     594    /// \brief Number of arcs.
     595    int arcNum() const { return Parent::arcNum(); }
     596    /// \brief Number of edges.
     597    int edgeNum() const { return Parent::edgeNum(); }
     598
    602599  };
    603600
    604601
  • test/digraph_test.cc

    diff --git a/test/digraph_test.cc b/test/digraph_test.cc
    a b  
    142142    checkConcept<ExtendableDigraphComponent<>, SmartDigraph>();
    143143    checkConcept<ClearableDigraphComponent<>, SmartDigraph>();
    144144  }
    145 //  { // Checking FullDigraph
    146 //    checkConcept<Digraph, FullDigraph>();
    147 //  }
     145  { // Checking FullDigraph
     146    checkConcept<Digraph, FullDigraph>();
     147  }
    148148//  { // Checking HyperCubeDigraph
    149149//    checkConcept<Digraph, HyperCubeDigraph>();
    150150//  }