COIN-OR::LEMON - Graph Library

Changeset 1193:c8fa41fcc4a7 in lemon for lemon/list_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/list_graph.h

    r1189 r1193  
    16481648    };
    16491649
     1650    class RedNode : public Node {
     1651      friend class ListBpGraphBase;
     1652    protected:
     1653
     1654      explicit RedNode(int pid) : Node(pid) {}
     1655
     1656    public:
     1657      RedNode() {}
     1658      RedNode(const RedNode& node) : Node(node) {}
     1659      RedNode(Invalid) : Node(INVALID){}
     1660    };
     1661
     1662    class BlueNode : public Node {
     1663      friend class ListBpGraphBase;
     1664    protected:
     1665
     1666      explicit BlueNode(int pid) : Node(pid) {}
     1667
     1668    public:
     1669      BlueNode() {}
     1670      BlueNode(const BlueNode& node) : Node(node) {}
     1671      BlueNode(Invalid) : Node(INVALID){}
     1672    };
     1673
    16501674    class Edge {
    16511675      friend class ListBpGraphBase;
     
    16931717    bool blue(Node n) const { return !nodes[n.id].red; }
    16941718
     1719    static RedNode asRedNodeUnsafe(Node n) { return RedNode(n.id); }
     1720    static BlueNode asBlueNodeUnsafe(Node n) { return BlueNode(n.id); }
     1721
    16951722    int maxNodeId() const { return nodes.size()-1; }
    16961723    int maxRedId() const { return max_red; }
     
    17021729    Node target(Arc e) const { return Node(arcs[e.id].target); }
    17031730
    1704     Node redNode(Edge e) const { return Node(arcs[2 * e.id].target); }
    1705     Node blueNode(Edge e) const { return Node(arcs[2 * e.id + 1].target); }
     1731    RedNode redNode(Edge e) const {
     1732      return RedNode(arcs[2 * e.id].target);
     1733    }
     1734    BlueNode blueNode(Edge e) const {
     1735      return BlueNode(arcs[2 * e.id + 1].target);
     1736    }
    17061737
    17071738    static bool direction(Arc e) {
     
    17211752    }
    17221753
    1723     void firstRed(Node& node) const {
     1754    void first(RedNode& node) const {
    17241755      node.id = first_red;
    17251756    }
    17261757
    1727     void nextRed(Node& node) const {
     1758    void next(RedNode& node) const {
    17281759      node.id = nodes[node.id].partition_next;
    17291760    }
    17301761
    1731     void firstBlue(Node& node) const {
     1762    void first(BlueNode& node) const {
    17321763      node.id = first_blue;
    17331764    }
    17341765
    1735     void nextBlue(Node& node) const {
     1766    void next(BlueNode& node) const {
    17361767      node.id = nodes[node.id].partition_next;
    17371768    }   
     
    18361867
    18371868    static int id(Node v) { return v.id; }
    1838     int redId(Node v) const {
    1839       LEMON_DEBUG(nodes[v.id].red, "Node has to be red");
    1840       return nodes[v.id].partition_index;
    1841     }
    1842     int blueId(Node v) const {
    1843       LEMON_DEBUG(!nodes[v.id].red, "Node has to be blue");
    1844       return nodes[v.id].partition_index;
    1845     }
     1869    int id(RedNode v) const { return nodes[v.id].partition_index; }
     1870    int id(BlueNode v) const { return nodes[v.id].partition_index; }
    18461871    static int id(Arc e) { return e.id; }
    18471872    static int id(Edge e) { return e.id; }
     
    18661891    }
    18671892
    1868     Node addRedNode() {
     1893    RedNode addRedNode() {
    18691894      int n;
    18701895
     
    18911916      nodes[n].first_out = -1;
    18921917
    1893       return Node(n);
    1894     }
    1895 
    1896     Node addBlueNode() {
     1918      return RedNode(n);
     1919    }
     1920
     1921    BlueNode addBlueNode() {
    18971922      int n;
    18981923
     
    19191944      nodes[n].first_out = -1;
    19201945
    1921       return Node(n);
     1946      return BlueNode(n);
    19221947    }
    19231948
     
    20302055  protected:
    20312056
    2032     void changeRed(Edge e, Node n) {
    2033       LEMON_DEBUG(nodes[n].red, "Node has to be red");
     2057    void changeRed(Edge e, RedNode n) {
    20342058      if(arcs[(2 * e.id) | 1].next_out != -1) {
    20352059        arcs[arcs[(2 * e.id) | 1].next_out].prev_out =
     
    20532077    }
    20542078
    2055     void changeBlue(Edge e, Node n) {
    2056       LEMON_DEBUG(nodes[n].red, "Node has to be blue");
    2057       if(arcs[2 * e.id].next_out != -1) {
     2079    void changeBlue(Edge e, BlueNode n) {
     2080       if(arcs[2 * e.id].next_out != -1) {
    20582081        arcs[arcs[2 * e.id].next_out].prev_out = arcs[2 * e.id].prev_out;
    20592082      }
     
    21202143    /// This function adds a red new node to the graph.
    21212144    /// \return The new node.
    2122     Node addRedNode() { return Parent::addRedNode(); }
     2145    RedNode addRedNode() { return Parent::addRedNode(); }
    21232146
    21242147    /// \brief Add a new blue node to the graph.
     
    21262149    /// This function adds a blue new node to the graph.
    21272150    /// \return The new node.
    2128     Node addBlueNode() { return Parent::addBlueNode(); }
     2151    BlueNode addBlueNode() { return Parent::addBlueNode(); }
    21292152
    21302153    /// \brief Add a new edge to the graph.
     
    21342157    /// node \c v.
    21352158    /// \return The new edge.
    2136     Edge addEdge(Node u, Node v) {
     2159    Edge addEdge(RedNode u, BlueNode v) {
     2160      return Parent::addEdge(u, v);
     2161    }
     2162    Edge addEdge(BlueNode v, RedNode u) {
    21372163      return Parent::addEdge(u, v);
    21382164    }
     
    21892215    ///\warning This functionality cannot be used together with the
    21902216    ///Snapshot feature.
    2191     void changeRed(Edge e, Node n) {
    2192       Parent::changeRed(e,n);
     2217    void changeRed(Edge e, RedNode n) {
     2218      Parent::changeRed(e, n);
    21932219    }
    21942220    /// \brief Change the blue node of an edge.
     
    22032229    ///\warning This functionality cannot be used together with the
    22042230    ///Snapshot feature.
    2205     void changeBlue(Edge e, Node n) {
    2206       Parent::changeBlue(e,n);
     2231    void changeBlue(Edge e, BlueNode n) {
     2232      Parent::changeBlue(e, n);
    22072233    }
    22082234
Note: See TracChangeset for help on using the changeset viewer.