COIN-OR::LEMON - Graph Library

Changeset 149:2f7ae34e1333 in lemon-1.2 for lemon


Ignore:
Timestamp:
04/24/08 14:53:09 (16 years ago)
Author:
Balazs Dezso <deba@…>
Branch:
default
Phase:
public
Message:

Item validity checking for ListGraph? and SmartGraph?

Location:
lemon
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • lemon/list_graph.h

    r73 r149  
    153153    static Arc arcFromId(int id) { return Arc(id);}
    154154
     155    bool valid(Node n) const {
     156      return n.id >= 0 && n.id < static_cast<int>(nodes.size()) &&
     157        nodes[n.id].prev != -2;
     158    }
     159
     160    bool valid(Arc a) const {
     161      return a.id >= 0 && a.id < static_cast<int>(arcs.size()) &&
     162        arcs[a.id].prev_in != -2;
     163    }
     164
    155165    Node addNode() {     
    156166      int n;
     
    220230      nodes[n].next = first_free_node;
    221231      first_free_node = n;
     232      nodes[n].prev = -2;
    222233
    223234    }
     
    248259     
    249260      arcs[n].next_in = first_free_arc;
    250       first_free_arc = n;     
    251 
     261      first_free_arc = n;
     262      arcs[n].prev_in = -2;
    252263    }
    253264
     
    350361      return Parent::addArc(s, t);
    351362    }
     363
     364    /// Node validity check
     365
     366    /// This function gives back true if the given node is valid,
     367    /// ie. it is a real node of the graph. 
     368    ///
     369    /// \warning A Node pointing to a removed item
     370    /// could become valid again later if new nodes are
     371    /// added to the graph.
     372    bool valid(Node n) const { return Parent::valid(n); }
     373
     374    /// Arc validity check
     375
     376    /// This function gives back true if the given arc is valid,
     377    /// ie. it is a real arc of the graph. 
     378    ///
     379    /// \warning An Arc pointing to a removed item
     380    /// could become valid again later if new nodes are
     381    /// added to the graph.
     382    bool valid(Arc a) const { return Parent::valid(a); }
    352383
    353384    /// Change the target of \c e to \c n
     
    946977    static Edge edgeFromId(int id) { return Edge(id);}
    947978
     979    bool valid(Node n) const {
     980      return n.id >= 0 && n.id < static_cast<int>(nodes.size()) &&
     981        nodes[n.id].prev != -2;
     982    }
     983
     984    bool valid(Arc a) const {
     985      return a.id >= 0 && a.id < static_cast<int>(arcs.size()) &&
     986        arcs[a.id].prev_out != -2;
     987    }
     988
     989    bool valid(Edge e) const {
     990      return e.id >= 0 && 2 * e.id < static_cast<int>(arcs.size()) &&
     991        arcs[2 * e.id].prev_out != -2;
     992    }
     993
    948994    Node addNode() {     
    949995      int n;
     
    10141060      nodes[n].next = first_free_node;
    10151061      first_free_node = n;
    1016 
     1062      nodes[n].prev = -2;
    10171063    }
    10181064   
     
    10421088      arcs[n].next_out = first_free_arc;
    10431089      first_free_arc = n;     
     1090      arcs[n].prev_out = -2;
     1091      arcs[n | 1].prev_out = -2;
    10441092
    10451093    }
     
    11581206      return Parent::addEdge(s, t);
    11591207    }
     1208    /// Node validity check
     1209
     1210    /// This function gives back true if the given node is valid,
     1211    /// ie. it is a real node of the graph. 
     1212    ///
     1213    /// \warning A Node pointing to a removed item
     1214    /// could become valid again later if new nodes are
     1215    /// added to the graph.
     1216    bool valid(Node n) const { return Parent::valid(n); }
     1217    /// Arc validity check
     1218
     1219    /// This function gives back true if the given arc is valid,
     1220    /// ie. it is a real arc of the graph. 
     1221    ///
     1222    /// \warning An Arc pointing to a removed item
     1223    /// could become valid again later if new edges are
     1224    /// added to the graph.
     1225    bool valid(Arc a) const { return Parent::valid(a); }
     1226    /// Edge validity check
     1227
     1228    /// This function gives back true if the given edge is valid,
     1229    /// ie. it is a real arc of the graph. 
     1230    ///
     1231    /// \warning A Edge pointing to a removed item
     1232    /// could become valid again later if new edges are
     1233    /// added to the graph.
     1234    bool valid(Edge e) const { return Parent::valid(e); }
    11601235    /// \brief Change the source of \c e to \c n
    11611236    ///
  • lemon/smart_graph.h

    r139 r149  
    116116    static Arc arcFromId(int id) { return Arc(id);}
    117117
     118    bool valid(Node n) const {
     119      return n._id >= 0 && n._id < static_cast<int>(nodes.size());
     120    }
     121    bool valid(Arc a) const {
     122      return a._id >= 0 && a._id < static_cast<int>(arcs.size());
     123    }
     124
    118125    class Node {
    119126      friend class SmartDigraphBase;
     
    261268    /// \sa reserveNode
    262269    void reserveArc(int m) { arcs.reserve(m); };
     270
     271    /// \brief Node validity check
     272    ///
     273    /// This function gives back true if the given node is valid,
     274    /// ie. it is a real node of the graph. 
     275    ///
     276    /// \warning A removed node (using Snapshot) could become valid again
     277    /// when new nodes are added to the graph.
     278    bool valid(Node n) const { return Parent::valid(n); }
     279
     280    /// \brief Arc validity check
     281    ///
     282    /// This function gives back true if the given arc is valid,
     283    /// ie. it is a real arc of the graph. 
     284    ///
     285    /// \warning A removed arc (using Snapshot) could become valid again
     286    /// when new arcs are added to the graph.
     287    bool valid(Arc a) const { return Parent::valid(a); }
    263288
    264289    ///Clear the digraph.
     
    551576    static Edge edgeFromId(int id) { return Edge(id);}
    552577
     578    bool valid(Node n) const {
     579      return n._id >= 0 && n._id < static_cast<int>(nodes.size());
     580    }
     581    bool valid(Arc a) const {
     582      return a._id >= 0 && a._id < static_cast<int>(arcs.size());
     583    }
     584    bool valid(Edge e) const {
     585      return e._id >= 0 && 2 * e._id < static_cast<int>(arcs.size());
     586    }
     587
    553588    Node addNode() {     
    554589      int n = nodes.size();
     
    642677      return Parent::addEdge(s, t);
    643678    }
     679
     680    /// \brief Node validity check
     681    ///
     682    /// This function gives back true if the given node is valid,
     683    /// ie. it is a real node of the graph. 
     684    ///
     685    /// \warning A removed node (using Snapshot) could become valid again
     686    /// when new nodes are added to the graph.
     687    bool valid(Node n) const { return Parent::valid(n); }
     688
     689    /// \brief Arc validity check
     690    ///
     691    /// This function gives back true if the given arc is valid,
     692    /// ie. it is a real arc of the graph. 
     693    ///
     694    /// \warning A removed arc (using Snapshot) could become valid again
     695    /// when new edges are added to the graph.
     696    bool valid(Arc a) const { return Parent::valid(a); }
     697
     698    /// \brief Edge validity check
     699    ///
     700    /// This function gives back true if the given edge is valid,
     701    /// ie. it is a real edge of the graph. 
     702    ///
     703    /// \warning A removed edge (using Snapshot) could become valid again
     704    /// when new edges are added to the graph.
     705    bool valid(Edge e) const { return Parent::valid(e); }
    644706
    645707    ///Clear the graph.
Note: See TracChangeset for help on using the changeset viewer.