ipopt-src 0.2.3+3.14.16

Redistribution of Coin-OR Ipopt as a crate
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
// Copyright (C) 2007, 2008 International Business Machines and others.
// All Rights Reserved.
// This code is published under the Eclipse Public License.
//
// Authors:  Andreas Waechter           IBM     2007-06-04
//                   based on IpIpoptData.hpp

#ifndef __IPCGPENALTYDATA_HPP__
#define __IPCGPENALTYDATA_HPP__

#include "IpIteratesVector.hpp"
#include "IpOptionsList.hpp"
#include "IpIpoptData.hpp"

namespace Ipopt
{

/** Class to organize all the additional data required by the
 *  Chen-Goldfarb penalty function algorithm.
 */
class CGPenaltyData: public IpoptAdditionalData
{
public:
   /**@name Constructors/Destructors */
   ///@{
   /** Constructor */
   CGPenaltyData();

   /** Destructor */
   ~CGPenaltyData();
   ///@}

   /** This method must be called to initialize the global
    *  algorithmic parameters.
    *
    *  The parameters are taken from the OptionsList object.
    */
   bool Initialize(
      const Journalist&  jnlst,
      const OptionsList& options,
      const std::string& prefix);

   /** Initialize Data Structures */
   bool InitializeDataStructures();

   /** Delta for the Chen-Goldfarb search direction */
   SmartPtr<const IteratesVector> delta_cgpen() const;

   /** Set the delta_cgpen
    *
    *  Like the trial point, this method copies
    *  the pointer for efficiency (no copy and to keep cache tags the
    *  same) so after you call set, you cannot modify the data.
    */
   void set_delta_cgpen(
      SmartPtr<IteratesVector>& delta_pen
   );

   /** Set the delta_cgpen
    *
    *  Like the trial point, this method copies
    *  the pointer for efficiency (no copy and to keep cache tags the
    *  same) so after you call set, you cannot modify the data.  This
    *  is the version that is happy with a pointer to const
    *  IteratesVector.
    */
   void set_delta_cgpen(
      SmartPtr<const IteratesVector>& delta_pen
   );

   /** Delta for the fast Chen-Goldfarb search direction */
   SmartPtr<const IteratesVector> delta_cgfast() const;

   /** Set the delta_cgfast
    *
    *  Like the trial point, this method copies
    *  the pointer for efficiency (no copy and to keep cache tags the
    *  same) so after you call set, you cannot modify the data.
    */
   void set_delta_cgfast(
      SmartPtr<IteratesVector>& delta_fast
   );

   /** @name Chen-Goldfarb step2.
    *
    *  Those fields can be used to store
    *  directions related to the Chen-Goldfarb algorithm
    */
   ///@{
   bool HaveCgPenDeltas() const
   {
      return have_cgpen_deltas_;
   }

   void SetHaveCgPenDeltas(
      bool have_cgpen_deltas
   )
   {
      have_cgpen_deltas_ = have_cgpen_deltas;
   }

   bool HaveCgFastDeltas() const
   {
      return have_cgfast_deltas_;
   }

   void SetHaveCgFastDeltas(
      bool have_cgfast_deltas
   )
   {
      have_cgfast_deltas_ = have_cgfast_deltas;
   }
   ///@}

   /** @name Public Methods for updating iterates */
   ///@{
   /** Set the current iterate values from the trial values. */
   void AcceptTrialPoint();
   ///@}

   Number CurrPenaltyPert()
   {
      return curr_penalty_pert_;
   }

   void SetCurrPenaltyPert(
      Number curr_penalty_pert)
   {
      curr_penalty_pert_ = curr_penalty_pert;
   }

   void SetNeverTryPureNewton(
      bool never_try_pure_Newton
   )
   {
      never_try_pure_Newton_ = never_try_pure_Newton;
   }

   Index NeverTryPureNewton()
   {
      return never_try_pure_Newton_;
   }

   Index restor_iter()
   {
      return restor_iter_;
   }

   void SetRestorIter(
      Index restor_iter
   )
   {
      restor_iter_ = restor_iter;
   }

   Number restor_counter()
   {
      return restor_counter_;
   }

   void SetRestorCounter(
      Number restor_counter
   )
   {
      restor_counter_ = restor_counter;
   }

   void SetPrimalStepSize(
      Number max_alpha_x
   )
   {
      max_alpha_x_ = max_alpha_x;
   }

   Number PrimalStepSize()
   {
      return max_alpha_x_;
   }

   Number curr_penalty() const
   {
      DBG_ASSERT(penalty_initialized_);
      return curr_penalty_;
   }

   void Set_penalty(
      Number penalty
   )
   {
      curr_penalty_ = penalty;
      penalty_initialized_ = true;
   }

   void SetPenaltyUninitialized()
   {
      penalty_initialized_ = false;
   }

   bool PenaltyInitialized() const
   {
      return penalty_initialized_;
   }

   Number curr_kkt_penalty() const
   {
      DBG_ASSERT(kkt_penalty_initialized_);
      return curr_kkt_penalty_;
   }

   void Set_kkt_penalty(
      Number kkt_penalty
   )
   {
      curr_kkt_penalty_ = kkt_penalty;
      kkt_penalty_initialized_ = true;
   }

   void SetKKTPenaltyUninitialized()
   {
      kkt_penalty_initialized_ = false;
   }

   bool KKTPenaltyInitialized() const
   {
      return kkt_penalty_initialized_;
   }

private:

