BWAPI
SPAR/AIModule/BWTA/vendors/CGAL/CGAL/QP_solver/QP_exact_bland_pricing.h
Go to the documentation of this file.
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_exact_bland_pricing.h $
00015 // $Id: QP_exact_bland_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_EXACT_BLAND_PRICING_H
00024 #define CGAL_QP_EXACT_BLAND_PRICING_H
00025 
00026 // includes
00027 #include <CGAL/QP_solver/QP_pricing_strategy.h>
00028 
00029 CGAL_BEGIN_NAMESPACE
00030 
00031 // =================
00032 // class declaration
00033 // =================
00034 template < typename Q, typename ET, typename Tags >
00035 class QP_exact_bland_pricing;
00036 
00037 // ===============
00038 // class interface
00039 // ===============
00040 template < typename Q, typename ET, typename Tags >
00041 class QP_exact_bland_pricing : public QP_pricing_strategy<Q,ET,Tags> {
00042 
00043   // self
00044   typedef  QP_pricing_strategy<Q,ET,Tags>    Base;
00045   typedef  QP_exact_bland_pricing<Q,ET,Tags>  Self;
00046 
00047   // types from the base class
00048   typedef  typename Tags::Is_nonnegative     Is_nonnegative;
00049   typedef  typename CGAL::QP_solver<Q,ET,Tags>    QP_solver;
00050 
00051  public:
00052 
00053   // creation
00054   QP_exact_bland_pricing();
00055 
00056   // operations
00057   int  pricing(int& direction );
00058     
00059   // cleanup
00060   ~QP_exact_bland_pricing() { };
00061     
00062  private:
00063   int pricing_helper(int& direction, Tag_true  /*is_in_standard_form*/);
00064   int pricing_helper(int& direction, Tag_false /*is_in_standard_form*/);
00065 };
00066 
00067 // ----------------------------------------------------------------------------
00068 
00069 // =============================
00070 // class implementation (inline)
00071 // =============================
00072 
00073 // construction
00074 template < typename Q, typename ET, typename Tags >  inline
00075 QP_exact_bland_pricing<Q,ET,Tags>::
00076 QP_exact_bland_pricing()
00077   : QP_pricing_strategy<Q,ET,Tags>("full exact")
00078 { }
00079     
00080 // operations
00081 template < typename Q, typename ET, typename Tags >
00082 int  QP_exact_bland_pricing<Q,ET,Tags>::
00083 pricing(int& direction )
00084 {
00085   return (pricing_helper(direction, Is_nonnegative()));
00086 }
00087 
00088 template < typename Q, typename ET, typename Tags >
00089 int  QP_exact_bland_pricing<Q,ET,Tags>::
00090 pricing_helper(int& /*direction*/, Tag_true /*is_in_standard_form*/)
00091 {
00092   // get properties of quadratic program:
00093   int  w = this->solver().number_of_working_variables();
00094 
00095   // loop over all non-basic variables:
00096   int  j;
00097   ET   mu;
00098   for (j = 0; j < w; ++j) {
00099 
00100     // variable non-basic?
00101     if (!this->solver().is_basic(j)) {
00102         
00103       // don't price artificial variables:
00104       if (this->solver().is_artificial(j)) {
00105         CGAL_qpe_debug { 
00106           this->vout() << "mu_" << j << ": artificial [ not priced ]"
00107                        << std::endl;
00108         }
00109         continue;
00110       }
00111 
00112       // compute mu_j:
00113       mu = this->mu_j(j);
00114 
00115       CGAL_qpe_debug {
00116         this->vout() << "mu_" << j << ": " << mu << std::endl;
00117       }
00118 
00119       // negative? 
00120       if (mu < this->et0) return j;
00121     }
00122   }
00123   CGAL_qpe_debug { 
00124     this->vout() << std::endl;
00125   }
00126 
00127   // fallback option
00128   return -1;
00129     
00130 }
00131 
00132 template < typename Q, typename ET, typename Tags >
00133 int  QP_exact_bland_pricing<Q,ET,Tags>::
00134 pricing_helper(int& direction, Tag_false /*is_in_standard_form*/)
00135 {
00136     
00137   // get properties of quadratic program:
00138   int  w = this->solver().number_of_working_variables();
00139 
00140   // loop over all non-basic variables:
00141   int  j,  min_j  = -1;
00142   ET min_mu = this->et0;
00143   // 
00144   for (j = 0; j < w; ++j) {
00145 
00146     // variable non-basic?
00147     if (!this->solver().is_basic(j)) {
00148         
00149       // don't price artificial variables:
00150       if (this->solver().is_artificial(j)) {
00151         CGAL_qpe_debug { 
00152           this->vout() << "mu_" << j << ": artificial [ not priced ]"
00153                        << std::endl;
00154         }
00155         continue;
00156       }
00157 
00158       const ET mu = this->mu_j(j);
00159       // from pricing strategy base class
00160       price_dantzig (j, mu, this->et0, min_j, min_mu, direction); 
00161       if (min_j >= 0) return j;
00162     }
00163   }
00164   CGAL_qpe_debug { 
00165     this->vout() << std::endl;
00166   }
00167   // fallback option
00168   return -1;
00169     
00170 }
00171 
00172 
00173 CGAL_END_NAMESPACE
00174 
00175 #endif // CGAL_QP_EXACT_BLAND_PRICING_H
00176 
00177 // ===== EOF ==================================================================
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines