Debian Codegraph @

Bonmin/src/Algorithms/QuadCuts/BonTMINLP2Quad.hpp

raw
1 // (C) Copyright International Business Machines Corporation 2007
2 // All Rights Reserved.
3 // This code is published under the Eclipse Public License.
4 //
5 // Authors :
6 // Pierre Bonami, International Business Machines Corporation
7 //
8 // Date : 10/06/2007
9
10 #ifndef __TMINLPQuad_HPP__
11 #define __TMINLPQuad_HPP__
12
13 #include "BonTMINLP2TNLP.hpp"
14 #include "BonQuadRow.hpp"
15
16 namespace Bonmin
17 {
18
19
20 /** This is a derived class fro TMINLP2TNLP to handle adding quadratic cuts.
21 */
22 class TMINLP2TNLPQuadCuts : public Bonmin::TMINLP2TNLP
23 {
24 public:
25 /**@name Constructors/Destructors */
26 //@{
27 TMINLP2TNLPQuadCuts(const Ipopt::SmartPtr<Bonmin::TMINLP> tminlp
28 #ifdef WARM_STARTER
29 ,
30 const OptionsList& options
31 #endif
32 );
33
34
35 /** Copy Constructor
36 * \warning source and copy point to the same tminlp_.
37 */
38 TMINLP2TNLPQuadCuts(const TMINLP2TNLPQuadCuts&);
39
40 /** Virtual copy.*/
41 virtual Bonmin::TMINLP2TNLP * clone() const{
42 printf("Cloning TMINLP2TNLPQuadCuts.\n");
43 return new TMINLP2TNLPQuadCuts(*this);}
44
45 /** Destructor */
46 virtual ~TMINLP2TNLPQuadCuts();
47 //@}
48 /**@name methods to gather information about the NLP */
49 //@{
50 /** This call is just passed onto parent class and add number of quadratic
51 cuts*/
52 virtual bool get_nlp_info(Ipopt::Index& n, Ipopt::Index& m, Ipopt::Index& nnz_jac_g,
53 Ipopt::Index& nnz_h_lag,
54 Ipopt::TNLP::IndexStyleEnum& index_style);
55
56 /** This call is just passed onto parent class and add bounds of quadratic
57 cuts*/
58 virtual bool get_bounds_info(Ipopt::Index n, Ipopt::Number* x_l, Ipopt::Number* x_u,
59 Ipopt::Index m, Ipopt::Number* g_l, Ipopt::Number* g_u);
60
61 virtual bool get_constraints_linearity(Ipopt::Index m, Ipopt::TNLP::LinearityType* const_types);
62
63 /** This call is just passed onto parent class and add
64 lambda for quadratic cuts*/
65 virtual bool get_starting_point(Ipopt::Index n, bool init_x, Ipopt::Number* x,
66 bool init_z, Ipopt::Number* z_L, Ipopt::Number* z_U,
67 Ipopt::Index m, bool init_lambda,
68 Ipopt::Number* lambda);
69
70 /** Method that returns scaling parameters (passed to parent all quadratic
71 not scaled).
72 */
73 virtual bool get_scaling_parameters(Ipopt::Number& obj_scaling,
74 bool& use_x_scaling, Ipopt::Index n,
75 Ipopt::Number* x_scaling,
76 bool& use_g_scaling, Ipopt::Index m,
77 Ipopt::Number* g_scaling);
78
79
80 /** Returns the value of the objective function in x*/
81 virtual bool eval_f(Ipopt::Index n, const Ipopt::Number* x, bool new_x,
82 Ipopt::Number& obj_value);
83
84 /** Returns the vector of the gradient of
85 * the objective w.r.t. x */
86 virtual bool eval_grad_f(Ipopt::Index n, const Ipopt::Number* x, bool new_x,
87 Ipopt::Number* grad_f);
88
89 /** Returns the vector of constraint values in x (appends constraint values for quadratics).*/
90 virtual bool eval_g(Ipopt::Index n, const Ipopt::Number* x, bool new_x,
91 Ipopt::Index m, Ipopt::Number* g);
92
93 /** Returns the jacobian of the
94 * constraints. The vectors iRow and jCol only need to be set
95 * once. The first call is used to set the structure only (iRow
96 * and jCol will be non-NULL, and values will be NULL) For
97 * subsequent calls, iRow and jCol will be NULL. */
98 virtual bool eval_jac_g(Ipopt::Index n, const Ipopt::Number* x, bool new_x,
99 Ipopt::Index m, Ipopt::Index nele_jac, Ipopt::Index* iRow,
100 Ipopt::Index *jCol, Ipopt::Number* values);
101 /** compute the value of a single constraint */
102 virtual bool eval_gi(Ipopt::Index n, const Ipopt::Number* x, bool new_x,
103 Ipopt::Index i, Ipopt::Number& gi);
104 /** compute the structure or values of the gradient for one
105 constraint */
106 virtual bool eval_grad_gi(Ipopt::Index n, const Ipopt::Number* x, bool new_x,
107 Ipopt::Index i, Ipopt::Index& nele_grad_gi, Ipopt::Index* jCol,
108 Ipopt::Number* values);
109 /** Return the hessian of the
110 * lagrangian. The vectors iRow and jCol only need to be set once
111 * (during the first call). The first call is used to set the
112 * structure only (iRow and jCol will be non-NULL, and values
113 * will be NULL) For subsequent calls, iRow and jCol will be
114 * NULL. This matrix is symmetric - specify the lower diagonal
115 * only */
116 virtual bool eval_h(Ipopt::Index n, const Ipopt::Number* x, bool new_x,
117 Ipopt::Number obj_factor, Ipopt::Index m, const Ipopt::Number* lambda,
118 bool new_lambda, Ipopt::Index nele_hess,
119 Ipopt::Index* iRow, Ipopt::Index* jCol, Ipopt::Number* values);
120 //@}
121
122
123 /** \name Cuts management. */
124 //@{
125
126
127 /** Add some linear or quadratic cuts to the problem formulation
128 if some of the OsiRowCuts are quadratic they will be well understood as long as safe is true.*/
129 void addCuts(const Cuts& cuts, bool safe);
130
131
132 /** Add some cuts to the problem formulaiton (handles Quadratics).*/
133 void addCuts(const OsiCuts &cuts);
134
135 /** Add some linear cuts to the problem formulation.*/
136 virtual void addCuts(unsigned int numberCuts, const OsiRowCut ** cuts);
137
138
139 /** Remove some cuts from the formulation */
140 void removeCuts(unsigned int number ,const int * toRemove);
141
142 //@}
143 //
144 /** Change objective to a linear one whith given objective function.*/
145 void set_linear_objective(int n_var, const double * obj, double c_0);
146
147 /** Reset objective to original one */
148 void reset_objective(){
149 obj_.clear();
150 }
151
152 protected:
153 /** Add some cuts to the problem formulaiton (handles Quadratics).*/
154 void addRowCuts(const OsiCuts &cuts, bool safe);
155 /**@name Default Compiler Generated Methods
156 * (Hidden to avoid implicit creation/calling).
157 * These methods are not implemented and
158 * we do not want the compiler to implement
159 * them for us, so we declare them private
160 * and do not define them. This ensures that
161 * they will not be implicitly created/called. */
162 //@{
163 /** Default Constructor */
164 TMINLP2TNLPQuadCuts();
165
166 /** Overloaded Equals Operator */
167 TMINLP2TNLPQuadCuts& operator=(const TMINLP2TNLP&);
168 //@}
169
170 private:
171 /** Some storage for quadratic cuts.*/
172 vector<QuadRow *> quadRows_;
173
174 /** Storage for the original hessian of the problem.*/
175 AdjustableMat H_;
176
177 /** print H_ for debug.*/
178 void printH();
179 /** Current umber of entries in the jacobian.*/
180 int curr_nnz_jac_;
181
182 /** Store user passed linear objective.*/
183 vector<double> obj_;
184 /** constant term in objective function.*/
185 double c_;
186 };
187
188 } // namespace Ipopt
189
190 #endif
191