COIN-OR::LEMON - Graph Library

Ticket #68: 68-5-new-eff1caf6d32e.patch

File 68-5-new-eff1caf6d32e.patch, 3.3 KB (added by Peter Kovacs, 15 years ago)
  • lemon/static_graph.h

    # HG changeset patch
    # User Peter Kovacs <kpeter@inf.elte.hu>
    # Date 1254213560 -7200
    # Node ID eff1caf6d32e2d57692d0b9397e611dac1324f0c
    # Parent  6cab2ab9d8e7df5a77ddbadbb4dabb920f9a913e
    Extend the interface of StaticDigraph (#68)
    with index(), arc() and node() functions similarly to
    other static graph structures.
    
    diff --git a/lemon/static_graph.h b/lemon/static_graph.h
    a b  
    239239  /// However it only provides build() and clear() functions and does not
    240240  /// support any other modification of the digraph.
    241241  ///
     242  /// Since this digraph structure is completely static, its nodes and arcs
     243  /// can be indexed with integers from the ranges <tt>[0..nodeNum()-1]</tt>
     244  /// and <tt>[0..arcNum()-1]</tt>, respectively.
     245  /// The index of an item is the same as its ID, it can be obtained
     246  /// using the corresponding \ref index() or \ref concepts::Digraph::id()
     247  /// "id()" function. A node or arc with a certain index can be obtained
     248  /// using node() or arc().
     249  ///
    242250  /// This type fully conforms to the \ref concepts::Digraph "Digraph concept".
    243251  /// Most of its member functions and nested classes are documented
    244252  /// only in the concept class.
     
    251259 
    252260  public:
    253261 
    254     /// \brief Clear the digraph.
     262    /// \brief Constructor
    255263    ///
    256     /// This function erases all nodes and arcs from the digraph.
    257     void clear() {
    258       Parent::clear();
    259     }
    260    
     264    /// Default constructor.
     265    StaticDigraph() : Parent() {}
     266
     267    /// \brief The node with the given index.
     268    ///
     269    /// This function returns the node with the given index.
     270    /// \sa index()
     271    Node node(int ix) const { return Parent::nodeFromId(ix); }
     272
     273    /// \brief The arc with the given index.
     274    ///
     275    /// This function returns the arc with the given index.
     276    /// \sa index()
     277    Arc arc(int ix) const { return Parent::arcFromId(ix); }
     278
     279    /// \brief The index of the given node.
     280    ///
     281    /// This function returns the index of the the given node.
     282    /// \sa node()
     283    int index(Node node) const { return Parent::id(node); }
     284
     285    /// \brief The index of the given arc.
     286    ///
     287    /// This function returns the index of the the given arc.
     288    /// \sa arc()
     289    int index(Arc arc) const { return Parent::id(arc); }
     290
     291    /// \brief Number of nodes.
     292    ///
     293    /// This function returns the number of nodes.
     294    int nodeNum() const { return node_num; }
     295
     296    /// \brief Number of arcs.
     297    ///
     298    /// This function returns the number of arcs.
     299    int arcNum() const { return arc_num; }
     300
    261301    /// \brief Build the digraph copying another digraph.
    262302    ///
    263303    /// This function builds the digraph copying another digraph of any
     
    288328      Parent::build(digraph, nodeRef, arcRef);
    289329    }
    290330 
     331    /// \brief Clear the digraph.
     332    ///
     333    /// This function erases all nodes and arcs from the digraph.
     334    void clear() {
     335      Parent::clear();
     336    }
    291337
    292338  protected:
    293339
  • test/digraph_test.cc

    diff --git a/test/digraph_test.cc b/test/digraph_test.cc
    a b  
    445445  checkArcIds(G);
    446446  checkGraphNodeMap(G);
    447447  checkGraphArcMap(G);
     448 
     449  int n = G.nodeNum();
     450  int m = G.arcNum();
     451  check(G.index(G.node(n-1)) == n-1, "Wrong index.");
     452  check(G.index(G.arc(m-1)) == m-1, "Wrong index.");
    448453}
    449454
    450455void checkFullDigraph(int num) {