Ipopt Documentation  
IpIpoptData.hpp
Go to the documentation of this file.
1 // Copyright (C) 2004, 2009 International Business Machines and others.
2 // All Rights Reserved.
3 // This code is published under the Eclipse Public License.
4 //
5 // Authors: Carl Laird, Andreas Waechter IBM 2004-08-13
6 
7 #ifndef __IPIPOPTDATA_HPP__
8 #define __IPIPOPTDATA_HPP__
9 
10 #include "IpSymMatrix.hpp"
11 #include "IpOptionsList.hpp"
12 #include "IpIteratesVector.hpp"
13 #include "IpRegOptions.hpp"
14 #include "IpTimingStatistics.hpp"
15 
16 #include <sstream>
17 #include <iomanip>
18 
19 namespace Ipopt
20 {
21 
22 /* Forward declaration */
23 class IpoptNLP;
24 
33 {
34 public:
36 
39  { }
40 
43  { }
45 
51  virtual bool Initialize(
52  const Journalist& jnlst,
53  const OptionsList& options,
54  const std::string& prefix
55  ) = 0;
56 
58  virtual bool InitializeDataStructures() = 0;
59 
65  virtual void AcceptTrialPoint() = 0;
66 
67 private:
77 
80  const IpoptAdditionalData&
81  );
82 
84  void operator=(
85  const IpoptAdditionalData&
86  );
88 };
89 
101 {
102 public:
104 
106  IpoptData(
107  SmartPtr<IpoptAdditionalData> add_data = NULL
108  );
109 
111  virtual ~IpoptData();
113 
115  bool InitializeDataStructures(
116  IpoptNLP& ip_nlp,
117  bool want_x,
118  bool want_y_c,
119  bool want_y_d,
120  bool want_z_L,
121  bool want_z_U
122  );
123 
129  bool Initialize(
130  const Journalist& jnlst,
131  const OptionsList& options,
132  const std::string& prefix
133  );
134 
136 
138  inline SmartPtr<const IteratesVector> curr() const;
139 
145  // SmartPtr<IteratesVector> curr_container() const;
147  inline SmartPtr<const IteratesVector> trial() const;
148 
154  //SmartPtr<IteratesVector> trial_container() const;
161  inline
162  void set_trial(
164  );
165  /* ToDo: I may need to add versions of set_trial like the
166  * following, but I am not sure
167  */
168  // void set_trial(const SmartPtr<IteratesVector>& trial_iterates);
169  // void set_trial(SmartPtr<const IteratesVector>& trial_iterates);
170 
174  void SetTrialPrimalVariablesFromStep(
175  Number alpha,
176  const Vector& delta_x,
177  const Vector& delta_s
178  );
183  void SetTrialEqMultipliersFromStep(
184  Number alpha,
185  const Vector& delta_y_c,
186  const Vector& delta_y_d
187  );
192  void SetTrialBoundMultipliersFromStep(
193  Number alpha,
194  const Vector& delta_z_L,
195  const Vector& delta_z_U,
196  const Vector& delta_v_L,
197  const Vector& delta_v_U
198  );
199 
201  inline SmartPtr<const IteratesVector> delta() const;
202 
209  inline
210  void set_delta(
212  );
213 
222  inline
223  void set_delta(
225  );
226 
228  inline SmartPtr<const IteratesVector> delta_aff() const;
229 
236  inline
237  void set_delta_aff(
238  SmartPtr<IteratesVector>& delta_aff
239  );
240 
243  {
244  return W_;
245  }
246 
248  void Set_W(
250  )
251  {
252  W_ = W;
253  }
254 
263 
274  bool HaveDeltas() const
275  {
276  return have_deltas_;
277  }
278 
288  bool have_deltas
289  )
290  {
291  have_deltas_ = have_deltas;
292  }
294 
303 
314  bool HaveAffineDeltas() const
315  {
316  return have_affine_deltas_;
317  }
318 
328  bool have_affine_deltas
329  )
330  {
331  have_affine_deltas_ = have_affine_deltas;
332  }
334 
336 
338  inline
339  void CopyTrialToCurrent();
340 
342  void AcceptTrialPoint();
344 
346  Index iter_count() const
348  {
349  return iter_count_;
350  }
352  Index iter_count
353  )
354  {
355  iter_count_ = iter_count;
356  }
357 
358  Number curr_mu() const
359  {
360  DBG_ASSERT(mu_initialized_);
361  return curr_mu_;
362  }
363  void Set_mu(
364  Number mu
365  )
366  {
367  curr_mu_ = mu;
368  mu_initialized_ = true;
369  }
370  bool MuInitialized() const
371  {
372  return mu_initialized_;
373  }
374 
375  Number curr_tau() const
376  {
377  DBG_ASSERT(tau_initialized_);
378  return curr_tau_;
379  }
380  void Set_tau(
381  Number tau
382  )
383  {
384  curr_tau_ = tau;
385  tau_initialized_ = true;
386  }
387  bool TauInitialized() const
388  {
389  return tau_initialized_;
390  }
391 
393  bool free_mu_mode
394  )
395  {
396  free_mu_mode_ = free_mu_mode;
397  }
398  bool FreeMuMode() const
399  {
400  return free_mu_mode_;
401  }
402 
407  bool flag
408  )
409  {
410  tiny_step_flag_ = flag;
411  }
413  {
414  return tiny_step_flag_;
415  }
417 
425 
427  Number tol() const
428  {
429  DBG_ASSERT(initialize_called_);
430  return tol_;
431  }
442  void Set_tol(
443  Number tol
444  )
445  {
446  tol_ = tol;
447  }
449 
459  {
460  return timing_statistics_.OverallAlgorithm().StartCpuTime();
461  }
462 
464  Number info_regu_x() const
466  {
467  return info_regu_x_;
468  }
470  Number regu_x
471  )
472  {
473  info_regu_x_ = regu_x;
474  }
476  {
477  return info_alpha_primal_;
478  }
480  Number alpha_primal
481  )
482  {
483  info_alpha_primal_ = alpha_primal;
484  }
486  {
487  return info_alpha_primal_char_;
488  }
490  char info_alpha_primal_char
491  )
492  {
493  info_alpha_primal_char_ = info_alpha_primal_char;
494  }
496  {
497  return info_alpha_dual_;
498  }
500  Number alpha_dual
501  )
502  {
503  info_alpha_dual_ = alpha_dual;
504  }
506  {
507  return info_ls_count_;
508  }
510  Index ls_count
511  )
512  {
513  info_ls_count_ = ls_count;
514  }
515  bool info_skip_output() const
516  {
517  return info_skip_output_;
518  }
520  const std::string& add_str
521  )
522  {
523  info_string_ += add_str;
524  }
527  const std::string& add_str,
528  double value
529  )
530  {
531  std::ostringstream sstream;
532  sstream << add_str << '=' << std::setw(8) << std::setprecision(2) << std::scientific << value;
533  info_string_ += sstream.str();
534  }
535  const std::string& info_string() const
536  {
537  return info_string_;
538  }
543  bool info_skip_output
544  )
545  {
546  info_skip_output_ = info_skip_output;
547  }
548 
551  {
552  return info_last_output_;
553  }
556  Number info_last_output
557  )
558  {
559  info_last_output_ = info_last_output;
560  }
561 
566  {
567  return info_iters_since_header_;
568  }
573  {
574  info_iters_since_header_++;
575  }
580  int info_iters_since_header
581  )
582  {
583  info_iters_since_header_ = info_iters_since_header;
584  }
585 
587  void ResetInfo()
588  {
589  info_regu_x_ = 0;
590  info_alpha_primal_ = 0;
591  info_alpha_dual_ = 0.;
592  info_alpha_primal_char_ = ' ';
593  info_skip_output_ = false;
594  info_string_.erase();
595  }
597 
600  {
601  return timing_statistics_;
602  }
603 
609  {
610  return timing_statistics_;
611  }
612 
614  bool HaveAddData()
615  {
616  return IsValid(add_data_);
617  }
618 
621  {
622  return *add_data_;
623  }
624 
628  )
629  {
630  // cppcheck-suppress assertWithSideEffect
631  DBG_ASSERT(!HaveAddData());
632  add_data_ = add_data;
633  }
634 
636  void setPDPert(
637  Number pd_pert_x,
638  Number pd_pert_s,
639  Number pd_pert_c,
640  Number pd_pert_d
641  )
642  {
643  pd_pert_x_ = pd_pert_x;
644  pd_pert_s_ = pd_pert_s;
645  pd_pert_c_ = pd_pert_c;
646  pd_pert_d_ = pd_pert_d;
647  }
648 
650  void getPDPert(
651  Number& pd_pert_x,
652  Number& pd_pert_s,
653  Number& pd_pert_c,
654  Number& pd_pert_d
655  )
656  {
657  pd_pert_x = pd_pert_x_;
658  pd_pert_s = pd_pert_s_;
659  pd_pert_c = pd_pert_c_;
660  pd_pert_d = pd_pert_d_;
661  }
662 
663  static void RegisterOptions(
664  const SmartPtr<RegisteredOptions>& roptions
665  );
666 
667 private:
669 
672 
675 
678 
689  // ToDo we could cue off of a null delta_
692 
708  // ToDo we could cue off of a null delta_aff_
711 
714 
718 
722 
725 
730 
738 
742 
744 
750 
752 
768  std::string info_string_;
776 
779 
782 
787 
789  Number pd_pert_x_;
795 
805 
807  IpoptData(
808  const IpoptData&
809  );
810 
812  void operator=(
813  const IpoptData&
814  );
816 
817 #if IPOPT_CHECKLEVEL > 0
818 
821  TaggedObject::Tag debug_curr_tag_;
823  TaggedObject::Tag debug_trial_tag_;
824  TaggedObject::Tag debug_delta_tag_;
825  TaggedObject::Tag debug_delta_aff_tag_;
826  TaggedObject::Tag debug_curr_tag_sum_;
827  TaggedObject::Tag debug_trial_tag_sum_;
828  TaggedObject::Tag debug_delta_tag_sum_;
829  TaggedObject::Tag debug_delta_aff_tag_sum_;
831 #endif
832 
833 };
834 
836 {
837  DBG_ASSERT(IsNull(curr_) || (curr_->GetTag() == debug_curr_tag_ && curr_->GetTagSum() == debug_curr_tag_sum_) );
838 
839  return curr_;
840 }
841 
843 {
844  DBG_ASSERT(IsNull(trial_) || (trial_->GetTag() == debug_trial_tag_ && trial_->GetTagSum() == debug_trial_tag_sum_) );
845 
846  return trial_;
847 }
848 
850 {
851  DBG_ASSERT(IsNull(delta_) || (delta_->GetTag() == debug_delta_tag_ && delta_->GetTagSum() == debug_delta_tag_sum_) );
852 
853  return delta_;
854 }
855 
857 {
858  DBG_ASSERT(IsNull(delta_aff_) || (delta_aff_->GetTag() == debug_delta_aff_tag_ && delta_aff_->GetTagSum() == debug_delta_aff_tag_sum_) );
859 
860  return delta_aff_;
861 }
862 
863 inline
865 {
866  curr_ = trial_;
867 #if IPOPT_CHECKLEVEL > 0
868 
869  if (IsValid(curr_))
870  {
871  debug_curr_tag_ = curr_->GetTag();
872  debug_curr_tag_sum_ = curr_->GetTagSum();
873  }
874  else
875  {
876  debug_curr_tag_ = 0;
877  debug_curr_tag_sum_ = 0;
878  }
879 #endif
880 
881 }
882 
883 inline
886 )
887 {
888  trial_ = ConstPtr(trial);
889 
890 #if IPOPT_CHECKLEVEL > 0
891  // verify the correct space
892  DBG_ASSERT(trial_->OwnerSpace() == static_cast<VectorSpace*>(GetRawPtr(iterates_space_)));
893  if (IsValid(trial))
894  {
895  debug_trial_tag_ = trial->GetTag();
896  debug_trial_tag_sum_ = trial->GetTagSum();
897  }
898  else
899  {
900  debug_trial_tag_ = 0;
901  debug_trial_tag_sum_ = 0;
902  }
903 #endif
904 
905  trial = NULL;
906 }
907 
908 inline
911 )
912 {
913  delta_ = ConstPtr(delta);
914 #if IPOPT_CHECKLEVEL > 0
915 
916  if (IsValid(delta))
917  {
918  debug_delta_tag_ = delta->GetTag();
919  debug_delta_tag_sum_ = delta->GetTagSum();
920  }
921  else
922  {
923  debug_delta_tag_ = 0;
924  debug_delta_tag_sum_ = 0;
925  }
926 #endif
927 
928  delta = NULL;
929 }
930 
931 inline
934 )
935 {
936  delta_ = delta;
937 #if IPOPT_CHECKLEVEL > 0
938 
939  if (IsValid(delta))
940  {
941  debug_delta_tag_ = delta->GetTag();
942  debug_delta_tag_sum_ = delta->GetTagSum();
943  }
944  else
945  {
946  debug_delta_tag_ = 0;
947  debug_delta_tag_sum_ = 0;
948  }
949 #endif
950 
951  delta = NULL;
952 }
953 
954 inline
956  SmartPtr<IteratesVector>& delta_aff
957 )
958 {
960 #if IPOPT_CHECKLEVEL > 0
961 
962  if (IsValid(delta_aff))
963  {
964  debug_delta_aff_tag_ = delta_aff->GetTag();
965  debug_delta_aff_tag_sum_ = delta_aff->GetTagSum();
966  }
967  else
968  {
969  debug_delta_aff_tag_ = 0;
970  debug_delta_aff_tag_sum_ = delta_aff->GetTagSum();
971  }
972 #endif
973 
974  delta_aff = NULL;
975 }
976 
977 } // namespace Ipopt
978 
979 #endif
bool IsValid(const SmartPtr< U > &smart_ptr)
Definition: IpSmartPtr.hpp:673
void Set_info_regu_x(Number regu_x)
void set_delta(SmartPtr< IteratesVector > &delta)
Set the current delta.
Number info_regu_x_
Size of regularization for the Hessian.
int info_iters_since_header_
number of iteration summaries actually printed since last summary header was printed ...
void Append_info_string(const std::string &add_str)
void getPDPert(Number &pd_pert_x, Number &pd_pert_s, Number &pd_pert_c, Number &pd_pert_d)
Get the current perturbation of the primal-dual system.
Number curr_tau_
current fraction to the boundary parameter
Number info_last_output()
gives time when the last summary output line was printed
void Set_mu(Number mu)
void SetHaveAffineDeltas(bool have_affine_deltas)
Method for setting the HaveDeltas flag.
Number curr_mu_
current barrier parameter
SmartPtr< IpoptAdditionalData > add_data_
Object for the data specific for the Chen-Goldfarb penalty method algorithm.
void ResetInfo()
Reset all info fields.
void Set_info_alpha_dual(Number alpha_dual)
IPOPT_DEPRECATED Number cpu_time_start() const
Cpu time counter at the beginning of the optimization.
#define IPOPTLIB_EXPORT
Definition: config.h:88
void set_delta_aff(SmartPtr< IteratesVector > &delta_aff)
Set the affine delta.
bool HaveDeltas() const
Returns true, if the primal-dual step have been already computed for the current iteration.
IpoptAdditionalData()
Default Constructor.
Definition: IpIpoptData.hpp:38
void Set_info_ls_count(Index ls_count)
TimingStatistics timing_statistics_
TimingStatistics object collecting all Ipopt timing statistics.
bool info_skip_output() const
void Set_tiny_step_flag(bool flag)
Setting the flag that indicates if a tiny step (below machine precision) has been detected...
Vector Base Class.
Definition: IpVector.hpp:47
bool IsNull(const SmartPtr< U > &smart_ptr)
Definition: IpSmartPtr.hpp:681
void Set_info_last_output(Number info_last_output)
sets time when the last summary output line was printed
void Set_iter_count(Index iter_count)
int info_iters_since_header()
gives number of iteration summaries actually printed since last summary header was printed ...
bool FreeMuMode() const
SmartPtr< const IteratesVector > trial() const
Get the current point in a copied container that is non-const.
bool HaveAffineDeltas() const
Returns true, if the affine-scaling step have been already computed for the current iteration...
Number info_last_output_
time when the last summary output line was printed
void Set_info_alpha_primal_char(char info_alpha_primal_char)
SmartPtr< const SymMatrix > W()
Hessian or Hessian approximation (do not hold on to it, it might be changed)
void SetFreeMuMode(bool free_mu_mode)
bool HaveAddData()
Check if additional data has been set.
void Set_W(SmartPtr< const SymMatrix > W)
Set Hessian approximation.
Number info_alpha_primal_
Primal step size.
ipindex Index
Type of all indices of vectors, matrices etc.
Definition: IpTypes.hpp:20
Number curr_tau() const
This file contains a base class for all exceptions and a set of macros to help with exceptions...
TimingStatistics & TimingStats()
Return Timing Statistics Object.
SmartPtr< const IteratesVector > curr_
Main iteration variables (current iteration)
This class collects all timing statistics for Ipopt.
std::string info_string_
any string of characters for the end of the output line
Template class for Smart Pointers.
Definition: IpSmartPtr.hpp:164
Storing the reference count of all the smart pointers that currently reference it.
This class stores a list of user set options.
bool info_skip_output_
true, if next summary output line should not be printed (eg after restoration phase).
void Append_info_string(const std::string &add_str, double value)
VectorSpace base class, corresponding to the Vector base class.
Definition: IpVector.hpp:472
bool have_affine_deltas_
The following flag is set to true, if some other part of the algorithm (like the method for computing...
SmartPtr< const IteratesVector > delta_aff_
U * GetRawPtr(const SmartPtr< U > &smart_ptr)
Definition: IpSmartPtr.hpp:650
SmartPtr< const IteratesVector > delta() const
get the current delta
Number curr_mu() const
char info_alpha_primal_char() const
Number tol_
Overall convergence tolerance.
SmartPtr< const IteratesVector > delta_
virtual ~IpoptAdditionalData()
Destructor.
Definition: IpIpoptData.hpp:42
bool have_prototypes_
flag for debugging whether we have already curr_ values available (from which new Vectors can be gene...
void Inc_info_iters_since_header()
increases number of iteration summaries actually printed since last summary header was printed ...
IpoptAdditionalData & AdditionalData()
Get access to additional data object.
Class to organize all the data required by the algorithm.
ipnumber Number
Type of all numbers.
Definition: IpTypes.hpp:17
const std::string & info_string() const
Number info_alpha_dual() const
#define DBG_ASSERT(test)
Definition: IpDebug.hpp:27
Number info_alpha_dual_
Dual step size.
bool tiny_step_flag_
flag indicating if a tiny step has been detected
void SetHaveDeltas(bool have_deltas)
Method for setting the HaveDeltas flag.
SmartPtr< const IteratesVector > delta_aff() const
Affine Delta.
SmartPtr< IteratesVectorSpace > iterates_space_
VectorSpace for all the iterates.
unsigned int Tag
Type for the Tag values.
void Set_info_skip_output(bool info_skip_output)
Set this to true, if the next time when output is written, the summary line should not be printed...
SmartPtr< const U > ConstPtr(const SmartPtr< U > &smart_ptr)
Definition: IpSmartPtr.hpp:664
Index iter_count_
iteration count
bool MuInitialized() const
void Set_info_iters_since_header(int info_iters_since_header)
sets number of iteration summaries actually printed since last summary header was printed ...
void Set_tol(Number tol)
Set a new value for the tolerance.
Class responsible for all message output.
bool TauInitialized() const
bool free_mu_mode_
flag indicating whether the algorithm is in the free mu mode
char info_alpha_primal_char_
Info character for primal step size.
SmartPtr< const SymMatrix > W_
Hessian (approximation) - might be changed elsewhere!
Index info_ls_count() const
bool initialize_called_
flag indicating if Initialize method has been called (for debugging)
const TimingStatistics & TimingStats() const
Return Timing Statistics Object.
void Set_tau(Number tau)
void SetAddData(SmartPtr< IpoptAdditionalData > add_data)
Set a new pointer for additional Ipopt data.
void setPDPert(Number pd_pert_x, Number pd_pert_s, Number pd_pert_c, Number pd_pert_d)
Set the perturbation of the primal-dual system.
This is the abstract base class for classes that map the traditional NLP into something that is more ...
Definition: IpIpoptNLP.hpp:35
Number info_alpha_primal() const
SmartPtr< const IteratesVector > curr() const
Current point.
#define IPOPT_DEPRECATED
macro to declare symbols as deprecated
Definition: IpTypes.h:25
Base class for additional data that is special to a particular type of algorithm, such as the CG pena...
Definition: IpIpoptData.hpp:32
bool have_deltas_
The following flag is set to true, if some other part of the algorithm (like the method for computing...
Number tol() const
Overall convergence tolerance.
void Set_info_alpha_primal(Number alpha_primal)
void set_trial(SmartPtr< IteratesVector > &trial)
Get Trial point in a copied container that is non-const.
void CopyTrialToCurrent()
Copy the trial values to the current values.
SmartPtr< const IteratesVector > trial_
Main iteration variables (trial calculations)
Index info_ls_count_
Number of backtracking trial steps.