Debian Codegraph @

Bonmin/src/Interfaces/BonBranchingTQP.hpp

raw
1 // (C) Copyright International Business Machines Corporation and
2 // Carnegie Mellon University 2006, 2008
3 // All Rights Reserved.
4 // This code is published under the Eclipse Public License.
5 //
6 // Authors :
7 // Andreas Waechter, International Business Machines Corporation
8 // (derived from BonTMINLP2TNLP.hpp) 12/22/2006
9
10 #ifndef __BONBRANCHINGTQP_HPP__
11 #define __BONBRANCHINGTQP_HPP__
12
13 #include "BonTMINLP2TNLP.hpp"
14
15 namespace Bonmin
16 {
17 /** This is an adapter class that converts a TMINLP2TNLP object into
18 * a TNLP, which is now just a QP. The QP is the linear quadratic
19 * of the TNLP at the optimal point. The purpose of the
20 * BranchingTQP is that it is used in a strong-branching framework,
21 * strong branching is only done for the QP approximation of the
22 * TNLP, not on the TNLP itself. The variables of the QP are the
23 * displacement from the reference point.
24 */
25 class BranchingTQP : public Ipopt::TNLP
26 {
27 public:
28 /**@name Constructors/Destructors */
29 //@{
30 BranchingTQP(Ipopt::SmartPtr<TMINLP2TNLP> tminlp2tnlp);
31
32 /** Default destructor */
33 virtual ~BranchingTQP();
34 //@}
35
36 /**@name methods to gather information about the NLP, only those
37 * that need to be overloaded from TNLP */
38 //@{
39 virtual bool get_nlp_info(Ipopt::Index& n, Ipopt::Index& m, Ipopt::Index& nnz_jac_g,
40 Ipopt::Index& nnz_h_lag, Ipopt::TNLP::IndexStyleEnum& index_style);
41 virtual bool get_bounds_info(Ipopt::Index n, Ipopt::Number* x_l, Ipopt::Number* x_u,
42 Ipopt::Index m, Ipopt::Number* g_l, Ipopt::Number* g_u);
43 /** Returns the constraint linearity. array should be alocated
44 * with length at least n. Since this is a QP, all constraints are
45 * linear.*/
46 virtual bool get_constraints_linearity(Ipopt::Index m, LinearityType* const_types);
47 /** Method called by Ipopt to get the starting point. The bools
48 * init_x and init_lambda are both inputs and outputs. As inputs,
49 * they indicate whether or not the algorithm wants you to
50 * initialize x and lambda respectively. If, for some reason, the
51 * algorithm wants you to initialize these and you cannot, set
52 * the respective bool to false.
53 */
54 virtual bool get_starting_point(Ipopt::Index n, bool init_x, Ipopt::Number* x,
55 bool init_z, Ipopt::Number* z_L, Ipopt::Number* z_U,
56 Ipopt::Index m, bool init_lambda,
57 Ipopt::Number* lambda);
58
59 /** Returns the value of the objective function in x*/
60 virtual bool eval_f(Ipopt::Index n, const Ipopt::Number* x, bool new_x,
61 Ipopt::Number& obj_value);
62
63 /** Returns the vector of the gradient of
64 * the objective w.r.t. x */
65 virtual bool eval_grad_f(Ipopt::Index n, const Ipopt::Number* x, bool new_x,
66 Ipopt::Number* grad_f);
67
68 /** Returns the vector of constraint values in x*/
69 virtual bool eval_g(Ipopt::Index n, const Ipopt::Number* x, bool new_x,
70 Ipopt::Index m, Ipopt::Number* g);
71
72 /** Returns the jacobian of the
73 * constraints. The vectors iRow and jCol only need to be set
74 * once. The first call is used to set the structure only (iRow
75 * and jCol will be non-NULL, and values will be NULL) For
76 * subsequent calls, iRow and jCol will be NULL. */
77 virtual bool eval_jac_g(Ipopt::Index n, const Ipopt::Number* x, bool new_x,
78 Ipopt::Index m, Ipopt::Index nele_jac, Ipopt::Index* iRow,
79 Ipopt::Index *jCol, Ipopt::Number* values);
80
81 /** Return the hessian of the
82 * lagrangian. The vectors iRow and jCol only need to be set once
83 * (during the first call). The first call is used to set the
84 * structure only (iRow and jCol will be non-NULL, and values
85 * will be NULL) For subsequent calls, iRow and jCol will be
86 * NULL. This matrix is symmetric - specify the lower diagonal
87 * only */
88 virtual bool eval_h(Ipopt::Index n, const Ipopt::Number* x, bool new_x,
89 Ipopt::Number obj_factor, Ipopt::Index m, const Ipopt::Number* lambda,
90 bool new_lambda, Ipopt::Index nele_hess,
91 Ipopt::Index* iRow, Ipopt::Index* jCol, Ipopt::Number* values);
92 virtual void finalize_solution(Ipopt::SolverReturn status,
93 Ipopt::Index n, const Ipopt::Number* x, const Ipopt::Number* z_L, const Ipopt::Number* z_U,
94 Ipopt::Index m, const Ipopt::Number* g, const Ipopt::Number* lambda,
95 Ipopt::Number obj_value,
96 const Ipopt::IpoptData* ip_data,
97 Ipopt::IpoptCalculatedQuantities* ip_cq);
98 //@}
99
100 /** Accessor Methods for QP data */
101 //@{
102 const Ipopt::Number ObjVal()
103 {
104 return obj_val_;
105 }
106 const Ipopt::Number* ObjGrad()
107 {
108 return obj_grad_;
109 }
110 const Ipopt::Number* ObjHessVals()
111 {
112 return obj_hess_;
113 }
114 const Ipopt::Index* ObjHessIRow()
115 {
116 return obj_hess_irow_;
117 }
118 const Ipopt::Index* ObjHessJCol()
119 {
120 return obj_hess_jcol_;
121 }
122 const Ipopt::Number* ConstrRhs()
123 {
124 return g_vals_;
125 }
126 const Ipopt::Number* ConstrJacVals()
127 {
128 return g_jac_;
129 }
130 const Ipopt::Index* ConstrJacIRow()
131 {
132 return g_jac_irow_;
133 }
134 const Ipopt::Index* ConstrJacJCol()
135 {
136 return g_jac_jcol_;
137 }
138 //@}
139
140 private:
141 /**@name Default Compiler Generated Methods
142 * (Hidden to avoid implicit creation/calling).
143 * These methods are not implemented and
144 * we do not want the compiler to implement
145 * them for us, so we declare them private
146 * and do not define them. This ensures that
147 * they will not be implicitly created/called. */
148 //@{
149 /** Default Constructor */
150 BranchingTQP();
151
152 /** Copy Constructor */
153 BranchingTQP(const BranchingTQP&);
154
155 /** Overloaded Equals Operator */
156 void operator=(const BranchingTQP&);
157 //@}
158
159 /** @name static information about the QP's constraints and
160 * objective function */
161 //@{
162 Ipopt::Number obj_val_;
163 Ipopt::Number* obj_grad_;
164 Ipopt::Number* obj_hess_;
165 Ipopt::Index* obj_hess_irow_;
166 Ipopt::Index* obj_hess_jcol_;
167 Ipopt::Number* g_vals_;
168 Ipopt::Number* g_jac_;
169 Ipopt::Index* g_jac_irow_;
170 Ipopt::Index* g_jac_jcol_;
171 //@}
172
173 /** @name Data from the MINLP */
174 //@{
175 Ipopt::Index n_;
176 Ipopt::Index m_;
177 Ipopt::Index nnz_jac_g_;
178 Ipopt::Index nnz_h_lag_;
179 Ipopt::TNLP::IndexStyleEnum index_style_;
180 //@}
181
182 /** Copy of original x_sol_. x_sol_ is changed after the first QP
183 * has been solved once. */
184 Ipopt::Number* x_sol_copy_;
185
186 /** Copy of original duals_sol_. duals_sol_ is changed after the
187 * first QP has been solved once. */
188 Ipopt::Number* duals_sol_copy_;
189
190 /** Pointer to the TMINLP2TNLP model which stores the bounds
191 * information */
192 Ipopt::SmartPtr<TMINLP2TNLP> tminlp2tnlp_;
193 };
194
195 } // namespace Ipopt
196
197 #endif