summaryrefslogtreecommitdiff
path: root/thirdparty/linux/include/coin/coin/IpAlgBuilder.hpp
blob: 05692bbc664f95f199baf95922e6eb8fbb24aa64 (plain)
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
// Copyright (C) 2004, 2007 International Business Machines and others.
// All Rights Reserved.
// This code is published under the Eclipse Public License.
//
// $Id: IpAlgBuilder.hpp 2666 2016-07-20 16:02:55Z stefan $
//
// Authors:  Carl Laird, Andreas Waechter     IBM    2004-09-29

#ifndef __IPALGBUILDER_HPP__
#define __IPALGBUILDER_HPP__

#include "IpIpoptAlg.hpp"
#include "IpReferenced.hpp"
#include "IpAugSystemSolver.hpp"
#include "IpPDSystemSolver.hpp"

namespace Ipopt
{

  // forward declarations
  class IterationOutput;
  class HessianUpdater;
  class ConvergenceCheck;
  class SearchDirectionCalculator;
  class EqMultiplierCalculator;
  class IterateInitializer;
  class LineSearch;
  class MuUpdate;

  /** Builder for creating a complete IpoptAlg object.  This object
   *  contains all subelements (such as line search objects etc).  How
   *  the resulting IpoptAlg object is built can be influenced by the
   *  options.
   *
   *  More advanced customization can be achieved by subclassing this
   *  class and overloading the virtual methods that build the
   *  individual parts. The advantage of doing this is that it allows
   *  one to reuse the extensive amount of options processing that
   *  takes place, for instance, when generating the symmetric linear
   *  system solver. Another method for customizing the algorithm is
   *  using the optional custom_solver argument, which allows the
   *  expert user to provide a specialized linear solver for the
   *  augmented system (e.g., type GenAugSystemSolver), possibly for
   *  user-defined matrix objects. The optional custom_solver constructor
   *  argument is likely obsolete, however, as more control over this
   *  this process can be achieved by implementing a subclass of this
   *  AlgBuilder (e.g., by overloading the AugSystemSolverFactory method).
   */
  class AlgorithmBuilder : public ReferencedObject
  {
  public:
    /**@name Constructors/Destructors */
    //@{
    /** Constructor */
    AlgorithmBuilder(SmartPtr<AugSystemSolver> custom_solver=NULL);

    /** Destructor */
    virtual ~AlgorithmBuilder()
    {}

    //@}

    /** Methods for IpoptTypeInfo */
    //@{
    /** register the options used by the algorithm builder */
    static void RegisterOptions(SmartPtr<RegisteredOptions> roptions);
    //@}

    /** @name Convenience methods for building solvers without having
     *  to duplicate the significant amount of preprocessor flag and
     *  option checking that takes place. These solvers are used to
     *  create a number of core algorithm components across the
     *  different Build* methods, but depending on what options are
     *  chosen, the first method requiring the solver to be used can
     *  vary. Therefore, each of the Factory methods below is paired
     *  with a Getter method, which is called by all parts of this
     *  algorithm builder to ensure the Factory is only called once. */
    //@{

    /** Create a solver that can be used to solve a symmetric linear
     *  system.
     *  Dependencies: None
     */
    virtual SmartPtr<SymLinearSolver>
        SymLinearSolverFactory(const Journalist& jnlst,
                               const OptionsList& options,
                               const std::string& prefix);

    /** Get the symmetric linear system solver for this
     *  algorithm. This method will call the SymLinearSolverFactory
     *  exactly once (the first time it is used), and store its
     *  instance on SymSolver_ for use in subsequent calls.
     */
    SmartPtr<SymLinearSolver> GetSymLinearSolver(const Journalist& jnlst,
                                                 const OptionsList& options,
                                                 const std::string& prefix);

    /** Create a solver that can be used to solve an
     *  augmented system.
     *  Dependencies:
     *     -> GetSymLinearSolver()
     *         -> SymLinearSolverFactory()
     *     -> custom_solver_
     */
    virtual SmartPtr<AugSystemSolver>
        AugSystemSolverFactory(const Journalist& jnlst,
                               const OptionsList& options,
                               const std::string& prefix);

    /** Get the augmented system solver for this algorithm. This
     *  method will call the AugSystemSolverFactory exactly once (the
     *  first time it is used), and store its instance on AugSolver_
     *  for use in subsequent calls.
     */
    SmartPtr<AugSystemSolver> GetAugSystemSolver(const Journalist& jnlst,
                                                 const OptionsList& options,
                                                 const std::string& prefix);

