My Project
|
00001 00006 #ifndef DENSITY_H_ 00007 #define DENSITY_H_ 00008 00009 #include "graph.h" 00010 00017 template <typename graph_t> 00018 class density 00019 { 00020 public: 00025 virtual ~density() {}; 00026 00036 virtual double operator ()(typename graph_t::edge_name_t win, typename graph_t::edge_name_t wout, lui k) const =0; 00037 }; 00038 00045 template <typename graph_t> 00046 class simple_density: public density<graph_t> 00047 { 00048 public: 00058 double operator ()(typename graph_t::edge_name_t win, 00059 typename graph_t::edge_name_t wout, lui k) const 00060 { 00061 k = k; // ? 00062 double num = win; 00063 double denom = win + wout + 1; 00064 return num / denom; 00065 } 00066 }; 00067 00068 00076 template <typename graph_t> 00077 class complex_density: public density<graph_t> 00078 { 00079 public: 00085 complex_density(double _lambda): lambda(_lambda) {}; 00086 00096 double operator ()(typename graph_t::edge_name_t win, 00097 typename graph_t::edge_name_t wout, lui k) const 00098 { 00099 if (k <= 1 || (win == 0 && wout == 0)) 00100 { 00101 return 0; 00102 } 00103 double part1 = (1 - lambda) * win/(win + wout); 00104 double part2 = lambda * win / (k * (k - 1)); 00105 return part1 + part2; 00106 } 00107 00108 private: 00109 double lambda; 00110 }; 00111 00119 template <typename graph_t> 00120 class negative_density: public density<graph_t> 00121 { 00122 public: 00128 negative_density(double param):lambda(param) {}; 00129 00139 double operator ()(typename graph_t::edge_name_t win, 00140 typename graph_t::edge_name_t wout, lui k) const 00141 { 00142 if (k <= 0) 00143 { 00144 return -numeric_limits<double>::max(); 00145 } 00146 double part1 = (1 - lambda) * (double)((win)-(wout))/(double)k; 00147 double part2; 00148 if (k == 1) 00149 part2 = 1; 00150 else if (k > 1) 00151 part2 = lambda * win / (k * (k - 1)); 00152 else 00153 cerr << "BAD DENSITY ROBOT" << endl; 00154 //Error 00155 return part1 + part2; 00156 } 00157 00158 private: 00159 double lambda; 00160 }; 00161 00169 void calculate_win_wout(const bidirected_t::graph& g, 00170 const std::set<bidirected_t::vertex>& s, 00171 bidirected_t::edge_name_t* win, bidirected_t::edge_name_t* wout); 00172 00173 00174 #endif