[Lemon-commits] Balazs Dezso: SmartBpGraph implementation (#69)

Lemon HG hg at lemon.cs.elte.hu
Fri Mar 1 17:49:46 CET 2013


details:   http://lemon.cs.elte.hu/hg/lemon/rev/4c89e925cfe2
changeset: 1187:4c89e925cfe2
user:      Balazs Dezso <deba [at] inf.elte.hu>
date:      Sun Nov 14 20:06:23 2010 +0100
description:
	SmartBpGraph implementation (#69)

diffstat:

 lemon/bits/graph_extender.h |  604 ++++++++++++++++++++++++++++++++++++++++++++
 lemon/bits/traits.h         |   82 +++++
 lemon/core.h                |  112 ++++++++-
 lemon/smart_graph.h         |  510 +++++++++++++++++++++++++++++++++++++-
 test/bpgraph_test.cc        |  205 ++++++++++++++-
 test/graph_test.h           |  118 ++++++++
 6 files changed, 1623 insertions(+), 8 deletions(-)

diffs (truncated from 1778 to 300 lines):

diff --git a/lemon/bits/graph_extender.h b/lemon/bits/graph_extender.h
--- a/lemon/bits/graph_extender.h
+++ b/lemon/bits/graph_extender.h
@@ -746,6 +746,610 @@
 
   };
 
+  // \ingroup _graphbits
+  //
+  // \brief Extender for the BpGraphs
+  template <typename Base>
+  class BpGraphExtender : public Base {
+    typedef Base Parent;
+
+  public:
+
+    typedef BpGraphExtender BpGraph;
+
+    typedef True UndirectedTag;
+
+    typedef typename Parent::Node Node;
+    typedef typename Parent::Arc Arc;
+    typedef typename Parent::Edge Edge;
+
+    // BpGraph extension
+
+    class RedNode : public Node {
+    public:
+      RedNode() {}
+      RedNode(const RedNode& node) : Node(node) {}
+      RedNode(Invalid) : Node(INVALID){}
+      RedNode(const Node& node) : Node(node) {}
+    };
+    class BlueNode : public Node {
+    public:
+      BlueNode() {}
+      BlueNode(const BlueNode& node) : Node(node) {}
+      BlueNode(Invalid) : Node(INVALID){}
+      BlueNode(const Node& node) : Node(node) {}
+    };
+
+    using Parent::first;
+    using Parent::next;
+
+    void first(RedNode& node) const {
+      Parent::firstRed(node);
+    }
+    
+    void next(RedNode& node) const {
+      Parent::nextRed(node);
+    }
+
+    void first(BlueNode& node) const {
+      Parent::firstBlue(node);
+    }
+
+    void next(BlueNode& node) const {
+      Parent::nextBlue(node);
+    }
+
+    using Parent::id;
+
+    int id(const RedNode& node) const {
+      return Parent::redId(node);
+    }
+
+    int id(const BlueNode& node) const {
+      return Parent::blueId(node);
+    }
+
+    int maxId(Node) const {
+      return Parent::maxNodeId();
+    }
+
+    int maxId(RedNode) const {
+      return Parent::maxRedId();
+    }
+
+    int maxId(BlueNode) const {
+      return Parent::maxBlueId();
+    }
+
+    int maxId(Arc) const {
+      return Parent::maxArcId();
+    }
+
+    int maxId(Edge) const {
+      return Parent::maxEdgeId();
+    }
+
+    static Node fromId(int id, Node) {
+      return Parent::nodeFromId(id);
+    }
+
+    static Arc fromId(int id, Arc) {
+      return Parent::arcFromId(id);
+    }
+
+    static Edge fromId(int id, Edge) {
+      return Parent::edgeFromId(id);
+    }
+
+    Node oppositeNode(const Node &n, const Edge &e) const {
+      if( n == Parent::u(e))
+        return Parent::v(e);
+      else if( n == Parent::v(e))
+        return Parent::u(e);
+      else
+        return INVALID;
+    }
+
+    Arc oppositeArc(const Arc &arc) const {
+      return Parent::direct(arc, !Parent::direction(arc));
+    }
+
+    using Parent::direct;
+    Arc direct(const Edge &edge, const Node &node) const {
+      return Parent::direct(edge, Parent::u(edge) == node);
+    }
+
+    // Alterable extension
+
+    typedef AlterationNotifier<BpGraphExtender, Node> NodeNotifier;
+    typedef AlterationNotifier<BpGraphExtender, RedNode> RedNodeNotifier; 
+    typedef AlterationNotifier<BpGraphExtender, BlueNode> BlueNodeNotifier;
+    typedef AlterationNotifier<BpGraphExtender, Arc> ArcNotifier;
+    typedef AlterationNotifier<BpGraphExtender, Edge> EdgeNotifier;
+
+
+  protected:
+
+    mutable NodeNotifier node_notifier;
+    mutable RedNodeNotifier red_node_notifier;
+    mutable BlueNodeNotifier blue_node_notifier;
+    mutable ArcNotifier arc_notifier;
+    mutable EdgeNotifier edge_notifier;
+
+  public:
+
+    NodeNotifier& notifier(Node) const {
+      return node_notifier;
+    }
+
+    RedNodeNotifier& notifier(RedNode) const {
+      return red_node_notifier;
+    }
+
+    BlueNodeNotifier& notifier(BlueNode) const {
+      return blue_node_notifier;
+    }
+
+    ArcNotifier& notifier(Arc) const {
+      return arc_notifier;
+    }
+
+    EdgeNotifier& notifier(Edge) const {
+      return edge_notifier;
+    }
+
+
+
+    class NodeIt : public Node {
+      const BpGraph* _graph;
+    public:
+
+      NodeIt() {}
+
+      NodeIt(Invalid i) : Node(i) { }
+
+      explicit NodeIt(const BpGraph& graph) : _graph(&graph) {
+        _graph->first(static_cast<Node&>(*this));
+      }
+
+      NodeIt(const BpGraph& graph, const Node& node)
+        : Node(node), _graph(&graph) {}
+
+      NodeIt& operator++() {
+        _graph->next(*this);
+        return *this;
+      }
+
+    };
+
+    class RedIt : public Node {
+      const BpGraph* _graph;
+    public:
+
+      RedIt() {}
+
+      RedIt(Invalid i) : Node(i) { }
+
+      explicit RedIt(const BpGraph& graph) : _graph(&graph) {
+        _graph->firstRed(static_cast<Node&>(*this));
+      }
+
+      RedIt(const BpGraph& graph, const Node& node)
+        : Node(node), _graph(&graph) {
+        LEMON_DEBUG(_graph->red(node), "Node has to be red.");
+      }
+
+      RedIt& operator++() {
+        _graph->nextRed(*this);
+        return *this;
+      }
+
+    };
+
+    class BlueIt : public Node {
+      const BpGraph* _graph;
+    public:
+
+      BlueIt() {}
+
+      BlueIt(Invalid i) : Node(i) { }
+
+      explicit BlueIt(const BpGraph& graph) : _graph(&graph) {
+        _graph->firstBlue(static_cast<Node&>(*this));
+      }
+
+      BlueIt(const BpGraph& graph, const Node& node)
+        : Node(node), _graph(&graph) {
+        LEMON_DEBUG(_graph->blue(node), "Node has to be blue.");
+      }
+
+      BlueIt& operator++() {
+        _graph->nextBlue(*this);
+        return *this;
+      }
+
+    };
+
+
+    class ArcIt : public Arc {
+      const BpGraph* _graph;
+    public:
+
+      ArcIt() { }
+
+      ArcIt(Invalid i) : Arc(i) { }
+
+      explicit ArcIt(const BpGraph& graph) : _graph(&graph) {
+        _graph->first(static_cast<Arc&>(*this));
+      }
+
+      ArcIt(const BpGraph& graph, const Arc& arc) :
+        Arc(arc), _graph(&graph) { }
+
+      ArcIt& operator++() {
+        _graph->next(*this);
+        return *this;
+      }
+
+    };
+
+
+    class OutArcIt : public Arc {
+      const BpGraph* _graph;
+    public:
+
+      OutArcIt() { }
+
+      OutArcIt(Invalid i) : Arc(i) { }
+
+      OutArcIt(const BpGraph& graph, const Node& node)
+        : _graph(&graph) {
+        _graph->firstOut(*this, node);
+      }
+
+      OutArcIt(const BpGraph& graph, const Arc& arc)
+        : Arc(arc), _graph(&graph) {}
+
+      OutArcIt& operator++() {
+        _graph->nextOut(*this);
+        return *this;
+      }
+
+    };
+
+
+    class InArcIt : public Arc {
+      const BpGraph* _graph;
+    public:
+
+      InArcIt() { }
+
+      InArcIt(Invalid i) : Arc(i) { }
+
+      InArcIt(const BpGraph& graph, const Node& node)
+        : _graph(&graph) {
+        _graph->firstIn(*this, node);
+      }
+
+      InArcIt(const BpGraph& graph, const Arc& arc) :
+        Arc(arc), _graph(&graph) {}
+
+      InArcIt& operator++() {
+        _graph->nextIn(*this);
+        return *this;
+      }
+



More information about the Lemon-commits mailing list