    /** Create a solver that can be used to solve a
     *  primal-dual system.
     *  Dependencies:
     *     -> GetAugSystemSolver()
     *         -> AugSystemSolverFactory()
     *             -> GetSymLinearSolver()
     *                 -> SymLinearSolverFactory()
     *             -> custom_solver_
     */
    virtual SmartPtr<PDSystemSolver>
        PDSystemSolverFactory(const Journalist& jnlst,
                              const OptionsList& options,
                              const std::string& prefix);

    /** Get the primal-dual system solver for this algorithm. This
     *  method will call the PDSystemSolverFactory exactly once (the
     *  first time it is used), and store its instance on PDSolver_
     *  for use in subsequent calls.
     */
    SmartPtr<PDSystemSolver> GetPDSystemSolver(const Journalist& jnlst,
                                               const OptionsList& options,
                                               const std::string& prefix);
    //@}

    /** @name Methods to build parts of the algorithm */
    //@{
    /** Allocates memory for the IpoptNLP, IpoptData, and
     *  IpoptCalculatedQuanties arguments.
     *  Dependencies: None
     */
    virtual void BuildIpoptObjects(const Journalist& jnlst,
                                   const OptionsList& options,
                                   const std::string& prefix,
                                   const SmartPtr<NLP>& nlp,
                                   SmartPtr<IpoptNLP>& ip_nlp,
                                   SmartPtr<IpoptData>& ip_data,
                                   SmartPtr<IpoptCalculatedQuantities>& ip_cq);

    /** Creates an instance of the IpoptAlgorithm class by building
     *  each of its required constructor arguments piece-by-piece. The
     *  default algorithm can be customized by overloading this method
     *  or by overloading one or more of the Build* methods called in
     *  this method's default implementation. Additional control can
     *  be achieved by overloading any of the *SolverFactory methods.
     *  This method will call (in this order):
     *     -> BuildIterationOutput()
     *     -> BuildHessianUpdater()
     *     -> BuildConvergenceCheck()
     *     -> BuildSearchDirectionCalculator()
     *     -> BuildEqMultiplierCalculator()
     *     -> BuildIterateInitializer()
     *     -> BuildLineSearch()
     *     -> BuildMuUpdate()
     */
    virtual SmartPtr<IpoptAlgorithm> BuildBasicAlgorithm(const Journalist& jnlst,
        const OptionsList& options,
        const std::string& prefix);

    /** Creates an instance of the IterationOutput class. This method
     *  is called in the default implementation of
     *  BuildBasicAlgorithm. It can be overloaded to customize that
     *  portion the default algorithm.
     *  Dependencies: None
     */
    virtual SmartPtr<IterationOutput>
        BuildIterationOutput(const Journalist& jnlst,
                             const OptionsList& options,
                             const std::string& prefix);

    /** Creates an instance of the HessianUpdater class. This method
     *  is called in the default implementation of
     *  BuildBasicAlgorithm.  It can be overloaded to customize that
     *  portion the default algorithm.
     *  Dependencies: None
     */
    virtual SmartPtr<HessianUpdater>
        BuildHessianUpdater(const Journalist& jnlst,
                            const OptionsList& options,
                            const std::string& prefix);

    /** Creates an instance of the ConvergenceCheck class. This method
     *  is called in the default implementation of
     *  BuildBasicAlgorithm.  It can be overloaded to customize that
     *  portion the default algorithm.
     *  Dependencies: None
     */
    virtual SmartPtr<ConvergenceCheck>
        BuildConvergenceCheck(const Journalist& jnlst,
                              const OptionsList& options,
                              const std::string& prefix);

    /** Creates an instance of the SearchDirectionCalculator
     *  class. This method is called in the default implementation of
     *  BuildBasicAlgorithm.  It can be overloaded to customize that
     *  portion the default algorithm.
     *  Dependencies:
     *     -> GetPDSystemSolver()
     *         -> PDSystemSolverFactory()
     *             -> GetAugSystemSolver()
     *                 -> AugSystemSolverFactory()
     *                     -> GetSymLinearSolver()
     *                         -> SymLinearSolverFactory()
     *                     -> custom_solver_
     */
     virtual SmartPtr<SearchDirectionCalculator>
        BuildSearchDirectionCalculator(const Journalist& jnlst,
                                       const OptionsList& options,
                                       const std::string& prefix);

