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 // $Id: IpIpoptData.hpp 1861 2010-12-21 21:34:47Z andreasw $
6 //
7 // Authors: Carl Laird, Andreas Waechter IBM 2004-08-13
8 
9 #ifndef __IPIPOPTDATA_HPP__
10 #define __IPIPOPTDATA_HPP__
11 
12 #include "IpSymMatrix.hpp"
13 #include "IpOptionsList.hpp"
14 #include "IpIteratesVector.hpp"
15 #include "IpRegOptions.hpp"
16 #include "IpTimingStatistics.hpp"
17 
18 namespace Ipopt
19 {
20 
21  /* Forward declaration */
22  class IpoptNLP;
23 
29  {
30  public:
35  {}
36 
39  {}
41 
45  virtual bool Initialize(const Journalist& jnlst,
46  const OptionsList& options,
47  const std::string& prefix) = 0;
48 
50  virtual bool InitializeDataStructures() = 0;
51 
55  virtual void AcceptTrialPoint() = 0;
56 
57  private:
68 
70  void operator=(const IpoptAdditionalData&);
72  };
73 
83  class IpoptData : public ReferencedObject
84  {
85  public:
90  Number cpu_time_start = -1.);
91 
93  virtual ~IpoptData();
95 
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 
107  bool Initialize(const Journalist& jnlst,
108  const OptionsList& options,
109  const std::string& prefix);
110 
115 
120  // SmartPtr<IteratesVector> curr_container() const;
121 
124 
129  //SmartPtr<IteratesVector> trial_container() const;
130 
135  void set_trial(SmartPtr<IteratesVector>& trial);
136 
141  const Vector& delta_x,
142  const Vector& delta_s);
148  const Vector& delta_y_c,
149  const Vector& delta_y_d);
155  const Vector& delta_z_L,
156  const Vector& delta_z_U,
157  const Vector& delta_v_L,
158  const Vector& delta_v_U);
159 
163  // void set_trial(const SmartPtr<IteratesVector>& trial_iterates);
164  // void set_trial(SmartPtr<const IteratesVector>& trial_iterates);
165 
168 
173  void set_delta(SmartPtr<IteratesVector>& delta);
174 
182 
185 
190  void set_delta_aff(SmartPtr<IteratesVector>& delta_aff);
191 
194  {
196  return W_;
197  }
198 
201  {
202  W_ = W;
203  }
204 
211 
219  bool HaveDeltas() const
220  {
221  return have_deltas_;
222  }
223 
229  void SetHaveDeltas(bool have_deltas)
230  {
231  have_deltas_ = have_deltas;
232  }
234 
241 
249  bool HaveAffineDeltas() const
250  {
251  return have_affine_deltas_;
252  }
253 
259  void SetHaveAffineDeltas(bool have_affine_deltas)
260  {
261  have_affine_deltas_ = have_affine_deltas;
262  }
264 
268  void CopyTrialToCurrent();
269 
272  void AcceptTrialPoint();
274 
278  {
279  return iter_count_;
280  }
282  {
284  }
285 
286  Number curr_mu() const
287  {
289  return curr_mu_;
290  }
291  void Set_mu(Number mu)
292  {
293  curr_mu_ = mu;
294  mu_initialized_ = true;
295  }
296  bool MuInitialized() const
297  {
298  return mu_initialized_;
299  }
300 
301  Number curr_tau() const
302  {
304  return curr_tau_;
305  }
306  void Set_tau(Number tau)
307  {
308  curr_tau_ = tau;
309  tau_initialized_ = true;
310  }
311  bool TauInitialized() const
312  {
313  return tau_initialized_;
314  }
315 
316  void SetFreeMuMode(bool free_mu_mode)
317  {
318  free_mu_mode_ = free_mu_mode;
319  }
320  bool FreeMuMode() const
321  {
322  return free_mu_mode_;
323  }
324 
327  void Set_tiny_step_flag(bool flag)
328  {
329  tiny_step_flag_ = flag;
330  }
332  {
333  return tiny_step_flag_;
334  }
336 
343  Number tol() const
344  {
346  return tol_;
347  }
356  {
357  tol_ = tol;
358  }
360 
365  {
366  return cpu_time_start_;
367  }
368 
372  {
373  return info_regu_x_;
374  }
375  void Set_info_regu_x(Number regu_x)
376  {
377  info_regu_x_ = regu_x;
378  }
380  {
381  return info_alpha_primal_;
382  }
383  void Set_info_alpha_primal(Number alpha_primal)
384  {
385  info_alpha_primal_ = alpha_primal;
386  }
388  {
390  }
392  {
394  }
396  {
397  return info_alpha_dual_;
398  }
399  void Set_info_alpha_dual(Number alpha_dual)
400  {
401  info_alpha_dual_ = alpha_dual;
402  }
404  {
405  return info_ls_count_;
406  }
407  void Set_info_ls_count(Index ls_count)
408  {
409  info_ls_count_ = ls_count;
410  }
411  bool info_skip_output() const
412  {
413  return info_skip_output_;
414  }
415  void Append_info_string(const std::string& add_str)
416  {
417  info_string_ += add_str;
418  }
419  const std::string& info_string() const
420  {
421  return info_string_;
422  }
426  {
428  }
429 
431  void ResetInfo()
432  {
433  info_regu_x_ = 0;
434  info_alpha_primal_ = 0;
435  info_alpha_dual_ = 0.;
437  info_skip_output_ = false;
438  info_string_.erase();
439  }
441 
444  {
445  return timing_statistics_;
446  }
447 
449  bool HaveAddData()
450  {
451  return IsValid(add_data_);
452  }
453 
456  {
457  return *add_data_;
458  }
459 
462  {
464  add_data_ = add_data;
465  }
466 
468  void setPDPert(Number pd_pert_x, Number pd_pert_s,
469  Number pd_pert_c, Number pd_pert_d)
470  {
471  pd_pert_x_ = pd_pert_x;
472  pd_pert_s_ = pd_pert_s;
473  pd_pert_c_ = pd_pert_c;
474  pd_pert_d_ = pd_pert_d;
475  }
476 
478  void getPDPert(Number& pd_pert_x, Number& pd_pert_s,
479  Number& pd_pert_c, Number& pd_pert_d)
480  {
481  pd_pert_x = pd_pert_x_;
482  pd_pert_s = pd_pert_s_;
483  pd_pert_c = pd_pert_c_;
484  pd_pert_d = pd_pert_d_;
485  }
486 
489  static void RegisterOptions(const SmartPtr<RegisteredOptions>& roptions);
491 
492  private:
498 
502 
505 
518 
533 
536 
540 
544 
548 
552 
561 
569 
586  std::string info_string_;
588 
591 
595 
598 
602 
611 
621  IpoptData(const IpoptData&);
622 
624  void operator=(const IpoptData&);
626 
627 #if COIN_IPOPT_CHECKLEVEL > 0
628 
632  TaggedObject::Tag debug_curr_tag_;
633  TaggedObject::Tag debug_trial_tag_;
634  TaggedObject::Tag debug_delta_tag_;
635  TaggedObject::Tag debug_delta_aff_tag_;
636  TaggedObject::Tag debug_curr_tag_sum_;
637  TaggedObject::Tag debug_trial_tag_sum_;
638  TaggedObject::Tag debug_delta_tag_sum_;
639  TaggedObject::Tag debug_delta_aff_tag_sum_;
641 #endif
642 
643  };
644 
645  inline
647  {
648  DBG_ASSERT(IsNull(curr_) || (curr_->GetTag() == debug_curr_tag_ && curr_->GetTagSum() == debug_curr_tag_sum_) );
649 
650  return curr_;
651  }
652 
653  inline
655  {
656  DBG_ASSERT(IsNull(trial_) || (trial_->GetTag() == debug_trial_tag_ && trial_->GetTagSum() == debug_trial_tag_sum_) );
657 
658  return trial_;
659  }
660 
661  inline
663  {
664  DBG_ASSERT(IsNull(delta_) || (delta_->GetTag() == debug_delta_tag_ && delta_->GetTagSum() == debug_delta_tag_sum_) );
665 
666  return delta_;
667  }
668 
669  inline
671  {
672  DBG_ASSERT(IsNull(delta_aff_) || (delta_aff_->GetTag() == debug_delta_aff_tag_ && delta_aff_->GetTagSum() == debug_delta_aff_tag_sum_) );
673 
674  return delta_aff_;
675  }
676 
677  inline
679  {
680  curr_ = trial_;
681 #if COIN_IPOPT_CHECKLEVEL > 0
682 
683  if (IsValid(curr_)) {
684  debug_curr_tag_ = curr_->GetTag();
685  debug_curr_tag_sum_ = curr_->GetTagSum();
686  }
687  else {
688  debug_curr_tag_ = 0;
689  debug_curr_tag_sum_ = 0;
690  }
691 #endif
692 
693  }
694 
695  inline
697  {
698  trial_ = ConstPtr(trial);
699 
700 #if COIN_IPOPT_CHECKLEVEL > 0
701  // verify the correct space
703  if (IsValid(trial)) {
704  debug_trial_tag_ = trial->GetTag();
705  debug_trial_tag_sum_ = trial->GetTagSum();
706  }
707  else {
708  debug_trial_tag_ = 0;
709  debug_trial_tag_sum_ = 0;
710  }
711 #endif
712 
713  trial = NULL;
714  }
715 
716  inline
718  {
719  delta_ = ConstPtr(delta);
720 #if COIN_IPOPT_CHECKLEVEL > 0
721 
722  if (IsValid(delta)) {
723  debug_delta_tag_ = delta->GetTag();
724  debug_delta_tag_sum_ = delta->GetTagSum();
725  }
726  else {
727  debug_delta_tag_ = 0;
728  debug_delta_tag_sum_ = 0;
729  }
730 #endif
731 
732  delta = NULL;
733  }
734 
735  inline
737  {
738  delta_ = delta;
739 #if COIN_IPOPT_CHECKLEVEL > 0
740 
741  if (IsValid(delta)) {
742  debug_delta_tag_ = delta->GetTag();
743  debug_delta_tag_sum_ = delta->GetTagSum();
744  }
745  else {
746  debug_delta_tag_ = 0;
747  debug_delta_tag_sum_ = 0;
748  }
749 #endif
750 
751  delta = NULL;
752  }
753 
754  inline
756  {
757  delta_aff_ = ConstPtr(delta_aff);
758 #if COIN_IPOPT_CHECKLEVEL > 0
759 
760  if (IsValid(delta_aff)) {
761  debug_delta_aff_tag_ = delta_aff->GetTag();
762  debug_delta_aff_tag_sum_ = delta_aff->GetTagSum();
763  }
764  else {
765  debug_delta_aff_tag_ = 0;
766  debug_delta_aff_tag_sum_ = delta_aff->GetTagSum();
767  }
768 #endif
769 
770  delta_aff = NULL;
771  }
772 
773 } // namespace Ipopt
774 
775 #endif