bioprocessing  5.1.2
edgeweightedgraph.h
Go to the documentation of this file.
1 /* Copyright (C) 2000-2013 CEA
2  *
3  * This software and supporting documentation were developed by
4  * bioPICSEL
5  * CEA/DSV/I²BM/MIRCen/LMN, Batiment 61,
6  * 18, route du Panorama
7  * 92265 Fontenay-aux-Roses
8  * France
9  */
10 
11 #ifndef BIOPROCESSING_GRAPH_EWGRAPH
12 #define BIOPROCESSING_GRAPH_EWGRAPH
13 
14 //--- bioprocessing ----------------------------------------------------------
15 #include <bioprocessing/graph/basegraph.h> // bio::BaseGraph
16 //--- cartobase --------------------------------------------------------------
17 #include <cartobase/smart/rcptr.h> // carto::rc_ptr
18 //--- std --------------------------------------------------------------------
19 #include <limits> // std::numeric_limits
20 //----------------------------------------------------------------------------
21 
22 namespace bio {
23 
24  template <typename E, typename W> class EWBaseGraph;
25  template <typename E, typename W> class EWBaseGraphRef;
26 
27 //============================================================================
28 // EW GRAPH
29 //============================================================================
38  template <typename E, typename W>
39  class EWBaseGraph: public BaseGraph<E>
40  {
41  //--- typedef ------------------------------------------------------------
42  protected:
44  typedef BaseGraph<E> Base;
45  public:
46  typedef W Weight;
47  typedef typename Base::Edge Edge;
48  typedef typename Base::Vertex Vertex;
51 
52  //--- constructor --------------------------------------------------------
53  public:
54  virtual ~EWBaseGraph() {}
55 
56  //--- virtual methods ----------------------------------------------------
57  public:
58  virtual void insert( Edge e, Weight w = (Weight)0 ) { throw; } //< not defined
59  virtual Weight weight( const Edge & e ) { throw; } //< not defined
60  virtual Weight weight( const Edge & e ) const { throw; } //< not defined
61 
62  //--- virtual properties -------------------------------------------------
63  // Methods specific to Edge weighted graph that may be defined in the
64  // implementation class. Utility methods are defined below and can be
65  // used to rapidely define these methods.
66  public:
67  virtual bool isMinimum( const Graph & g ) const { throw; } //< not defined
68  virtual bool isMinimumSpanningForestRelativeTo( const Graph & h, const Graph & g ) const { throw; } //< not defined
69  virtual bool isMinimumSpanningTree( const Graph & g ) const { throw; } //< not defined
70  template <typename Path>
71  bool isDescending( const Path & p ) const { throw; } //< not defined
72  template <typename Path>
73  bool isPathofSteepestdescent( const Path & p ) const { throw; } //< not defined
74  template <typename EdgeSet>
75  bool isWatershedCut( const EdgeSet & s ) const { throw; } //< not defined
76  template <typename EdgeSet>
77  bool isBasinCut( const EdgeSet & es ) const { throw; } //< not defined
78 
79  //--- virtual computation ------------------------------------------------
80  // Methods specific to Edge weighted graph that may be defined in the
81  // implementation class. Utility methods are defined below and can be
82  // used to rapidely define these methods.
83  public:
84  virtual Graph getMinOfF() const { throw; } //< not defined
85  virtual Weight weight( const Graph & g ) const { throw; } //< not defined
86  virtual Weight Fm( const Vertex & v ) const { throw; } //< not defined
87 
88  //--- utility templated methods ------------------------------------------
89  protected:
90  template <typename G>
91  static Weight Fm( const G & thisg, const Vertex & v );
92 
93  //--- friend -------------------------------------------------------------
94  friend class EWBaseGraphRef<E,W>;
95  };
96 
97  template <typename E, typename W>
98  template <typename G>
99  W EWBaseGraph<E,W>::Fm( const G & thisg, const Vertex & v )
100  {
101  typename G::edge_const_iterator e;
102  W min = std::numeric_limits<W>::max();
103  W cur;
104  for( e = thisg.beginEdge(v); e != thisg.endEdge(v); ++e )
105  {
106  cur = thisg.weight( *e );
107  if( min > cur )
108  min = cur;
109  }
110  return min;
111  }
112 
113 //============================================================================
114 // EW GRAPH REF
115 //============================================================================
121  template <typename E, typename W>
122  class EWBaseGraphRef: public BaseGraphRef<E>
123  {
124  //--- typedef ------------------------------------------------------------
125  protected:
129  public:
130  typedef typename Pointed::Weight Weight;
131  typedef typename Pointed::Edge Edge;
132  typedef typename Pointed::Vertex Vertex;
133  typedef typename Pointed::Graph Graph;
134 
135  //--- constructors -------------------------------------------------------
136  public:
137  EWBaseGraphRef(): Base( new Pointed() ) {}
138  EWBaseGraphRef( Pointed * g ): Base( g ) {}
139  EWBaseGraphRef( const Base & other ): Base(other) {}
140  virtual ~EWBaseGraphRef() {}
141 
142  //--- none factory -------------------------------------------------------
143  public:
144  static Graph none() { return This( (Pointed*)0 ); }
145 
146  //--- virtual methods ----------------------------------------------------
147  public:
148  virtual void insert( Edge e, Weight w = (Weight)0 ) { return ((Pointed*)(this->get()))->insert(e,w); }
149  virtual Weight weight( const Edge & e ) { return ((Pointed*)(this->get()))->weight(e); }
150  virtual Weight weight( const Edge & e ) const { return ((Pointed*)(this->get()))->weight(e); }
151 
152  //--- virtual properties -------------------------------------------------
153  public:
154  // virtual bool isMinimum( const Graph & g ) const { return ((Pointed*)(this->get()))->isMinimum(g); }
155  // virtual bool isMinimumSpanningForestRelativeTo( const Graph & h, const Graph & g ) const { return ((Pointed*)(this->get()))->isMinimumSpanningForestRelativeTo(h,g); }
156  // virtual bool isMinimumSpanningTree( const Graph & g ) const { return ((Pointed*)(this->get()))->isMinimumSpanningTree(g); }
157  // template <typename Path>
158  // bool isDescending( const Path & p ) const { return ((Pointed*)(this->get()))->isDescending(p); }
159  // template <typename Path>
160  // bool isPathofSteepestdescent( const Path & p ) const { return ((Pointed*)(this->get()))->isPathofSteepestdescent(p); }
161  // template <typename EdgeSet>
162  // bool isWatershedCut( const EdgeSet & s ) const { return ((Pointed*)(this->get()))->isWatershedCut(s); }
163  // template <typename EdgeSet>
164  // bool isBasinCut( const EdgeSet & es ) const { return ((Pointed*)(this->get()))->isBasinCut(es); }
165 
166  //--- virtual computation ------------------------------------------------
167  public:
168  // virtual Graph getMinOfF() const { return ((Pointed*)(this->get()))->getMinOfF(); }
169  // virtual Weight weight( const Graph & g ) const { return ((Pointed*)(this->get()))->weight(g); }
170  virtual Weight Fm( const Vertex & v ) const { return ((Pointed*)(this->get()))->Fm(v); }
171 
172  //--- friends ------------------------------------------------------------
173  friend class EWBaseGraph<E,W>;
174  };
175 
176 } // namesapce bio
177 
178 #endif // BIOPROCESSING_GRAPH_EWGRAPH
Reference to a BaseGraph.
Definition: basegraph.h:312
Pointed::Vertex Vertex
Definition: basegraph.h:319
carto::rc_ptr< BaseGraph< E > > Base
Definition: basegraph.h:315
Pointed::Edge Edge
Definition: basegraph.h:320
Base class for graphs.
Definition: basegraph.h:40
E Edge
Usable edge type.
Definition: basegraph.h:45
Edge::Vertex Vertex
Usable vertex type.
Definition: basegraph.h:46
Reference to a EWBaseGraph.
virtual Weight weight(const Edge &e) const
EWBaseGraphRef< E, W > This
virtual Weight Fm(const Vertex &v) const
virtual Weight weight(const Edge &e)
Pointed::Vertex Vertex
Pointed::Weight Weight
virtual void insert(Edge e, Weight w=(Weight) 0)
EWBaseGraph< E, W > Pointed
EWBaseGraphRef(const Base &other)
BaseGraphRef< E > Base
Base class for edge weighted graphs.
virtual Weight Fm(const Vertex &v) const
virtual Graph getMinOfF() const
virtual Weight weight(const Edge &e) const
Base::Vertex Vertex
Usable vertex type.
virtual bool isMinimumSpanningTree(const Graph &g) const
bool isWatershedCut(const EdgeSet &s) const
virtual bool isMinimumSpanningForestRelativeTo(const Graph &h, const Graph &g) const
bool isDescending(const Path &p) const
Base::Edge Edge
Usable edge type.
EWBaseGraph< E, W > This
Type of *this.
EWBaseGraphRef< E, W > Graph
Usable graph type.
BaseGraph< E > Base
Base class.
virtual Weight weight(const Edge &e)
bool isBasinCut(const EdgeSet &es) const
virtual bool isMinimum(const Graph &g) const
W Weight
Weight type.
virtual Weight weight(const Graph &g) const
virtual void insert(Edge e, Weight w=(Weight) 0)
EWBaseGraphRef< E, W > Ref
Reference type.
bool isPathofSteepestdescent(const Path &p) const