Bonmin  1.8.8
BonCutStrengthener.hpp
Go to the documentation of this file.
1 // Copyright (C) 2007 International Business Machines and others.
2 // All Rights Reserved.
3 // This code is published under the Eclipse Public License.
4 //
5 // $Id: BonCutStrengthener.hpp 2106 2015-01-20 10:33:55Z stefan $
6 //
7 // Author: Andreas Waechter IBM 2007-03-29
8 
9 #ifndef __BONCUTSTRENGTHENER_HPP__
10 #define __BONCUTSTRENGTHENER_HPP__
11 
12 #include "BonTMINLP.hpp"
13 #include "CoinPackedVector.hpp"
14 #include "BonTNLPSolver.hpp"
15 
16 namespace Bonmin
17 {
23  };
24 
28  };
29 
32  class CutStrengthener: public Ipopt::ReferencedObject
33  {
36  class StrengtheningTNLP: public Ipopt::TNLP {
37  public:
39  StrengtheningTNLP(Ipopt::SmartPtr<TMINLP> tminlp,
40  const CoinPackedVector& cut,
41  bool lower_bound,
42  Ipopt::Index n,
43  const Ipopt::Number* starting_point,
44  const double* x_l_orig,
45  const double* x_u_orig,
46  Ipopt::Index constr_index,
47  Ipopt::Index nvar_constr ,
48  const Ipopt::Index* jCol);
49 
52 
56  virtual bool get_nlp_info(Ipopt::Index& n, Ipopt::Index& m, Ipopt::Index& nnz_jac_g,
57  Ipopt::Index& nnz_h_lag, Ipopt::TNLP::IndexStyleEnum& index_style);
58 
60  virtual bool get_bounds_info(Ipopt::Index n, Ipopt::Number* x_l, Ipopt::Number* x_u,
61  Ipopt::Index m, Ipopt::Number* g_l, Ipopt::Number* g_u);
62 
64  virtual bool get_starting_point(Ipopt::Index n, bool init_x, Ipopt::Number* x,
65  bool init_z, Ipopt::Number* z_L, Ipopt::Number* z_U,
66  Ipopt::Index m, bool init_lambda,
67  Ipopt::Number* lambda);
68 
70  virtual bool eval_f(Ipopt::Index n, const Ipopt::Number* x, bool new_x, Ipopt::Number& obj_value);
71 
73  virtual bool eval_grad_f(Ipopt::Index n, const Ipopt::Number* x, bool new_x, Ipopt::Number* grad_f);
74 
76  virtual bool eval_g(Ipopt::Index n, const Ipopt::Number* x, bool new_x, Ipopt::Index m, Ipopt::Number* g);
77 
82  virtual bool eval_jac_g(Ipopt::Index n, const Ipopt::Number* x, bool new_x,
83  Ipopt::Index m, Ipopt::Index nele_jac, Ipopt::Index* iRow, Ipopt::Index *jCol,
84  Ipopt::Number* values);
85 
90  virtual bool eval_h(Ipopt::Index n, const Ipopt::Number* x, bool new_x,
91  Ipopt::Number obj_factor, Ipopt::Index m, const Ipopt::Number* lambda,
92  bool new_lambda, Ipopt::Index nele_hess, Ipopt::Index* iRow,
93  Ipopt::Index* jCol, Ipopt::Number* values);
94 
96 
99  virtual void finalize_solution(Ipopt::SolverReturn status,
100  Ipopt::Index n, const Ipopt::Number* x, const Ipopt::Number* z_L, const Ipopt::Number* z_U,
101  Ipopt::Index m, const Ipopt::Number* g, const Ipopt::Number* lambda,
102  Ipopt::Number obj_value,
103  const Ipopt::IpoptData* ip_data,
104  Ipopt::IpoptCalculatedQuantities* ip_cq);
106 
108  Ipopt::Number StrengthenedBound() const;
109 
110  private:
117 
120  const Ipopt::SmartPtr<TMINLP> tminlp_;
121 
123  Ipopt::Number* obj_grad_;
124 
126  const Ipopt::Index n_orig_;
127 
129  Ipopt::Index m_orig_;
130 
132  Ipopt::Number* starting_point_;
133 
136  Ipopt::Number* x_full_;
137 
139  Ipopt::Number* x_l_;
140 
142  Ipopt::Number* x_u_;
143 
145  const Ipopt::Index constr_index_;
146 
148  const Ipopt::Index nvar_constr_;
149 
151  Ipopt::Index* var_indices_;
152 
155 
158 
160  Ipopt::Number strengthened_bound_;
161 
163  Ipopt::Number* grad_f_;
164 
166  void update_x_full(const Ipopt::Number *x);
167  };
168 
169  public:
174  CutStrengthener(Ipopt::SmartPtr<TNLPSolver> tnlp_solver,
175  Ipopt::SmartPtr<Ipopt::OptionsList> options);
176 
178  virtual ~CutStrengthener();
180 
182  bool ComputeCuts(OsiCuts &cs,
183  TMINLP* tminlp,
184  TMINLP2TNLP* problem,
185  const int gindex, CoinPackedVector& cut,
186  double& cut_lb, double& cut_ub,
187  const double g_val, const double g_lb,
188  const double g_ub,
189  int n, const double* x,
190  double infty);
191 
192  private:
202  CutStrengthener();
203 
206 
208  void operator=(const CutStrengthener&);
210 
212  bool StrengthenCut(Ipopt::SmartPtr<TMINLP> tminlp ,
213  int constr_index ,
214  const CoinPackedVector& row ,
215  int n ,
216  const double* x ,
217  const double* x_l ,
218  const double* x_u ,
219  double& lb,
220  double& ub);
221 
223  bool HandleOneCut(bool is_tight, TMINLP* tminlp,
224  TMINLP2TNLP* problem,
225  const double* minlp_lb,
226  const double* minlp_ub,
227  const int gindex, CoinPackedVector& cut,
228  double& cut_lb, double& cut_ub,
229  int n, const double* x,
230  double infty);
231 
233  Ipopt::SmartPtr<TNLPSolver> tnlp_solver_;
234 
241  };
242 
243 } // namespace Ipopt
244 #endif
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)
Method to return: 1) The structure of the jacobian (if &quot;values&quot; is NULL) 2) The values of the jacobia...
bool have_final_bound_
Flag indicating if we TNLP has been solved successfully.
const Ipopt::SmartPtr< TMINLP > tminlp_
TMINLP (with current bounds) for which the cut it to be generated.
virtual bool eval_f(Ipopt::Index n, const Ipopt::Number *x, bool new_x, Ipopt::Number &obj_value)
Method to return the objective value.
CutStrengthener()
Default Constructor.
StrengtheningTNLP & operator=(const StrengtheningTNLP &)
virtual bool eval_grad_f(Ipopt::Index n, const Ipopt::Number *x, bool new_x, Ipopt::Number *grad_f)
Method to return the gradient of the objective.
Ipopt::Number StrengthenedBound() const
Method for asking for the strengthened bound.
Ipopt::Number * grad_f_
space for original gradient if objective function is handled
Ipopt::Number * x_full_
Full dimentional x which is used to call the TMINLP evaluation routines.
int cut_strengthening_type_
Type of OA cut strengthener.
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)
Method to return the bounds for my problem.
Ipopt::Number * starting_point_
Starting point.
Ipopt::Number * x_l_
Lower bounds for constraint variables.
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)
Method to return: 1) The structure of the hessian of the lagrangian (if &quot;values&quot; is NULL) 2) The valu...
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)
Method to return some info about the nlp.
Ipopt::Number * x_u_
Upper bounds for constraint variables.
Ipopt::Index * var_indices_
List of variables appearing on the constraints.
virtual void finalize_solution(Ipopt::SolverReturn status, Ipopt::Index n, const Ipopt::Number *x, const Ipopt::Number *z_L, const Ipopt::Number *z_U, Ipopt::Index m, const Ipopt::Number *g, const Ipopt::Number *lambda, Ipopt::Number obj_value, const Ipopt::IpoptData *ip_data, Ipopt::IpoptCalculatedQuantities *ip_cq)
This method is called when the algorithm is complete so the TNLP can store/write the solution...
void operator=(const CutStrengthener &)
Overloaded Equals Operator.
const Ipopt::Index n_orig_
Dimension of original problem.
Ipopt::Index m_orig_
Ipopt::Number of constraints in original problem.
virtual bool eval_g(Ipopt::Index n, const Ipopt::Number *x, bool new_x, Ipopt::Index m, Ipopt::Number *g)
Method to return the constraint residuals.
bool StrengthenCut(Ipopt::SmartPtr< TMINLP > tminlp, int constr_index, const CoinPackedVector &row, int n, const double *x, const double *x_l, const double *x_u, double &lb, double &ub)
Method for strengthening one cut.
Ipopt::Number * obj_grad_
Gradient of the (linear) objective function.
const Ipopt::Index constr_index_
Ipopt::Index of the constraint.
Ipopt::SmartPtr< TNLPSolver > tnlp_solver_
Object for solving the TNLPs.
Class implementing the TNLP for strengthening one cut.
Class for strengthening OA cuts, and generating additional ones.
bool lower_bound_
Flag indicating if the cut has a lower or upper bound.
bool HandleOneCut(bool is_tight, TMINLP *tminlp, TMINLP2TNLP *problem, const double *minlp_lb, const double *minlp_ub, const int gindex, CoinPackedVector &cut, double &cut_lb, double &cut_ub, int n, const double *x, double infty)
Method for generating one type of cut (strengthened or disjunctive)
const Ipopt::Index nvar_constr_
Ipopt::Number of variables appearing in the constraint.
Ipopt::Number strengthened_bound_
Final strengthened bound.
This is an adapter class that converts a TMINLP to a TNLP to be solved by Ipopt.
int oa_log_level_
verbosity level for OA-related output
virtual ~CutStrengthener()
Destructor.
void update_x_full(const Ipopt::Number *x)
Auxilliary method for updating the full x variable.
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)
Method to return the starting point for the algorithm.
int disjunctive_cut_type_
What kind of disjuntion should be done.
bool ComputeCuts(OsiCuts &cs, TMINLP *tminlp, TMINLP2TNLP *problem, const int gindex, CoinPackedVector &cut, double &cut_lb, double &cut_ub, const double g_val, const double g_lb, const double g_ub, int n, const double *x, double infty)
Method for generating and strenghtening all desired cuts.