Bonmin 1.4trunk
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 static_cast<int>(x_l_.size());
00065     }
00066 
00068     inline Index num_constraints() const
00069     {
00070       assert(g_l_.size() == g_u_.size());
00071       return static_cast<int>(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 Set_dual_sol(Index n, const Number* dual_sol);
00220 
00222     void SetVariableType(Index n, TMINLP::VariableType type);
00224 
00228     void outputDiffs(const std::string& probName, const std::string* varNames);
00229 
00233     virtual bool get_nlp_info(Index& n, Index& m, Index& nnz_jac_g,
00234         Index& nnz_h_lag,
00235         TNLP::IndexStyleEnum& index_style);
00236 
00240     virtual bool get_bounds_info(Index n, Number* x_l, Number* x_u,
00241         Index m, Number* g_l, Number* g_u);
00242 
00246     virtual bool get_constraints_linearity(Index m, LinearityType* const_types)
00247     {
00248       return tminlp_->get_constraints_linearity(m, const_types);
00249     }
00250 
00252     virtual bool hasLinearObjective(){return tminlp_->hasLinearObjective();}
00260     virtual bool get_starting_point(Index n, bool init_x, Number* x,
00261         bool init_z, Number* z_L, Number* z_U,
00262         Index m, bool init_lambda,
00263         Number* lambda);
00264 
00267     virtual bool get_scaling_parameters(Number& obj_scaling,
00268                                         bool& use_x_scaling, Index n,
00269                                         Number* x_scaling,
00270                                         bool& use_g_scaling, Index m,
00271                                         Number* g_scaling);
00272 
00273 
00276     virtual bool get_warm_start_iterate(IteratesVector& warm_start_iterate);
00277 
00279     virtual bool eval_f(Index n, const Number* x, bool new_x,
00280         Number& obj_value);
00281 
00284     virtual bool eval_grad_f(Index n, const Number* x, bool new_x,
00285         Number* grad_f);
00286 
00288     virtual bool eval_g(Index n, const Number* x, bool new_x,
00289         Index m, Number* g);
00290 
00296     virtual bool eval_jac_g(Index n, const Number* x, bool new_x,
00297         Index m, Index nele_jac, Index* iRow,
00298         Index *jCol, Number* values);
00299 
00301     virtual bool eval_gi(Index n, const Number* x, bool new_x,
00302                          Index i, Number& gi);
00305     virtual bool eval_grad_gi(Index n, const Number* x, bool new_x,
00306                               Index i, Index& nele_grad_gi, Index* jCol,
00307                               Number* values);
00308 
00316     virtual bool eval_h(Index n, const Number* x, bool new_x,
00317         Number obj_factor, Index m, const Number* lambda,
00318         bool new_lambda, Index nele_hess,
00319         Index* iRow, Index* jCol, Number* values);
00321 
00325     virtual void finalize_solution(SolverReturn status,
00326         Index n, const Number* x, const Number* z_L, const Number* z_U,
00327         Index m, const Number* g, const Number* lambda,
00328         Number obj_value,
00329         const IpoptData* ip_data,
00330         IpoptCalculatedQuantities* ip_cq);
00334     virtual bool intermediate_callback(AlgorithmMode mode,
00335         Index iter, Number obj_value,
00336         Number inf_pr, Number inf_du,
00337         Number mu, Number d_norm,
00338         Number regularization_size,
00339         Number alpha_du, Number alpha_pr,
00340         Index ls_trials,
00341         const IpoptData* ip_data,
00342         IpoptCalculatedQuantities* ip_cq);
00344 
00350     void SetWarmStarter(SmartPtr<IpoptInteriorWarmStarter> warm_starter);
00351 
00352       SmartPtr<IpoptInteriorWarmStarter> GetWarmStarter();
00353 
00355       
00357       virtual bool hasUpperBoundingObjective(){
00358         return tminlp_->hasUpperBoundingObjective();}
00359 
00361     double evaluateUpperBoundingFunction(const double * x);
00362     
00366 
00367 
00369    virtual void addCuts(unsigned int numberCuts, const OsiRowCut ** cuts){
00370     if(numberCuts > 0)
00371     throw CoinError("BonTMINLP2TNLP", "addCuts", "Not implemented");}
00372 
00373 
00375   virtual void addCuts(const OsiCuts &cuts){
00376     if(cuts.sizeRowCuts() > 0 || cuts.sizeColCuts() > 0)
00377     throw CoinError("BonTMINLP2TNLP", "addCuts", "Not implemented");}
00378 
00380   virtual void removeCuts(unsigned int number ,const int * toRemove){
00381     if(number > 0)
00382     throw CoinError("BonTMINLP2TNLP", "removeCuts", "Not implemented");}
00383 
00385 
00387     double check_solution(OsiObject ** objects = 0, int nObjects = -1);
00388    protected:
00393 
00394     vector<TMINLP::VariableType> var_types_;
00396     vector<Number> x_l_;
00398     vector<Number> x_u_;
00400     vector<Number> orig_x_l_;
00402     vector<Number> orig_x_u_;
00404     vector<Number> g_l_; 
00406     vector<Number> g_u_;
00408     vector<Number> x_init_;
00410     Number * duals_init_;
00412     vector<Number> x_init_user_;
00414     vector<Number> x_sol_;
00416     vector<Number> g_sol_;
00418     vector<Number> duals_sol_;
00422     Index nnz_h_lag() const{
00423      return nnz_h_lag_;}
00425     Index nnz_jac_g() const{
00426      return nnz_jac_g_;}
00427 
00429      TNLP::IndexStyleEnum index_style() const{
00430        return index_style_;}
00431   private:
00441     TMINLP2TNLP();
00442 
00444     TMINLP2TNLP& operator=(const TMINLP2TNLP&);
00446 
00448     SmartPtr<TMINLP> tminlp_;
00449 
00452 
00453     Index nnz_jac_g_;
00455     Index nnz_h_lag_;
00457     TNLP::IndexStyleEnum index_style_;
00458 
00460     SolverReturn return_status_;
00462     Number obj_value_;
00464 
00468     SmartPtr<IpoptInteriorWarmStarter> curr_warm_starter_;
00470     Number nlp_lower_bound_inf_;
00472     Number nlp_upper_bound_inf_;
00476     bool warm_start_entire_iterate_;
00478     bool need_new_warm_starter_;
00480 
00481 
00484     void throw_exception_on_bad_variable_bound(Index i);
00485     
00486     private:
00487     // Delete all arrays
00488     void gutsOfDelete();
00489     
00495     void gutsOfCopy(const TMINLP2TNLP &source);
00496   };
00497 
00498 } // namespace Ipopt
00499 
00500 #endif