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
|
// Copyright (C) 2004, 2006 International Business Machines and others.
// All Rights Reserved.
// This code is published under the Eclipse Public License.
//
// $Id: IpAlgStrategy.hpp 1861 2010-12-21 21:34:47Z andreasw $
//
// Authors: Carl Laird, Andreas Waechter IBM 2004-08-13
#ifndef __IPALGSTRATEGY_HPP__
#define __IPALGSTRATEGY_HPP__
#include "IpOptionsList.hpp"
#include "IpJournalist.hpp"
#include "IpIpoptCalculatedQuantities.hpp"
#include "IpIpoptNLP.hpp"
#include "IpIpoptData.hpp"
namespace Ipopt
{
/** This is the base class for all algorithm strategy objects. The
* AlgorithmStrategyObject base class implements a common interface
* for all algorithm strategy objects. A strategy object is a
* component of the algorithm for which different alternatives or
* implementations exists. It allows to compose the algorithm
* before execution for a particular configuration, without the
* need to call alternatives based on enums. For example, the
* LineSearch object is a strategy object, since different line
* search options might be used for different runs.
*
* This interface is used for
* things that are done to all strategy objects, like
* initialization and setting options.
*/
class AlgorithmStrategyObject : public ReferencedObject
{
public:
/**@name Constructors/Destructors */
//@{
/** Default Constructor */
AlgorithmStrategyObject()
:
initialize_called_(false)
{}
/** Default Destructor */
virtual ~AlgorithmStrategyObject()
{}
//@}
/** This method is called every time the algorithm starts again -
* it is used to reset any internal state. The pointers to the
* Journalist, as well as to the IpoptNLP, IpoptData, and
* IpoptCalculatedQuantities objects should be stored in the
* instanciation of this base class. This method is also used to
* get all required user options from the OptionsList. Here, if
* prefix is given, each tag (identifying the options) is first
* looked for with the prefix in front, and if not found, without
* the prefix. Note: you should not cue off of the iteration
* count to indicate the "start" of an algorithm!
*
* Do not overload this method, since it does some general
* initialization that is common for all strategy objects.
* Overload the protected InitializeImpl method instead.
*/
bool Initialize(const Journalist& jnlst,
IpoptNLP& ip_nlp,
IpoptData& ip_data,
IpoptCalculatedQuantities& ip_cq,
const OptionsList& options,
const std::string& prefix)
{
initialize_called_ = true;
// Copy the pointers for the problem defining objects
jnlst_ = &jnlst;
ip_nlp_ = &ip_nlp;
ip_data_ = &ip_data;
ip_cq_ = &ip_cq;
bool retval = InitializeImpl(options, prefix);
if (!retval) {
initialize_called_ = false;
}
return retval;
}
/** Reduced version of the Initialize method, which does not
* require special Ipopt information. This is useful for
* algorithm objects that could be used outside Ipopt, such as
* linear solvers. */
bool ReducedInitialize(const Journalist& jnlst,
const OptionsList& options,
const std::string& prefix)
{
initialize_called_ = true;
// Copy the pointers for the problem defining objects
jnlst_ = &jnlst;
ip_nlp_ = NULL;
ip_data_ = NULL;
ip_cq_ = NULL;
bool retval = InitializeImpl(options, prefix);
if (!retval) {
initialize_called_ = false;
}
return retval;
}
protected:
/** Implementation of the initialization method that has to be
* overloaded by for each derived class. */
virtual bool InitializeImpl(const OptionsList& options,
const std::string& prefix)=0;
/** @name Accessor methods for the problem defining objects.
* Those should be used by the derived classes. */
//@{
const Journalist& Jnlst() const
{
DBG_ASSERT(initialize_called_);
return *jnlst_;
}
IpoptNLP& IpNLP() const
{
DBG_ASSERT(initialize_called_);
DBG_ASSERT(IsValid(ip_nlp_));
return *ip_nlp_;
}
IpoptData& IpData() const
{
DBG_ASSERT(initialize_called_);
DBG_ASSERT(IsValid(ip_data_));
return *ip_data_;
}
IpoptCalculatedQuantities& IpCq() const
{
DBG_ASSERT(initialize_called_);
DBG_ASSERT(IsValid(ip_cq_));
return *ip_cq_;
}
bool HaveIpData() const
{
return IsValid(ip_data_);
}
//@}
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 */
//AlgorithmStrategyObject();
/** Copy Constructor */
AlgorithmStrategyObject(const AlgorithmStrategyObject&);
/** Overloaded Equals Operator */
void operator=(const AlgorithmStrategyObject&);
//@}
/** @name Pointers to objects defining a particular optimization
* problem */
//@{
SmartPtr<const Journalist> jnlst_;
SmartPtr<IpoptNLP> ip_nlp_;
SmartPtr<IpoptData> ip_data_;
SmartPtr<IpoptCalculatedQuantities> ip_cq_;
//@}
/** flag indicating if Initialize method has been called (for
* debugging) */
bool initialize_called_;
};
} // namespace Ipopt
#endif
|