    /** Creates an instance of the EqMultiplierCalculator class. This
     *  method is called in the default implementation of
     *  BuildBasicAlgorithm.  It can be overloaded to customize that
     *  portion the default algorithm.
     *  Dependencies:
     *     -> GetAugSystemSolver()
     *         -> AugSystemSolverFactory()
     *             -> GetSymLinearSolver()
     *                 -> SymLinearSolverFactory()
     *             -> custom_solver_
     */
    virtual SmartPtr<EqMultiplierCalculator>
        BuildEqMultiplierCalculator(const Journalist& jnlst,
                                    const OptionsList& options,
                                    const std::string& prefix);

    /** Creates an instance of the IterateInitializer class. This
     *  method is called in the default implementation of
     *  BuildBasicAlgorithm.  It can be overloaded to customize that
     *  portion the default algorithm.
     *  Dependencies:
     *     -> EqMultCalculator_
     *     -> GetAugSystemSolver()
     *         -> AugSystemSolverFactory()
     *             -> GetSymLinearSolver()
     *                 -> SymLinearSolverFactory()
     *             -> custom_solver_
     */
    virtual SmartPtr<IterateInitializer>
        BuildIterateInitializer(const Journalist& jnlst,
                                const OptionsList& options,
                                const std::string& prefix);

    /** Creates an instance of the LineSearch class. This method is
     *  called in the default implementation of BuildBasicAlgorithm.
     *  It can be overloaded to customize that portion the default
     *  algorithm.
     *  Dependencies:
     *     -> EqMultCalculator_
     *     -> ConvCheck_
     *     -> GetAugSystemSolver()
     *         -> AugSystemSolverFactory()
     *             -> GetSymLinearSolver()
     *                 -> SymLinearSolverFactory()
     *             -> custom_solver_
     *     -> GetPDSystemSolver()
     *         -> PDSystemSolverFactory()
     *             -> GetAugSystemSolver()
     *                 -> AugSystemSolverFactory()
     *                     -> GetSymLinearSolver()
     *                         -> SymLinearSolverFactory()
     *                     -> custom_solver_
     */
    virtual SmartPtr<LineSearch> BuildLineSearch(const Journalist& jnlst,
                                                 const OptionsList& options,
                                                 const std::string& prefix);

    /** Creates an instance of the MuUpdate class. This method is
     *  called in the default implementation of BuildBasicAlgorithm.
     *  It can be overloaded to customize that portion the default
     *  algorithm.
     *  Dependencies:
     *     -> LineSearch_
     *         -> EqMultCalculator_
     *         -> ConvCheck_
     *     -> GetPDSystemSolver()
     *         -> PDSystemSolverFactory()
     *             -> GetAugSystemSolver()
     *                 -> AugSystemSolverFactory()
     *                     -> GetSymLinearSolver()
     *                         -> SymLinearSolverFactory()
     *                     -> custom_solver_
     */
    virtual SmartPtr<MuUpdate> BuildMuUpdate(const Journalist& jnlst,
                                             const OptionsList& options,
                                             const std::string& prefix);
    //@}

  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 */
    //AlgorithmBuilder();

    /** Copy Constructor */
    AlgorithmBuilder(const AlgorithmBuilder&);

    /** Overloaded Equals Operator */
    void operator=(const AlgorithmBuilder&);
    //@}

    /** @name IpoptAlgorithm constructor arguments.
     *  These components are built in separate Build
     *  methods in the order defined by BuildBasicAlgorithm.
     *  A single core component may require one or more
     *  other core components in its constructor, so the
     *  this class holds pointers to each component for use
     *  between the separate Build methods. */
    //@{
    SmartPtr<IterationOutput> IterOutput_;
    SmartPtr<HessianUpdater> HessUpdater_;
    SmartPtr<ConvergenceCheck> ConvCheck_;
    SmartPtr<SearchDirectionCalculator> SearchDirCalc_;
    SmartPtr<EqMultiplierCalculator> EqMultCalculator_;
    SmartPtr<IterateInitializer> IterInitializer_;
    SmartPtr<LineSearch> LineSearch_;
    SmartPtr<MuUpdate> MuUpdate_;
    //@}

    /** @name Commonly used solver components
     *  for building core algorithm components. Each
     *  of these members is paired with a Factory/Getter
     *  method. */
    //@{
    SmartPtr<SymLinearSolver> SymSolver_;
    SmartPtr<AugSystemSolver> AugSolver_;
    SmartPtr<PDSystemSolver> PDSolver_;
    //@}

    /** Optional pointer to AugSystemSolver.  If this is set in the
     *  contructor, we will use this to solve the linear systems. */
    SmartPtr<AugSystemSolver> custom_solver_;

  };
} // namespace Ipopt

#endif