00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
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
00023
00024 struct ASL_pfgh;
00025 struct SufDecl;
00026 struct SufDesc;
00027
00028
00029
00030 namespace Ipopt
00031 {
00032 class AmplSuffixHandler;
00033 class AmplOptionsList;
00034 class AmplTNLP;
00035 }
00036
00037 namespace Bonmin
00038 {
00039
00045 class AmplTMINLP : public TMINLP
00046 {
00047 public:
00051 AmplTMINLP(const SmartPtr<const Journalist>& jnlst,
00052 const SmartPtr<Bonmin::RegisteredOptions> roptions,
00053 const SmartPtr<OptionsList> options,
00054 char**& argv,
00055 AmplSuffixHandler* suffix_handler = NULL,
00056 const std::string& appName = "bonmin",
00057 std::string* nl_file_content = NULL);
00058
00059 virtual void Initialize(const SmartPtr<const Journalist>& jnlst,
00060 const SmartPtr<Bonmin::RegisteredOptions> roptions,
00061 const SmartPtr<OptionsList> options,
00062 char**& argv,
00063 AmplSuffixHandler* suffix_handler =NULL,
00064 const std::string& appName = "bonmin",
00065 std::string* nl_file_content = NULL);
00066
00068 void read_priorities();
00069
00071 void read_sos();
00072
00074 void read_convexities();
00075
00077 void read_obj_suffixes();
00078
00080 AmplTMINLP();
00081
00082 virtual AmplTMINLP * createEmpty()
00083 {
00084 AmplTMINLP * tminlp = new AmplTMINLP;
00085 return tminlp;
00086 }
00087
00089 virtual ~AmplTMINLP();
00091
00093 const ASL_pfgh* AmplSolverObject() const;
00094
00095
00101 virtual bool get_nlp_info(Index& n, Index& m, Index& nnz_jac_g,
00102 Index& nnz_h_lag,
00103 TNLP::IndexStyleEnum& index_style);
00104
00106 virtual bool get_variables_types(Index n, VariableType* var_types);
00107
00109 virtual bool get_variables_linearity(Index n, Ipopt::TNLP::LinearityType * var_types);
00110
00113 virtual bool get_constraints_linearity(Index m,
00114 Ipopt::TNLP::LinearityType* const_types);
00115
00117 virtual bool get_bounds_info(Index n, Number* x_l, Number* x_u,
00118 Index m, Number* g_l, Number* g_u);
00119
00122 virtual bool get_starting_point(Index n, bool init_x, Number* x,
00123 bool init_z, Number* z_L, Number* z_U,
00124 Index m, bool init_lambda, Number* lambda);
00125
00127 virtual bool eval_f(Index n, const Number* x, bool new_x,
00128 Number& obj_value);
00129
00132 virtual bool eval_grad_f(Index n, const Number* x, bool new_x,
00133 Number* grad_f);
00134
00136 virtual bool eval_g(Index n, const Number* x, bool new_x,
00137 Index m, Number* g);
00138
00142 virtual bool eval_jac_g(Index n, const Number* x, bool new_x,
00143 Index m, Index nele_jac, Index* iRow,
00144 Index *jCol, Number* values);
00145
00149 virtual bool eval_h(Index n, const Number* x, bool new_x,
00150 Number obj_factor, Index m, const Number* lambda,
00151 bool new_lambda, Index nele_hess, Index* iRow,
00152 Index* jCol, Number* values);
00153
00155 virtual bool eval_gi(Index n, const Number* x, bool new_x,
00156 Index i, Number& gi);
00159 virtual bool eval_grad_gi(Index n, const Number* x, bool new_x,
00160 Index i, Index& nele_grad_gi, Index* jCol,
00161 Number* values);
00163
00178 virtual void finalize_solution(TMINLP::SolverReturn status,
00179 Index n, const Number* x, Number obj_value);
00180
00182 void write_solution(const std::string & message, const Number *x_sol);
00184
00186
00187
00188 virtual const BranchingInfo * branchingInfo() const
00189 {
00190 return &branch_;
00191 }
00192
00193 virtual const SosInfo * sosConstraints() const
00194 {
00195 return &sos_;
00196 }
00197
00198 virtual const PerturbInfo* perturbInfo() const
00199 {
00200 return &perturb_info_;
00201 }
00202
00206 virtual void fillApplicationOptions(AmplOptionsList* amplOptList)
00207 {}
00209
00210
00212 virtual void getLinearPartOfObjective(double * obj);
00213
00214
00216 void fillAmplOptionList(AmplOptionsList* amplOptList);
00217
00219 virtual bool hasUpperBoundingObjective()
00220 {
00221 return upperBoundingObj_ != -1;
00222 }
00223
00226 virtual bool eval_upper_bound_f(Index n, const Number* x,
00227 Number& obj_value);
00228
00230 virtual bool get_constraint_convexities(int m, TMINLP::Convexity * constraints_convexities)const
00231 {
00232 if (constraintsConvexities_ != NULL) {
00233 CoinCopyN(constraintsConvexities_, m, constraints_convexities);
00234 }
00235 else {
00236 CoinFillN(constraints_convexities, m, TMINLP::Convex);
00237 }
00238 return true;
00239 }
00241 virtual bool get_number_nonconvex(int & number_non_conv, int & number_concave) const
00242 {
00243 number_non_conv = numberNonConvex_;
00244 number_concave = numberSimpleConcave_;
00245 return true;
00246 }
00248 virtual bool get_constraint_convexities(int number_non_conv, MarkedNonConvex * non_convexes) const
00249 {
00250 assert(number_non_conv == numberNonConvex_);
00251 CoinCopyN( nonConvexConstraintsAndRelaxations_, number_non_conv, non_convexes);
00252 return true;
00253 }
00255 virtual bool get_simple_concave_constraints(int number_concave, SimpleConcaveConstraint * simple_concave) const
00256 {
00257 assert(number_concave == numberSimpleConcave_);
00258 CoinCopyN(simpleConcaves_, numberSimpleConcave_, simple_concave);
00259 return true;
00260 }
00261
00263 virtual bool hasLinearObjective()
00264 {
00265 return hasLinearObjective_;
00266 }
00267 private:
00276
00278 AmplTMINLP(const AmplTMINLP&);
00279
00281 void operator=(const AmplTMINLP&);
00283
00284 std::string appName_;
00285
00287 int upperBoundingObj_;
00289 AmplTNLP* ampl_tnlp_;
00291 SmartPtr<const Journalist> jnlst_;
00292
00294 BranchingInfo branch_;
00296 SosInfo sos_;
00298 PerturbInfo perturb_info_;
00300 SmartPtr<AmplSuffixHandler> suffix_handler_;
00301
00303 TMINLP::Convexity * constraintsConvexities_;
00304
00306 int numberNonConvex_;
00308 MarkedNonConvex * nonConvexConstraintsAndRelaxations_;
00310 int numberSimpleConcave_;
00312 SimpleConcaveConstraint * simpleConcaves_;
00313
00315 bool hasLinearObjective_;
00316
00318 int writeAmplSolFile_;
00319 };
00320 }
00321
00322 #endif
00323