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

Last change on this file since 414 was 414, checked in by andreasw, 14 years ago
  • several changes handling the NLP scaling
  • compute unscaled quantities in CalculatedQuantities? (such as errors)
  • print unscaled errors in output file and on console after solution
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.7 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 414 2005-07-28 15:53:28Z 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    reg_options->AddLowerBoundedNumberOption(
56      "dual_inf_tol",
57      "Acceptance threshold for the unscaled dual infeasibility.",
58      0.0, true, 1e-2,
59      "Absolute tolerance on the dual infesaibility.  Successful termination "
60      "requires that the (unscaled) dual infeasibility is less than this "
61      "threshold.");
62    reg_options->AddLowerBoundedNumberOption(
63      "primal_inf_tol",
64      "Acceptance threshold for the unscaled primal infeasibility.",
65      0.0, true, 1e-2,
66      "Absolute tolerance on the dual infesaibility.  Successful termination "
67      "requires that the (unscaled) primal infeasibility is less than this "
68      "threshold.");
69    reg_options->AddLowerBoundedNumberOption(
70      "compl_inf_tol",
71      "Acceptance threshold for the complementarity conditions.",
72      0.0, true, 1e-2,
73      "Absolute tolerance on the complementarity.  Successful termination "
74      "requires that the (unscaled) complementarity is less than this "
75      "threshold.");
76  }
77
78  bool IpoptData::Initialize(const Journalist& jnlst,
79                             const OptionsList& options,
80                             const std::string& prefix)
81  {
82    options.GetNumericValue("tol", tol_, prefix);
83    options.GetNumericValue("dual_inf_tol", dual_inf_tol_, prefix);
84    options.GetNumericValue("primal_inf_tol", primal_inf_tol_, prefix);
85    options.GetNumericValue("compl_inf_tol", compl_inf_tol_, prefix);
86
87    iter_count_=0;
88
89    have_prototypes_ = false;
90    tau_initialized_ = false;
91    have_deltas_ = false;
92
93    initialize_called_ = true;
94    return true;
95  }
96
97  bool IpoptData::InitializeDataStructures(IpoptNLP& ip_nlp,
98      bool want_x,
99      bool want_y_c,
100      bool want_y_d,
101      bool want_z_L,
102      bool want_z_U)
103  {
104    DBG_ASSERT(initialize_called_);
105    /*
106     * Allocate space for all the required linear algebra
107     * structures
108     */
109
110    SmartPtr<Vector> new_x;
111    SmartPtr<Vector> new_s;
112    SmartPtr<Vector> new_y_c;
113    SmartPtr<Vector> new_y_d;
114    SmartPtr<Vector> new_z_L;
115    SmartPtr<Vector> new_z_U;
116    SmartPtr<Vector> new_v_L;
117    SmartPtr<Vector> new_v_U;
118
119    // Get the required linear algebra structures from the model
120    bool retValue
121    = ip_nlp.InitializeStructures(new_x, want_x,
122                                  new_y_c, want_y_c,
123                                  new_y_d, want_y_d,
124                                  new_z_L, want_z_L,
125                                  new_z_U, want_z_U,
126                                  new_v_L, new_v_U);
127    if (!retValue) {
128      return false;
129    }
130
131    new_s = new_y_d->MakeNew(); // same dimension as d
132
133    iterates_space_ = new IteratesVectorSpace(*(new_x->OwnerSpace()), *(new_s->OwnerSpace()),
134                      *(new_y_c->OwnerSpace()), *(new_y_d->OwnerSpace()),
135                      *(new_z_L->OwnerSpace()), *(new_z_U->OwnerSpace()),
136                      *(new_v_L->OwnerSpace()), *(new_v_U->OwnerSpace())
137                                             );
138
139    curr_ = iterates_space_->MakeNewIteratesVector(*new_x,
140            *new_s,
141            *new_y_c,
142            *new_y_d,
143            *new_z_L,
144            *new_z_U,
145            *new_v_L,
146            *new_v_U);
147#ifdef IP_DEBUG
148
149    debug_curr_tag_ = curr_->GetTag();
150    debug_curr_tag_sum_ = curr_->GetTagSum();
151    debug_trial_tag_ = 0;
152    debug_trial_tag_sum_ = 0;
153    debug_delta_tag_ = 0;
154    debug_delta_tag_sum_ = 0;
155    debug_delta_aff_tag_ = 0;
156    debug_delta_aff_tag_sum_ = 0;
157#endif
158
159    trial_ = NULL;
160
161    // Set the pointers for storing steps to NULL
162    delta_ = NULL;
163
164    // Set the pointers for storing steps to NULL
165    delta_aff_ = NULL;
166
167    have_prototypes_ = true;
168    have_deltas_ = false;
169
170    return true;
171  }
172
173  void IpoptData::SetTrialPrimalVariablesFromStep(Number alpha,
174      const Vector& delta_x,
175      const Vector& delta_s)
176  {
177    DBG_ASSERT(have_prototypes_);
178
179    if (IsNull(trial_)) {
180      trial_ = iterates_space_->MakeNewIteratesVector(false);
181    }
182
183    SmartPtr<IteratesVector> newvec = trial_->MakeNewContainer();
184    newvec->create_new_x();
185    newvec->x_NonConst()->AddTwoVectors(1., *curr_->x(), alpha, delta_x, 0.);
186
187    newvec->create_new_s();
188    newvec->s_NonConst()->AddTwoVectors(1., *curr_->s(), alpha, delta_s, 0.);
189
190    set_trial(newvec);
191  }
192
193  void IpoptData::SetTrialEqMultipliersFromStep(Number alpha,
194      const Vector& delta_y_c,
195      const Vector& delta_y_d)
196  {
197    DBG_ASSERT(have_prototypes_);
198
199    SmartPtr<IteratesVector> newvec = trial()->MakeNewContainer();
200    newvec->create_new_y_c();
201    newvec->y_c_NonConst()->AddTwoVectors(1., *curr()->y_c(), alpha, delta_y_c, 0.);
202
203    newvec->create_new_y_d();
204    newvec->y_d_NonConst()->AddTwoVectors(1., *curr()->y_d(), alpha, delta_y_d, 0.);
205
206    set_trial(newvec);
207  }
208
209  void IpoptData::SetTrialBoundMultipliersFromStep(Number alpha,
210      const Vector& delta_z_L,
211      const Vector& delta_z_U,
212      const Vector& delta_v_L,
213      const Vector& delta_v_U)
214  {
215    DBG_ASSERT(have_prototypes_);
216
217    SmartPtr<IteratesVector> newvec = trial()->MakeNewContainer();
218    newvec->create_new_z_L();
219    newvec->z_L_NonConst()->AddTwoVectors(1., *curr()->z_L(), alpha, delta_z_L, 0.);
220
221    newvec->create_new_z_U();
222    newvec->z_U_NonConst()->AddTwoVectors(1., *curr()->z_U(), alpha, delta_z_U, 0.);
223
224    newvec->create_new_v_L();
225    newvec->v_L_NonConst()->AddTwoVectors(1., *curr()->v_L(), alpha, delta_v_L, 0.);
226
227    newvec->create_new_v_U();
228    newvec->v_U_NonConst()->AddTwoVectors(1., *curr()->v_U(), alpha, delta_v_U, 0.);
229
230    set_trial(newvec);
231  }
232
233  void IpoptData::AcceptTrialPoint()
234  {
235    DBG_ASSERT(IsValid(trial_));
236    DBG_ASSERT(IsValid(trial_->x()));
237    DBG_ASSERT(IsValid(trial_->s()));
238    DBG_ASSERT(IsValid(trial_->y_c()));
239    DBG_ASSERT(IsValid(trial_->y_d()));
240    DBG_ASSERT(IsValid(trial_->z_L()));
241    DBG_ASSERT(IsValid(trial_->z_U()));
242    DBG_ASSERT(IsValid(trial_->v_L()));
243    DBG_ASSERT(IsValid(trial_->v_U()));
244
245    CopyTrialToCurrent();
246
247    // Set trial pointers to Null (frees memory unless someone else is
248    // still referring to it, and it makes sure that indeed all trial
249    // values are set before a new trial point is accepted)
250    trial_ = NULL;
251
252    // ToDo: Why don't we free the delta_ here?
253
254    // Free the memory for the affine-scaling step
255    delta_aff_ = NULL;
256
257    have_deltas_ = false;
258    have_affine_deltas_ = false;
259  }
260
261} // namespace Ipopt
Note: See TracBrowser for help on using the repository browser.