   /** @name Pure Chen-Goldfarb step for the penalty function.
    *
    *  This used to transfer the information about the step from the
    *  computation of the overall search direction to the line
    *  search.
    */
   ///@{
   SmartPtr<const IteratesVector> delta_cgpen_;

   /** The following flag is set to true, if some other part of the
    *  algorithm has already computed the Chen-Goldfarb step.  This
    *  flag is reset when the AcceptTrialPoint method is called.
    */
   // ToDo we could cue off of a null delta_cgpen_
   bool have_cgpen_deltas_;
   ///@}

   /** @name Fast Chen-Goldfarb step for the penalty function.
    *
    *  This used to transfer the information about the step from the
    *  computation of the overall search direction to the line
    *  search.
    */
   ///@{
   SmartPtr<const IteratesVector> delta_cgfast_;

   /** The following flag is set to true, if some other part of the
    *  algorithm has already computed the fast Chen-Goldfarb step.
    *
    *  This flag is reset when the AcceptTrialPoint method is called.
    */
   // ToDo we could cue off of a null delta_cgfast_
   bool have_cgfast_deltas_;
   ///@}

   /** @name penalty method **/
   ///@{
   /** Flag indicating whether the pure Newton method is used */
   bool never_try_pure_Newton_;

   /** The iteration at which pure Newton method is given up*/
   Index restor_iter_;
   Number restor_counter_;

   /**@name  penalty parameters */
   Number curr_penalty_;
   bool penalty_initialized_;
   Number curr_kkt_penalty_;
   bool kkt_penalty_initialized_;
   Number curr_penalty_pert_;
   Number max_alpha_x_;
   ///@}

   /** flag indicating if Initialize method has been called (for debugging) */
   bool initialize_called_;

   /**@name Default Compiler Generated Methods
    * (Hidden to avoid implicit creation/calling).
    *
    * These methods are not implemented and
    * we do not want the compiler to implement
    * them for us, so we declare them private
    * and do not define them. This ensures that
    * they will not be implicitly created/called.
    */
   ///@{
   /** Copy Constructor */
   CGPenaltyData(
      const CGPenaltyData&
   );

   /** Default Assignment Operator */
   void operator=(
      const CGPenaltyData&
   );
   ///@}

#if IPOPT_CHECKLEVEL > 0
   /** Some debug flags to make sure vectors are not changed
    *  behind the CGPenaltyData's back
    */
   ///@{
   TaggedObject::Tag debug_delta_cgpen_tag_;
   TaggedObject::Tag debug_delta_cgfast_tag_;
   TaggedObject::Tag debug_delta_cgpen_tag_sum_;
   TaggedObject::Tag debug_delta_cgfast_tag_sum_;
   ///@}
#endif

};

inline SmartPtr<const IteratesVector> CGPenaltyData::delta_cgpen() const
{
   DBG_ASSERT(IsNull(delta_cgpen_) || (delta_cgpen_->GetTag() == debug_delta_cgpen_tag_ && delta_cgpen_->GetTagSum() == debug_delta_cgpen_tag_sum_) );

   return delta_cgpen_;
}

inline SmartPtr<const IteratesVector> CGPenaltyData::delta_cgfast() const
{
   DBG_ASSERT(IsNull(delta_cgfast_) || (delta_cgfast_->GetTag() == debug_delta_cgfast_tag_ && delta_cgfast_->GetTagSum() == debug_delta_cgfast_tag_sum_) );

   return delta_cgfast_;
}

inline
void CGPenaltyData::set_delta_cgpen(
   SmartPtr<IteratesVector>& delta_cgpen
)
{
   delta_cgpen_ = ConstPtr(delta_cgpen);
#if IPOPT_CHECKLEVEL > 0

   if (IsValid(delta_cgpen))
   {
      debug_delta_cgpen_tag_ = delta_cgpen->GetTag();
      debug_delta_cgpen_tag_sum_ = delta_cgpen->GetTagSum();
   }
   else
   {
      debug_delta_cgpen_tag_ = 0;
      debug_delta_cgpen_tag_sum_ = delta_cgpen->GetTagSum();
   }
#endif

   delta_cgpen = NULL;
}

inline
void CGPenaltyData::set_delta_cgpen(
   SmartPtr<const IteratesVector>& delta_cgpen
)
{
   delta_cgpen_ = delta_cgpen;
#if IPOPT_CHECKLEVEL > 0

   if (IsValid(delta_cgpen))
   {
      debug_delta_cgpen_tag_ = delta_cgpen->GetTag();
      debug_delta_cgpen_tag_sum_ = delta_cgpen->GetTagSum();
   }
   else
   {
      debug_delta_cgpen_tag_ = 0;
      debug_delta_cgpen_tag_sum_ = delta_cgpen->GetTagSum();
   }
#endif

   delta_cgpen = NULL;
}

inline
void CGPenaltyData::set_delta_cgfast(
   SmartPtr<IteratesVector>& delta_cgfast
)
{
   delta_cgfast_ = ConstPtr(delta_cgfast);
#if IPOPT_CHECKLEVEL > 0

   if (IsValid(delta_cgfast))
   {
      debug_delta_cgfast_tag_ = delta_cgfast->GetTag();
      debug_delta_cgfast_tag_sum_ = delta_cgfast->GetTagSum();
   }
   else
   {
      debug_delta_cgfast_tag_ = 0;
      debug_delta_cgfast_tag_sum_ = delta_cgfast->GetTagSum();
   }
#endif

   delta_cgfast = NULL;
}

} // namespace Ipopt

#endif