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 virtual bool hasUpperBoundingObjective()
00217 {
00218 return upperBoundingObj_ != -1;
00219 }
00220
00223 virtual bool eval_upper_bound_f(Index n, const Number* x,
00224 Number& obj_value);
00225
00227 virtual bool get_constraint_convexities(int m, TMINLP::Convexity * constraints_convexities)const
00228 {
00229 if (constraintsConvexities_ != NULL) {
00230 CoinCopyN(constraintsConvexities_, m, constraints_convexities);
00231 }
00232 else {
00233 CoinFillN(constraints_convexities, m, TMINLP::Convex);
00234 }
00235 return true;
00236 }
00238 virtual bool get_number_nonconvex(int & number_non_conv, int & number_concave) const
00239 {
00240 number_non_conv = numberNonConvex_;
00241 number_concave = numberSimpleConcave_;
00242 return true;
00243 }
00245 virtual bool get_constraint_convexities(int number_non_conv, MarkedNonConvex * non_convexes) const
00246 {
00247 assert(number_non_conv == numberNonConvex_);
00248 CoinCopyN( nonConvexConstraintsAndRelaxations_, number_non_conv, non_convexes);
00249 return true;
00250 }
00252 virtual bool get_simple_concave_constraints(int number_concave, SimpleConcaveConstraint * simple_concave) const
00253 {
00254 assert(number_concave == numberSimpleConcave_);
00255 CoinCopyN(simpleConcaves_, numberSimpleConcave_, simple_concave);
00256 return true;
00257 }
00258
00260 virtual bool hasLinearObjective()
00261 {
00262 return hasLinearObjective_;
00263 }
00264 private:
00273
00275 AmplTMINLP(const AmplTMINLP&);
00276
00278 void operator=(const AmplTMINLP&);
00280
00281 std::string appName_;
00282
00284 int upperBoundingObj_;
00286 AmplTNLP* ampl_tnlp_;
00288 SmartPtr<const Journalist> jnlst_;
00289
00291 BranchingInfo branch_;
00293 SosInfo sos_;
00295 PerturbInfo perturb_info_;
00297 SmartPtr<AmplSuffixHandler> suffix_handler_;
00298
00300 TMINLP::Convexity * constraintsConvexities_;
00301
00303 int numberNonConvex_;
00305 MarkedNonConvex * nonConvexConstraintsAndRelaxations_;
00307 int numberSimpleConcave_;
00309 SimpleConcaveConstraint * simpleConcaves_;
00310
00312 bool hasLinearObjective_;
00313
00315 int writeAmplSolFile_;
00316 };
00317 }
00318
00319 #endif
00320