Bonmin  1.7
BonAmplTMINLP.hpp
Go to the documentation of this file.
00001 // (C) Copyright International Business Machines Corporation and
00002 // Carnegie Mellon University 2004, 2007
00003 //
00004 // All Rights Reserved.
00005 // This code is published under the Common Public License.
00006 //
00007 // Authors :
00008 // Carl D. Laird, Carnegie Mellon University,
00009 // Andreas Waechter, International Business Machines Corporation
00010 // Pierre Bonami, Carnegie Mellon University,
00011 //
00012 // Date : 12/01/2004
00013 
00014 #ifndef __IPAMPLTMINLP_HPP__
00015 #define __IPAMPLTMINLP_HPP__
00016 
00017 #include "BonTMINLP.hpp"
00018 #include "IpSmartPtr.hpp"
00019 #include "CoinPackedMatrix.hpp"
00020 #include "OsiCuts.hpp"
00021 #include "BonRegisteredOptions.hpp"
00022 #include "BonTypes.hpp"
00023 
00024 /* non Ipopt forward declaration */
00025 struct ASL_pfgh;
00026 struct SufDecl;
00027 struct SufDesc;
00028 
00029 
00030 // Declarations, so that we don't have to include the Ipopt AMPL headers
00031 namespace Ipopt
00032 {
00033   class AmplSuffixHandler;
00034   class AmplOptionsList;
00035   class AmplTNLP;
00036 }
00037 
00038 namespace Bonmin
00039 {
00040 
00046   class AmplTMINLP : public TMINLP
00047   {
00048   public:
00052     AmplTMINLP(const Ipopt::SmartPtr<const Ipopt::Journalist>& jnlst,
00053         const Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions,
00054         const Ipopt::SmartPtr<Ipopt::OptionsList> options,
00055         char**& argv,
00056         Ipopt::AmplSuffixHandler* suffix_handler = NULL,
00057         const std::string& appName = "bonmin",
00058         std::string* nl_file_content = NULL);
00059 
00060     virtual void Initialize(const Ipopt::SmartPtr<const Ipopt::Journalist>& jnlst,
00061         const Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions,
00062         const Ipopt::SmartPtr<Ipopt::OptionsList> options,
00063         char**& argv,
00064         Ipopt::AmplSuffixHandler* suffix_handler =NULL,
00065         const std::string& appName = "bonmin",
00066         std::string* nl_file_content = NULL);
00067 
00069     void read_priorities();
00070 
00072     void read_sos();
00073 
00075     void read_convexities();
00076 
00078     void read_onoff();
00079 
00081     void read_obj_suffixes();
00082 
00084     AmplTMINLP();
00085 
00086     virtual AmplTMINLP * createEmpty()
00087     {
00088       AmplTMINLP * tminlp = new AmplTMINLP;
00089       return tminlp;
00090     }
00091 
00093     virtual ~AmplTMINLP();
00095 
00097     const ASL_pfgh* AmplSolverObject() const;
00098 
00099 
00105     virtual bool get_nlp_info(Ipopt::Index& n, Ipopt::Index& m, Ipopt::Index& nnz_jac_g,
00106         Ipopt::Index& nnz_h_lag,
00107         Ipopt::TNLP::IndexStyleEnum& index_style);
00108 
00110     virtual bool get_variables_types(Ipopt::Index n, VariableType* var_types);
00111 
00113     virtual bool get_variables_linearity(Ipopt::Index n, Ipopt::TNLP::LinearityType * var_types);
00114 
00117     virtual bool get_constraints_linearity(Ipopt::Index m,
00118         Ipopt::TNLP::LinearityType* const_types);
00119 
00121     virtual bool get_bounds_info(Ipopt::Index n, Ipopt::Number* x_l, Ipopt::Number* x_u,
00122         Ipopt::Index m, Ipopt::Number* g_l, Ipopt::Number* g_u);
00123 
00126     virtual bool get_starting_point(Ipopt::Index n, bool init_x, Ipopt::Number* x,
00127         bool init_z, Ipopt::Number* z_L, Ipopt::Number* z_U,
00128         Ipopt::Index m, bool init_lambda, Ipopt::Number* lambda);
00129 
00131     virtual bool eval_f(Ipopt::Index n, const Ipopt::Number* x, bool new_x,
00132         Ipopt::Number& obj_value);
00133 
00136     virtual bool eval_grad_f(Ipopt::Index n, const Ipopt::Number* x, bool new_x,
00137         Ipopt::Number* grad_f);
00138 
00140     virtual bool eval_g(Ipopt::Index n, const Ipopt::Number* x, bool new_x,
00141         Ipopt::Index m, Ipopt::Number* g);
00142 
00146     virtual bool eval_jac_g(Ipopt::Index n, const Ipopt::Number* x, bool new_x,
00147         Ipopt::Index m, Ipopt::Index nele_jac, Ipopt::Index* iRow,
00148         Ipopt::Index *jCol, Ipopt::Number* values);
00149 
00153     virtual bool eval_h(Ipopt::Index n, const Ipopt::Number* x, bool new_x,
00154         Ipopt::Number obj_factor, Ipopt::Index m, const Ipopt::Number* lambda,
00155         bool new_lambda, Ipopt::Index nele_hess, Ipopt::Index* iRow,
00156         Ipopt::Index* jCol, Ipopt::Number* values);
00157 
00159     virtual bool eval_gi(Ipopt::Index n, const Ipopt::Number* x, bool new_x,
00160         Ipopt::Index i, Ipopt::Number& gi);
00163     virtual bool eval_grad_gi(Ipopt::Index n, const Ipopt::Number* x, bool new_x,
00164         Ipopt::Index i, Ipopt::Index& nele_grad_gi, Ipopt::Index* jCol,
00165         Ipopt::Number* values);
00167 
00182     virtual void finalize_solution(TMINLP::SolverReturn status,
00183         Ipopt::Index n, const Ipopt::Number* x, Ipopt::Number obj_value);
00184 
00186     void write_solution(const std::string & message, const Ipopt::Number *x_sol);
00188 
00190 
00191 
00192     virtual const BranchingInfo * branchingInfo() const
00193     {
00194       return &branch_;
00195     }
00196 
00197     virtual const SosInfo * sosConstraints() const
00198     {
00199       return &sos_;
00200     }
00201 
00202     virtual const PerturbInfo* perturbInfo() const
00203     {
00204       return &perturb_info_;
00205     }
00206 
00210     virtual void fillApplicationOptions(Ipopt::AmplOptionsList* amplOptList)
00211     {}
00213 
00214 
00216     virtual void getLinearPartOfObjective(double * obj);
00217 
00218 
00220     virtual bool hasUpperBoundingObjective()
00221     {
00222       return upperBoundingObj_ != -1;
00223     }
00224 
00227     virtual bool eval_upper_bound_f(Ipopt::Index n, const Ipopt::Number* x,
00228         Ipopt::Number& obj_value);
00229 
00231     virtual bool get_constraint_convexities(int m, TMINLP::Convexity * constraints_convexities)const
00232     {
00233       if (constraintsConvexities_ != NULL) {
00234         CoinCopyN(constraintsConvexities_, m, constraints_convexities);
00235       }
00236       else {
00237         CoinFillN(constraints_convexities, m, TMINLP::Convex);
00238       }
00239       return true;
00240     }
00242     virtual bool get_number_nonconvex(int & number_non_conv, int & number_concave) const
00243     {
00244       number_non_conv = numberNonConvex_;
00245       number_concave = numberSimpleConcave_;
00246       return true;
00247     }
00249     virtual bool get_constraint_convexities(int number_non_conv, MarkedNonConvex * non_convexes) const
00250     {
00251       assert(number_non_conv == numberNonConvex_);
00252       CoinCopyN( nonConvexConstraintsAndRelaxations_, number_non_conv, non_convexes);
00253       return true;
00254     }
00256     virtual bool get_simple_concave_constraints(int number_concave, SimpleConcaveConstraint * simple_concave) const
00257     {
00258       assert(number_concave == numberSimpleConcave_);
00259       CoinCopyN(simpleConcaves_, numberSimpleConcave_, simple_concave);
00260       return true;
00261     }
00262 
00264     virtual bool hasLinearObjective()
00265     {
00266       return hasLinearObjective_;
00267     }
00268 
00270   virtual const int * get_const_xtra_id() const{
00271     return c_extra_id_();
00272   }
00273   private:
00282 
00284     AmplTMINLP(const AmplTMINLP&);
00285 
00287     void operator=(const AmplTMINLP&);
00289 
00290     std::string appName_;
00291 
00293     int upperBoundingObj_;
00295     Ipopt::AmplTNLP* ampl_tnlp_;
00297     Ipopt::SmartPtr<const Ipopt::Journalist> jnlst_;
00298 
00300     BranchingInfo branch_;
00302     SosInfo sos_;
00304     PerturbInfo perturb_info_;
00306     Ipopt::SmartPtr<Ipopt::AmplSuffixHandler> suffix_handler_;
00307 
00309     TMINLP::Convexity * constraintsConvexities_;
00310 
00312     vector<int> c_extra_id_; 
00313 
00315     int numberNonConvex_;
00317     MarkedNonConvex * nonConvexConstraintsAndRelaxations_;
00319     int numberSimpleConcave_;
00321     SimpleConcaveConstraint * simpleConcaves_;
00322 
00324     bool hasLinearObjective_;
00325 
00327     int writeAmplSolFile_;
00328   };
00329 } // namespace Ipopt
00330 
00331 #endif
00332