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 namespace Ipopt
17 {
18 
19 /* Forward declaration */
20 class IpoptNLP;
21 
30 {
31 public:
33 
36  { }
37 
40  { }
42 
48  virtual bool Initialize(
49  const Journalist& jnlst,
50  const OptionsList& options,
51  const std::string& prefix
52  ) = 0;
53 
55  virtual bool InitializeDataStructures() = 0;
56 
62  virtual void AcceptTrialPoint() = 0;
63 
64 private:
74 
77  const IpoptAdditionalData&
78  );
79 
81  void operator=(
82  const IpoptAdditionalData&
83  );
85 };
86 
98 {
99 public:
101 
103  IpoptData(
104  SmartPtr<IpoptAdditionalData> add_data = NULL
105  );
106 
108  virtual ~IpoptData();
110 
112  bool InitializeDataStructures(
113  IpoptNLP& ip_nlp,
114  bool want_x,
115  bool want_y_c,
116  bool want_y_d,
117  bool want_z_L,
118  bool want_z_U
119  );
120 
126  bool Initialize(
127  const Journalist& jnlst,
128  const OptionsList& options,
129  const std::string& prefix
130  );
131 
133 
135  inline SmartPtr<const IteratesVector> curr() const;
136 
142  // SmartPtr<IteratesVector> curr_container() const;
144  inline SmartPtr<const IteratesVector> trial() const;
145 
151  //SmartPtr<IteratesVector> trial_container() const;
158  inline
159  void set_trial(
161  );
162  /* ToDo: I may need to add versions of set_trial like the
163  * following, but I am not sure
164  */
165  // void set_trial(const SmartPtr<IteratesVector>& trial_iterates);
166  // void set_trial(SmartPtr<const IteratesVector>& trial_iterates);
167 
171  void SetTrialPrimalVariablesFromStep(
172  Number alpha,
173  const Vector& delta_x,
174  const Vector& delta_s
175  );
180  void SetTrialEqMultipliersFromStep(
181  Number alpha,
182  const Vector& delta_y_c,
183  const Vector& delta_y_d
184  );
189  void SetTrialBoundMultipliersFromStep(
190  Number alpha,
191  const Vector& delta_z_L,
192  const Vector& delta_z_U,
193  const Vector& delta_v_L,
194  const Vector& delta_v_U
195  );
196 
198  inline SmartPtr<const IteratesVector> delta() const;
199 
206  inline
207  void set_delta(
209  );
210 
219  inline
220  void set_delta(
222  );
223 
225  inline SmartPtr<const IteratesVector> delta_aff() const;
226 
233  inline
234  void set_delta_aff(
235  SmartPtr<IteratesVector>& delta_aff
236  );
237 
240  {
241  DBG_ASSERT(IsValid(W_));
242  return W_;
243  }
244 
246  void Set_W(
248  )
249  {
250  W_ = W;
251  }
252 
261 
272  bool HaveDeltas() const
273  {
274  return have_deltas_;
275  }
276 
286  bool have_deltas
287  )
288  {
289  have_deltas_ = have_deltas;
290  }
292 
301 
312  bool HaveAffineDeltas() const
313  {
314  return have_affine_deltas_;
315  }
316 
326  bool have_affine_deltas
327  )
328  {
329  have_affine_deltas_ = have_affine_deltas;
330  }
332 
334 
336  inline
337  void CopyTrialToCurrent();
338 
340  void AcceptTrialPoint();
342 
344  Index iter_count() const
346  {
347  return iter_count_;
348  }
350  Index iter_count
351  )
352  {
353  iter_count_ = iter_count;
354  }
355 
356  Number curr_mu() const
357  {
358  DBG_ASSERT(mu_initialized_);
359  return curr_mu_;
360  }
361  void Set_mu(
362  Number mu
363  )
364  {
365  curr_mu_ = mu;
366  mu_initialized_ = true;
367  }
368  bool MuInitialized() const
369  {
370  return mu_initialized_;
371  }
372 
373  Number curr_tau() const
374  {
375  DBG_ASSERT(tau_initialized_);
376  return curr_tau_;
377  }
378  void Set_tau(
379  Number tau
380  )
381  {
382  curr_tau_ = tau;
383  tau_initialized_ = true;
384  }
385  bool TauInitialized() const
386  {
387  return tau_initialized_;
388  }
389 
391  bool free_mu_mode
392  )
393  {
394  free_mu_mode_ = free_mu_mode;
395  }
396  bool FreeMuMode() const
397  {
398  return free_mu_mode_;
399  }
400 
405  bool flag
406  )
407  {
408  tiny_step_flag_ = flag;
409  }
411  {
412  return tiny_step_flag_;
413  }
415 
423 
425  Number tol() const
426  {
427  DBG_ASSERT(initialize_called_);
428  return tol_;
429  }
440  void Set_tol(
441  Number tol
442  )
443  {
444  tol_ = tol;
445  }
447 
457  {
458  return timing_statistics_.OverallAlgorithm().StartCpuTime();
459  }
460 
462  Number info_regu_x() const
464  {
465  return info_regu_x_;
466  }
468  Number regu_x
469  )
470  {
471  info_regu_x_ = regu_x;
472  }
474  {
475  return info_alpha_primal_;
476  }
478  Number alpha_primal
479  )
480  {
481  info_alpha_primal_ = alpha_primal;
482  }
484  {
485  return info_alpha_primal_char_;
486  }
488  char info_alpha_primal_char
489  )
490  {
491  info_alpha_primal_char_ = info_alpha_primal_char;
492  }
494  {
495  return info_alpha_dual_;
496  }
498  Number alpha_dual
499  )
500  {
501  info_alpha_dual_ = alpha_dual;
502  }
504  {
505  return info_ls_count_;
506  }
508  Index ls_count
509  )
510  {
511  info_ls_count_ = ls_count;
512  }
513  bool info_skip_output() const
514  {
515  return info_skip_output_;
516  }
518  const std::string& add_str
519  )
520  {
521  info_string_ += add_str;
522  }
523  const std::string& info_string() const
524  {
525  return info_string_;
526  }
531  bool info_skip_output
532  )
533  {
534  info_skip_output_ = info_skip_output;
535  }
536 
539  {
540  return info_last_output_;
541  }
544  Number info_last_output
545  )
546  {
547  info_last_output_ = info_last_output;
548  }
549 
554  {
555  return info_iters_since_header_;
556  }
561  {
562  info_iters_since_header_++;
563  }
568  int info_iters_since_header
569  )
570  {
571  info_iters_since_header_ = info_iters_since_header;
572  }
573 
575  void ResetInfo()
576  {
577  info_regu_x_ = 0;
578  info_alpha_primal_ = 0;
579  info_alpha_dual_ = 0.;
580  info_alpha_primal_char_ = ' ';
581  info_skip_output_ = false;
582  info_string_.erase();
583  }
585 
588  {
589  return timing_statistics_;
590  }
591 
593  bool HaveAddData()
594  {
595  return IsValid(add_data_);
596  }
597 
600  {
601  return *add_data_;
602  }
603 
607  )
608  {
609  // cppcheck-suppress assertWithSideEffect
610  DBG_ASSERT(!HaveAddData());
611  add_data_ = add_data;
612  }
613 
615  void setPDPert(
616  Number pd_pert_x,
617  Number pd_pert_s,
618  Number pd_pert_c,
619  Number pd_pert_d
620  )
621  {
622  pd_pert_x_ = pd_pert_x;
623  pd_pert_s_ = pd_pert_s;
624  pd_pert_c_ = pd_pert_c;
625  pd_pert_d_ = pd_pert_d;
626  }
627 
629  void getPDPert(
630  Number& pd_pert_x,
631  Number& pd_pert_s,
632  Number& pd_pert_c,
633  Number& pd_pert_d
634  )
635  {
636  pd_pert_x = pd_pert_x_;
637  pd_pert_s = pd_pert_s_;
638  pd_pert_c = pd_pert_c_;
639  pd_pert_d = pd_pert_d_;
640  }
641 
642  static void RegisterOptions(
643  const SmartPtr<RegisteredOptions>& roptions
644  );
645 
646 private:
648 
651 
654 
657 
668  // ToDo we could cue off of a null delta_
671 
687  // ToDo we could cue off of a null delta_aff_
690 
693 
697 
701 
704 
709 
717 
721 
723 
729 
731 
747  std::string info_string_;
755 
758 
761 
766 
768  Number pd_pert_x_;
774 
784 
786  IpoptData(
787  const IpoptData&
788  );
789 
791  void operator=(
792  const IpoptData&
793  );
795 
796 #if IPOPT_CHECKLEVEL > 0
797 
800  TaggedObject::Tag debug_curr_tag_;
802  TaggedObject::Tag debug_trial_tag_;
803  TaggedObject::Tag debug_delta_tag_;
804  TaggedObject::Tag debug_delta_aff_tag_;
805  TaggedObject::Tag debug_curr_tag_sum_;
806  TaggedObject::Tag debug_trial_tag_sum_;
807  TaggedObject::Tag debug_delta_tag_sum_;
808  TaggedObject::Tag debug_delta_aff_tag_sum_;
810 #endif
811 
812 };
813 
815 {
816  DBG_ASSERT(IsNull(curr_) || (curr_->GetTag() == debug_curr_tag_ && curr_->GetTagSum() == debug_curr_tag_sum_) );
817 
818  return curr_;
819 }
820 
822 {
823  DBG_ASSERT(IsNull(trial_) || (trial_->GetTag() == debug_trial_tag_ && trial_->GetTagSum() == debug_trial_tag_sum_) );
824 
825  return trial_;
826 }
827 
829 {
830  DBG_ASSERT(IsNull(delta_) || (delta_->GetTag() == debug_delta_tag_ && delta_->GetTagSum() == debug_delta_tag_sum_) );
831 
832  return delta_;
833 }
834 
836 {
837  DBG_ASSERT(IsNull(delta_aff_) || (delta_aff_->GetTag() == debug_delta_aff_tag_ && delta_aff_->GetTagSum() == debug_delta_aff_tag_sum_) );
838 
839  return delta_aff_;
840 }
841 
842 inline
844 {
845  curr_ = trial_;
846 #if IPOPT_CHECKLEVEL > 0
847 
848  if (IsValid(curr_))
849  {
850  debug_curr_tag_ = curr_->GetTag();
851  debug_curr_tag_sum_ = curr_->GetTagSum();
852  }
853  else
854  {
855  debug_curr_tag_ = 0;
856  debug_curr_tag_sum_ = 0;
857  }
858 #endif
859 
860 }
861 
862 inline
865 )
866 {
867  trial_ = ConstPtr(trial);
868 
869 #if IPOPT_CHECKLEVEL > 0
870  // verify the correct space
871  DBG_ASSERT(trial_->OwnerSpace() == static_cast<VectorSpace*>(GetRawPtr(iterates_space_)));
872  if (IsValid(trial))
873  {
874  debug_trial_tag_ = trial->GetTag();
875  debug_trial_tag_sum_ = trial->GetTagSum();
876  }
877  else
878  {
879  debug_trial_tag_ = 0;
880  debug_trial_tag_sum_ = 0;
881  }
882 #endif
883 
884  trial = NULL;
885 }
886 
887 inline
890 )
891 {
892  delta_ = ConstPtr(delta);
893 #if IPOPT_CHECKLEVEL > 0
894 
895  if (IsValid(delta))
896  {
897  debug_delta_tag_ = delta->GetTag();
898  debug_delta_tag_sum_ = delta->GetTagSum();
899  }
900  else
901  {
902  debug_delta_tag_ = 0;
903  debug_delta_tag_sum_ = 0;
904  }
905 #endif
906 
907  delta = NULL;
908 }
909 
910 inline
913 )
914 {
915  delta_ = delta;
916 #if IPOPT_CHECKLEVEL > 0
917 
918  if (IsValid(delta))
919  {
920  debug_delta_tag_ = delta->GetTag();
921  debug_delta_tag_sum_ = delta->GetTagSum();
922  }
923  else
924  {
925  debug_delta_tag_ = 0;
926  debug_delta_tag_sum_ = 0;
927  }
928 #endif
929 
930  delta = NULL;
931 }
932 
933 inline
935  SmartPtr<IteratesVector>& delta_aff
936 )
937 {
939 #if IPOPT_CHECKLEVEL > 0
940 
941  if (IsValid(delta_aff))
942  {
943  debug_delta_aff_tag_ = delta_aff->GetTag();
944  debug_delta_aff_tag_sum_ = delta_aff->GetTagSum();
945  }
946  else
947  {
948  debug_delta_aff_tag_ = 0;
949  debug_delta_aff_tag_sum_ = delta_aff->GetTagSum();
950  }
951 #endif
952 
953  delta_aff = NULL;
954 }
955 
956 } // namespace Ipopt
957 
958 #endif
bool IsValid(const SmartPtr< U > &smart_ptr)
Definition: IpSmartPtr.hpp:672
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:94
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:35
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:680
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).
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:649
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:39
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.
Definition: IpIpoptData.hpp:97
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:663
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)
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:29
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.