source: branches/dev/Algorithm/IpOrigIterationOutput.cpp @ 546

Last change on this file since 546 was 546, checked in by andreasw, 15 years ago
  • added missing svn:keyword for a few files
  • increased factor for theta reduction in restoration convergence check from 1e1 to 1e2
  • trigger restoration phase in expect_infeasible_problem mode if multipliers become larger than 1e8
  • revert to regular restoration phase if more than max_soft_resto_iters (new option) iterations are taken in soft restoration phase
  • made quality_function default for adaptive barrier strategy
  • added new print level to avoid one line of output per iteration
  • fixed TNLPAdapter, so that only some parts of the problem (objective, constraints, variables) are scaled if desired
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.6 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: IpOrigIterationOutput.cpp 546 2005-10-20 22:40:15Z andreasw $
6//
7// Authors:  Carl Laird, Andreas Waechter              IBM    2004-09-23
8
9#include "IpOrigIterationOutput.hpp"
10
11#ifdef HAVE_CMATH
12# include <cmath>
13#else
14# ifdef HAVE_MATH_H
15#  include <math.h>
16# else
17#  error "don't have header file for math"
18# endif
19#endif
20
21namespace Ipopt
22{
23#ifdef IP_DEBUG
24  static const Index dbg_verbosity = 0;
25#endif
26
27  OrigIterationOutput::OrigIterationOutput()
28  {}
29
30  OrigIterationOutput::~OrigIterationOutput()
31  {}
32
33  void
34  OrigIterationOutput::RegisterOptions(SmartPtr<RegisteredOptions> roptions)
35  {
36    std::string prev_cat = roptions->RegisteringCategory();
37    roptions->SetRegisteringCategory("Output");
38    roptions->AddStringOption2(
39      "print_info_string",
40      "Enables printing of additional info string at end of iteration output.",
41      "no",
42      "no", "don't print string",
43      "yes", "print string at end of each iteration output",
44      "This string contains some insider information about the current iteration.");
45    roptions->SetRegisteringCategory(prev_cat);
46  }
47
48  bool OrigIterationOutput::InitializeImpl(const OptionsList& options,
49      const std::string& prefix)
50  {
51    options.GetBoolValue("print_info_string", print_info_string_, prefix);
52
53    return true;
54  }
55
56  void OrigIterationOutput::WriteOutput()
57  {
58    //////////////////////////////////////////////////////////////////////
59    //         First print the summary line for the iteration           //
60    //////////////////////////////////////////////////////////////////////
61
62    Index iter = IpData().iter_count();
63    std::string header =
64      "iter    objective    inf_pr   inf_du lg(mu)  ||d||  lg(rg) alpha_du alpha_pr  ls\n";
65    Jnlst().Printf(J_DETAILED, J_MAIN,
66                   "\n\n**************************************************\n");
67    Jnlst().Printf(J_DETAILED, J_MAIN,
68                   "*** Summary of Iteration: %d:", IpData().iter_count());
69    Jnlst().Printf(J_DETAILED, J_MAIN,
70                   "\n**************************************************\n\n");
71    if (iter%10 == 0 && !IpData().info_skip_output()) {
72      // output the header
73      Jnlst().Printf(J_ITERSUMMARY, J_MAIN, header.c_str());
74    }
75    else {
76      Jnlst().Printf(J_DETAILED, J_MAIN, header.c_str());
77    }
78    Number inf_pr = IpCq().curr_primal_infeasibility(NORM_MAX);
79    Number inf_du = IpCq().curr_dual_infeasibility(NORM_MAX);
80    Number mu = IpData().curr_mu();
81    Number dnrm;
82    if (IsValid(IpData().delta()) && IsValid(IpData().delta()->x()) && IsValid(IpData().delta()->s())) {
83      dnrm = Max(IpData().delta()->x()->Amax(), IpData().delta()->s()->Amax());
84    }
85    else {
86      // This is the first iteration - no search direction has been
87      // computed yet.
88      dnrm = 0.;
89    }
90    Number unscaled_f = IpCq().unscaled_curr_f();
91
92    // Retrieve some information set in the different parts of the algorithm
93    char info_iter=' ';
94    Number alpha_primal = IpData().info_alpha_primal();
95    char alpha_primal_char = IpData().info_alpha_primal_char();
96    Number alpha_dual = IpData().info_alpha_dual();
97    Number regu_x = IpData().info_regu_x();
98    char regu_x_buf[8];
99    char dashes[]="   - ";
100    char *regu_x_ptr;
101    if (regu_x==.0) {
102      regu_x_ptr = dashes;
103    }
104    else {
105      sprintf(regu_x_buf, "%5.1f", log10(regu_x));
106      regu_x_ptr = regu_x_buf;
107    }
108    Index ls_count = IpData().info_ls_count();
109    const std::string info_string = IpData().info_string();
110
111    if (!IpData().info_skip_output()) {
112      Jnlst().Printf(J_ITERSUMMARY, J_MAIN,
113                     "%4d%c%14.7e %7.2e %7.2e %5.1f %7.2e %5s %7.2e %7.2e%c%3d",
114                     iter, info_iter, unscaled_f, inf_pr, inf_du, log10(mu), dnrm, regu_x_ptr,
115                     alpha_dual, alpha_primal, alpha_primal_char,
116                     ls_count);
117      if (print_info_string_) {
118        Jnlst().Printf(J_ITERSUMMARY, J_MAIN, " %s", info_string.c_str());
119      }
120      else {
121        Jnlst().Printf(J_DETAILED, J_MAIN, " %s", info_string.c_str());
122      }
123      Jnlst().Printf(J_ITERSUMMARY, J_MAIN, "\n");
124    }
125
126
127    //////////////////////////////////////////////////////////////////////
128    //           Now if desired more detail on the iterates             //
129    //////////////////////////////////////////////////////////////////////
130
131    if (Jnlst().ProduceOutput(J_DETAILED, J_MAIN)) {
132      Jnlst().Printf(J_DETAILED, J_MAIN,
133                     "\n**************************************************\n");
134      Jnlst().Printf(J_DETAILED, J_MAIN,
135                     "*** Beginning Iteration %d from the following point:",
136                     IpData().iter_count());
137      Jnlst().Printf(J_DETAILED, J_MAIN,
138                     "\n**************************************************\n\n");
139
140      Jnlst().Printf(J_DETAILED, J_MAIN,
141                     "Current barrier parameter mu = %21.16e\n", IpData().curr_mu());
142      Jnlst().Printf(J_DETAILED, J_MAIN,
143                     "Current fraction-to-the-boundary parameter tau = %21.16e\n\n",
144                     IpData().curr_tau());
145      Jnlst().Printf(J_DETAILED, J_MAIN,
146                     "||curr_x||_inf   = %.16e\n", IpData().curr()->x()->Amax());
147      Jnlst().Printf(J_DETAILED, J_MAIN,
148                     "||curr_s||_inf   = %.16e\n", IpData().curr()->s()->Amax());
149      Jnlst().Printf(J_DETAILED, J_MAIN,
150                     "||curr_y_c||_inf = %.16e\n", IpData().curr()->y_c()->Amax());
151      Jnlst().Printf(J_DETAILED, J_MAIN,
152                     "||curr_y_d||_inf = %.16e\n", IpData().curr()->y_d()->Amax());
153      Jnlst().Printf(J_DETAILED, J_MAIN,
154                     "||curr_z_L||_inf = %.16e\n", IpData().curr()->z_L()->Amax());
155      Jnlst().Printf(J_DETAILED, J_MAIN,
156                     "||curr_z_U||_inf = %.16e\n", IpData().curr()->z_U()->Amax());
157      Jnlst().Printf(J_DETAILED, J_MAIN,
158                     "||curr_v_L||_inf = %.16e\n", IpData().curr()->v_L()->Amax());
159      Jnlst().Printf(J_DETAILED, J_MAIN,
160                     "||curr_v_U||_inf = %.16e\n", IpData().curr()->v_U()->Amax());
161    }
162    if (Jnlst().ProduceOutput(J_MOREDETAILED, J_MAIN)) {
163      if (IsValid(IpData().delta())) {
164        Jnlst().Printf(J_MOREDETAILED, J_MAIN,
165                       "\n||delta_x||_inf   = %.16e\n", IpData().delta()->x()->Amax());
166        Jnlst().Printf(J_MOREDETAILED, J_MAIN,
167                       "||delta_s||_inf   = %.16e\n", IpData().delta()->s()->Amax());
168        Jnlst().Printf(J_MOREDETAILED, J_MAIN,
169                       "||delta_y_c||_inf = %.16e\n", IpData().delta()->y_c()->Amax());
170        Jnlst().Printf(J_MOREDETAILED, J_MAIN,
171                       "||delta_y_d||_inf = %.16e\n", IpData().delta()->y_d()->Amax());
172        Jnlst().Printf(J_MOREDETAILED, J_MAIN,
173                       "||delta_z_L||_inf = %.16e\n", IpData().delta()->z_L()->Amax());
174        Jnlst().Printf(J_MOREDETAILED, J_MAIN,
175                       "||delta_z_U||_inf = %.16e\n", IpData().delta()->z_U()->Amax());
176        Jnlst().Printf(J_MOREDETAILED, J_MAIN,
177                       "||delta_v_L||_inf = %.16e\n", IpData().delta()->v_L()->Amax());
178        Jnlst().Printf(J_MOREDETAILED, J_MAIN,
179                       "||delta_v_U||_inf = %.16e\n", IpData().delta()->v_U()->Amax());
180      }
181      else {
182        Jnlst().Printf(J_MOREDETAILED, J_MAIN,
183                       "\nNo search direction has been computed yet.\n");
184      }
185    }
186    if (Jnlst().ProduceOutput(J_VECTOR, J_MAIN)) {
187      IpData().curr()->x()->Print(Jnlst(), J_VECTOR, J_MAIN, "curr_x");
188      IpData().curr()->s()->Print(Jnlst(), J_VECTOR, J_MAIN, "curr_s");
189
190      IpData().curr()->y_c()->Print(Jnlst(), J_VECTOR, J_MAIN, "curr_y_c");
191      IpData().curr()->y_d()->Print(Jnlst(), J_VECTOR, J_MAIN, "curr_y_d");
192
193      IpCq().curr_slack_x_L()->Print(Jnlst(), J_VECTOR, J_MAIN, "curr_slack_x_L");
194      IpCq().curr_slack_x_U()->Print(Jnlst(), J_VECTOR, J_MAIN, "curr_slack_x_U");
195      IpData().curr()->z_L()->Print(Jnlst(), J_VECTOR, J_MAIN, "curr_z_L");
196      IpData().curr()->z_U()->Print(Jnlst(), J_VECTOR, J_MAIN, "curr_z_U");
197
198      IpCq().curr_slack_s_L()->Print(Jnlst(), J_VECTOR, J_MAIN, "curr_slack_s_L");
199      IpCq().curr_slack_s_U()->Print(Jnlst(), J_VECTOR, J_MAIN, "curr_slack_s_U");
200      IpData().curr()->v_L()->Print(Jnlst(), J_VECTOR, J_MAIN, "curr_v_L");
201      IpData().curr()->v_U()->Print(Jnlst(), J_VECTOR, J_MAIN, "curr_v_U");
202    }
203    if (Jnlst().ProduceOutput(J_MOREVECTOR, J_MAIN)) {
204      IpCq().curr_grad_lag_x()->Print(Jnlst(), J_MOREVECTOR, J_MAIN, "curr_grad_lag_x");
205      IpCq().curr_grad_lag_s()->Print(Jnlst(), J_MOREVECTOR, J_MAIN, "curr_grad_lag_s");
206      if (IsValid(IpData().delta())) {
207        IpData().delta()->Print(Jnlst(), J_MOREVECTOR, J_MAIN, "delta");
208      }
209    }
210
211    if (Jnlst().ProduceOutput(J_DETAILED, J_MAIN)) {
212      Jnlst().Printf(J_DETAILED, J_MAIN,
213                     "\n\n***Current NLP Values for Iteration %d:\n",
214                     IpData().iter_count());
215      Jnlst().Printf(J_DETAILED, J_MAIN, "\n                                   (scaled)                 (unscaled)\n");
216      Jnlst().Printf(J_DETAILED, J_MAIN, "Objective...............: %24.16e  %24.16e\n", IpCq().curr_f(), IpCq().unscaled_curr_f());
217      Jnlst().Printf(J_DETAILED, J_MAIN, "Dual infeasibility......: %24.16e  %24.16e\n", IpCq().curr_dual_infeasibility(NORM_MAX), IpCq().unscaled_curr_dual_infeasibility(NORM_MAX));
218      Jnlst().Printf(J_DETAILED, J_MAIN, "Constraint violation....: %24.16e  %24.16e\n", IpCq().curr_nlp_constraint_violation(NORM_MAX), IpCq().unscaled_curr_nlp_constraint_violation(NORM_MAX));
219      Jnlst().Printf(J_DETAILED, J_MAIN, "Complementarity.........: %24.16e  %24.16e\n", IpCq().curr_complementarity(0., NORM_MAX), IpCq().unscaled_curr_complementarity(0., NORM_MAX));
220      Jnlst().Printf(J_DETAILED, J_MAIN, "Overall NLP error.......: %24.16e  %24.16e\n\n", IpCq().curr_nlp_error(), IpCq().unscaled_curr_nlp_error());
221    }
222    if (Jnlst().ProduceOutput(J_VECTOR, J_MAIN)) {
223      IpCq().curr_grad_f()->Print(Jnlst(), J_VECTOR, J_MAIN, "grad_f");
224      IpCq().curr_c()->Print(Jnlst(), J_VECTOR, J_MAIN, "curr_c");
225      IpCq().curr_d()->Print(Jnlst(), J_VECTOR, J_MAIN, "curr_d");
226      IpCq().curr_d_minus_s()->Print(Jnlst(), J_VECTOR, J_MAIN,
227                                     "curr_d - curr_s");
228    }
229
230    if (Jnlst().ProduceOutput(J_MATRIX, J_MAIN)) {
231      IpCq().curr_jac_c()->Print(Jnlst(), J_MATRIX, J_MAIN, "jac_c");
232      IpCq().curr_jac_d()->Print(Jnlst(), J_MATRIX, J_MAIN, "jac_d");
233      IpCq().curr_exact_hessian()->Print(Jnlst(), J_MATRIX, J_MAIN, "h");
234    }
235
236    Jnlst().Printf(J_DETAILED, J_MAIN, "\n\n");
237
238  }
239
240} // namespace Ipopt
Note: See TracBrowser for help on using the repository browser.