/home/coin/SVN-release/OS-2.0.0/Bonmin/src/Interfaces/BonTMINLP2TNLP.hpp

Go to the documentation of this file.
00001 // (C) Copyright International Business Machines Corporation and Carnegie Mellon University 2004, 2006
00002 // All Rights Reserved.
00003 // This code is published under the Common Public License.
00004 //
00005 // Authors :
00006 // Pierre Bonami, Carnegie Mellon University,
00007 // Carl D. Laird, Carnegie Mellon University,
00008 // Andreas Waechter, International Business Machines Corporation
00009 //
00010 // Date : 12/01/2004
00011 
00012 #ifndef __TMINLP2TNLP_HPP__
00013 #define __TMINLP2TNLP_HPP__
00014 
00015 #include "IpTNLP.hpp"
00016 #include "BonTMINLP.hpp"
00017 #include "IpSmartPtr.hpp"
00018 #include "IpIpoptApplication.hpp"
00019 #include "IpOptionsList.hpp"
00020 #include "BonTypes.hpp"
00021 
00022 namespace Bonmin
00023 {
00024   class IpoptInteriorWarmStarter;
00025 
00032   class TMINLP2TNLP : public Ipopt::TNLP
00033   {
00034   public:
00037     TMINLP2TNLP(const SmartPtr<TMINLP> tminlp
00038 #ifdef WARM_STARTER
00039         ,
00040         const OptionsList& options
00041 #endif
00042         );
00043 
00047     TMINLP2TNLP(const TMINLP2TNLP&);
00048 
00050     virtual TMINLP2TNLP * clone() const{
00051        return new TMINLP2TNLP(*this);}
00052 
00054     virtual ~TMINLP2TNLP();
00056 
00059 
00061     inline Index num_variables() const
00062     {
00063       assert(x_l_.size() == x_u_.size());
00064       return x_l_.size();
00065     }
00066 
00068     inline Index num_constraints() const
00069     {
00070       assert(g_l_.size() == g_u_.size());
00071       return g_l_.size();
00072     }
00074     Index nnz_h_lag()
00075     {
00076       return nnz_h_lag_;
00077     }
00079     const TMINLP::VariableType* var_types()
00080     {
00081       return &var_types_[0];
00082     }
00083 
00085     const Number* x_l()
00086     {
00087       return &x_l_[0];
00088     }
00090     const Number* x_u()
00091     {
00092       return &x_u_[0];
00093     }
00094 
00096     const Number* orig_x_l() const
00097     {
00098       return &orig_x_l_[0];
00099     }
00101     const Number* orig_x_u() const
00102     {
00103       return orig_x_u_();
00104     }
00105 
00107     const Number* g_l()
00108     {
00109       return g_l_();
00110     }
00112     const Number* g_u()
00113     {
00114       return g_u_();
00115     }
00116 
00118     const Number * x_init() const
00119     {
00120       return x_init_();
00121     }
00122 
00124     const Number * x_init_user() const
00125     {
00126       return x_init_user_();
00127     }
00128 
00130     const Number * duals_init() const
00131     {
00132       return duals_init_;
00133     }
00134 
00136     const Number* x_sol() const
00137     {
00138       return x_sol_();
00139     }
00140 
00142     const Number* g_sol() const
00143     {
00144       return g_sol_();
00145     }
00146 
00148     const Number* duals_sol() const
00149     {
00150       return duals_sol_();
00151     }
00152 
00154     SolverReturn optimization_status() const
00155     {
00156       return return_status_;
00157     }
00158 
00160     Number obj_value() const
00161     {
00162       return obj_value_;
00163     }
00164 
00166     void set_obj_value(Number value)
00167     {
00168       obj_value_ = value;
00169     }
00170 
00172     void force_fractionnal_sol();
00173 
00175     void SetVariablesBounds(Index n,
00176                             const Number * x_l,
00177                             const Number * x_u);
00178 
00180     void SetVariablesLowerBounds(Index n,
00181                                const Number * x_l);
00182 
00184     void SetVariablesUpperBounds(Index n,
00185                                 const Number * x_u);
00186 
00188     void SetVariableBounds(Index var_no, Number x_l, Number x_u);
00189 
00191     void SetVariableLowerBound(Index var_no, Number x_l);
00192 
00194     void SetVariableUpperBound(Index var_no, Number x_u);
00195 
00197     void SetStartingPoint(Index n, const Number* x_init);
00198 
00200     void resetStartingPoint();
00201 
00203     void setxInit(Index ind,const Number val);
00204 
00206     void setxInit(Index n,const Number* x_init);
00207 
00209     void setDualInit(Index ind, const Number val);
00210 
00212     void setDualsInit(Index n, const Number* duals_init);
00213 
00214 
00216     void Set_x_sol(Index n, const Number* x_sol);
00217 
00219     void SetVariableType(Index n, TMINLP::VariableType type);
00221 
00225     void outputDiffs(const std::string& probName, const std::string* varNames);
00226 
00230     virtual bool get_nlp_info(Index& n, Index& m, Index& nnz_jac_g,
00231         Index& nnz_h_lag,
00232         TNLP::IndexStyleEnum& index_style);
00233 
00237     virtual bool get_bounds_info(Index n, Number* x_l, Number* x_u,
00238         Index m, Number* g_l, Number* g_u);
00239 
00243     virtual bool get_constraints_linearity(Index m, LinearityType* const_types)
00244     {
00245       return tminlp_->get_constraints_linearity(m, const_types);
00246     }
00247 
00249     virtual bool hasLinearObjective(){return tminlp_->hasLinearObjective();}
00257     virtual bool get_starting_point(Index n, bool init_x, Number* x,
00258         bool init_z, Number* z_L, Number* z_U,
00259         Index m, bool init_lambda,
00260         Number* lambda);
00261 
00264     virtual bool get_scaling_parameters(Number& obj_scaling,
00265                                         bool& use_x_scaling, Index n,
00266                                         Number* x_scaling,
00267                                         bool& use_g_scaling, Index m,
00268                                         Number* g_scaling);
00269 
00270 
00273     virtual bool get_warm_start_iterate(IteratesVector& warm_start_iterate);
00274 
00276     virtual bool eval_f(Index n, const Number* x, bool new_x,
00277         Number& obj_value);
00278 
00281     virtual bool eval_grad_f(Index n, const Number* x, bool new_x,
00282         Number* grad_f);
00283 
00285     virtual bool eval_g(Index n, const Number* x, bool new_x,
00286         Index m, Number* g);
00287 
00293     virtual bool eval_jac_g(Index n, const Number* x, bool new_x,
00294         Index m, Index nele_jac, Index* iRow,
00295         Index *jCol, Number* values);
00296 
00298     virtual bool eval_gi(Index n, const Number* x, bool new_x,
00299                          Index i, Number& gi);
00302     virtual bool eval_grad_gi(Index n, const Number* x, bool new_x,
00303                               Index i, Index& nele_grad_gi, Index* jCol,
00304                               Number* values);
00305 
00313     virtual bool eval_h(Index n, const Number* x, bool new_x,
00314         Number obj_factor, Index m, const Number* lambda,
00315         bool new_lambda, Index nele_hess,
00316         Index* iRow, Index* jCol, Number* values);
00318 
00322     virtual void finalize_solution(SolverReturn status,
00323         Index n, const Number* x, const Number* z_L, const Number* z_U,
00324         Index m, const Number* g, const Number* lambda,
00325         Number obj_value,
00326         const IpoptData* ip_data,
00327         IpoptCalculatedQuantities* ip_cq);
00331     virtual bool intermediate_callback(AlgorithmMode mode,
00332         Index iter, Number obj_value,
00333         Number inf_pr, Number inf_du,
00334         Number mu, Number d_norm,
00335         Number regularization_size,
00336         Number alpha_du, Number alpha_pr,
00337         Index ls_trials,
00338         const IpoptData* ip_data,
00339         IpoptCalculatedQuantities* ip_cq);
00341 
00347     void SetWarmStarter(SmartPtr<IpoptInteriorWarmStarter> warm_starter);
00348 
00349       SmartPtr<IpoptInteriorWarmStarter> GetWarmStarter();
00350 
00352       
00354       virtual bool hasUpperBoundingObjective(){
00355         return tminlp_->hasUpperBoundingObjective();}
00356 
00358     double evaluateUpperBoundingFunction(const double * x);
00359     
00363 
00364 
00366    virtual void addCuts(unsigned int numberCuts, const OsiRowCut ** cuts){
00367     if(numberCuts > 0)
00368     throw CoinError("BonTMINLP2TNLP", "addCuts", "Not implemented");}
00369 
00370 
00372   virtual void addCuts(const OsiCuts &cuts){
00373     if(cuts.sizeRowCuts() > 0 || cuts.sizeColCuts() > 0)
00374     throw CoinError("BonTMINLP2TNLP", "addCuts", "Not implemented");}
00375 
00377   virtual void removeCuts(unsigned int number ,const int * toRemove){
00378     if(number > 0)
00379     throw CoinError("BonTMINLP2TNLP", "removeCuts", "Not implemented");}
00380 
00382 
00383    protected:
00388 
00389     vector<TMINLP::VariableType> var_types_;
00391     vector<Number> x_l_;
00393     vector<Number> x_u_;
00395     vector<Number> orig_x_l_;
00397     vector<Number> orig_x_u_;
00399     vector<Number> g_l_; 
00401     vector<Number> g_u_;
00403     vector<Number> x_init_;
00405     Number * duals_init_;
00407     vector<Number> x_init_user_;
00409     vector<Number> x_sol_;
00411     vector<Number> g_sol_;
00413     vector<Number> duals_sol_;
00417     Index nnz_h_lag() const{
00418      return nnz_h_lag_;}
00420     Index nnz_jac_g() const{
00421      return nnz_jac_g_;}
00422 
00424      TNLP::IndexStyleEnum index_style() const{
00425        return index_style_;}
00426   private:
00436     TMINLP2TNLP();
00437 
00439     TMINLP2TNLP& operator=(const TMINLP2TNLP&);
00441 
00443     SmartPtr<TMINLP> tminlp_;
00444 
00447 
00448     Index nnz_jac_g_;
00450     Index nnz_h_lag_;
00452     TNLP::IndexStyleEnum index_style_;
00453 
00455     SolverReturn return_status_;
00457     Number obj_value_;
00459 
00463     SmartPtr<IpoptInteriorWarmStarter> curr_warm_starter_;
00465     Number nlp_lower_bound_inf_;
00467     Number nlp_upper_bound_inf_;
00471     bool warm_start_entire_iterate_;
00473     bool need_new_warm_starter_;
00475 
00476 
00479     void throw_exception_on_bad_variable_bound(Index i);
00480     
00481     private:
00482     // Delete all arrays
00483     void gutsOfDelete();
00484     
00490     void gutsOfCopy(const TMINLP2TNLP &source);
00491   };
00492 
00493 } // namespace Ipopt
00494 
00495 #endif

Generated on Mon Aug 3 03:02:18 2009 by  doxygen 1.4.7