BWAPI
|
00001 // Copyright (c) 1997-2007 ETH Zurich (Switzerland). 00002 // All rights reserved. 00003 // 00004 // This file is part of CGAL (www.cgal.org); you may redistribute it under 00005 // the terms of the Q Public License version 1.0. 00006 // See the file LICENSE.QPL distributed with CGAL. 00007 // 00008 // Licensees holding a valid commercial license may use this file in 00009 // accordance with the commercial license agreement provided with the software. 00010 // 00011 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 00012 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 00013 // 00014 // $URL: svn+ssh://scm.gforge.inria.fr/svn/cgal/branches/CGAL-3.5-branch/QP_solver/include/CGAL/QP_solver/QP_partial_exact_pricing.h $ 00015 // $Id: QP_partial_exact_pricing.h 38453 2007-04-27 00:34:44Z gaertner $ 00016 // 00017 // 00018 // Author(s) : Sven Schoenherr 00019 // Bernd Gaertner <gaertner@inf.ethz.ch> 00020 // Franz Wessendorp 00021 // Kaspar Fischer 00022 00023 #ifndef CGAL_QP_PARTIAL_EXACT_PRICING_H 00024 #define CGAL_QP_PARTIAL_EXACT_PRICING_H 00025 00026 // includes 00027 #include <CGAL/QP_solver/QP__partial_base.h> 00028 00029 CGAL_BEGIN_NAMESPACE 00030 00031 // ================= 00032 // class declaration 00033 // ================= 00034 template < typename Q, typename ET, typename Tags > 00035 class QP_partial_exact_pricing; 00036 00037 // =============== 00038 // class interface 00039 // =============== 00040 template < typename Q, typename ET, typename Tags > 00041 class QP_partial_exact_pricing : public QP__partial_base<Q,ET,Tags> { 00042 00043 // self 00044 typedef QP_pricing_strategy<Q,ET,Tags> Base; 00045 typedef QP__partial_base<Q,ET,Tags> Partial_base; 00046 typedef QP_partial_exact_pricing<Q,ET,Tags> Self; 00047 00048 // types from the pricing base class 00049 typedef typename Tags::Is_nonnegative Is_nonnegative; 00050 typedef typename Partial_base::Index_iterator Index_iterator; 00051 typedef typename Partial_base::Index_const_iterator Index_const_iterator; 00052 00053 public: 00054 00055 // creation 00056 QP_partial_exact_pricing( bool randomize = false, 00057 Random& random = default_random); 00058 00059 // operations 00060 int pricing(int& direction ); 00061 00062 // creation 00063 ~QP_partial_exact_pricing(){ }; 00064 00065 private: 00066 int pricing_helper(int& direction, Tag_true /*is_in_standard_form*/); 00067 int pricing_helper(int& direction, Tag_false /*is_in_standard_form*/); 00068 }; 00069 00070 // ---------------------------------------------------------------------------- 00071 00072 // ============================= 00073 // class implementation (inline) 00074 // ============================= 00075 00076 // construction 00077 template < typename Q, typename ET, typename Tags > inline 00078 QP_partial_exact_pricing<Q,ET,Tags>:: 00079 QP_partial_exact_pricing( bool randomize, Random& random) 00080 : Base( "partial exact"), 00081 Partial_base( randomize, random) 00082 { } 00083 00084 // operations 00085 template < typename Q, typename ET, typename Tags > 00086 int QP_partial_exact_pricing<Q,ET,Tags>:: 00087 pricing(int& direction ) 00088 { 00089 return (pricing_helper(direction, Is_nonnegative())); 00090 } 00091 00092 template < typename Q, typename ET, typename Tags > 00093 int QP_partial_exact_pricing<Q,ET,Tags>:: 00094 pricing_helper(int& /*direction*/, Tag_true /*is_in_standard_form*/) 00095 { 00096 Index_const_iterator it, min_it; 00097 ET mu, min_mu = this->et0; 00098 00099 // loop over all active non-basic variables 00100 CGAL_qpe_debug { 00101 this->vout() << "active variables:" << std::endl; 00102 } 00103 for ( it = this->active_set_begin(); it != this->active_set_end(); ++it) { 00104 00105 // don't price artificial variables 00106 if (this->solver().is_artificial( *it) || 00107 this->solver().is_basic( *it)) // added by kf 00108 continue; 00109 00110 // compute mu_j 00111 mu = mu_j( *it); 00112 00113 CGAL_qpe_debug { 00114 this->vout() << " mu_" << *it << ": " << mu << std::endl; 00115 } 00116 00117 // new minimum? 00118 if ( mu < min_mu) { min_it = it; min_mu = mu; } 00119 } 00120 00121 // no entering variable found so far? 00122 if ( ( min_mu == this->et0) && ( this->inactive_set_begin() < 00123 this->inactive_set_end())) { 00124 00125 // loop over all inactive non-basic variables 00126 CGAL_qpe_debug { 00127 this->vout() << "inactive variables:" << std::endl; 00128 } 00129 Index_const_iterator active_it; 00130 for ( it = this->inactive_set_begin(); it != this->inactive_set_end(); ++it) { 00131 00132 // don't price artificial variables 00133 if (this->solver().is_artificial( *it)) continue; 00134 00135 // compute mu_j 00136 mu = mu_j( *it); 00137 00138 CGAL_qpe_debug { 00139 this->vout() << " mu_" << *it << ": " << mu << std::endl; 00140 } 00141 00142 // candidate for entering? 00143 if ( mu < this->et0) { 00144 00145 // make variable active 00146 active_it = it; 00147 activating( active_it); 00148 00149 // new minimum? 00150 if ( mu < min_mu) { min_it = active_it; min_mu = mu; } 00151 } 00152 } 00153 } 00154 CGAL_qpe_debug { 00155 this->vout() << std::endl; 00156 } 00157 00158 // return index of entering variable, if any 00159 if ( min_mu < this->et0) { 00160 int j = *min_it; 00161 entering_basis( min_it); 00162 return j; 00163 } 00164 00165 // no entering variable found 00166 return -1; 00167 } 00168 template < typename Q, typename ET, typename Tags > 00169 int QP_partial_exact_pricing<Q,ET,Tags>:: 00170 pricing_helper(int& direction, Tag_false /*is_in_standard_form*/) 00171 { 00172 Index_const_iterator it, min_it; 00173 int min_j = -1; 00174 ET mu, min_mu = this->et0; 00175 00176 // loop over all active non-basic variables 00177 CGAL_qpe_debug { 00178 this->vout() << "active variables:" << std::endl; 00179 } 00180 for ( it = this->active_set_begin(); it != this->active_set_end(); ++it) { 00181 00182 // don't price artificial variables 00183 if (this->solver().is_artificial( *it) || 00184 this->solver().is_basic( *it)) // added by kf 00185 continue; 00186 00187 // compute mu_j 00188 mu = this->mu_j( *it); 00189 00190 if (price_dantzig (*it, mu, this->et0, min_j, min_mu, direction)) 00191 min_it = it; 00192 } 00193 00194 // no entering variable found so far? 00195 if ( ( min_j == -1) && ( this->inactive_set_begin() < 00196 this->inactive_set_end())) 00197 { 00198 00199 // loop over all inactive non-basic variables 00200 CGAL_qpe_debug { 00201 this->vout() << "inactive variables:" << std::endl; 00202 } 00203 Index_const_iterator active_it; 00204 for ( it = this->inactive_set_begin(); 00205 it != this->inactive_set_end(); ++it) { 00206 00207 // don't price basics/artificials 00208 CGAL_qpe_assertion (!this->solver().is_basic(*it)); 00209 if (this->solver().is_artificial( *it)) continue; 00210 00211 // compute mu_j 00212 mu = mu_j( *it); 00213 00214 CGAL_qpe_debug { 00215 this->vout() << " mu_" << *it << ": " << mu << std::endl; 00216 } 00217 00218 // candidate for entering? 00219 if ( is_improving(*it, mu, this->et0)) { 00220 00221 // make variable active 00222 active_it = it; 00223 activating( active_it); 00224 00225 // new minimum? 00226 if (price_dantzig (*active_it, mu, this->et0, 00227 min_j, min_mu, direction)) 00228 min_it = active_it; 00229 } 00230 } 00231 } 00232 CGAL_qpe_debug { 00233 this->vout() << std::endl; 00234 } 00235 00236 // return index of entering variable, if any 00237 if ( min_j >= 0) { 00238 CGAL_qpe_assertion(min_j == *min_it); 00239 entering_basis( min_it); 00240 return min_j; 00241 } 00242 00243 // no entering variable found 00244 return -1; 00245 } 00246 00247 CGAL_END_NAMESPACE 00248 00249 #endif // CGAL_QP_PARTIAL_EXACT_PRICING_H 00250 00251 // ===== EOF ==================================================================