COIN-OR::LEMON - Graph Library

Changeset 1025:c8fa41fcc4a7 in lemon-main for lemon/full_graph.h


Ignore:
Timestamp:
12/01/11 09:05:47 (12 years ago)
Author:
Balazs Dezso <deba@…>
Branch:
default
Phase:
public
Message:

Type safe red and blue node set (#69)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lemon/full_graph.h

    r1024 r1025  
    652652    };
    653653
     654    class RedNode : public Node {
     655      friend class FullBpGraphBase;
     656    protected:
     657
     658      explicit RedNode(int pid) : Node(pid) {}
     659
     660    public:
     661      RedNode() {}
     662      RedNode(const RedNode& node) : Node(node) {}
     663      RedNode(Invalid) : Node(INVALID){}
     664    };
     665
     666    class BlueNode : public Node {
     667      friend class FullBpGraphBase;
     668    protected:
     669
     670      explicit BlueNode(int pid) : Node(pid) {}
     671
     672    public:
     673      BlueNode() {}
     674      BlueNode(const BlueNode& node) : Node(node) {}
     675      BlueNode(Invalid) : Node(INVALID){}
     676    };
     677
    654678    class Edge {
    655679      friend class FullBpGraphBase;
     
    718742    bool blue(Node n) const { return n._id >= _red_num; }
    719743
     744    static RedNode asRedNodeUnsafe(Node n) { return RedNode(n._id); }
     745    static BlueNode asBlueNodeUnsafe(Node n) { return BlueNode(n._id); }
     746
    720747    Node source(Arc a) const {
    721748      if (a._id & 1) {
     
    733760    }
    734761
    735     Node redNode(Edge e) const {
    736       return Node(e._id % _red_num);
    737     }
    738     Node blueNode(Edge e) const {
    739       return Node(e._id / _red_num + _red_num);
     762    RedNode redNode(Edge e) const {
     763      return RedNode(e._id % _red_num);
     764    }
     765    BlueNode blueNode(Edge e) const {
     766      return BlueNode(e._id / _red_num + _red_num);
    740767    }
    741768
     
    756783    }
    757784
    758     void firstRed(Node& node) const {
     785    void first(RedNode& node) const {
    759786      node._id = _red_num - 1;
    760787    }
    761788
    762     static void nextRed(Node& node) {
     789    static void next(RedNode& node) {
    763790      --node._id;
    764791    }
    765792
    766     void firstBlue(Node& node) const {
     793    void first(BlueNode& node) const {
    767794      if (_red_num == _node_num) node._id = -1;
    768795      else node._id = _node_num - 1;
    769796    }
    770797
    771     void nextBlue(Node& node) const {
     798    void next(BlueNode& node) const {
    772799      if (node._id == _red_num) node._id = -1;
    773800      else --node._id;
     
    843870    }
    844871
    845     static int id(Node v) { return v._id; }
    846     int redId(Node v) const {
    847       LEMON_DEBUG(v._id < _red_num, "Node has to be red");
    848       return v._id;
    849     }
    850     int blueId(Node v) const {
    851       LEMON_DEBUG(v._id >= _red_num, "Node has to be blue");
    852       return v._id - _red_num;
    853     }
     872    static int id(const Node& v) { return v._id; }
     873    int id(const RedNode& v) const { return v._id; }
     874    int id(const BlueNode& v) const { return v._id - _red_num; }
    854875    static int id(Arc e) { return e._id; }
    855876    static int id(Edge e) { return e._id; }
     
    869890    }
    870891
    871     Node redNode(int index) const {
    872       return Node(index);
    873     }
    874 
    875     int redIndex(Node n) const {
     892    RedNode redNode(int index) const {
     893      return RedNode(index);
     894    }
     895
     896    int index(RedNode n) const {
    876897      return n._id;
    877898    }
    878899
    879     Node blueNode(int index) const {
    880       return Node(index + _red_num);
    881     }
    882 
    883     int blueIndex(Node n) const {
     900    BlueNode blueNode(int index) const {
     901      return BlueNode(index + _red_num);
     902    }
     903
     904    int index(BlueNode n) const {
    884905      return n._id - _red_num;
    885906    }
     
    10011022    /// with integers from the range <tt>[0..redNum()-1]</tt>.
    10021023    /// \sa redIndex()
    1003     Node redNode(int index) const { return Parent::redNode(index); }
     1024    RedNode redNode(int index) const { return Parent::redNode(index); }
    10041025
    10051026    /// \brief Returns the index of the given red node.
     
    10101031    ///
    10111032    /// \sa operator()()
    1012     int redIndex(Node node) const { return Parent::redIndex(node); }
     1033    int index(RedNode node) const { return Parent::index(node); }
    10131034
    10141035    /// \brief Returns the blue node with the given index.
     
    10181039    /// with integers from the range <tt>[0..blueNum()-1]</tt>.
    10191040    /// \sa blueIndex()
    1020     Node blueNode(int index) const { return Parent::blueNode(index); }
     1041    BlueNode blueNode(int index) const { return Parent::blueNode(index); }
    10211042
    10221043    /// \brief Returns the index of the given blue node.
     
    10271048    ///
    10281049    /// \sa operator()()
    1029     int blueIndex(Node node) const { return Parent::blueIndex(node); }
     1050    int index(BlueNode node) const { return Parent::index(node); }
    10301051
    10311052    /// \brief Returns the edge which connects the given nodes.
Note: See TracChangeset for help on using the changeset viewer.