Bonmin  1.8.8
BonTMINLP.hpp
Go to the documentation of this file.
1 // (C) Copyright International Business Machines Corporation and
2 // Carnegie Mellon University 2004, 2007
3 //
4 // All Rights Reserved.
5 // This code is published under the Eclipse Public License.
6 //
7 // Authors :
8 // Pierre Bonami, Carnegie Mellon University,
9 // Carl D. Laird, Carnegie Mellon University,
10 // Andreas Waechter, International Business Machines Corporation
11 //
12 // Date : 12/01/2004
13 
14 #ifndef __TMINLP_HPP__
15 #define __TMINLP_HPP__
16 
17 #include "IpUtils.hpp"
18 #include "IpReferenced.hpp"
19 #include "IpException.hpp"
20 #include "IpAlgTypes.hpp"
21 #include "CoinPackedMatrix.hpp"
22 #include "OsiCuts.hpp"
23 #include "IpTNLP.hpp"
24 #include "CoinError.hpp"
25 #include "CoinHelperFunctions.hpp"
26 
27 namespace Bonmin
28 {
29  DECLARE_STD_EXCEPTION(TMINLP_INVALID);
30  DECLARE_STD_EXCEPTION(TMINLP_INVALID_VARIABLE_BOUNDS);
31 
59  class TMINLP : public Ipopt::ReferencedObject
60  {
61  public:
62  friend class TMINLP2TNLP;
72  struct SosInfo
73  {
75  int num;
77  char * types;
79  int * priorities;
80 
84  int numNz;
86  int * starts;
88  int * indices;
90  double * weights;
93  SosInfo();
95  SosInfo(const SosInfo & source);
96 
97 
100  {
102  }
103 
104 
106  void gutsOfDestructor();
107 
108  };
109 
112  {
114  int size;
116  int * priorities;
120  double * upPsCosts;
122  double * downPsCosts;
124  size(0),
125  priorities(NULL),
126  branchingDirections(NULL),
127  upPsCosts(NULL),
128  downPsCosts(NULL)
129  {}
131  {
133  size = other.size;
134  priorities = CoinCopyOfArray(other.priorities, size);
135  branchingDirections = CoinCopyOfArray(other.branchingDirections, size);
136  upPsCosts = CoinCopyOfArray(other.upPsCosts, size);
137  downPsCosts = CoinCopyOfArray(other.downPsCosts, size);
138  }
140  {
141  if (priorities != NULL) delete [] priorities;
142  priorities = NULL;
143  if (branchingDirections != NULL) delete [] branchingDirections;
144  branchingDirections = NULL;
145  if (upPsCosts != NULL) delete [] upPsCosts;
146  upPsCosts = NULL;
147  if (downPsCosts != NULL) delete [] downPsCosts;
148  downPsCosts = NULL;
149  }
151  {
153  }
154  };
155 
158  {
159  public:
162  perturb_radius_(NULL)
163  {}
164 
167  {
168  delete [] perturb_radius_;
169  }
170 
172  void SetPerturbationArray(Ipopt::Index numvars, const double* perturb_radius);
173 
176  const double* GetPerturbationArray() const {
177  return perturb_radius_;
178  }
179 
180  private:
182  PerturbInfo(const PerturbInfo & source);
183 
189  };
190 
193  {
197  };
198 
201  TMINLP();
202 
204  virtual ~TMINLP();
206 
212  virtual bool get_nlp_info(Ipopt::Index& n, Ipopt::Index& m, Ipopt::Index& nnz_jac_g,
213  Ipopt::Index& nnz_h_lag, Ipopt::TNLP::IndexStyleEnum& index_style)=0;
214 
222  virtual bool get_scaling_parameters(Ipopt::Number& obj_scaling,
223  bool& use_x_scaling, Ipopt::Index n,
224  Ipopt::Number* x_scaling,
225  bool& use_g_scaling, Ipopt::Index m,
226  Ipopt::Number* g_scaling)
227  {
228  return false;
229  }
230 
231 
234  virtual bool get_variables_types(Ipopt::Index n, VariableType* var_types)=0;
235 
238  virtual bool get_variables_linearity(Ipopt::Index n,
239  Ipopt::TNLP::LinearityType* var_types) = 0;
240 
243  virtual bool get_constraints_linearity(Ipopt::Index m,
244  Ipopt::TNLP::LinearityType* const_types) = 0;
245 
254  virtual bool get_bounds_info(Ipopt::Index n, Ipopt::Number* x_l, Ipopt::Number* x_u,
255  Ipopt::Index m, Ipopt::Number* g_l, Ipopt::Number* g_u)=0;
256 
264  virtual bool get_starting_point(Ipopt::Index n, bool init_x, Ipopt::Number* x,
265  bool init_z, Ipopt::Number* z_L, Ipopt::Number* z_U,
266  Ipopt::Index m, bool init_lambda,
267  Ipopt::Number* lambda)=0;
268 
270  virtual bool eval_f(Ipopt::Index n, const Ipopt::Number* x, bool new_x,
271  Ipopt::Number& obj_value)=0;
272 
275  virtual bool eval_grad_f(Ipopt::Index n, const Ipopt::Number* x, bool new_x,
276  Ipopt::Number* grad_f)=0;
277 
279  virtual bool eval_g(Ipopt::Index n, const Ipopt::Number* x, bool new_x,
280  Ipopt::Index m, Ipopt::Number* g)=0;
281 
287  virtual bool eval_jac_g(Ipopt::Index n, const Ipopt::Number* x, bool new_x,
288  Ipopt::Index m, Ipopt::Index nele_jac, Ipopt::Index* iRow,
289  Ipopt::Index *jCol, Ipopt::Number* values)=0;
290 
298  virtual bool eval_h(Ipopt::Index n, const Ipopt::Number* x, bool new_x,
299  Ipopt::Number obj_factor, Ipopt::Index m, const Ipopt::Number* lambda,
300  bool new_lambda, Ipopt::Index nele_hess,
301  Ipopt::Index* iRow, Ipopt::Index* jCol, Ipopt::Number* values)=0;
304  virtual bool eval_gi(Ipopt::Index n, const Ipopt::Number* x, bool new_x,
305  Ipopt::Index i, Ipopt::Number& gi)
306  {
307  std::cerr << "Method eval_gi not overloaded from TMINLP\n";
308  throw -1;
309  }
313  virtual bool eval_grad_gi(Ipopt::Index n, const Ipopt::Number* x, bool new_x,
314  Ipopt::Index i, Ipopt::Index& nele_grad_gi, Ipopt::Index* jCol,
315  Ipopt::Number* values)
316  {
317  std::cerr << "Method eval_grad_gi not overloaded from TMINLP\n";
318  throw -1;
319  }
321 
325  virtual void finalize_solution(TMINLP::SolverReturn status,
326  Ipopt::Index n, const Ipopt::Number* x, Ipopt::Number obj_value) =0;
328 
329  virtual const BranchingInfo * branchingInfo() const = 0;
330 
331  virtual const SosInfo * sosConstraints() const = 0;
332 
333  virtual const PerturbInfo* perturbInfo() const
334  {
335  return NULL;
336  }
337 
340  return false;}
341 
344  virtual bool eval_upper_bound_f(Ipopt::Index n, const Ipopt::Number* x,
345  Ipopt::Number& obj_value){ return false; }
346 
348  enum Convexity {
352 
358  cIdx(-1), cRelaxIdx(-1){}
360  int cIdx;
362  int cRelaxIdx;};
369  xIdx(-1), yIdx(-1), cIdx(-1){}
371  int xIdx;
373  int yIdx;
375  int cIdx;};
377  virtual bool get_constraint_convexities(int m, TMINLP::Convexity * constraints_convexities)const {
378  CoinFillN(constraints_convexities, m, TMINLP::Convex);
379  return true;}
381  virtual bool get_number_nonconvex(int & number_non_conv, int & number_concave) const{
382  number_non_conv = 0;
383  number_concave = 0;
384  return true;}
386  virtual bool get_constraint_convexities(int number_non_conv, MarkedNonConvex * non_convs) const{
387  assert(number_non_conv == 0);
388  return true;}
390  virtual bool get_simple_concave_constraints(int number_concave, SimpleConcaveConstraint * simple_concave) const{
391  assert(number_concave == 0);
392  return true;}
393 
395  virtual bool hasLinearObjective(){return false;}
396 
398  bool hasGeneralInteger();
399 
401  virtual const int * get_const_xtra_id() const{
402  return NULL;
403  }
404  protected:
408  TMINLP(const TMINLP&);
409 
411  void operator=(const TMINLP&);
413 
414  private:
415  };
416 
417 } // namespace Ipopt
418 
419 #endif
420 
Constraint is non-convex.
Definition: BonTMINLP.hpp:350
DECLARE_STD_EXCEPTION(TMINLP_INVALID)
Base class for all MINLPs that use a standard triplet matrix form and dense vectors.
Definition: BonTMINLP.hpp:59
virtual bool eval_jac_g(Ipopt::Index n, const Ipopt::Number *x, bool new_x, Ipopt::Index m, Ipopt::Index nele_jac, Ipopt::Index *iRow, Ipopt::Index *jCol, Ipopt::Number *values)=0
overload this method to return the jacobian of the constraints.
virtual const int * get_const_xtra_id() const
Access array describing constraint to which perspectives should be applied.
Definition: BonTMINLP.hpp:401
int num
Number of SOS constraints.
Definition: BonTMINLP.hpp:75
virtual ~TMINLP()
Default destructor.
Structure for marked non-convex constraints.
Definition: BonTMINLP.hpp:355
virtual bool get_bounds_info(Ipopt::Index n, Ipopt::Number *x_l, Ipopt::Number *x_u, Ipopt::Index m, Ipopt::Number *g_l, Ipopt::Number *g_u)=0
overload this method to return the information about the bound on the variables and constraints...
virtual bool get_constraint_convexities(int m, TMINLP::Convexity *constraints_convexities) const
Get accest to constraint convexities.
Definition: BonTMINLP.hpp:377
SimpleConcaveConstraint()
Default constructor gives &quot;safe&quot; values.
Definition: BonTMINLP.hpp:368
virtual bool eval_h(Ipopt::Index n, const Ipopt::Number *x, bool new_x, Ipopt::Number obj_factor, Ipopt::Index m, const Ipopt::Number *lambda, bool new_lambda, Ipopt::Index nele_hess, Ipopt::Index *iRow, Ipopt::Index *jCol, Ipopt::Number *values)=0
overload this method to return the hessian of the lagrangian.
virtual const SosInfo * sosConstraints() const =0
~SosInfo()
destructor
Definition: BonTMINLP.hpp:99
PerturbInfo()
default constructor.
Definition: BonTMINLP.hpp:161
void operator=(const TMINLP &)
Overloaded Equals Operator.
virtual bool get_simple_concave_constraints(int number_concave, SimpleConcaveConstraint *simple_concave) const
Fill array containing indices of simple concave constraints.
Definition: BonTMINLP.hpp:390
virtual bool get_scaling_parameters(Ipopt::Number &obj_scaling, bool &use_x_scaling, Ipopt::Index n, Ipopt::Number *x_scaling, bool &use_g_scaling, Ipopt::Index m, Ipopt::Number *g_scaling)
overload this method to return scaling parameters.
Definition: BonTMINLP.hpp:222
virtual bool get_variables_types(Ipopt::Index n, VariableType *var_types)=0
overload this method to provide the variables types.
double * downPsCosts
User set down pseudo costs.
Definition: BonTMINLP.hpp:122
TMINLP()
Default destructor.
Class to store sos constraints for model.
Definition: BonTMINLP.hpp:72
virtual bool get_nlp_info(Ipopt::Index &n, Ipopt::Index &m, Ipopt::Index &nnz_jac_g, Ipopt::Index &nnz_h_lag, Ipopt::TNLP::IndexStyleEnum &index_style)=0
overload this method to return the number of variables and constraints, and the number of non-zeros i...
virtual bool eval_upper_bound_f(Ipopt::Index n, const Ipopt::Number *x, Ipopt::Number &obj_value)
overload this method to return the value of an alternative objective function for upper bounding (to ...
Definition: BonTMINLP.hpp:344
BranchingInfo(const BranchingInfo &other)
Definition: BonTMINLP.hpp:130
int * branchingDirections
User set preferered branching direction.
Definition: BonTMINLP.hpp:118
virtual bool get_constraints_linearity(Ipopt::Index m, Ipopt::TNLP::LinearityType *const_types)=0
overload this method to provide the constraint linearity.
Constraint is convex.
Definition: BonTMINLP.hpp:349
int * starts
For 0 &lt;= i &lt; nums, start[i] gives the indice of indices and weights arrays at which the description o...
Definition: BonTMINLP.hpp:86
int * priorities
User set priorities on variables.
Definition: BonTMINLP.hpp:116
const double * GetPerturbationArray() const
Method for getting the array for the perturbation radii in order to use the values.
Definition: BonTMINLP.hpp:176
Structure which describes a constraints of the form $f[ y F(x) ] with a concave function...
Definition: BonTMINLP.hpp:366
virtual void finalize_solution(TMINLP::SolverReturn status, Ipopt::Index n, const Ipopt::Number *x, Ipopt::Number obj_value)=0
This method is called when the algorithm is complete so the TNLP can store/write the solution...
SolverReturn
Return statuses of algorithm.
Definition: BonTMINLP.hpp:64
int numNz
Total number of non zeroes in SOS constraints.
Definition: BonTMINLP.hpp:84
virtual bool get_number_nonconvex(int &number_non_conv, int &number_concave) const
Get dimension information on nonconvex constraints.
Definition: BonTMINLP.hpp:381
Constraint is concave of the simple form y &gt;= F(x).
Definition: BonTMINLP.hpp:351
virtual bool eval_gi(Ipopt::Index n, const Ipopt::Number *x, bool new_x, Ipopt::Index i, Ipopt::Number &gi)
Compute the value of a single constraint.
Definition: BonTMINLP.hpp:304
int * priorities
priorities of sos constraints.
Definition: BonTMINLP.hpp:79
Convexity
Used to mark constraints of the problem.
Definition: BonTMINLP.hpp:348
char * types
Type of sos.
Definition: BonTMINLP.hpp:77
int xIdx
Index of the variable x.
Definition: BonTMINLP.hpp:371
virtual bool eval_grad_gi(Ipopt::Index n, const Ipopt::Number *x, bool new_x, Ipopt::Index i, Ipopt::Index &nele_grad_gi, Ipopt::Index *jCol, Ipopt::Number *values)
Compute the structure or values of the gradient for one constraint.
Definition: BonTMINLP.hpp:313
bool hasGeneralInteger()
Say if problem has general integer variables.
int cIdx
Index of the constraint.
Definition: BonTMINLP.hpp:375
int * indices
indices of elements belonging to the SOS.
Definition: BonTMINLP.hpp:88
int cIdx
Index of the nonconvex constraint.
Definition: BonTMINLP.hpp:360
void SetPerturbationArray(Ipopt::Index numvars, const double *perturb_radius)
Method for setting the perturbation radii.
virtual bool eval_grad_f(Ipopt::Index n, const Ipopt::Number *x, bool new_x, Ipopt::Number *grad_f)=0
overload this method to return the vector of the gradient of the objective w.r.t. ...
virtual bool get_starting_point(Ipopt::Index n, bool init_x, Ipopt::Number *x, bool init_z, Ipopt::Number *z_L, Ipopt::Number *z_U, Ipopt::Index m, bool init_lambda, Ipopt::Number *lambda)=0
overload this method to return the starting point.
double * perturb_radius_
Perturbation radii for all variables.
Definition: BonTMINLP.hpp:188
virtual const BranchingInfo * branchingInfo() const =0
Stores branching priorities information.
Definition: BonTMINLP.hpp:111
int size
number of variables
Definition: BonTMINLP.hpp:114
virtual bool get_constraint_convexities(int number_non_conv, MarkedNonConvex *non_convs) const
Get array describing the constraints marked nonconvex in the model.
Definition: BonTMINLP.hpp:386
MarkedNonConvex()
Default constructor gives &quot;safe&quot; values.
Definition: BonTMINLP.hpp:357
virtual bool eval_g(Ipopt::Index n, const Ipopt::Number *x, bool new_x, Ipopt::Index m, Ipopt::Number *g)=0
overload this method to return the vector of constraint values
This is an adapter class that converts a TMINLP to a TNLP to be solved by Ipopt.
int cRelaxIdx
Index of constraint relaxing the nonconvex constraint.
Definition: BonTMINLP.hpp:362
Class to store perturbation radii for variables in the model.
Definition: BonTMINLP.hpp:157
virtual bool hasLinearObjective()
Say if problem has a linear objective (for OA)
Definition: BonTMINLP.hpp:395
virtual bool eval_f(Ipopt::Index n, const Ipopt::Number *x, bool new_x, Ipopt::Number &obj_value)=0
overload this method to return the value of the objective function
VariableType
Type of the variables.
Definition: BonTMINLP.hpp:192
void gutsOfDestructor()
Reset information.
double * upPsCosts
User set up pseudo costs.
Definition: BonTMINLP.hpp:120
int yIdx
Index of the variable y.
Definition: BonTMINLP.hpp:373
SosInfo()
default constructor.
double * weights
weights of the elements of the SOS.
Definition: BonTMINLP.hpp:90
virtual const PerturbInfo * perturbInfo() const
Definition: BonTMINLP.hpp:333
virtual bool hasUpperBoundingObjective()
Say if has a specific function to compute upper bounds.
Definition: BonTMINLP.hpp:339
virtual bool get_variables_linearity(Ipopt::Index n, Ipopt::TNLP::LinearityType *var_types)=0
overload this method to provide the variables linearity.