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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
// Copyright (C) 2004, 2010 International Business Machines and others.
// All Rights Reserved.
// This code is published under the Eclipse Public License.
//
// Authors: Carl Laird, Andreas Waechter IBM 2004-08-13
#ifndef __IPIPOPTAPPLICATION_HPP__
#define __IPIPOPTAPPLICATION_HPP__
#include <iostream>
#include "IpJournalist.hpp"
#include "IpTNLP.hpp"
#include "IpNLP.hpp"
#include "IpReturnCodes.hpp"
namespace Ipopt
{
DECLARE_STD_EXCEPTION(IPOPT_APPLICATION_ERROR);
/* forward declarations */
class IpoptAlgorithm;
class IpoptNLP;
class IpoptData;
class IpoptCalculatedQuantities;
class AlgorithmBuilder;
class RegisteredOptions;
class OptionsList;
class SolveStatistics;
/** This is the main application class for making calls to Ipopt. */
class IPOPTLIB_EXPORT IpoptApplication: public ReferencedObject
{
public:
IpoptApplication(
bool create_console_out = true,
bool create_empty = false
);
/** Another constructor that assumes that the code in the
* (default) constructor has already been executed
*/
IpoptApplication(
SmartPtr<RegisteredOptions> reg_options,
SmartPtr<OptionsList> options,
SmartPtr<Journalist> jnlst
);
virtual ~IpoptApplication();
/** Method for creating a new IpoptApplication that uses the same
* journalist and registered options, and a copy of the options list.
*/
virtual SmartPtr<IpoptApplication> clone();
/** Initialization method.
*
* This method reads options from the
* input stream and initializes the journalists.
*
* @return Solve_Succeeded or something else if there was a
* problem in the initialization (such as an invalid option).
*
* You should call one of the initialization methods at some
* point before the first optimize call.
* Set @par allow_clobber to true if you want to allow
* overwriting options that are set by the input stream.
*/
virtual ApplicationReturnStatus Initialize(
std::istream& is,
bool allow_clobber = false
);
/** Initialization method.
*
* This method reads options from the
* params file and initializes the journalists.
* @return Solve_Succeeded or something else if there was a
* problem in the initialization (such as an invalid option).
* You should call one of the initialization methods at some
* point before the first optimize call.
*
* @note You can skip the processing of a params file by
* setting params_file to "".
*
* Set @par allow_clobber to true if you want to allow
* overwriting options that are set by the params file.
*/
virtual ApplicationReturnStatus Initialize(
std::string params_file,
bool allow_clobber = false
);
/** Initialization method.
*
* This method reads options from the
* params file and initializes the journalists.
* @return Solve_Succeeded or something else if there was a
* problem in the initialization (such as an invalid option).
*
* You should call one of the initialization methods at some
* point before the first optimize call.
*
* @note You can skip the processing of a params file by
* setting params_file to "".
*
* Set @par allow_clobber to true if you want to allow
* overwriting options that are set by the params file.
*/
virtual ApplicationReturnStatus Initialize(
const char* params_file,
bool allow_clobber = false
)
{
return Initialize(std::string(params_file), allow_clobber);
}
/** Initialize method.
*
* This method reads the options file specified
* by the option_file_name option and initializes the journalists.
* @return Solve_Succeeded or something else if there was a
* problem in the initialization (such as an invalid option).
* You should call this method at some point before the first optimize
* call.
* Set @par allow_clobber to true if you want to allow
* overwriting options that are set by the options file.
*/
virtual ApplicationReturnStatus Initialize(
bool allow_clobber = false
);
/**@name Solve methods */
///@{
/** Solve a problem that inherits from TNLP */
virtual ApplicationReturnStatus OptimizeTNLP(
const SmartPtr<TNLP>& tnlp
);
/** Solve a problem that inherits from NLP */
virtual ApplicationReturnStatus OptimizeNLP(
const SmartPtr<NLP>& nlp
);
/** Solve a problem that inherits from NLP */
virtual ApplicationReturnStatus OptimizeNLP(
const SmartPtr<NLP>& nlp,
SmartPtr<AlgorithmBuilder>& alg_builder
);
/** Solve a problem (that inherits from TNLP) for a repeated time.
*
* The OptimizeTNLP method must have been called before. The
* TNLP must be the same object. The IpoptAlgorithm object from the
* previous solve will be reused.
*/
virtual ApplicationReturnStatus ReOptimizeTNLP(
const SmartPtr<TNLP>& tnlp
);
/** Solve a problem (that inherits from NLP) for a repeated time.
*
* The OptimizeNLP method must have been called before. The
* NLP must be the same object. The IpoptAlgorithm object from the
* previous solve will be reused.
*/
virtual ApplicationReturnStatus ReOptimizeNLP(
const SmartPtr<NLP>& nlp
);
///@}
/** Method for opening an output file with given print_level.
*
* @return false if there was a problem
*/
virtual bool OpenOutputFile(
std::string file_name, /**< name of file to open */
EJournalLevel print_level, /**< print level to be used */
bool file_append = false /**< whether to append to file or truncate (since 3.14.13) */
);
/**@name Accessor methods */
///@{
/** Get the Journalist for printing output */
virtual SmartPtr<Journalist> Jnlst()
{
return jnlst_;
}
/** Get a pointer to RegisteredOptions object to add new options */
virtual SmartPtr<RegisteredOptions> RegOptions()
{
return reg_options_;
}
/** Get the options list for setting options */
virtual SmartPtr<OptionsList> Options()
{
return options_;
}
/** Get the options list for setting options (const version) */
virtual SmartPtr<const OptionsList> Options() const
{
return ConstPtr(options_);
}
/** Get the object with the statistics about the most recent
* optimization run.
*
* @note Statistics are not available if optimization terminated
* with a serious problem, that is, an ApplicationReturnStatus of
* Not_Enough_Degrees_Of_Freedom or lower.
*/
virtual SmartPtr<SolveStatistics> Statistics();
/** Get the IpoptNLP Object */
virtual SmartPtr<IpoptNLP> IpoptNLPObject();
/** Get the IpoptData Object */
SmartPtr<IpoptData> IpoptDataObject();
/** Get the IpoptCQ Object */
virtual SmartPtr<IpoptCalculatedQuantities> IpoptCQObject();
/** Get the Algorithm Object */
SmartPtr<IpoptAlgorithm> AlgorithmObject();
///@}
/** Method for printing Ipopt copyright message now instead of
* just before the optimization.
*
* If you want to have the copy right message printed earlier
* than by default, call this method at the convenient time.
*/
void PrintCopyrightMessage();
/** Method to set whether non-ipopt non-bad_alloc non-overflow_error exceptions
* are rethrown by Ipopt.
*
* By default, non-Ipopt and non-bad_alloc and non-overflow_error exceptions are
* caught by Ipopts initialization and optimization methods
* and the status NonIpopt_Exception_Thrown is returned.
* This function allows to enable rethrowing of such exceptions.
*
* @return Returns whether non-ipopt exceptions were rethrown before.
*/
bool RethrowNonIpoptException(
bool dorethrow
)
{
bool oldval = rethrow_nonipoptexception_;
rethrow_nonipoptexception_ = dorethrow;
return oldval;
}
static void RegisterOptions(
SmartPtr<RegisteredOptions> roptions
);
/** Method to register all Ipopt options. */
static void
RegisterAllIpoptOptions(
const SmartPtr<RegisteredOptions>& roptions
);
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. */
///@{
/** Copy Constructor */
IpoptApplication(
const IpoptApplication&
);
/** Default Assignment Operator */
void operator=(
const IpoptApplication&
);
///@}
/** Method for the actual optimize call of the Ipopt algorithm.
*
* This is used both for Optimize and ReOptimize
*/
ApplicationReturnStatus call_optimize();
/**@name Variables that customize the application behavior */
///@{
/** Decide whether or not the ipopt.opt file should be read */
bool read_params_dat_;
/** Decide whether non-ipopt non-bad_alloc non-overflow_error exceptions should be rethrown */
bool rethrow_nonipoptexception_;
///@}
/** Journalist for reporting output */
SmartPtr<Journalist> jnlst_;
/** RegisteredOptions */
SmartPtr<RegisteredOptions> reg_options_;
/** OptionsList used for the application */
SmartPtr<OptionsList> options_;
/** Object for storing statistics about the most recent
* optimization run.
*/
SmartPtr<SolveStatistics> statistics_;
/** Object with the algorithm skeleton.
*/
SmartPtr<IpoptAlgorithm> alg_;
/** IpoptNLP Object for the NLP.
*
* We keep this around for a ReOptimize warm start.
*/
SmartPtr<IpoptNLP> ip_nlp_;
/** IpoptData Object for the NLP.
*
* We keep this around for a ReOptimize warm start.
*/
SmartPtr<IpoptData> ip_data_;
/** IpoptCalculatedQuantities Object for the NLP.
*
* We keep this around for a ReOptimize warm start.
*/
SmartPtr<IpoptCalculatedQuantities> ip_cq_;
/** Pointer to the TNLPAdapter used to convert the TNLP to an NLP.
*
* We keep this around for the ReOptimizerTNLP call.
*/
SmartPtr<NLP> nlp_adapter_;
/** @name Algorithmic parameters */
///@{
/** Flag indicating if we are to use the inexact linear solver option */
bool inexact_algorithm_;
/** Flag indicating if all bounds should be replaced by inequality
* constraints.
*
* This is necessary for the inexact algorithm.
*/
bool replace_bounds_;
///@}
};
} // namespace Ipopt
extern "C" IPOPTLIB_EXPORT class Ipopt::IpoptApplication* IPOPT_CALLCONV IpoptApplicationFactory();
#endif