source: trunk/Algorithm/IpIpoptData.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: 15.8 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: IpIpoptData.hpp 2 2004-10-21 01:03:09Z andreasw $
6//
7// Authors:  Carl Laird, Andreas Waechter     IBM    2004-08-13
8
9#ifndef __IPIPOPTDATA_HPP__
10#define __IPIPOPTDATA_HPP__
11
12#include "IpUtils.hpp"
13#include "IpSmartPtr.hpp"
14#include "IpVector.hpp"
15#include "IpSymMatrix.hpp"
16#include "IpReferenced.hpp"
17#include "IpOptionsList.hpp"
18
19namespace Ipopt
20{
21  /* Forward declaration */
22  class IpoptNLP;
23
24  /** Class to organize all the data required by the algorithm.
25   *  Internally, once this Data object has been initialized, all
26   *  internal curr_ vectors must always be set (so that prototyes are
27   *  available).  The current values can only be set from the trial
28   *  values.  The trial values can be set by copying from a vector or
29   *  by adding some fraction of a step to the current values.  This
30   *  object also stores steps, which allows to easily communicate the
31   *  step from the step computation object to the line search object.
32   */
33  class IpoptData : public ReferencedObject
34  {
35  public:
36    /**@name Constructors/Destructors */
37    //@{
38    /** Constructor */
39    IpoptData();
40
41    /** Default destructor */
42    ~IpoptData();
43    //@}
44
45    /** Initialize Data Structures */
46    bool InitializeDataStructures(IpoptNLP& ip_nlp,
47                                  bool want_x,
48                                  bool want_y_c,
49                                  bool want_y_d,
50                                  bool want_z_L,
51                                  bool want_z_U,
52                                  bool want_v_L,
53                                  bool want_v_U);
54
55    /** This method must be called to initialize the global
56     *  algorithmic parameters.  The parameters are taken from the
57     *  OptionsList object. */
58    bool Initialize(const Journalist& jnlst,
59                    const OptionsList& options,
60                    const std::string& prefix);
61
62    /** @name Get Methods for Iterates */
63    //@{
64    /** Main iteration variables
65     * (current iteration) */
66    SmartPtr<const Vector> curr_x()
67    {
68      DBG_ASSERT(IsValid(curr_x_));
69      return curr_x_;
70    }
71
72    /** Main iteration variables
73     *  (trial calculations) */
74    SmartPtr<const Vector> trial_x()
75    {
76      DBG_ASSERT(IsValid(trial_x_));
77      return trial_x_;
78    }
79
80    /** Slacks from inequality constraints
81     *  (current iteration) */
82    SmartPtr<const Vector> curr_s()
83    {
84      DBG_ASSERT(IsValid(curr_s_));
85      return curr_s_;
86    }
87
88    /** Slacks from inequality constraints
89     *  (trial calculations) */
90    SmartPtr<const Vector> trial_s()
91    {
92      DBG_ASSERT(IsValid(trial_s_));
93      return trial_s_;
94    }
95
96    /** Multipliers for equality constraints
97     *  (current iteration) */
98    SmartPtr<const Vector> curr_y_c()
99    {
100      DBG_ASSERT(IsValid(curr_y_c_));
101      return curr_y_c_;
102    }
103
104    /** Multipliers for equality constraints
105     *  (trial iteration) */
106    SmartPtr<const Vector> trial_y_c()
107    {
108      DBG_ASSERT(IsValid(trial_y_c_));
109      return trial_y_c_;
110    }
111
112    /** Multipliers for the inequality constraints
113     *  - Note, inequalities made equality
114     *  by introduction of slacks)
115     *  (current iteration) */
116    SmartPtr<const Vector> curr_y_d()
117    {
118      DBG_ASSERT(IsValid(curr_y_d_));
119      return curr_y_d_;
120    }
121
122    /** Multipliers for the inequality constraints
123     *  - Note, inequalities made equality
124     *  by introduction of slacks)
125     *  (trial calculations) */
126    SmartPtr<const Vector> trial_y_d()
127    {
128      DBG_ASSERT(IsValid(trial_y_d_));
129      return trial_y_d_;
130    }
131
132    /** Multipliers for the lower bound on x
133     *  (current iteration) */
134    SmartPtr<const Vector> curr_z_L()
135    {
136      DBG_ASSERT(IsValid(curr_z_L_));
137      return curr_z_L_;
138    }
139
140    /** Multipliers for the lower bound on x
141     *  (trial calculations) */
142    SmartPtr<const Vector> trial_z_L()
143    {
144      DBG_ASSERT(IsValid(trial_z_L_));
145      return trial_z_L_;
146    }
147
148    /** Multipliers for the upper bound on x
149     *  (current iteration) */
150    SmartPtr<const Vector> curr_z_U()
151    {
152      DBG_ASSERT(IsValid(curr_z_U_));
153      return curr_z_U_;
154    }
155
156    /** Multipliers for the upper bound on x
157     * (trial calculations) */
158    SmartPtr<const Vector> trial_z_U()
159    {
160      DBG_ASSERT(IsValid(trial_z_L_));
161      return trial_z_U_;
162    }
163
164    /** Multipliers for the lower bound on s
165     *  (current iteration) */
166    SmartPtr<const Vector> curr_v_L()
167    {
168      DBG_ASSERT(IsValid(curr_v_L_));
169      return curr_v_L_;
170    }
171
172    /** Multipliers for the lower bound on s
173     *  (trial calculations) */
174    SmartPtr<const Vector> trial_v_L()
175    {
176      DBG_ASSERT(IsValid(trial_v_L_));
177      return trial_v_L_;
178    }
179
180    /** Multipliers for the upper bound on s
181     *  (current iteration) */
182    SmartPtr<const Vector> curr_v_U()
183    {
184      DBG_ASSERT(IsValid(curr_v_U_));
185      return curr_v_U_;
186    }
187
188    /** Multipliers for the upper bound on s
189     * (trial calculations) */
190    SmartPtr<const Vector> trial_v_U()
191    {
192      DBG_ASSERT(IsValid(trial_v_U_));
193      return trial_v_U_;
194    }
195
196    /** Hessian or Hessian approximation (do not hold on to it, it might be changed) */
197    SmartPtr<const SymMatrix> W()
198    {
199      DBG_ASSERT(IsValid(W_));
200      return W_;
201    }
202
203    /** Set Hessian approximation */
204    void Set_W(SmartPtr<const SymMatrix> W)
205    {
206      W_ = W;
207      ;
208    }
209
210    /** @name ("Main") Search direction.  They are used to store the
211     *  search directions computed from solving the primal-dual
212     *  system, and can be used in the line search.  They are
213     *  overwritten in every iteration, so do not hold on to the
214     *  pointers (make copies instead)*/
215    //@{
216    SmartPtr<const Vector> delta_x()
217    {
218      return ConstPtr(delta_x_);
219    }
220
221    SmartPtr<const Vector> delta_s()
222    {
223      return ConstPtr(delta_s_);
224    }
225
226    SmartPtr<const Vector> delta_y_c()
227    {
228      return ConstPtr(delta_y_c_);
229    }
230
231    SmartPtr<const Vector> delta_y_d()
232    {
233      return ConstPtr(delta_y_d_);
234    }
235
236    SmartPtr<const Vector> delta_z_L()
237    {
238      return ConstPtr(delta_z_L_);
239    }
240
241    SmartPtr<const Vector> delta_z_U()
242    {
243      return ConstPtr(delta_z_U_);
244    }
245
246    SmartPtr<const Vector> delta_v_L()
247    {
248      return ConstPtr(delta_v_L_);
249    }
250
251    SmartPtr<const Vector> delta_v_U()
252    {
253      return ConstPtr(delta_v_U_);
254    }
255
256    SmartPtr<Vector> NonConst_delta_x()
257    {
258      return delta_x_;
259    }
260
261    SmartPtr<Vector> NonConst_delta_s()
262    {
263      return delta_s_;
264    }
265
266    SmartPtr<Vector> NonConst_delta_y_c()
267    {
268      return delta_y_c_;
269    }
270
271    SmartPtr<Vector> NonConst_delta_y_d()
272    {
273      return delta_y_d_;
274    }
275
276    SmartPtr<Vector> NonConst_delta_z_L()
277    {
278      return delta_z_L_;
279    }
280
281    SmartPtr<Vector> NonConst_delta_z_U()
282    {
283      return delta_z_U_;
284    }
285
286    SmartPtr<Vector> NonConst_delta_v_L()
287    {
288      return delta_v_L_;
289    }
290
291    SmartPtr<Vector> NonConst_delta_v_U()
292    {
293      return delta_v_U_;
294    }
295    //@}
296
297    /** @name Public Methods for updating iterates */
298    //@{
299    void SetTrialPrimalVariables(const Vector& x, const Vector& s);
300    void SetTrialXVariables(const Vector& x);
301    void SetTrialSVariables(const Vector& s);
302    void SetTrialEqMultipliers(const Vector& y_c, const Vector& y_d);
303    void SetTrialBoundMultipliers(const Vector& z_L, const Vector& z_U,
304                                  const Vector& v_L, const Vector& v_U);
305    /** Set the values of the primal trial variables (x and s) from
306     *  provided Step with step length alpha.
307     */
308    void SetTrialPrimalVariablesFromStep(Number alpha,
309                                         const Vector& delta_x,
310                                         const Vector& delta_s);
311    /** Set the values of the trial values for the equality constraint
312     *  multipliers (y_c and y_d) from provided step with step length
313     *  alpha.
314     */
315    void SetTrialEqMultipilersFromStep(Number alpha,
316                                       const Vector& delta_y_c,
317                                       const Vector& delta_y_d);
318    /** Set the value of the trial values for the bound multipliers
319     *  (z_L, z_U, v_L, v_U) from provided step with step length
320     *  alpha.
321     */
322    void SetTrialBoundMutlipliersFromStep(Number alpha,
323                                          const Vector& delta_z_L,
324                                          const Vector& delta_z_U,
325                                          const Vector& delta_v_L,
326                                          const Vector& delta_v_U);
327
328    /** Copy the trial values to the current values */
329    void CopyTrialToCurrent();
330
331    /** Set the current iterate values from the
332     *  trial values. */
333    void AcceptTrialPoint();
334
335    /** Set the pointers for the primal trial variables.  Make sure
336    that you are not modifying the incoming vectors afterwards! */
337    void SetTrialPrimalVariablesFromPtr(const SmartPtr<const Vector>& xptr,
338                                        const SmartPtr<const Vector>& sptr);
339    //@}
340
341    /** @name General algorithmic data */
342    //@{
343    Index iter_count() const
344    {
345      return iter_count_;
346    }
347    void Set_iter_count(Index iter_count)
348    {
349      iter_count_ = iter_count;
350    }
351
352    Number curr_mu() const
353    {
354      DBG_ASSERT(mu_initialized_);
355      return curr_mu_;
356    }
357    void Set_mu(Number mu)
358    {
359      curr_mu_ = mu;
360      mu_initialized_ = true;
361    }
362    bool MuInitialized() const
363    {
364      return mu_initialized_;
365    }
366
367    Number curr_tau() const
368    {
369      DBG_ASSERT(tau_initialized_);
370      return curr_tau_;
371    }
372    void Set_tau(Number tau)
373    {
374      curr_tau_ = tau;
375      tau_initialized_ = true;
376    }
377    bool TauInitialized() const
378    {
379      return tau_initialized_;
380    }
381    //@}
382
383    /**@name Algorithm Parameters (these will later be
384     *  moved to a specific IpoptParameters class, once
385     *  I get time to write one) */
386    //@{
387    Number epsilon_tol() const
388    {
389      DBG_ASSERT(initialize_called_);
390      return epsilon_tol_;
391    }
392    //@}
393
394    /** @name Information gathered for iteration output */
395    //@{
396    Number info_regu_x() const
397    {
398      return info_regu_x_;
399    }
400    void Set_info_regu_x(Number regu_x)
401    {
402      info_regu_x_ = regu_x;
403    }
404    Number info_alpha_primal() const
405    {
406      return info_alpha_primal_;
407    }
408    void Set_info_alpha_primal(Number alpha_primal)
409    {
410      info_alpha_primal_ = alpha_primal;
411    }
412    char info_alpha_primal_char() const
413    {
414      return info_alpha_primal_char_;
415    }
416    void Set_info_alpha_primal_char(char info_alpha_primal_char)
417    {
418      info_alpha_primal_char_ = info_alpha_primal_char;
419    }
420    Number info_alpha_dual() const
421    {
422      return info_alpha_dual_;
423    }
424    void Set_info_alpha_dual(Number alpha_dual)
425    {
426      info_alpha_dual_ = alpha_dual;
427    }
428    Index info_ls_count() const
429    {
430      return info_ls_count_;
431    }
432    void Set_info_ls_count(Index ls_count)
433    {
434      info_ls_count_ = ls_count;
435    }
436    bool info_skip_output() const
437    {
438      return info_skip_output_;
439    }
440    /** Set this to true, if the next time when output is written, the
441     *  summary line should not be printed. */
442    void Set_info_skip_output(bool info_skip_output)
443    {
444      info_skip_output_ = info_skip_output;
445    }
446
447    /** Reset all info fields */
448    void ResetInfo()
449    {
450      info_regu_x_ = 0;
451      info_alpha_primal_ = 0;
452      info_alpha_dual_ = 0.;
453      info_alpha_primal_char_ = ' ';
454      info_ls_count_ = -1;
455      info_skip_output_ = false;
456    }
457    //@}
458
459  private:
460    /** @name Iterates */
461    //@{
462    /** Main iteration variables
463     * (current iteration) */
464    SmartPtr<const Vector> curr_x_;
465
466    /** Main iteration variables
467     *  (trial calculations) */
468    SmartPtr<const Vector> trial_x_;
469
470    /** Slacks from inequality constraints
471     *  (current iteration) */
472    SmartPtr<const Vector> curr_s_;
473
474    /** Slacks from inequality constraints
475     *  (trial calculations) */
476    SmartPtr<const Vector> trial_s_;
477
478    /** Multipliers for equality constraints
479     *  (current iteration) */
480    SmartPtr<const Vector> curr_y_c_;
481
482    /** Multipliers for equality constraints
483     *  (trial iteration) */
484    SmartPtr<const Vector> trial_y_c_;
485
486    /** Multipliers for the inequality constraints
487     *  - Note, inequalities made equality
488     *  by introduction of slacks)
489     *  (current iteration) */
490    SmartPtr<const Vector> curr_y_d_;
491
492    /** Multipliers for the inequality constraints
493     *  - Note, inequalities made equality
494     *  by introduction of slacks)
495     *  (trial calculations) */
496    SmartPtr<const Vector> trial_y_d_;
497
498    /** Multipliers for the lower bound on x
499     *  (current iteration) */
500    SmartPtr<const Vector> curr_z_L_;
501
502    /** Multipliers for the lower bound on x
503     *  (trial calculations) */
504    SmartPtr<const Vector> trial_z_L_;
505
506    /** Multipliers for the upper bound on x
507     *  (current iteration) */
508    SmartPtr<const Vector> curr_z_U_;
509
510    /** Multipliers for the upper bound on x
511     * (trial calculations) */
512    SmartPtr<const Vector> trial_z_U_;
513
514    /** Multipliers for the lower bound on s
515     *  (current iteration) */
516    SmartPtr<const Vector> curr_v_L_;
517
518    /** Multipliers for the lower bound on s
519     *  (trial calculations) */
520    SmartPtr<const Vector> trial_v_L_;
521
522    /** Multipliers for the upper bound on s
523     *  (current iteration) */
524    SmartPtr<const Vector> curr_v_U_;
525
526    /** Multipliers for the upper bound on s
527     * (trial calculations) */
528    SmartPtr<const Vector> trial_v_U_;
529
530    /** Hessian (approximation) - might be changed elsewhere! */
531    SmartPtr<const SymMatrix> W_;
532
533    /** @name Delta Variables (steps) */
534    //@{
535    SmartPtr<Vector> delta_x_;
536    SmartPtr<Vector> delta_s_;
537    SmartPtr<Vector> delta_y_c_;
538    SmartPtr<Vector> delta_y_d_;
539    SmartPtr<Vector> delta_z_L_;
540    SmartPtr<Vector> delta_z_U_;
541    SmartPtr<Vector> delta_v_L_;
542    SmartPtr<Vector> delta_v_U_;
543    //@}
544
545    /** iteration count */
546    Index iter_count_;
547
548    /** current barrier parameter */
549    Number curr_mu_;
550    bool mu_initialized_;
551
552    /** current fraction to the boundary parameter */
553    Number curr_tau_;
554    bool tau_initialized_;
555
556    /** flag indicating if Initialize method has been called (for
557     *  debugging) */
558    bool initialize_called_;
559
560    /** flag for debugging whether we have already curr_ values
561     *  available (from which new Vectors can be generated */
562    bool have_prototypes_;
563
564    /** @name Global algorithm parameters.  Those are options that can
565     *  be modified by the user and appear at different places in the
566     *  algorithm.  They are set using an OptionsList object in the
567     *  Initialize method.  */
568    //@{
569    /** Overall convergence tolerance */
570    Number epsilon_tol_;
571    //@}
572
573    /** @name Gathered information for iteration output */
574    //@{
575    /** Size of regularization for the Hessian */
576    Number info_regu_x_;
577    /** Primal step size */
578    Number info_alpha_primal_;
579    /** Info character for primal step size */
580    char info_alpha_primal_char_;
581    /** Dual step size */
582    Number info_alpha_dual_;
583    /** Number of backtracking trial steps */
584    Index info_ls_count_;
585    /** true, if next summary output line should not be printed (eg
586     *  after restoration phase. */
587    bool info_skip_output_;
588    //@}
589
590    /**@name Default Compiler Generated Methods
591     * (Hidden to avoid implicit creation/calling).
592     * These methods are not implemented and
593     * we do not want the compiler to implement
594     * them for us, so we declare them private
595     * and do not define them. This ensures that
596     * they will not be implicitly created/called. */
597    //@{
598    /** Copy Constructor */
599    IpoptData(const IpoptData&);
600
601    /** Overloaded Equals Operator */
602    void operator=(const IpoptData&);
603    //@}
604
605  };
606
607} // namespace Ipopt
608
609#endif
Note: See TracBrowser for help on using the repository browser.