COIN-OR::LEMON - Graph Library

Changeset 827:580af8cf2f6a in lemon


Ignore:
Timestamp:
11/05/09 10:23:16 (10 years ago)
Author:
Alpar Juttner <alpar@…>
Branch:
default
Parents:
826:c160bf9f18ef (diff), 819:f964a00b9068 (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 #68 (Port static graph implementation)

Files:
10 edited

Legend:

Unmodified
Added
Removed
  • lemon/Makefile.am

    r817 r827  
    114114        lemon/smart_graph.h \
    115115        lemon/soplex.h \
     116        lemon/static_graph.h \
    116117        lemon/suurballe.h \
    117118        lemon/time_measure.h \
  • lemon/Makefile.am

    r820 r827  
    5858        lemon/arg_parser.h \
    5959        lemon/assert.h \
     60        lemon/bellman_ford.h \
    6061        lemon/bfs.h \
    6162        lemon/bin_heap.h \
     63        lemon/binom_heap.h \
    6264        lemon/bucket_heap.h \
    6365        lemon/cbc.h \
     
    7981        lemon/euler.h \
    8082        lemon/fib_heap.h \
     83        lemon/fourary_heap.h \
    8184        lemon/full_graph.h \
    8285        lemon/glpk.h \
     
    8487        lemon/graph_to_eps.h \
    8588        lemon/grid_graph.h \
     89        lemon/hartmann_orlin.h \
     90        lemon/howard.h \
    8691        lemon/hypercube_graph.h \
     92        lemon/karp.h \
     93        lemon/kary_heap.h \
    8794        lemon/kruskal.h \
    8895        lemon/hao_orlin.h \
     
    99106        lemon/nauty_reader.h \
    100107        lemon/network_simplex.h \
     108        lemon/pairing_heap.h \
    101109        lemon/path.h \
    102110        lemon/preflow.h \
  • lemon/full_graph.h

    r782 r827  
    5252
    5353    Node operator()(int ix) const { return Node(ix); }
    54     int index(const Node& node) const { return node._id; }
     54    static int index(const Node& node) { return node._id; }
    5555
    5656    Arc arc(const Node& s, const Node& t) const {
     
    214214    /// the range <tt>[0..nodeNum()-1]</tt>.
    215215    /// \sa operator()()
    216     int index(Node node) const { return Parent::index(node); }
     216    static int index(const Node& node) { return Parent::index(node); }
    217217
    218218    /// \brief Returns the arc connecting the given nodes.
     
    288288
    289289    Node operator()(int ix) const { return Node(ix); }
    290     int index(const Node& node) const { return node._id; }
     290    static int index(const Node& node) { return node._id; }
    291291
    292292    Edge edge(const Node& u, const Node& v) const {
     
    589589    /// the range <tt>[0..nodeNum()-1]</tt>.
    590590    /// \sa operator()()
    591     int index(Node node) const { return Parent::index(node); }
     591    static int index(const Node& node) { return Parent::index(node); }
    592592
    593593    /// \brief Returns the arc connecting the given nodes.
  • lemon/full_graph.h

    r825 r827  
    2525///\ingroup graphs
    2626///\file
    27 ///\brief FullGraph and FullDigraph classes.
     27///\brief FullDigraph and FullGraph classes.
    2828
    2929namespace lemon {
     
    149149  /// \ingroup graphs
    150150  ///
    151   /// \brief A full digraph class.
    152   ///
    153   /// This is a simple and fast directed full graph implementation.
    154   /// From each node go arcs to each node (including the source node),
    155   /// therefore the number of the arcs in the digraph is the square of
    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
    158   /// constant space in memory.
    159   ///
    160   /// This class fully conforms to the \ref concepts::Digraph
    161   /// "Digraph concept".
    162   ///
    163   /// The \c FullDigraph and \c FullGraph classes are very similar,
     151  /// \brief A directed full graph class.
     152  ///
     153  /// FullDigraph is a simple and fast implmenetation of directed full
     154  /// (complete) graphs. It contains an arc from each node to each node
     155  /// (including a loop for each node), therefore the number of arcs
     156  /// is the square of the number of nodes.
     157  /// This class is completely static and it needs constant memory space.
     158  /// Thus you can neither add nor delete nodes or arcs, however
     159  /// the structure can be resized using resize().
     160  ///
     161  /// This type fully conforms to the \ref concepts::Digraph "Digraph concept".
     162  /// Most of its member functions and nested classes are documented
     163  /// only in the concept class.
     164  ///
     165  /// \note FullDigraph and FullGraph classes are very similar,
    164166  /// but there are two differences. While this class conforms only
    165   /// to the \ref concepts::Digraph "Digraph" concept, the \c FullGraph
    166   /// class conforms to the \ref concepts::Graph "Graph" concept,
    167   /// moreover \c FullGraph does not contain a loop arc for each
    168   /// node as \c FullDigraph does.
     167  /// to the \ref concepts::Digraph "Digraph" concept, FullGraph
     168  /// conforms to the \ref concepts::Graph "Graph" concept,
     169  /// moreover FullGraph does not contain a loop for each
     170  /// node as this class does.
    169171  ///
    170172  /// \sa FullGraph
     
    174176  public:
    175177
    176     /// \brief Constructor
     178    /// \brief Default constructor.
     179    ///
     180    /// Default constructor. The number of nodes and arcs will be zero.
    177181    FullDigraph() { construct(0); }
    178182
     
    185189    /// \brief Resizes the digraph
    186190    ///
    187     /// Resizes the digraph. The function will fully destroy and
    188     /// rebuild the digraph. This cause that the maps of the digraph will
     191    /// This function resizes the digraph. It fully destroys and
     192    /// rebuilds the structure, therefore the maps of the digraph will be
    189193    /// reallocated automatically and the previous values will be lost.
    190194    void resize(int n) {
     
    198202    /// \brief Returns the node with the given index.
    199203    ///
    200     /// Returns the node with the given index. Since it is a static
    201     /// digraph its nodes can be indexed with integers from the range
    202     /// <tt>[0..nodeNum()-1]</tt>.
     204    /// Returns the node with the given index. Since this structure is
     205    /// completely static, the nodes can be indexed with integers from
     206    /// the range <tt>[0..nodeNum()-1]</tt>.
    203207    /// \sa index()
    204208    Node operator()(int ix) const { return Parent::operator()(ix); }
     
    206210    /// \brief Returns the index of the given node.
    207211    ///
    208     /// Returns the index of the given node. Since it is a static
    209     /// digraph its nodes can be indexed with integers from the range
    210     /// <tt>[0..nodeNum()-1]</tt>.
    211     /// \sa operator()
     212    /// Returns the index of the given node. Since this structure is
     213    /// completely static, the nodes can be indexed with integers from
     214    /// the range <tt>[0..nodeNum()-1]</tt>.
     215    /// \sa operator()()
    212216    static int index(const Node& node) { return Parent::index(node); }
    213217
     
    215219    ///
    216220    /// Returns the arc connecting the given nodes.
    217     Arc arc(const Node& u, const Node& v) const {
     221    Arc arc(Node u, Node v) const {
    218222      return Parent::arc(u, v);
    219223    }
     
    521525  /// \brief An undirected full graph class.
    522526  ///
    523   /// This is a simple and fast undirected full graph
    524   /// implementation. From each node go edge to each other node,
    525   /// therefore the number of edges in the graph is \f$n(n-1)/2\f$.
    526   /// This graph type is completely static, so you can neither
    527   /// add nor delete either edges or nodes, and it needs constant
    528   /// space in memory.
    529   ///
    530   /// This class fully conforms to the \ref concepts::Graph "Graph concept".
    531   ///
    532   /// The \c FullGraph and \c FullDigraph classes are very similar,
    533   /// but there are two differences. While the \c FullDigraph class
     527  /// FullGraph is a simple and fast implmenetation of undirected full
     528  /// (complete) graphs. It contains an edge between every distinct pair
     529  /// of nodes, therefore the number of edges is <tt>n(n-1)/2</tt>.
     530  /// This class is completely static and it needs constant memory space.
     531  /// Thus you can neither add nor delete nodes or edges, however
     532  /// the structure can be resized using resize().
     533  ///
     534  /// This type fully conforms to the \ref concepts::Graph "Graph concept".
     535  /// Most of its member functions and nested classes are documented
     536  /// only in the concept class.
     537  ///
     538  /// \note FullDigraph and FullGraph classes are very similar,
     539  /// but there are two differences. While FullDigraph
    534540  /// conforms only to the \ref concepts::Digraph "Digraph" concept,
    535541  /// this class conforms to the \ref concepts::Graph "Graph" concept,
    536   /// moreover \c FullGraph does not contain a loop arc for each
    537   /// node as \c FullDigraph does.
     542  /// moreover this class does not contain a loop for each
     543  /// node as FullDigraph does.
    538544  ///
    539545  /// \sa FullDigraph
     
    543549  public:
    544550
    545     /// \brief Constructor
     551    /// \brief Default constructor.
     552    ///
     553    /// Default constructor. The number of nodes and edges will be zero.
    546554    FullGraph() { construct(0); }
    547555
     
    554562    /// \brief Resizes the graph
    555563    ///
    556     /// Resizes the graph. The function will fully destroy and
    557     /// rebuild the graph. This cause that the maps of the graph will
     564    /// This function resizes the graph. It fully destroys and
     565    /// rebuilds the structure, therefore the maps of the graph will be
    558566    /// reallocated automatically and the previous values will be lost.
    559567    void resize(int n) {
     
    569577    /// \brief Returns the node with the given index.
    570578    ///
    571     /// Returns the node with the given index. Since it is a static
    572     /// graph its nodes can be indexed with integers from the range
    573     /// <tt>[0..nodeNum()-1]</tt>.
     579    /// Returns the node with the given index. Since this structure is
     580    /// completely static, the nodes can be indexed with integers from
     581    /// the range <tt>[0..nodeNum()-1]</tt>.
    574582    /// \sa index()
    575583    Node operator()(int ix) const { return Parent::operator()(ix); }
     
    577585    /// \brief Returns the index of the given node.
    578586    ///
    579     /// Returns the index of the given node. Since it is a static
    580     /// graph its nodes can be indexed with integers from the range
    581     /// <tt>[0..nodeNum()-1]</tt>.
    582     /// \sa operator()
     587    /// Returns the index of the given node. Since this structure is
     588    /// completely static, the nodes can be indexed with integers from
     589    /// the range <tt>[0..nodeNum()-1]</tt>.
     590    /// \sa operator()()
    583591    static int index(const Node& node) { return Parent::index(node); }
    584592
     
    586594    ///
    587595    /// Returns the arc connecting the given nodes.
    588     Arc arc(const Node& s, const Node& t) const {
     596    Arc arc(Node s, Node t) const {
    589597      return Parent::arc(s, t);
    590598    }
    591599
    592     /// \brief Returns the edge connects the given nodes.
    593     ///
    594     /// Returns the edge connects the given nodes.
    595     Edge edge(const Node& u, const Node& v) const {
     600    /// \brief Returns the edge connecting the given nodes.
     601    ///
     602    /// Returns the edge connecting the given nodes.
     603    Edge edge(Node u, Node v) const {
    596604      return Parent::edge(u, v);
    597605    }
  • lemon/hypercube_graph.h

    r784 r827  
    263263    }
    264264
    265     int index(Node node) const {
     265    static int index(Node node) {
    266266      return node._id;
    267267    }
     
    357357    /// Gives back the index of the given node.
    358358    /// The lower bits of the integer describes the node.
    359     int index(Node node) const {
     359    static int index(Node node) {
    360360      return Parent::index(node);
    361361    }
  • lemon/hypercube_graph.h

    r825 r827  
    283283  /// \brief Hypercube graph class
    284284  ///
    285   /// This class implements a special graph type. The nodes of the graph
    286   /// are indiced with integers with at most \c dim binary digits.
     285  /// HypercubeGraph implements a special graph type. The nodes of the
     286  /// graph are indexed with integers having at most \c dim binary digits.
    287287  /// Two nodes are connected in the graph if and only if their indices
    288288  /// differ only on one position in the binary form.
     289  /// This class is completely static and it needs constant memory space.
     290  /// Thus you can neither add nor delete nodes or edges, however
     291  /// the structure can be resized using resize().
     292  ///
     293  /// This type fully conforms to the \ref concepts::Graph "Graph concept".
     294  /// Most of its member functions and nested classes are documented
     295  /// only in the concept class.
    289296  ///
    290297  /// \note The type of the indices is chosen to \c int for efficiency
    291298  /// reasons. Thus the maximum dimension of this implementation is 26
    292299  /// (assuming that the size of \c int is 32 bit).
    293   ///
    294   /// This graph type fully conforms to the \ref concepts::Graph
    295   /// "Graph concept".
    296300  class HypercubeGraph : public ExtendedHypercubeGraphBase {
    297301    typedef ExtendedHypercubeGraphBase Parent;
     
    303307    /// Constructs a hypercube graph with \c dim dimensions.
    304308    HypercubeGraph(int dim) { construct(dim); }
     309
     310    /// \brief Resizes the graph
     311    ///
     312    /// This function resizes the graph. It fully destroys and
     313    /// rebuilds the structure, therefore the maps of the graph will be
     314    /// reallocated automatically and the previous values will be lost.
     315    void resize(int dim) {
     316      Parent::notifier(Arc()).clear();
     317      Parent::notifier(Edge()).clear();
     318      Parent::notifier(Node()).clear();
     319      construct(dim);
     320      Parent::notifier(Node()).build();
     321      Parent::notifier(Edge()).build();
     322      Parent::notifier(Arc()).build();
     323    }
    305324
    306325    /// \brief The number of dimensions.
     
    321340    ///
    322341    /// Gives back the dimension id of the given edge.
    323     /// It is in the [0..dim-1] range.
     342    /// It is in the range <tt>[0..dim-1]</tt>.
    324343    int dimension(Edge edge) const {
    325344      return Parent::dimension(edge);
     
    329348    ///
    330349    /// Gives back the dimension id of the given arc.
    331     /// It is in the [0..dim-1] range.
     350    /// It is in the range <tt>[0..dim-1]</tt>.
    332351    int dimension(Arc arc) const {
    333352      return Parent::dimension(arc);
  • lemon/smart_graph.h

    r783 r827  
    498498    }
    499499
    500     void next(Node& node) const {
     500    static void next(Node& node) {
    501501      --node._id;
    502502    }
     
    506506    }
    507507
    508     void next(Arc& arc) const {
     508    static void next(Arc& arc) {
    509509      --arc._id;
    510510    }
     
    514514    }
    515515
    516     void next(Edge& arc) const {
     516    static void next(Edge& arc) {
    517517      --arc._id;
    518518    }
  • lemon/smart_graph.h

    r825 r827  
    3333
    3434  class SmartDigraph;
    35   ///Base of SmartDigraph
    36 
    37   ///Base of SmartDigraph
    38   ///
     35
    3936  class SmartDigraphBase {
    4037  protected:
     
    188185  ///\brief A smart directed graph class.
    189186  ///
    190   ///This is a simple and fast digraph implementation.
    191   ///It is also quite memory efficient, but at the price
    192   ///that <b> it does support only limited (only stack-like)
    193   ///node and arc deletions</b>.
    194   ///It fully conforms to the \ref concepts::Digraph "Digraph concept".
     187  ///\ref SmartDigraph is a simple and fast digraph implementation.
     188  ///It is also quite memory efficient but at the price
     189  ///that it does not support node and arc deletion
     190  ///(except for the Snapshot feature).
    195191  ///
    196   ///\sa concepts::Digraph.
     192  ///This type fully conforms to the \ref concepts::Digraph "Digraph concept"
     193  ///and it also provides some additional functionalities.
     194  ///Most of its member functions and nested classes are documented
     195  ///only in the concept class.
     196  ///
     197  ///\sa concepts::Digraph
     198  ///\sa SmartGraph
    197199  class SmartDigraph : public ExtendedSmartDigraphBase {
    198200    typedef ExtendedSmartDigraphBase Parent;
    199201
    200202  private:
    201 
    202     ///SmartDigraph is \e not copy constructible. Use DigraphCopy() instead.
    203 
    204     ///SmartDigraph is \e not copy constructible. Use DigraphCopy() instead.
    205     ///
     203    /// Digraphs are \e not copy constructible. Use DigraphCopy instead.
    206204    SmartDigraph(const SmartDigraph &) : ExtendedSmartDigraphBase() {};
    207     ///\brief Assignment of SmartDigraph to another one is \e not allowed.
    208     ///Use DigraphCopy() instead.
    209 
    210     ///Assignment of SmartDigraph to another one is \e not allowed.
    211     ///Use DigraphCopy() instead.
     205    /// \brief Assignment of a digraph to another one is \e not allowed.
     206    /// Use DigraphCopy instead.
    212207    void operator=(const SmartDigraph &) {}
    213208
     
    222217    ///Add a new node to the digraph.
    223218
    224     /// Add a new node to the digraph.
    225     /// \return The new node.
     219    ///This function adds a new node to the digraph.
     220    ///\return The new node.
    226221    Node addNode() { return Parent::addNode(); }
    227222
    228223    ///Add a new arc to the digraph.
    229224
    230     ///Add a new arc to the digraph with source node \c s
     225    ///This function adds a new arc to the digraph with source node \c s
    231226    ///and target node \c t.
    232227    ///\return The new arc.
    233     Arc addArc(const Node& s, const Node& t) {
     228    Arc addArc(Node s, Node t) {
    234229      return Parent::addArc(s, t);
    235230    }
    236231
    237     /// \brief Using this it is possible to avoid the superfluous memory
    238     /// allocation.
    239 
    240     /// Using this it is possible to avoid the superfluous memory
    241     /// allocation: if you know that the digraph you want to build will
    242     /// be very large (e.g. it will contain millions of nodes and/or arcs)
    243     /// then it is worth reserving space for this amount before starting
    244     /// to build the digraph.
    245     /// \sa reserveArc
    246     void reserveNode(int n) { nodes.reserve(n); };
    247 
    248     /// \brief Using this it is possible to avoid the superfluous memory
    249     /// allocation.
    250 
    251     /// Using this it is possible to avoid the superfluous memory
    252     /// allocation: if you know that the digraph you want to build will
    253     /// be very large (e.g. it will contain millions of nodes and/or arcs)
    254     /// then it is worth reserving space for this amount before starting
    255     /// to build the digraph.
    256     /// \sa reserveNode
    257     void reserveArc(int m) { arcs.reserve(m); };
    258 
    259232    /// \brief Node validity check
    260233    ///
    261     /// This function gives back true if the given node is valid,
    262     /// ie. it is a real node of the graph.
     234    /// This function gives back \c true if the given node is valid,
     235    /// i.e. it is a real node of the digraph.
    263236    ///
    264237    /// \warning A removed node (using Snapshot) could become valid again
    265     /// when new nodes are added to the graph.
     238    /// if new nodes are added to the digraph.
    266239    bool valid(Node n) const { return Parent::valid(n); }
    267240
    268241    /// \brief Arc validity check
    269242    ///
    270     /// This function gives back true if the given arc is valid,
    271     /// ie. it is a real arc of the graph.
     243    /// This function gives back \c true if the given arc is valid,
     244    /// i.e. it is a real arc of the digraph.
    272245    ///
    273246    /// \warning A removed arc (using Snapshot) could become valid again
    274     /// when new arcs are added to the graph.
     247    /// if new arcs are added to the graph.
    275248    bool valid(Arc a) const { return Parent::valid(a); }
    276249
    277     ///Clear the digraph.
    278 
    279     ///Erase all the nodes and arcs from the digraph.
    280     ///
    281     void clear() {
    282       Parent::clear();
    283     }
    284 
    285250    ///Split a node.
    286251
    287     ///This function splits a node. First a new node is added to the digraph,
    288     ///then the source of each outgoing arc of \c n is moved to this new node.
    289     ///If \c connect is \c true (this is the default value), then a new arc
    290     ///from \c n to the newly created node is also added.
     252    ///This function splits the given node. First, a new node is added
     253    ///to the digraph, then the source of each outgoing arc of node \c n
     254    ///is moved to this new node.
     255    ///If the second parameter \c connect is \c true (this is the default
     256    ///value), then a new arc from node \c n to the newly created node
     257    ///is also added.
    291258    ///\return The newly created node.
    292259    ///
    293     ///\note The <tt>Arc</tt>s
    294     ///referencing a moved arc remain
    295     ///valid. However <tt>InArc</tt>'s and <tt>OutArc</tt>'s
    296     ///may be invalidated.
     260    ///\note All iterators remain valid.
     261    ///
    297262    ///\warning This functionality cannot be used together with the Snapshot
    298263    ///feature.
     
    309274    }
    310275
     276    ///Clear the digraph.
     277
     278    ///This function erases all nodes and arcs from the digraph.
     279    ///
     280    void clear() {
     281      Parent::clear();
     282    }
     283
     284    /// Reserve memory for nodes.
     285
     286    /// Using this function, it is possible to avoid superfluous memory
     287    /// allocation: if you know that the digraph you want to build will
     288    /// be large (e.g. it will contain millions of nodes and/or arcs),
     289    /// then it is worth reserving space for this amount before starting
     290    /// to build the digraph.
     291    /// \sa reserveArc()
     292    void reserveNode(int n) { nodes.reserve(n); };
     293
     294    /// Reserve memory for arcs.
     295
     296    /// Using this function, it is possible to avoid superfluous memory
     297    /// allocation: if you know that the digraph you want to build will
     298    /// be large (e.g. it will contain millions of nodes and/or arcs),
     299    /// then it is worth reserving space for this amount before starting
     300    /// to build the digraph.
     301    /// \sa reserveNode()
     302    void reserveArc(int m) { arcs.reserve(m); };
     303
    311304  public:
    312305
     
    333326  public:
    334327
    335     ///Class to make a snapshot of the digraph and to restrore to it later.
    336 
    337     ///Class to make a snapshot of the digraph and to restrore to it later.
     328    ///Class to make a snapshot of the digraph and to restore it later.
     329
     330    ///Class to make a snapshot of the digraph and to restore it later.
    338331    ///
    339332    ///The newly added nodes and arcs can be removed using the
    340     ///restore() function.
    341     ///\note After you restore a state, you cannot restore
    342     ///a later state, in other word you cannot add again the arcs deleted
    343     ///by restore() using another one Snapshot instance.
    344     ///
    345     ///\warning If you do not use correctly the snapshot that can cause
    346     ///either broken program, invalid state of the digraph, valid but
    347     ///not the restored digraph or no change. Because the runtime performance
    348     ///the validity of the snapshot is not stored.
     333    ///restore() function. This is the only way for deleting nodes and/or
     334    ///arcs from a SmartDigraph structure.
     335    ///
     336    ///\note After a state is restored, you cannot restore a later state,
     337    ///i.e. you cannot add the removed nodes and arcs again using
     338    ///another Snapshot instance.
     339    ///
     340    ///\warning Node splitting cannot be restored.
     341    ///\warning The validity of the snapshot is not stored due to
     342    ///performance reasons. If you do not use the snapshot correctly,
     343    ///it can cause broken program, invalid or not restored state of
     344    ///the digraph or no change.
    349345    class Snapshot
    350346    {
     
    358354
    359355      ///Default constructor.
    360       ///To actually make a snapshot you must call save().
    361       ///
     356      ///You have to call save() to actually make a snapshot.
    362357      Snapshot() : _graph(0) {}
    363358      ///Constructor that immediately makes a snapshot
    364359
    365       ///This constructor immediately makes a snapshot of the digraph.
    366       ///\param graph The digraph we make a snapshot of.
    367       Snapshot(SmartDigraph &graph) : _graph(&graph) {
     360      ///This constructor immediately makes a snapshot of the given digraph.
     361      ///
     362      Snapshot(SmartDigraph &gr) : _graph(&gr) {
    368363        node_num=_graph->nodes.size();
    369364        arc_num=_graph->arcs.size();
     
    372367      ///Make a snapshot.
    373368
    374       ///Make a snapshot of the digraph.
    375       ///
    376       ///This function can be called more than once. In case of a repeated
     369      ///This function makes a snapshot of the given digraph.
     370      ///It can be called more than once. In case of a repeated
    377371      ///call, the previous snapshot gets lost.
    378       ///\param graph The digraph we make the snapshot of.
    379       void save(SmartDigraph &graph)
    380       {
    381         _graph=&graph;
     372      void save(SmartDigraph &gr) {
     373        _graph=&gr;
    382374        node_num=_graph->nodes.size();
    383375        arc_num=_graph->arcs.size();
     
    386378      ///Undo the changes until a snapshot.
    387379
    388       ///Undo the changes until a snapshot created by save().
    389       ///
    390       ///\note After you restored a state, you cannot restore
    391       ///a later state, in other word you cannot add again the arcs deleted
    392       ///by restore().
     380      ///This function undos the changes until the last snapshot
     381      ///created by save() or Snapshot(SmartDigraph&).
    393382      void restore()
    394383      {
     
    622611  /// \brief A smart undirected graph class.
    623612  ///
    624   /// This is a simple and fast graph implementation.
    625   /// It is also quite memory efficient, but at the price
    626   /// that <b> it does support only limited (only stack-like)
    627   /// node and arc deletions</b>.
    628   /// It fully conforms to the \ref concepts::Graph "Graph concept".
     613  /// \ref SmartGraph is a simple and fast graph implementation.
     614  /// It is also quite memory efficient but at the price
     615  /// that it does not support node and edge deletion
     616  /// (except for the Snapshot feature).
    629617  ///
    630   /// \sa concepts::Graph.
     618  /// This type fully conforms to the \ref concepts::Graph "Graph concept"
     619  /// and it also provides some additional functionalities.
     620  /// Most of its member functions and nested classes are documented
     621  /// only in the concept class.
     622  ///
     623  /// \sa concepts::Graph
     624  /// \sa SmartDigraph
    631625  class SmartGraph : public ExtendedSmartGraphBase {
    632626    typedef ExtendedSmartGraphBase Parent;
    633627
    634628  private:
    635 
    636     ///SmartGraph is \e not copy constructible. Use GraphCopy() instead.
    637 
    638     ///SmartGraph is \e not copy constructible. Use GraphCopy() instead.
    639     ///
     629    /// Graphs are \e not copy constructible. Use GraphCopy instead.
    640630    SmartGraph(const SmartGraph &) : ExtendedSmartGraphBase() {};
    641 
    642     ///\brief Assignment of SmartGraph to another one is \e not allowed.
    643     ///Use GraphCopy() instead.
    644 
    645     ///Assignment of SmartGraph to another one is \e not allowed.
    646     ///Use GraphCopy() instead.
     631    /// \brief Assignment of a graph to another one is \e not allowed.
     632    /// Use GraphCopy instead.
    647633    void operator=(const SmartGraph &) {}
    648634
     
    655641    SmartGraph() {}
    656642
    657     ///Add a new node to the graph.
    658 
    659     /// Add a new node to the graph.
     643    /// \brief Add a new node to the graph.
     644    ///
     645    /// This function adds a new node to the graph.
    660646    /// \return The new node.
    661647    Node addNode() { return Parent::addNode(); }
    662648
    663     ///Add a new edge to the graph.
    664 
    665     ///Add a new edge to the graph with node \c s
    666     ///and \c t.
    667     ///\return The new edge.
    668     Edge addEdge(const Node& s, const Node& t) {
    669       return Parent::addEdge(s, t);
     649    /// \brief Add a new edge to the graph.
     650    ///
     651    /// This function adds a new edge to the graph between nodes
     652    /// \c u and \c v with inherent orientation from node \c u to
     653    /// node \c v.
     654    /// \return The new edge.
     655    Edge addEdge(Node u, Node v) {
     656      return Parent::addEdge(u, v);
    670657    }
    671658
    672659    /// \brief Node validity check
    673660    ///
    674     /// This function gives back true if the given node is valid,
    675     /// ie. it is a real node of the graph.
     661    /// This function gives back \c true if the given node is valid,
     662    /// i.e. it is a real node of the graph.
    676663    ///
    677664    /// \warning A removed node (using Snapshot) could become valid again
    678     /// when new nodes are added to the graph.
     665    /// if new nodes are added to the graph.
    679666    bool valid(Node n) const { return Parent::valid(n); }
    680667
     668    /// \brief Edge validity check
     669    ///
     670    /// This function gives back \c true if the given edge is valid,
     671    /// i.e. it is a real edge of the graph.
     672    ///
     673    /// \warning A removed edge (using Snapshot) could become valid again
     674    /// if new edges are added to the graph.
     675    bool valid(Edge e) const { return Parent::valid(e); }
     676
    681677    /// \brief Arc validity check
    682678    ///
    683     /// This function gives back true if the given arc is valid,
    684     /// ie. it is a real arc of the graph.
     679    /// This function gives back \c true if the given arc is valid,
     680    /// i.e. it is a real arc of the graph.
    685681    ///
    686682    /// \warning A removed arc (using Snapshot) could become valid again
    687     /// when new edges are added to the graph.
     683    /// if new edges are added to the graph.
    688684    bool valid(Arc a) const { return Parent::valid(a); }
    689685
    690     /// \brief Edge validity check
    691     ///
    692     /// This function gives back true if the given edge is valid,
    693     /// ie. it is a real edge of the graph.
    694     ///
    695     /// \warning A removed edge (using Snapshot) could become valid again
    696     /// when new edges are added to the graph.
    697     bool valid(Edge e) const { return Parent::valid(e); }
    698 
    699686    ///Clear the graph.
    700687
    701     ///Erase all the nodes and edges from the graph.
     688    ///This function erases all nodes and arcs from the graph.
    702689    ///
    703690    void clear() {
    704691      Parent::clear();
    705692    }
     693
     694    /// Reserve memory for nodes.
     695
     696    /// Using this function, it is possible to avoid superfluous memory
     697    /// allocation: if you know that the graph you want to build will
     698    /// be large (e.g. it will contain millions of nodes and/or edges),
     699    /// then it is worth reserving space for this amount before starting
     700    /// to build the graph.
     701    /// \sa reserveEdge()
     702    void reserveNode(int n) { nodes.reserve(n); };
     703
     704    /// Reserve memory for edges.
     705
     706    /// Using this function, it is possible to avoid superfluous memory
     707    /// allocation: if you know that the graph you want to build will
     708    /// be large (e.g. it will contain millions of nodes and/or edges),
     709    /// then it is worth reserving space for this amount before starting
     710    /// to build the graph.
     711    /// \sa reserveNode()
     712    void reserveEdge(int m) { arcs.reserve(2 * m); };
    706713
    707714  public:
     
    743750  public:
    744751
    745     ///Class to make a snapshot of the digraph and to restrore to it later.
    746 
    747     ///Class to make a snapshot of the digraph and to restrore to it later.
    748     ///
    749     ///The newly added nodes and arcs can be removed using the
    750     ///restore() function.
    751     ///
    752     ///\note After you restore a state, you cannot restore
    753     ///a later state, in other word you cannot add again the arcs deleted
    754     ///by restore() using another one Snapshot instance.
    755     ///
    756     ///\warning If you do not use correctly the snapshot that can cause
    757     ///either broken program, invalid state of the digraph, valid but
    758     ///not the restored digraph or no change. Because the runtime performance
    759     ///the validity of the snapshot is not stored.
     752    ///Class to make a snapshot of the graph and to restore it later.
     753
     754    ///Class to make a snapshot of the graph and to restore it later.
     755    ///
     756    ///The newly added nodes and edges can be removed using the
     757    ///restore() function. This is the only way for deleting nodes and/or
     758    ///edges from a SmartGraph structure.
     759    ///
     760    ///\note After a state is restored, you cannot restore a later state,
     761    ///i.e. you cannot add the removed nodes and edges again using
     762    ///another Snapshot instance.
     763    ///
     764    ///\warning The validity of the snapshot is not stored due to
     765    ///performance reasons. If you do not use the snapshot correctly,
     766    ///it can cause broken program, invalid or not restored state of
     767    ///the graph or no change.
    760768    class Snapshot
    761769    {
     
    769777
    770778      ///Default constructor.
    771       ///To actually make a snapshot you must call save().
    772       ///
     779      ///You have to call save() to actually make a snapshot.
    773780      Snapshot() : _graph(0) {}
    774781      ///Constructor that immediately makes a snapshot
    775782
    776       ///This constructor immediately makes a snapshot of the digraph.
    777       ///\param graph The digraph we make a snapshot of.
    778       Snapshot(SmartGraph &graph) {
    779         graph.saveSnapshot(*this);
     783      /// This constructor immediately makes a snapshot of the given graph.
     784      ///
     785      Snapshot(SmartGraph &gr) {
     786        gr.saveSnapshot(*this);
    780787      }
    781788
    782789      ///Make a snapshot.
    783790
    784       ///Make a snapshot of the graph.
    785       ///
    786       ///This function can be called more than once. In case of a repeated
     791      ///This function makes a snapshot of the given graph.
     792      ///It can be called more than once. In case of a repeated
    787793      ///call, the previous snapshot gets lost.
    788       ///\param graph The digraph we make the snapshot of.
    789       void save(SmartGraph &graph)
     794      void save(SmartGraph &gr)
    790795      {
    791         graph.saveSnapshot(*this);
    792       }
    793 
    794       ///Undo the changes until a snapshot.
    795 
    796       ///Undo the changes until a snapshot created by save().
    797       ///
    798       ///\note After you restored a state, you cannot restore
    799       ///a later state, in other word you cannot add again the arcs deleted
    800       ///by restore().
     796        gr.saveSnapshot(*this);
     797      }
     798
     799      ///Undo the changes until the last snapshot.
     800
     801      ///This function undos the changes until the last snapshot
     802      ///created by save() or Snapshot(SmartGraph&).
    801803      void restore()
    802804      {
  • test/digraph_test.cc

    r787 r827  
    2020#include <lemon/list_graph.h>
    2121#include <lemon/smart_graph.h>
     22#include <lemon/static_graph.h>
    2223#include <lemon/full_graph.h>
    2324
     
    329330    checkConcept<ClearableDigraphComponent<>, SmartDigraph>();
    330331  }
     332  { // Checking StaticDigraph
     333    checkConcept<Digraph, StaticDigraph>();
     334    checkConcept<ClearableDigraphComponent<>, StaticDigraph>();
     335  }
    331336  { // Checking FullDigraph
    332337    checkConcept<Digraph, FullDigraph>();
     
    382387  check(!g.valid(g.nodeFromId(-1)), "Wrong validity check");
    383388  check(!g.valid(g.arcFromId(-1)), "Wrong validity check");
     389}
     390
     391void checkStaticDigraph() {
     392  SmartDigraph g;
     393  SmartDigraph::NodeMap<StaticDigraph::Node> nref(g);
     394  SmartDigraph::ArcMap<StaticDigraph::Arc> aref(g);
     395 
     396  StaticDigraph G;
     397 
     398  checkGraphNodeList(G, 0);
     399  checkGraphArcList(G, 0);
     400
     401  G.build(g, nref, aref);
     402
     403  checkGraphNodeList(G, 0);
     404  checkGraphArcList(G, 0);
     405
     406  SmartDigraph::Node
     407    n1 = g.addNode(),
     408    n2 = g.addNode(),
     409    n3 = g.addNode();
     410
     411  G.build(g, nref, aref);
     412
     413  checkGraphNodeList(G, 3);
     414  checkGraphArcList(G, 0);
     415
     416  SmartDigraph::Arc a1 = g.addArc(n1, n2);
     417
     418  G.build(g, nref, aref);
     419
     420  check(G.source(aref[a1]) == nref[n1] && G.target(aref[a1]) == nref[n2],
     421        "Wrong arc or wrong references");
     422  checkGraphNodeList(G, 3);
     423  checkGraphArcList(G, 1);
     424
     425  checkGraphOutArcList(G, nref[n1], 1);
     426  checkGraphOutArcList(G, nref[n2], 0);
     427  checkGraphOutArcList(G, nref[n3], 0);
     428
     429  checkGraphInArcList(G, nref[n1], 0);
     430  checkGraphInArcList(G, nref[n2], 1);
     431  checkGraphInArcList(G, nref[n3], 0);
     432
     433  checkGraphConArcList(G, 1);
     434
     435  SmartDigraph::Arc
     436    a2 = g.addArc(n2, n1),
     437    a3 = g.addArc(n2, n3),
     438    a4 = g.addArc(n2, n3);
     439
     440  digraphCopy(g, G).nodeRef(nref).run();
     441
     442  checkGraphNodeList(G, 3);
     443  checkGraphArcList(G, 4);
     444
     445  checkGraphOutArcList(G, nref[n1], 1);
     446  checkGraphOutArcList(G, nref[n2], 3);
     447  checkGraphOutArcList(G, nref[n3], 0);
     448
     449  checkGraphInArcList(G, nref[n1], 1);
     450  checkGraphInArcList(G, nref[n2], 1);
     451  checkGraphInArcList(G, nref[n3], 2);
     452
     453  checkGraphConArcList(G, 4);
     454
     455  std::vector<std::pair<int,int> > arcs;
     456  arcs.push_back(std::make_pair(0,1));
     457  arcs.push_back(std::make_pair(0,2));
     458  arcs.push_back(std::make_pair(1,3));
     459  arcs.push_back(std::make_pair(1,2));
     460  arcs.push_back(std::make_pair(3,0));
     461  arcs.push_back(std::make_pair(3,3));
     462  arcs.push_back(std::make_pair(4,2));
     463  arcs.push_back(std::make_pair(4,3));
     464  arcs.push_back(std::make_pair(4,1));
     465
     466  G.build(6, arcs.begin(), arcs.end());
     467 
     468  checkGraphNodeList(G, 6);
     469  checkGraphArcList(G, 9);
     470
     471  checkGraphOutArcList(G, G.node(0), 2);
     472  checkGraphOutArcList(G, G.node(1), 2);
     473  checkGraphOutArcList(G, G.node(2), 0);
     474  checkGraphOutArcList(G, G.node(3), 2);
     475  checkGraphOutArcList(G, G.node(4), 3);
     476  checkGraphOutArcList(G, G.node(5), 0);
     477
     478  checkGraphInArcList(G, G.node(0), 1);
     479  checkGraphInArcList(G, G.node(1), 2);
     480  checkGraphInArcList(G, G.node(2), 3);
     481  checkGraphInArcList(G, G.node(3), 3);
     482  checkGraphInArcList(G, G.node(4), 0);
     483  checkGraphInArcList(G, G.node(5), 0);
     484
     485  checkGraphConArcList(G, 9);
     486
     487  checkNodeIds(G);
     488  checkArcIds(G);
     489  checkGraphNodeMap(G);
     490  checkGraphArcMap(G);
     491 
     492  int n = G.nodeNum();
     493  int m = G.arcNum();
     494  check(G.index(G.node(n-1)) == n-1, "Wrong index.");
     495  check(G.index(G.arc(m-1)) == m-1, "Wrong index.");
    384496}
    385497
     
    436548    checkDigraphValidity<SmartDigraph>();
    437549  }
     550  { // Checking StaticDigraph
     551    checkStaticDigraph();
     552  }
    438553  { // Checking FullDigraph
    439554    checkFullDigraph(8);
  • test/digraph_test.cc

    r824 r827  
    3737  checkGraphArcList(G, 0);
    3838
     39  G.reserveNode(3);
     40  G.reserveArc(4);
     41
    3942  Node
    4043    n1 = G.addNode(),
     
    281284  G.addNode();
    282285  snapshot.save(G);
     286
     287  G.addArc(G.addNode(), G.addNode());
     288
     289  snapshot.restore();
     290  snapshot.save(G);
     291
     292  checkGraphNodeList(G, 4);
     293  checkGraphArcList(G, 4);
    283294
    284295  G.addArc(G.addNode(), G.addNode());
     
    488499  typedef FullDigraph Digraph;
    489500  DIGRAPH_TYPEDEFS(Digraph);
     501
    490502  Digraph G(num);
     503  check(G.nodeNum() == num && G.arcNum() == num * num, "Wrong size");
     504
     505  G.resize(num);
     506  check(G.nodeNum() == num && G.arcNum() == num * num, "Wrong size");
    491507
    492508  checkGraphNodeList(G, num);
Note: See TracChangeset for help on using the changeset viewer.