source: branches/dev/Algorithm/IpIpoptData.cpp @ 416

Last change on this file since 416 was 416, checked in by andreasw, 14 years ago
  • revised handling of "acceptable level of accuracy" (now in ConvCheck?)
  • fixed uncaught evaluation error exceptions
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.6 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.cpp 416 2005-07-29 19:11:41Z andreasw $
6//
7// Authors:  Carl Laird, Andreas Waechter     IBM    2004-08-13
8
9#include "IpIpoptData.hpp"
10#include "IpIpoptNLP.hpp"
11
12namespace Ipopt
13{
14
15  DBG_SET_VERBOSITY(0);
16
17  DefineIpoptType(IpoptData);
18
19  IpoptData::IpoptData()
20      :
21      iter_count_(0),
22      curr_mu_(-1.),
23      mu_initialized_(false),
24      curr_tau_(-1.),
25      tau_initialized_(false),
26      initialize_called_(false),
27      have_prototypes_(false),
28      free_mu_mode_(false),
29      tiny_step_flag_(false),
30
31      info_alpha_primal_(0.),
32      info_alpha_primal_char_(' '),
33      info_alpha_dual_(0.),
34      info_regu_x_(0.),
35      info_ls_count_(0),
36      info_skip_output_(false)
37  {}
38
39  IpoptData::~IpoptData()
40  {}
41
42  void IpoptData::RegisterOptions(SmartPtr<RegisteredOptions> reg_options)
43  {
44    reg_options->AddLowerBoundedNumberOption(
45      "tol",
46      "Convergence tolerance (relative).",
47      0.0, true,  1e-8,
48      "Determines the convergence tolerance for the algorthim.  The "
49      "algorithm terminates successfully, if the (scaled) NLP error "
50      "becomes smaller than this value, and if the (absolute) criteria "
51      "according to \"dual_inf_tol\", \"primal_inf_tol\", and "
52      "\"cmpl_inf_tol\" are met.  (This is epsilon_tol in Eqn. (6) in "
53      "implementation paper).  [Some other algorithmic features also use "
54      "this quantity.]");
55  }
56
57  bool IpoptData::Initialize(const Journalist& jnlst,
58                             const OptionsList& options,
59                             const std::string& prefix)
60  {
61    options.GetNumericValue("tol", tol_, prefix);
62
63    iter_count_=0;
64
65    have_prototypes_ = false;
66    tau_initialized_ = false;
67    have_deltas_ = false;
68
69    initialize_called_ = true;
70    return true;
71  }
72
73  bool IpoptData::InitializeDataStructures(IpoptNLP& ip_nlp,
74      bool want_x,
75      bool want_y_c,
76      bool want_y_d,
77      bool want_z_L,
78      bool want_z_U)
79  {
80    DBG_ASSERT(initialize_called_);
81    /*
82     * Allocate space for all the required linear algebra
83     * structures
84     */
85
86    SmartPtr<Vector> new_x;
87    SmartPtr<Vector> new_s;
88    SmartPtr<Vector> new_y_c;
89    SmartPtr<Vector> new_y_d;
90    SmartPtr<Vector> new_z_L;
91    SmartPtr<Vector> new_z_U;
92    SmartPtr<Vector> new_v_L;
93    SmartPtr<Vector> new_v_U;
94
95    // Get the required linear algebra structures from the model
96    bool retValue
97    = ip_nlp.InitializeStructures(new_x, want_x,
98                                  new_y_c, want_y_c,
99                                  new_y_d, want_y_d,
100                                  new_z_L, want_z_L,
101                                  new_z_U, want_z_U,
102                                  new_v_L, new_v_U);
103    if (!retValue) {
104      return false;
105    }
106
107    new_s = new_y_d->MakeNew(); // same dimension as d
108
109    iterates_space_ = new IteratesVectorSpace(*(new_x->OwnerSpace()), *(new_s->OwnerSpace()),
110                      *(new_y_c->OwnerSpace()), *(new_y_d->OwnerSpace()),
111                      *(new_z_L->OwnerSpace()), *(new_z_U->OwnerSpace()),
112                      *(new_v_L->OwnerSpace()), *(new_v_U->OwnerSpace())
113                                             );
114
115    curr_ = iterates_space_->MakeNewIteratesVector(*new_x,
116            *new_s,
117            *new_y_c,
118            *new_y_d,
119            *new_z_L,
120            *new_z_U,
121            *new_v_L,
122            *new_v_U);
123#ifdef IP_DEBUG
124
125    debug_curr_tag_ = curr_->GetTag();
126    debug_curr_tag_sum_ = curr_->GetTagSum();
127    debug_trial_tag_ = 0;
128    debug_trial_tag_sum_ = 0;
129    debug_delta_tag_ = 0;
130    debug_delta_tag_sum_ = 0;
131    debug_delta_aff_tag_ = 0;
132    debug_delta_aff_tag_sum_ = 0;
133#endif
134
135    trial_ = NULL;
136
137    // Set the pointers for storing steps to NULL
138    delta_ = NULL;
139
140    // Set the pointers for storing steps to NULL
141    delta_aff_ = NULL;
142
143    have_prototypes_ = true;
144    have_deltas_ = false;
145
146    return true;
147  }
148
149  void IpoptData::SetTrialPrimalVariablesFromStep(Number alpha,
150      const Vector& delta_x,
151      const Vector& delta_s)
152  {
153    DBG_ASSERT(have_prototypes_);
154
155    if (IsNull(trial_)) {
156      trial_ = iterates_space_->MakeNewIteratesVector(false);
157    }
158
159    SmartPtr<IteratesVector> newvec = trial_->MakeNewContainer();
160    newvec->create_new_x();
161    newvec->x_NonConst()->AddTwoVectors(1., *curr_->x(), alpha, delta_x, 0.);
162
163    newvec->create_new_s();
164    newvec->s_NonConst()->AddTwoVectors(1., *curr_->s(), alpha, delta_s, 0.);
165
166    set_trial(newvec);
167  }
168
169  void IpoptData::SetTrialEqMultipliersFromStep(Number alpha,
170      const Vector& delta_y_c,
171      const Vector& delta_y_d)
172  {
173    DBG_ASSERT(have_prototypes_);
174
175    SmartPtr<IteratesVector> newvec = trial()->MakeNewContainer();
176    newvec->create_new_y_c();
177    newvec->y_c_NonConst()->AddTwoVectors(1., *curr()->y_c(), alpha, delta_y_c, 0.);
178
179    newvec->create_new_y_d();
180    newvec->y_d_NonConst()->AddTwoVectors(1., *curr()->y_d(), alpha, delta_y_d, 0.);
181
182    set_trial(newvec);
183  }
184
185  void IpoptData::SetTrialBoundMultipliersFromStep(Number alpha,
186      const Vector& delta_z_L,
187      const Vector& delta_z_U,
188      const Vector& delta_v_L,
189      const Vector& delta_v_U)
190  {
191    DBG_ASSERT(have_prototypes_);
192
193    SmartPtr<IteratesVector> newvec = trial()->MakeNewContainer();
194    newvec->create_new_z_L();
195    newvec->z_L_NonConst()->AddTwoVectors(1., *curr()->z_L(), alpha, delta_z_L, 0.);
196
197    newvec->create_new_z_U();
198    newvec->z_U_NonConst()->AddTwoVectors(1., *curr()->z_U(), alpha, delta_z_U, 0.);
199
200    newvec->create_new_v_L();
201    newvec->v_L_NonConst()->AddTwoVectors(1., *curr()->v_L(), alpha, delta_v_L, 0.);
202
203    newvec->create_new_v_U();
204    newvec->v_U_NonConst()->AddTwoVectors(1., *curr()->v_U(), alpha, delta_v_U, 0.);
205
206    set_trial(newvec);
207  }
208
209  void IpoptData::AcceptTrialPoint()
210  {
211    DBG_ASSERT(IsValid(trial_));
212    DBG_ASSERT(IsValid(trial_->x()));
213    DBG_ASSERT(IsValid(trial_->s()));
214    DBG_ASSERT(IsValid(trial_->y_c()));
215    DBG_ASSERT(IsValid(trial_->y_d()));
216    DBG_ASSERT(IsValid(trial_->z_L()));
217    DBG_ASSERT(IsValid(trial_->z_U()));
218    DBG_ASSERT(IsValid(trial_->v_L()));
219    DBG_ASSERT(IsValid(trial_->v_U()));
220
221    CopyTrialToCurrent();
222
223    // Set trial pointers to Null (frees memory unless someone else is
224    // still referring to it, and it makes sure that indeed all trial
225    // values are set before a new trial point is accepted)
226    trial_ = NULL;
227
228    // ToDo: Why don't we free the delta_ here?
229
230    // Free the memory for the affine-scaling step
231    delta_aff_ = NULL;
232
233    have_deltas_ = false;
234    have_affine_deltas_ = false;
235  }
236
237} // namespace Ipopt
Note: See TracBrowser for help on using the repository browser.