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
00022
00023 struct ASL_pfgh;
00024 struct SufDecl;
00025 struct SufDesc;
00026
00027
00028
00029 namespace Ipopt
00030 {
00031 class AmplSuffixHandler;
00032 class AmplOptionsList;
00033 class AmplTNLP;
00034 }
00035
00036 namespace Bonmin
00037 {
00038
00044 class AmplTMINLP : public TMINLP
00045 {
00046 public:
00050 AmplTMINLP(const SmartPtr<const Journalist>& jnlst,
00051 const SmartPtr<OptionsList> options,
00052 char**& argv,
00053 AmplSuffixHandler* suffix_handler = NULL,
00054 const std::string& appName = "bonmin",
00055 std::string* nl_file_content = NULL);
00056
00057 virtual void Initialize(const SmartPtr<const Journalist>& jnlst,
00058 const SmartPtr<OptionsList> options,
00059 char**& argv,
00060 AmplSuffixHandler* suffix_handler =NULL,
00061 const std::string& appName = "bonmin",
00062 std::string* nl_file_content = NULL);
00063
00065 void read_priorities();
00066
00068 void read_sos();
00069
00071 void read_convexities();
00072
00074 void read_obj_suffixes();
00075
00077 AmplTMINLP();
00078
00079 virtual AmplTMINLP * createEmpty()
00080 {
00081 AmplTMINLP * tminlp = new AmplTMINLP;
00082 return tminlp;
00083 }
00084
00086 virtual ~AmplTMINLP();
00088
00090 const ASL_pfgh* AmplSolverObject() const;
00091
00092
00098 virtual bool get_nlp_info(Index& n, Index& m, Index& nnz_jac_g,
00099 Index& nnz_h_lag,
00100 TNLP::IndexStyleEnum& index_style);
00101
00103 virtual bool get_variables_types(Index n, VariableType* var_types);
00104
00106 virtual bool get_variables_linearity(Index n, Ipopt::TNLP::LinearityType * var_types);
00107
00110 virtual bool get_constraints_linearity(Index m,
00111 Ipopt::TNLP::LinearityType* const_types);
00112
00114 virtual bool get_bounds_info(Index n, Number* x_l, Number* x_u,
00115 Index m, Number* g_l, Number* g_u);
00116
00119 virtual bool get_starting_point(Index n, bool init_x, Number* x,
00120 bool init_z, Number* z_L, Number* z_U,
00121 Index m, bool init_lambda, Number* lambda);
00122
00124 virtual bool eval_f(Index n, const Number* x, bool new_x,
00125 Number& obj_value);
00126
00129 virtual bool eval_grad_f(Index n, const Number* x, bool new_x,
00130 Number* grad_f);
00131
00133 virtual bool eval_g(Index n, const Number* x, bool new_x,
00134 Index m, Number* g);
00135
00139 virtual bool eval_jac_g(Index n, const Number* x, bool new_x,
00140 Index m, Index nele_jac, Index* iRow,
00141 Index *jCol, Number* values);
00142
00146 virtual bool eval_h(Index n, const Number* x, bool new_x,
00147 Number obj_factor, Index m, const Number* lambda,
00148 bool new_lambda, Index nele_hess, Index* iRow,
00149 Index* jCol, Number* values);
00150
00152 virtual bool eval_gi(Index n, const Number* x, bool new_x,
00153 Index i, Number& gi);
00156 virtual bool eval_grad_gi(Index n, const Number* x, bool new_x,
00157 Index i, Index& nele_grad_gi, Index* jCol,
00158 Number* values);
00160
00163 virtual void finalize_solution(TMINLP::SolverReturn status,
00164 Index n, const Number* x, Number obj_value);
00165
00166 void write_solution(const std::string & message, const Number *x_sol);
00168
00172 void write_solution_file(const std::string& message) const;
00174
00175
00176 virtual const BranchingInfo * branchingInfo() const
00177 {
00178 return &branch_;
00179 }
00180
00181 virtual const SosInfo * sosConstraints() const
00182 {
00183 return &sos_;
00184 }
00185
00186 virtual const PerturbInfo* perturbInfo() const
00187 {
00188 return &perturb_info_;
00189 }
00190
00194 virtual void fillApplicationOptions(AmplOptionsList* amplOptList)
00195 {}
00197
00198
00200 virtual void getLinearPartOfObjective(double * obj);
00201
00202
00204 void fillAmplOptionList(AmplOptionsList* amplOptList);
00205
00207 virtual bool hasUpperBoundingObjective()
00208 {
00209 return upperBoundingObj_ != -1;
00210 }
00211
00214 virtual bool eval_upper_bound_f(Index n, const Number* x,
00215 Number& obj_value);
00216
00218 virtual bool get_constraint_convexities(int m, TMINLP::Convexity * constraints_convexities)const
00219 {
00220 if (constraintsConvexities_ != NULL) {
00221 CoinCopyN(constraintsConvexities_, m, constraints_convexities);
00222 }
00223 else {
00224 CoinFillN(constraints_convexities, m, TMINLP::Convex);
00225 }
00226 return true;
00227 }
00229 virtual bool get_number_nonconvex(int & number_non_conv, int & number_concave) const
00230 {
00231 number_non_conv = numberNonConvex_;
00232 number_concave = numberSimpleConcave_;
00233 return true;
00234 }
00236 virtual bool get_constraint_convexities(int number_non_conv, MarkedNonConvex * non_convexes) const
00237 {
00238 assert(number_non_conv == numberNonConvex_);
00239 CoinCopyN( nonConvexConstraintsAndRelaxations_, number_non_conv, non_convexes);
00240 return true;
00241 }
00243 virtual bool get_simple_concave_constraints(int number_concave, SimpleConcaveConstraint * simple_concave) const
00244 {
00245 assert(number_concave == numberSimpleConcave_);
00246 CoinCopyN(simpleConcaves_, numberSimpleConcave_, simple_concave);
00247 return true;
00248 }
00249
00251 virtual bool hasLinearObjective()
00252 {
00253 return hasLinearObjective_;
00254 }
00255 private:
00264
00266 AmplTMINLP(const AmplTMINLP&);
00267
00269 void operator=(const AmplTMINLP&);
00271
00273 int upperBoundingObj_;
00275 AmplTNLP* ampl_tnlp_;
00277 SmartPtr<const Journalist> jnlst_;
00278
00280 BranchingInfo branch_;
00282 SosInfo sos_;
00284 PerturbInfo perturb_info_;
00286 SmartPtr<AmplSuffixHandler> suffix_handler_;
00287
00289 TMINLP::Convexity * constraintsConvexities_;
00290
00292 int numberNonConvex_;
00294 MarkedNonConvex * nonConvexConstraintsAndRelaxations_;
00296 int numberSimpleConcave_;
00298 SimpleConcaveConstraint * simpleConcaves_;
00299
00301 bool hasLinearObjective_;
00302
00304 int writeAmplSolFile_;
00305 };
00306 }
00307
00308 #endif
00309