00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #ifndef __TMINLP_HPP__
00015 #define __TMINLP_HPP__
00016
00017 #include "IpUtils.hpp"
00018 #include "IpReferenced.hpp"
00019 #include "IpException.hpp"
00020 #include "IpAlgTypes.hpp"
00021 #include "CoinPackedMatrix.hpp"
00022 #include "OsiCuts.hpp"
00023 #include "IpTNLP.hpp"
00024 #include "CoinError.hpp"
00025
00026 #include "CoinHelperFunctions.hpp"
00027 using namespace Ipopt;
00028 namespace Bonmin
00029 {
00030 DECLARE_STD_EXCEPTION(TMINLP_INVALID);
00031 DECLARE_STD_EXCEPTION(TMINLP_INVALID_VARIABLE_BOUNDS);
00032
00060 class TMINLP : public Ipopt::ReferencedObject
00061 {
00062 public:
00063 friend class TMINLP2TNLP;
00065 enum SolverReturn{
00066 SUCCESS,
00067 INFEASIBLE,
00068 CONTINUOUS_UNBOUNDED,
00069 LIMIT_EXCEEDED,
00070 MINLP_ERROR};
00072 struct SosInfo
00073 {
00075 int num;
00077 char * types;
00079 int * priorities;
00080
00084 int numNz;
00086 int * starts;
00088 int * indices;
00090 double * weights;
00093 SosInfo();
00095 SosInfo(const SosInfo & source);
00096
00097
00099 ~SosInfo()
00100 {
00101 gutsOfDestructor();
00102 }
00103
00104
00106 void gutsOfDestructor();
00107
00108 };
00109
00111 struct BranchingInfo
00112 {
00114 int size;
00116 int * priorities;
00118 int * branchingDirections;
00120 double * upPsCosts;
00122 double * downPsCosts;
00123 BranchingInfo():
00124 size(0),
00125 priorities(NULL),
00126 branchingDirections(NULL),
00127 upPsCosts(NULL),
00128 downPsCosts(NULL)
00129 {}
00130 BranchingInfo(const BranchingInfo &other)
00131 {
00132 gutsOfDestructor();
00133 size = other.size;
00134 priorities = CoinCopyOfArray(other.priorities, size);
00135 branchingDirections = CoinCopyOfArray(other.branchingDirections, size);
00136 upPsCosts = CoinCopyOfArray(other.upPsCosts, size);
00137 downPsCosts = CoinCopyOfArray(other.downPsCosts, size);
00138 }
00139 void gutsOfDestructor()
00140 {
00141 if (priorities != NULL) delete [] priorities;
00142 priorities = NULL;
00143 if (branchingDirections != NULL) delete [] branchingDirections;
00144 branchingDirections = NULL;
00145 if (upPsCosts != NULL) delete [] upPsCosts;
00146 upPsCosts = NULL;
00147 if (downPsCosts != NULL) delete [] downPsCosts;
00148 downPsCosts = NULL;
00149 }
00150 ~BranchingInfo()
00151 {
00152 gutsOfDestructor();
00153 }
00154 };
00155
00157 class PerturbInfo
00158 {
00159 public:
00161 PerturbInfo() :
00162 perturb_radius_(NULL)
00163 {}
00164
00166 ~PerturbInfo()
00167 {
00168 delete [] perturb_radius_;
00169 }
00170
00172 void SetPerturbationArray(Index numvars, const double* perturb_radius);
00173
00176 const double* GetPerturbationArray() const {
00177 return perturb_radius_;
00178 }
00179
00180 private:
00182 PerturbInfo(const PerturbInfo & source);
00183
00188 double* perturb_radius_;
00189 };
00190
00192 enum VariableType
00193 {
00194 CONTINUOUS,
00195 BINARY,
00196 INTEGER
00197 };
00198
00201 TMINLP();
00202
00204 virtual ~TMINLP();
00206
00212 virtual bool get_nlp_info(Index& n, Index& m, Index& nnz_jac_g,
00213 Index& nnz_h_lag, TNLP::IndexStyleEnum& index_style)=0;
00214
00222 virtual bool get_scaling_parameters(Number& obj_scaling,
00223 bool& use_x_scaling, Index n,
00224 Number* x_scaling,
00225 bool& use_g_scaling, Index m,
00226 Number* g_scaling)
00227 {
00228 return false;
00229 }
00230
00231
00234 virtual bool get_variables_types(Index n, VariableType* var_types)=0;
00235
00238 virtual bool get_variables_linearity(Index n,
00239 Ipopt::TNLP::LinearityType* var_types) = 0;
00240
00243 virtual bool get_constraints_linearity(Index m,
00244 Ipopt::TNLP::LinearityType* const_types) = 0;
00245
00254 virtual bool get_bounds_info(Index n, Number* x_l, Number* x_u,
00255 Index m, Number* g_l, Number* g_u)=0;
00256
00264 virtual bool get_starting_point(Index n, bool init_x, Number* x,
00265 bool init_z, Number* z_L, Number* z_U,
00266 Index m, bool init_lambda,
00267 Number* lambda)=0;
00268
00270 virtual bool eval_f(Index n, const Number* x, bool new_x,
00271 Number& obj_value)=0;
00272
00275 virtual bool eval_grad_f(Index n, const Number* x, bool new_x,
00276 Number* grad_f)=0;
00277
00279 virtual bool eval_g(Index n, const Number* x, bool new_x,
00280 Index m, Number* g)=0;
00281
00287 virtual bool eval_jac_g(Index n, const Number* x, bool new_x,
00288 Index m, Index nele_jac, Index* iRow,
00289 Index *jCol, Number* values)=0;
00290
00298 virtual bool eval_h(Index n, const Number* x, bool new_x,
00299 Number obj_factor, Index m, const Number* lambda,
00300 bool new_lambda, Index nele_hess,
00301 Index* iRow, Index* jCol, Number* values)=0;
00304 virtual bool eval_gi(Index n, const Number* x, bool new_x,
00305 Index i, Number& gi)
00306 {
00307 std::cerr << "Method eval_gi not overloaded from TMINLP\n";
00308 throw -1;
00309 }
00313 virtual bool eval_grad_gi(Index n, const Number* x, bool new_x,
00314 Index i, Index& nele_grad_gi, Index* jCol,
00315 Number* values)
00316 {
00317 std::cerr << "Method eval_grad_gi not overloaded from TMINLP\n";
00318 throw -1;
00319 }
00321
00325 virtual void finalize_solution(TMINLP::SolverReturn status,
00326 Index n, const Number* x, Number obj_value) =0;
00328
00329 virtual const BranchingInfo * branchingInfo() const = 0;
00330
00331 virtual const SosInfo * sosConstraints() const = 0;
00332
00333 virtual const PerturbInfo* perturbInfo() const
00334 {
00335 return NULL;
00336 }
00337
00339 virtual bool hasUpperBoundingObjective(){
00340 return false;}
00341
00344 virtual bool eval_upper_bound_f(Index n, const Number* x,
00345 Number& obj_value){ return false; }
00346
00348 enum Convexity {
00349 Convex,
00350 NonConvex,
00351 SimpleConcave};
00352
00355 struct MarkedNonConvex {
00357 MarkedNonConvex():
00358 cIdx(-1), cRelaxIdx(-1){}
00360 int cIdx;
00362 int cRelaxIdx;};
00366 struct SimpleConcaveConstraint{
00368 SimpleConcaveConstraint():
00369 xIdx(-1), yIdx(-1), cIdx(-1){}
00371 int xIdx;
00373 int yIdx;
00375 int cIdx;};
00377 virtual bool get_constraint_convexities(int m, TMINLP::Convexity * constraints_convexities)const {
00378 CoinFillN(constraints_convexities, m, TMINLP::Convex);
00379 return true;}
00381 virtual bool get_number_nonconvex(int & number_non_conv, int & number_concave) const{
00382 number_non_conv = 0;
00383 number_concave = 0;
00384 return true;}
00386 virtual bool get_constraint_convexities(int number_non_conv, MarkedNonConvex * non_convs) const{
00387 assert(number_non_conv == 0);
00388 return true;}
00390 virtual bool get_simple_concave_constraints(int number_concave, SimpleConcaveConstraint * simple_concave) const{
00391 assert(number_concave == 0);
00392 return true;}
00393
00395 virtual bool hasLinearObjective(){return false;}
00396
00398 bool hasGeneralInteger();
00399 protected:
00403 TMINLP(const TMINLP&);
00404
00406 void operator=(const TMINLP&);
00408
00409 private:
00410 };
00411
00412 }
00413
00414 #endif
00415