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

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

forgot to remove debug line

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