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:
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:
77  const IpoptAdditionalData&
78  );
79 
81  void operator=(
82  const IpoptAdditionalData&
83  );
85 };
86 
98 {
99 public:
104  SmartPtr<IpoptAdditionalData> add_data = NULL,
105  Number cpu_time_start = -1.
106  );
107 
109  virtual ~IpoptData();
111 
114  IpoptNLP& ip_nlp,
115  bool want_x,
116  bool want_y_c,
117  bool want_y_d,
118  bool want_z_L,
119  bool want_z_U
120  );
121 
128  const Journalist& jnlst,
129  const OptionsList& options,
130  const std::string& prefix
131  );
132 
136  inline SmartPtr<const IteratesVector> curr() const;
137 
143  // SmartPtr<IteratesVector> curr_container() const;
145  inline SmartPtr<const IteratesVector> trial() const;
146 
152  //SmartPtr<IteratesVector> trial_container() const;
159  inline
160  void set_trial(
162  );
163 
168  Number alpha,
169  const Vector& delta_x,
170  const Vector& delta_s
171  );
177  Number alpha,
178  const Vector& delta_y_c,
179  const Vector& delta_y_d
180  );
186  Number alpha,
187  const Vector& delta_z_L,
188  const Vector& delta_z_U,
189  const Vector& delta_v_L,
190  const Vector& delta_v_U
191  );
192 
196  // void set_trial(const SmartPtr<IteratesVector>& trial_iterates);
197  // void set_trial(SmartPtr<const IteratesVector>& trial_iterates);
199  inline SmartPtr<const IteratesVector> delta() const;
200 
207  inline
208  void set_delta(
210  );
211 
220  inline
221  void set_delta(
223  );
224 
226  inline SmartPtr<const IteratesVector> delta_aff() const;
227 
234  inline
235  void set_delta_aff(
236  SmartPtr<IteratesVector>& delta_aff
237  );
238 
241  {
242  DBG_ASSERT(IsValid(W_));
243  return W_;
244  }
245 
247  void Set_W(
249  )
250  {
251  W_ = W;
252  }
253 
273  bool HaveDeltas() const
274  {
275  return have_deltas_;
276  }
277 
287  bool have_deltas
288  )
289  {
290  have_deltas_ = have_deltas;
291  }
293 
313  bool HaveAffineDeltas() const
314  {
315  return have_affine_deltas_;
316  }
317 
327  bool have_affine_deltas
328  )
329  {
330  have_affine_deltas_ = have_affine_deltas;
331  }
333 
337  inline
338  void CopyTrialToCurrent();
339 
343 
347  {
348  return iter_count_;
349  }
351  Index iter_count
352  )
353  {
354  iter_count_ = iter_count;
355  }
356 
357  Number curr_mu() const
358  {
359  DBG_ASSERT(mu_initialized_);
360  return curr_mu_;
361  }
362  void Set_mu(
363  Number mu
364  )
365  {
366  curr_mu_ = mu;
367  mu_initialized_ = true;
368  }
369  bool MuInitialized() const
370  {
371  return mu_initialized_;
372  }
373 
374  Number curr_tau() const
375  {
376  DBG_ASSERT(tau_initialized_);
377  return curr_tau_;
378  }
379  void Set_tau(
380  Number tau
381  )
382  {
383  curr_tau_ = tau;
384  tau_initialized_ = true;
385  }
386  bool TauInitialized() const
387  {
388  return tau_initialized_;
389  }
390 
392  bool free_mu_mode
393  )
394  {
395  free_mu_mode_ = free_mu_mode;
396  }
397  bool FreeMuMode() const
398  {
399  return free_mu_mode_;
400  }
401 
406  bool flag
407  )
408  {
409  tiny_step_flag_ = flag;
410  }
412  {
413  return tiny_step_flag_;
414  }
416 
426  Number tol() const
427  {
428  DBG_ASSERT(initialize_called_);
429  return tol_;
430  }
441  void Set_tol(
442  Number tol
443  )
444  {
445  tol_ = tol;
446  }
448 
457  {
458  DBG_ASSERT(cpu_time_start_ >= 0);
459  return cpu_time_start_;
460  }
461 
465  {
466  return info_regu_x_;
467  }
469  Number regu_x
470  )
471  {
472  info_regu_x_ = regu_x;
473  }
475  {
476  return info_alpha_primal_;
477  }
479  Number alpha_primal
480  )
481  {
482  info_alpha_primal_ = alpha_primal;
483  }
485  {
486  return info_alpha_primal_char_;
487  }
489  char info_alpha_primal_char
490  )
491  {
492  info_alpha_primal_char_ = info_alpha_primal_char;
493  }
495  {
496  return info_alpha_dual_;
497  }
499  Number alpha_dual
500  )
501  {
502  info_alpha_dual_ = alpha_dual;
503  }
505  {
506  return info_ls_count_;
507  }
509  Index ls_count
510  )
511  {
512  info_ls_count_ = ls_count;
513  }
514  bool info_skip_output() const
515  {
516  return info_skip_output_;
517  }
519  const std::string& add_str
520  )
521  {
522  info_string_ += add_str;
523  }
524  const std::string& info_string() const
525  {
526  return info_string_;
527  }
532  bool info_skip_output
533  )
534  {
535  info_skip_output_ = info_skip_output;
536  }
537 
540  {
541  return info_last_output_;
542  }
545  Number info_last_output
546  )
547  {
548  info_last_output_ = info_last_output;
549  }
550 
555  {
556  return info_iters_since_header_;
557  }
562  {
563  info_iters_since_header_++;
564  }
569  int info_iters_since_header
570  )
571  {
572  info_iters_since_header_ = info_iters_since_header;
573  }
574 
576  void ResetInfo()
577  {
578  info_regu_x_ = 0;
579  info_alpha_primal_ = 0;
580  info_alpha_dual_ = 0.;
581  info_alpha_primal_char_ = ' ';
582  info_skip_output_ = false;
583  info_string_.erase();
584  }
586 
589  {
590  return timing_statistics_;
591  }
592 
595  {
596  cpu_time_start_ = CpuTime();
597  }
598 
600  bool HaveAddData()
601  {
602  return IsValid(add_data_);
603  }
604 
607  {
608  return *add_data_;
609  }
610 
614  )
615  {
616  DBG_ASSERT(!HaveAddData());
617  add_data_ = add_data;
618  }
619 
621  void setPDPert(
622  Number pd_pert_x,
623  Number pd_pert_s,
624  Number pd_pert_c,
625  Number pd_pert_d
626  )
627  {
628  pd_pert_x_ = pd_pert_x;
629  pd_pert_s_ = pd_pert_s;
630  pd_pert_c_ = pd_pert_c;
631  pd_pert_d_ = pd_pert_d;
632  }
633 
635  void getPDPert(
636  Number& pd_pert_x,
637  Number& pd_pert_s,
638  Number& pd_pert_c,
639  Number& pd_pert_d
640  )
641  {
642  pd_pert_x = pd_pert_x_;
643  pd_pert_s = pd_pert_s_;
644  pd_pert_c = pd_pert_c_;
645  pd_pert_d = pd_pert_d_;
646  }
647 
648  static void RegisterOptions(
649  const SmartPtr<RegisteredOptions>& roptions
650  );
651 
652 private:
657 
660 
663 
677 
696 
699 
703 
707 
710 
715 
727 
735 
753  std::string info_string_;
761 
764 
767 
770 
775 
783 
796  const IpoptData&
797  );
798 
800  void operator=(
801  const IpoptData&
802  );
804 
805 #if COIN_IPOPT_CHECKLEVEL > 0
810  TaggedObject::Tag debug_curr_tag_;
811  TaggedObject::Tag debug_trial_tag_;
812  TaggedObject::Tag debug_delta_tag_;
813  TaggedObject::Tag debug_delta_aff_tag_;
814  TaggedObject::Tag debug_curr_tag_sum_;
815  TaggedObject::Tag debug_trial_tag_sum_;
816  TaggedObject::Tag debug_delta_tag_sum_;
817  TaggedObject::Tag debug_delta_aff_tag_sum_;
819 #endif
820 
821 };
822 
824 {
825  DBG_ASSERT(IsNull(curr_) || (curr_->GetTag() == debug_curr_tag_ && curr_->GetTagSum() == debug_curr_tag_sum_) );
826 
827  return curr_;
828 }
829 
831 {
832  DBG_ASSERT(IsNull(trial_) || (trial_->GetTag() == debug_trial_tag_ && trial_->GetTagSum() == debug_trial_tag_sum_) );
833 
834  return trial_;
835 }
836 
838 {
839  DBG_ASSERT(IsNull(delta_) || (delta_->GetTag() == debug_delta_tag_ && delta_->GetTagSum() == debug_delta_tag_sum_) );
840 
841  return delta_;
842 }
843 
845 {
846  DBG_ASSERT(IsNull(delta_aff_) || (delta_aff_->GetTag() == debug_delta_aff_tag_ && delta_aff_->GetTagSum() == debug_delta_aff_tag_sum_) );
847 
848  return delta_aff_;
849 }
850 
851 inline
853 {
854  curr_ = trial_;
855 #if COIN_IPOPT_CHECKLEVEL > 0
856 
857  if (IsValid(curr_))
858  {
859  debug_curr_tag_ = curr_->GetTag();
860  debug_curr_tag_sum_ = curr_->GetTagSum();
861  }
862  else
863  {
864  debug_curr_tag_ = 0;
865  debug_curr_tag_sum_ = 0;
866  }
867 #endif
868 
869 }
870 
871 inline
874 )
875 {
876  trial_ = ConstPtr(trial);
877 
878 #if COIN_IPOPT_CHECKLEVEL > 0
879  // verify the correct space
881  if (IsValid(trial))
882  {
883  debug_trial_tag_ = trial->GetTag();
884  debug_trial_tag_sum_ = trial->GetTagSum();
885  }
886  else
887  {
888  debug_trial_tag_ = 0;
889  debug_trial_tag_sum_ = 0;
890  }
891 #endif
892 
893  trial = NULL;
894 }
895 
896 inline
899 )
900 {
901  delta_ = ConstPtr(delta);
902 #if COIN_IPOPT_CHECKLEVEL > 0
903 
904  if (IsValid(delta))
905  {
906  debug_delta_tag_ = delta->GetTag();
907  debug_delta_tag_sum_ = delta->GetTagSum();
908  }
909  else
910  {
911  debug_delta_tag_ = 0;
912  debug_delta_tag_sum_ = 0;
913  }
914 #endif
915 
916  delta = NULL;
917 }
918 
919 inline
922 )
923 {
924  delta_ = delta;
925 #if COIN_IPOPT_CHECKLEVEL > 0
926 
927  if (IsValid(delta))
928  {
929  debug_delta_tag_ = delta->GetTag();
930  debug_delta_tag_sum_ = delta->GetTagSum();
931  }
932  else
933  {
934  debug_delta_tag_ = 0;
935  debug_delta_tag_sum_ = 0;
936  }
937 #endif
938 
939  delta = NULL;
940 }
941 
942 inline
944  SmartPtr<IteratesVector>& delta_aff
945 )
946 {
948 #if COIN_IPOPT_CHECKLEVEL > 0
949 
950  if (IsValid(delta_aff))
951  {
952  debug_delta_aff_tag_ = delta_aff->GetTag();
953  debug_delta_aff_tag_sum_ = delta_aff->GetTagSum();
954  }
955  else
956  {
957  debug_delta_aff_tag_ = 0;
958  debug_delta_aff_tag_sum_ = delta_aff->GetTagSum();
959  }
960 #endif
961 
962  delta_aff = NULL;
963 }
964 
965 } // namespace Ipopt
966 
967 #endif
#define DBG_ASSERT(test)
Definition: IpDebug.hpp:28
Base class for additional data that is special to a particular type of algorithm, such as the CG pena...
Definition: IpIpoptData.hpp:30
IpoptAdditionalData()
Default Constructor.
Definition: IpIpoptData.hpp:35
IpoptAdditionalData(const IpoptAdditionalData &)
Copy Constructor.
void operator=(const IpoptAdditionalData &)
Default Assignment Operator.
virtual bool Initialize(const Journalist &jnlst, const OptionsList &options, const std::string &prefix)=0
This method is called to initialize the global algorithmic parameters.
virtual bool InitializeDataStructures()=0
Initialize Data Structures at the beginning.
virtual ~IpoptAdditionalData()
Destructor.
Definition: IpIpoptData.hpp:39
virtual void AcceptTrialPoint()=0
Do whatever is necessary to accept a trial point as current iterate.
Class to organize all the data required by the algorithm.
Definition: IpIpoptData.hpp:98
TimingStatistics timing_statistics_
TimingStatistics object collecting all Ipopt timing statistics.
Number cpu_time_start() const
Cpu time counter at the beginning of the optimization.
Number info_alpha_primal() const
Index info_ls_count_
Number of backtracking trial steps.
void operator=(const IpoptData &)
Default Assignment Operator.
bool HaveAddData()
Check if additional data has been set.
Number info_regu_x() const
std::string info_string_
any string of characters for the end of the output line
void set_delta_aff(SmartPtr< IteratesVector > &delta_aff)
Set the affine delta.
void Append_info_string(const std::string &add_str)
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.
bool free_mu_mode_
flag indicating whether the algorithm is in the free mu mode
void Set_info_last_output(Number info_last_output)
sets time when the last summary output line was printed
void Set_info_regu_x(Number regu_x)
void Set_W(SmartPtr< const SymMatrix > W)
Set Hessian approximation.
SmartPtr< const IteratesVector > trial_
Main iteration variables (trial calculations)
SmartPtr< const IteratesVector > delta_aff_
void Inc_info_iters_since_header()
increases number of iteration summaries actually printed since last summary header was printed
bool have_deltas_
The following flag is set to true, if some other part of the algorithm (like the method for computing...
bool initialize_called_
flag indicating if Initialize method has been called (for debugging)
Index info_ls_count() const
void SetTrialEqMultipliersFromStep(Number alpha, const Vector &delta_y_c, const Vector &delta_y_d)
Set the values of the trial values for the equality constraint multipliers (y_c and y_d) from provide...
void SetHaveDeltas(bool have_deltas)
Method for setting the HaveDeltas flag.
Number curr_tau() const
SmartPtr< const SymMatrix > W()
Hessian or Hessian approximation (do not hold on to it, it might be changed)
int info_iters_since_header_
number of iteration summaries actually printed since last summary header was printed
bool HaveDeltas() const
Returns true, if the primal-dual step have been already computed for the current iteration.
Number info_alpha_dual_
Dual step size.
SmartPtr< const IteratesVector > delta() const
ToDo: I may need to add versions of set_trial like the following, but I am not sure.
void Set_info_ls_count(Index ls_count)
TimingStatistics & TimingStats()
Return Timing Statistics Object.
SmartPtr< IpoptAdditionalData > add_data_
Object for the data specific for the Chen-Goldfarb penalty method algorithm.
const std::string & info_string() const
bool have_affine_deltas_
The following flag is set to true, if some other part of the algorithm (like the method for computing...
Number cpu_time_start_
CPU time counter at begin of optimization.
SmartPtr< const IteratesVector > curr_
Main iteration variables (current iteration)
void SetTrialPrimalVariablesFromStep(Number alpha, const Vector &delta_x, const Vector &delta_s)
Set the values of the primal trial variables (x and s) from provided Step with step length alpha.
IpoptData(SmartPtr< IpoptAdditionalData > add_data=NULL, Number cpu_time_start=-1.)
Constructor.
void AcceptTrialPoint()
Set the current iterate values from the trial values.
Number info_alpha_primal_
Primal step size.
void CopyTrialToCurrent()
Copy the trial values to the current values.
void Set_info_alpha_primal_char(char info_alpha_primal_char)
void ResetCpuStartTime()
Resetting CPU Start Time.
Number info_alpha_dual() const
IpoptData(const IpoptData &)
Copy Constructor.
void Set_tiny_step_flag(bool flag)
Setting the flag that indicates if a tiny step (below machine precision) has been detected.
Index iter_count() const
SmartPtr< const IteratesVector > curr() const
Current point.
void Set_info_alpha_dual(Number alpha_dual)
void ResetInfo()
Reset all info fields.
void SetTrialBoundMultipliersFromStep(Number alpha, const Vector &delta_z_L, const Vector &delta_z_U, const Vector &delta_v_L, const Vector &delta_v_U)
Set the value of the trial values for the bound multipliers (z_L, z_U, v_L, v_U) from provided step w...
void Set_iter_count(Index iter_count)
Number curr_tau_
current fraction to the boundary parameter
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.
int info_iters_since_header()
gives number of iteration summaries actually printed since last summary header was printed
bool tiny_step_flag_
flag indicating if a tiny step has been detected
IpoptAdditionalData & AdditionalData()
Get access to additional data object.
void Set_info_iters_since_header(int info_iters_since_header)
sets number of iteration summaries actually printed since last summary header was printed
SmartPtr< IteratesVectorSpace > iterates_space_
VectorSpace for all the iterates.
void Set_tau(Number tau)
bool info_skip_output() const
Number tol_
Overall convergence tolerance.
Number curr_mu_
current barrier parameter
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.
Number tol() const
Overall convergence tolerance.
bool FreeMuMode() const
char info_alpha_primal_char_
Info character for primal step size.
bool have_prototypes_
flag for debugging whether we have already curr_ values available (from which new Vectors can be gene...
void Set_tol(Number tol)
Set a new value for the tolerance.
bool info_skip_output_
true, if next summary output line should not be printed (eg after restoration phase).
void SetFreeMuMode(bool free_mu_mode)
static void RegisterOptions(const SmartPtr< RegisteredOptions > &roptions)
virtual ~IpoptData()
Destructor.
bool InitializeDataStructures(IpoptNLP &ip_nlp, bool want_x, bool want_y_c, bool want_y_d, bool want_z_L, bool want_z_U)
Initialize Data Structures.
char info_alpha_primal_char() const
SmartPtr< const IteratesVector > delta_
bool Initialize(const Journalist &jnlst, const OptionsList &options, const std::string &prefix)
This method must be called to initialize the global algorithmic parameters.
Number info_last_output_
time when the last summary output line was printed
Index iter_count_
iteration count
Number info_last_output()
gives time when the last summary output line was printed
void set_delta(SmartPtr< IteratesVector > &delta)
Set the current delta.
Number curr_mu() const
SmartPtr< const SymMatrix > W_
Hessian (approximation) - might be changed elsewhere!
void Set_mu(Number mu)
bool MuInitialized() const
void SetHaveAffineDeltas(bool have_affine_deltas)
Method for setting the HaveDeltas flag.
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 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.
bool TauInitialized() const
SmartPtr< const IteratesVector > delta_aff() const
Affine Delta.
Number info_regu_x_
Size of regularization for the Hessian.
void SetAddData(SmartPtr< IpoptAdditionalData > add_data)
Set a new pointer for additional Ipopt data.
This is the abstract base class for classes that map the traditional NLP into something that is more ...
Definition: IpIpoptNLP.hpp:28
Class responsible for all message output.
This class stores a list of user set options.
Storing the reference count of all the smart pointers that currently reference it.
Template class for Smart Pointers.
Definition: IpSmartPtr.hpp:172
unsigned int Tag
Type for the Tag values.
This class collects all timing statistics for Ipopt.
VectorSpace base class, corresponding to the Vector base class.
Definition: IpVector.hpp:459
Vector Base Class.
Definition: IpVector.hpp:48
#define IPOPTLIB_EXPORT
This file contains a base class for all exceptions and a set of macros to help with exceptions.
SmartPtr< const U > ConstPtr(const SmartPtr< U > &smart_ptr)
Definition: IpSmartPtr.hpp:665
bool IsValid(const SmartPtr< U > &smart_ptr)
Definition: IpSmartPtr.hpp:674
IPOPTLIB_EXPORT Number CpuTime()
method determining CPU time
U * GetRawPtr(const SmartPtr< U > &smart_ptr)
Definition: IpSmartPtr.hpp:651
int Index
Type of all indices of vectors, matrices etc.
Definition: IpTypes.hpp:17
bool IsNull(const SmartPtr< U > &smart_ptr)
Definition: IpSmartPtr.hpp:682
double Number
Type of all numbers.
Definition: IpTypes.hpp:15