source: trunk/Algorithm/IpAlgStrategy.hpp @ 2

Last change on this file since 2 was 2, checked in by andreasw, 15 years ago

Initial revision

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.1 KB
Line 
1// Copyright (C) 2004, International Business Machines and others.
2// All Rights Reserved.
3// This code is published under the Common Public License.
4//
5// $Id: IpAlgStrategy.hpp 2 2004-10-21 01:03:09Z andreasw $
6//
7// Authors:  Carl Laird, Andreas Waechter     IBM    2004-08-13
8
9#ifndef __IPALGSTRATEGY_HPP__
10#define __IPALGSTRATEGY_HPP__
11
12#include "IpUtils.hpp"
13#include "IpOptionsList.hpp"
14#include "IpJournalist.hpp"
15#include "IpIpoptCalculatedQuantities.hpp"
16
17namespace Ipopt
18{
19
20  /** This is the base class for all algorithm strategy objects.  The
21   *  AlgorithmStrategyObject base class implements a common interface
22   *  for all algorithm strategy objects.  A strategy object is a
23   *  component of the algorithm for which different alternatives or
24   *  implementations exists.  It allows to compose the algorithm
25   *  before execution for a particular configuration, without the
26   *  need to call alternatives based on enums. For example, the
27   *  LineSearch object is a strategy object, since different line
28   *  search options might be used for different runs.
29   *
30   *  This interface is used for
31   *  things that are done to all strategy objects, like
32   *  initialization and setting options.
33   */
34  class AlgorithmStrategyObject : public ReferencedObject
35  {
36  public:
37    /**@name Constructors/Destructors */
38    //@{
39    /** Default Constructor */
40    AlgorithmStrategyObject()
41        :
42        initialize_called_(false)
43    {}
44
45    /** Default Destructor */
46    virtual ~AlgorithmStrategyObject()
47    {}
48    //@}
49
50    /** @name Exceptions */
51    //@{
52    /** Exception FAILED_INITIALIZATION for problem during
53     *  initialization of a strategy object.  This is thrown by a
54     *  strategy object, if a problem arises during initialization,
55     *  such as a value out of a feasible range.
56     */
57    DECLARE_STD_EXCEPTION(FAILED_INITIALIZATION);
58    //@}
59
60    /** This method is called every time the algorithm starts again -
61     *  it is used to reset any internal state.  The pointers to the
62     *  Journalist, as well as to the IpoptNLP, IpoptData, and
63     *  IpoptCalculatedQuantities objects should be stored in the
64     *  instanciation of this base class.  This method is also used to
65     *  get all required user options from the OptionsList.  Here, if
66     *  prefix is given, each tag (identifying the options) is first
67     *  looked for with the prefix in front, and if not found, without
68     *  the prefix.  Note: you should not cue off of the iteration
69     *  count to indicate the "start" of an algorithm!
70     *
71     *  Do not overload this method, since it does some general
72     *  initialization that is common for all strategy objects.
73     *  Overload the protected InitializeImpl method instead.
74     */
75    bool Initialize(const Journalist& jnlst,
76                    IpoptNLP& ip_nlp,
77                    IpoptData& ip_data,
78                    IpoptCalculatedQuantities& ip_cq,
79                    const OptionsList& options,
80                    const std::string& prefix)
81    {
82      initialize_called_ = true;
83      // Copy the pointers for the problem defining objects
84      jnlst_ = &jnlst;
85      ip_nlp_ = &ip_nlp;
86      ip_data_ = &ip_data;
87      ip_cq_ = &ip_cq;
88
89      bool retval = InitializeImpl(options, prefix);
90      if (!retval) {
91        initialize_called_ = false;
92      }
93
94      return retval;
95    }
96
97  protected:
98    /** Implementation of the initialization method that has to be
99     *  overloaded by for each derived class. */
100    virtual bool InitializeImpl(const OptionsList& options,
101                                const std::string& prefix)=0;
102
103    /** @name Accessor methods for the problem defining objects.
104     *  Those should be used by the derived classes. */
105    //@{
106    const Journalist& Jnlst() const
107    {
108      DBG_ASSERT(initialize_called_);
109      return *jnlst_;
110    }
111    IpoptNLP& IpNLP() const
112    {
113      DBG_ASSERT(initialize_called_);
114      return *ip_nlp_;
115    }
116    IpoptData& IpData() const
117    {
118      DBG_ASSERT(initialize_called_);
119      return *ip_data_;
120    }
121    IpoptCalculatedQuantities& IpCq() const
122    {
123      DBG_ASSERT(initialize_called_);
124      return *ip_cq_;
125    }
126    //@}
127
128  private:
129    /**@name Default Compiler Generated Methods
130     * (Hidden to avoid implicit creation/calling).
131     * These methods are not implemented and
132     * we do not want the compiler to implement
133     * them for us, so we declare them private
134     * and do not define them. This ensures that
135     * they will not be implicitly created/called. */
136    //@{
137    /** Default Constructor */
138    //AlgorithmStrategyObject();
139
140
141    /** Copy Constructor */
142    AlgorithmStrategyObject(const AlgorithmStrategyObject&);
143
144    /** Overloaded Equals Operator */
145    void operator=(const AlgorithmStrategyObject&);
146    //@}
147
148    /** @name Pointers to objects defining a particular optimization
149     *  problem */
150    //@{
151    SmartPtr<const Journalist> jnlst_;
152    SmartPtr<IpoptNLP> ip_nlp_;
153    SmartPtr<IpoptData> ip_data_;
154    SmartPtr<IpoptCalculatedQuantities> ip_cq_;
155    //@}
156
157    /** flag indicating if Initialize method has been called (for
158     *  debugging) */
159    bool initialize_called_;
160  };
161
162} // namespace Ipopt
163
164#endif
Note: See TracBrowser for help on using the repository browser.