1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
// Copyright (C) 2008, 2010 International Business Machines and others.
// All Rights Reserved.
// This code is published under the Eclipse Public License.
//
// Authors: Andreas Waechter IBM 2008-08-25
#ifndef __IPNLPBOUNDSREMOVER_HPP__
#define __IPNLPBOUNDSREMOVER_HPP__
#include "IpNLP.hpp"
namespace Ipopt
{
/** This is an adapter for an NLP that converts variable bound
* constraints to inequality constraints. This is necessary for
* the version of Ipopt that uses iterative linear solvers. At
* this point, none of the original inequality constraints is
* allowed to have both lower and upper bounds. The NLP visible to
* Ipopt via this adapter will not have any bounds on variables,
* but have equivalent inequality constraints.
*/
class NLPBoundsRemover: public NLP
{
public:
/**@name Constructors / Destructor */
///@{
/** The constructor is given the NLP of which the bounds are to be
* replaced by inequality constraints.
*/
NLPBoundsRemover(
NLP& nlp,
bool allow_twosided_inequalities = false
);
/** Destructor */
virtual ~NLPBoundsRemover()
{ }
///@}
/** @name NLP Initialization.*/
///@{
/** Overload if you want the chance to process options or parameters that
* may be specific to the NLP
*/
virtual bool ProcessOptions(
const OptionsList& options,
const std::string& prefix
)
{
return nlp_->ProcessOptions(options, prefix);
}
/** Method for creating the derived vector / matrix types. The
* Hess_lagrangian_space pointer can be NULL if a quasi-Newton
* options is chosen.
*/
virtual bool GetSpaces(
SmartPtr<const VectorSpace>& x_space,
SmartPtr<const VectorSpace>& c_space,
SmartPtr<const VectorSpace>& d_space,
SmartPtr<const VectorSpace>& x_l_space,
SmartPtr<const MatrixSpace>& px_l_space,
SmartPtr<const VectorSpace>& x_u_space,
SmartPtr<const MatrixSpace>& px_u_space,
SmartPtr<const VectorSpace>& d_l_space,
SmartPtr<const MatrixSpace>& pd_l_space,
SmartPtr<const VectorSpace>& d_u_space,
SmartPtr<const MatrixSpace>& pd_u_space,
SmartPtr<const MatrixSpace>& Jac_c_space,
SmartPtr<const MatrixSpace>& Jac_d_space,
SmartPtr<const SymMatrixSpace>& Hess_lagrangian_space
);
/** Method for obtaining the bounds information */
virtual bool GetBoundsInformation(
const Matrix& Px_L,
Vector& x_L,
const Matrix& Px_U,
Vector& x_U,
const Matrix& Pd_L,
Vector& d_L,
const Matrix& Pd_U,
Vector& d_U
);
/** Method for obtaining the starting point for all the iterates. */
// ToDo it might not make sense to ask for initial values for v_L and v_U?
virtual bool GetStartingPoint(
SmartPtr<Vector> x,
bool need_x,
SmartPtr<Vector> y_c,
bool need_y_c,
SmartPtr<Vector> y_d,
bool need_y_d,
SmartPtr<Vector> z_L,
bool need_z_L,
SmartPtr<Vector> z_U,
bool need_z_U
);
/** Method for obtaining an entire iterate as a warmstart point.
*
* The incoming IteratesVector has to be filled. This has not
* yet been implemented for this adapter.
*/
virtual bool GetWarmStartIterate(
IteratesVector& warm_start_iterate
)
{
return nlp_->GetWarmStartIterate(warm_start_iterate);
}
///@}
/** @name NLP evaluation routines. */
///@{
virtual bool Eval_f(
const Vector& x,
Number& f
)
{
return nlp_->Eval_f(x, f);
}
virtual bool Eval_grad_f(
const Vector& x,
Vector& g_f
)
{
return nlp_->Eval_grad_f(x, g_f);
}
virtual bool Eval_c(
const Vector& x,
Vector& c
)
{
return nlp_->Eval_c(x, c);
}
virtual bool Eval_jac_c(
const Vector& x,
Matrix& jac_c
)
{
return nlp_->Eval_jac_c(x, jac_c);
}
virtual bool Eval_d(
const Vector& x,
Vector& d
);
virtual bool Eval_jac_d(
const Vector& x,
Matrix& jac_d
);
virtual bool Eval_h(
const Vector& x,
Number obj_factor,
const Vector& yc,
const Vector& yd,
SymMatrix& h
);
///@}
/** @name NLP solution routines. */
///@{
virtual void FinalizeSolution(
SolverReturn status,
const Vector& x,
const Vector& z_L,
const Vector& z_U,
const Vector& c,
const Vector& d,
const Vector& y_c,
const Vector& y_d,
Number obj_value,
const IpoptData* ip_data,
IpoptCalculatedQuantities* ip_cq
);
virtual bool IntermediateCallBack(
AlgorithmMode mode,
Index iter,
Number obj_value,
Number inf_pr,
Number inf_du,
Number mu,
Number d_norm,
Number regularization_size,
Number alpha_du,
Number alpha_pr,
Index ls_trials,
const IpoptData* ip_data,
IpoptCalculatedQuantities* ip_cq
)
{
return nlp_->IntermediateCallBack(mode, iter, obj_value, inf_pr, inf_du, mu, d_norm, regularization_size,
alpha_du, alpha_pr, ls_trials, ip_data, ip_cq);
}
///@}
/** Routines to get the scaling parameters. */
///@{
virtual void GetScalingParameters(
const SmartPtr<const VectorSpace> x_space,
const SmartPtr<const VectorSpace> c_space,
const SmartPtr<const VectorSpace> d_space,
Number& obj_scaling,
SmartPtr<Vector>& x_scaling,
SmartPtr<Vector>& c_scaling,
SmartPtr<Vector>& d_scaling
) const;
///@}
virtual void GetQuasiNewtonApproximationSpaces(
SmartPtr<VectorSpace>& approx_space,
SmartPtr<Matrix>& P_approx
)
{
nlp_->GetQuasiNewtonApproximationSpaces(approx_space, P_approx);
}
/** Accessor method to the original NLP */
SmartPtr<NLP> nlp()
{
return nlp_;
}
private:
/**@name Default Compiler Generated Methods
* (Hidden to avoid implicit creation/calling).
*
* These methods are not implemented and
* we do not want the compiler to implement
* them for us, so we declare them private
* and do not define them. This ensures that
* they will not be implicitly created/called.
*/
///@{
/** Default Constructor */
NLPBoundsRemover();
/** Copy Constructor */
NLPBoundsRemover(
const NLPBoundsRemover&
);
/** Default Assignment Operator */
void operator=(
const NLPBoundsRemover&
);
///@}
/** Pointer to the original NLP */
SmartPtr<NLP> nlp_;
/** Pointer to the expansion matrix for the lower x bounds */
SmartPtr<const Matrix> Px_l_orig_;
/** Pointer to the expansion matrix for the upper x bounds */
SmartPtr<const Matrix> Px_u_orig_;
/** Pointer to the original d space */
SmartPtr<const VectorSpace> d_space_orig_;
/** Flag indicating whether twosided inequality constraints are allowed */
bool allow_twosided_inequalities_;
};
} // namespace Ipopt
#endif