Ipopt 3.12.10

- Main Page
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
IpDenseVector.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: IpDenseVector.hpp 2269 2013-05-05 11:32:40Z stefan $
6 //
7 // Authors: Carl Laird, Andreas Waechter IBM 2004-08-13
8
9 #ifndef __IPDENSEVECTOR_HPP__
10 #define __IPDENSEVECTOR_HPP__
11
12 #include "IpUtils.hpp"
13 #include "IpVector.hpp"
14 #include <map>
15
16 namespace Ipopt
17 {
18
19 /* forward declarations */
20 class DenseVectorSpace;
21
24 DECLARE_STD_EXCEPTION(METADATA_ERROR);
26
40 class DenseVector : public Vector
41 {
42 public:
43
48 DenseVector(const DenseVectorSpace* owner_space);
49
52 virtual ~DenseVector();
54
58 SmartPtr<DenseVector> MakeNewDenseVector() const;
59
61 void SetValues(const Number *x);
62
68 inline Number* Values();
69
78 inline const Number* Values() const;
79
83 const Number* ExpandedValues() const;
84
87 inline Number* ExpandedValues()
88 {
89 return Values();
90 }
91
94 bool IsHomogeneous() const
95 {
96 return homogeneous_;
97 }
98
100 Number Scalar() const
101 {
102 DBG_ASSERT(homogeneous_);
103 return scalar_;
104 }
106
112 void CopyToPos(Index Pos, const Vector& x);
116 void CopyFromPos(Index Pos, const Vector& x);
118
119 protected:
123 virtual void CopyImpl(const Vector& x);
124
126 virtual void ScalImpl(Number alpha);
127
129 virtual void AxpyImpl(Number alpha, const Vector &x);
130
132 virtual Number DotImpl(const Vector &x) const;
133
135 virtual Number Nrm2Impl() const;
136
138 virtual Number AsumImpl() const;
139
141 virtual Number AmaxImpl() const;
142
144 virtual void SetImpl(Number value);
145
147 virtual void ElementWiseDivideImpl(const Vector& x);
148
150 virtual void ElementWiseMultiplyImpl(const Vector& x);
151
153 virtual void ElementWiseMaxImpl(const Vector& x);
154
156 virtual void ElementWiseMinImpl(const Vector& x);
157
159 virtual void ElementWiseReciprocalImpl();
160
162 virtual void ElementWiseAbsImpl();
163
165 virtual void ElementWiseSqrtImpl();
166
168 virtual void ElementWiseSgnImpl();
169
171 virtual void AddScalarImpl(Number scalar);
172
174 virtual Number MaxImpl() const;
175
177 virtual Number MinImpl() const;
178
180 virtual Number SumImpl() const;
181
183 virtual Number SumLogsImpl() const;
184
189 void AddTwoVectorsImpl(Number a, const Vector& v1,
190 Number b, const Vector& v2, Number c);
192 Number FracToBoundImpl(const Vector& delta, Number tau) const;
194 void AddVectorQuotientImpl(Number a, const Vector& z, const Vector& s,
195 Number c);
197
200 /* Print the entire vector with padding */
201 virtual void PrintImpl(const Journalist& jnlst,
202 EJournalLevel level,
203 EJournalCategory category,
204 const std::string& name,
205 Index indent,
206 const std::string& prefix) const
207 {
208 PrintImplOffset(jnlst, level, category, name, indent, prefix, 1);
209 }
210 /* Print the entire vector with padding, and start counting with
211 an offset. */
212 void PrintImplOffset(const Journalist& jnlst,
213 EJournalLevel level,
214 EJournalCategory category,
215 const std::string& name,
216 Index indent,
217 const std::string& prefix,
218 Index offset) const;
220 friend class ParVector;
221
222 private:
232 DenseVector();
233
235 DenseVector(const DenseVector&);
236
238 void operator=(const DenseVector&);
240
244 const DenseVectorSpace* owner_space_;
245
247 Number* values_;
248
250 mutable Number* expanded_values_;
251
254 inline
255 Number* values_allocated();
256
259 bool initialized_;
260
265 bool homogeneous_;
266
269 Number scalar_;
270
273 void set_values_from_scalar();
274 };
275
279 typedef std::map<std::string, std::vector<std::string> > StringMetaDataMapType;
280 typedef std::map<std::string, std::vector<Index> > IntegerMetaDataMapType;
281 typedef std::map<std::string, std::vector<Number> > NumericMetaDataMapType;
282
285 class DenseVectorSpace : public VectorSpace
286 {
287 public:
293 DenseVectorSpace(Index dim)
294 :
295 VectorSpace(dim)
296 {}
297
299 ~DenseVectorSpace()
300 {}
302
304 inline
305 DenseVector* MakeNewDenseVector() const
306 {
307 return new DenseVector(this);
308 }
309
313 virtual Vector* MakeNew() const
314 {
315 return MakeNewDenseVector();
316 }
317
324 inline
325 Number* AllocateInternalStorage() const;
326
328 inline
329 void FreeInternalStorage(Number* values) const;
331
336 inline
337 bool HasStringMetaData(const std::string tag) const;
338
340 inline
341 bool HasIntegerMetaData(const std::string tag) const;
342
344 inline
345 bool HasNumericMetaData(const std::string tag) const;
346
348 inline
349 const std::vector<std::string>& GetStringMetaData(const std::string& tag) const;
350
352 inline
353 const std::vector<Index>& GetIntegerMetaData(const std::string& tag) const;
354
356 inline
357 const std::vector<Number>& GetNumericMetaData(const std::string& tag) const;
358
360 inline
361 void SetStringMetaData(std::string tag, std::vector<std::string> meta_data);
362
364 inline
365 void SetIntegerMetaData(std::string tag, std::vector<Index> meta_data);
366
368 inline
369 void SetNumericMetaData(std::string tag, std::vector<Number> meta_data);
370
372 inline
373 const StringMetaDataMapType& GetStringMetaData() const;
374
376 inline
377 const IntegerMetaDataMapType& GetIntegerMetaData() const;
378
380 inline
381 const NumericMetaDataMapType& GetNumericMetaData() const;
383
384 private:
385 // variables to store vector meta data
386 StringMetaDataMapType string_meta_data_;
387 IntegerMetaDataMapType integer_meta_data_;
388 NumericMetaDataMapType numeric_meta_data_;
389
390 };
391
392 // inline functions
393 inline Number* DenseVector::Values()
394 {
395 // Here we assume that every time someone requests this direct raw
396 // pointer, the data is going to change and the Tag for this
397 // vector has to be updated.
398
399 if (initialized_ && homogeneous_) {
400 // If currently the vector is a homogeneous vector, set all elements
401 // explicitly to this value
402 set_values_from_scalar();
403 }
404 ObjectChanged();
405 initialized_= true;
406 homogeneous_ = false;
407 return values_allocated();
408 }
409
410 inline const Number* DenseVector::Values() const
411 {
412 DBG_ASSERT(initialized_ && (Dim()==0 || values_));
413 return values_;
414 }
415
416 inline Number* DenseVector::values_allocated()
417 {
418 if (values_==NULL) {
419 values_ = owner_space_->AllocateInternalStorage();
420 }
421 return values_;
422 }
423
424 inline
425 Number* DenseVectorSpace::AllocateInternalStorage() const
426 {
427 if (Dim()>0) {
428 return new Number[Dim()];
429 }
430 else {
431 return NULL;
432 }
433 }
434
435 inline
436 void DenseVectorSpace::FreeInternalStorage(Number* values) const
437 {
438 delete [] values;
439 }
440
441 inline
442 SmartPtr<DenseVector> DenseVector::MakeNewDenseVector() const
443 {
444 return owner_space_->MakeNewDenseVector();
445 }
446
447 inline
448 bool DenseVectorSpace::HasStringMetaData(const std::string tag) const
449 {
450 StringMetaDataMapType::const_iterator iter;
451 iter = string_meta_data_.find(tag);
452
453 if (iter != string_meta_data_.end()) {
454 return true;
455 }
456
457 return false;
458 }
459
460 inline
461 bool DenseVectorSpace::HasIntegerMetaData(const std::string tag) const
462 {
463 IntegerMetaDataMapType::const_iterator iter;
464 iter = integer_meta_data_.find(tag);
465
466 if (iter != integer_meta_data_.end()) {
467 return true;
468 }
469
470 return false;
471 }
472
473 inline
474 bool DenseVectorSpace::HasNumericMetaData(const std::string tag) const
475 {
476 NumericMetaDataMapType::const_iterator iter;
477 iter = numeric_meta_data_.find(tag);
478
479 if (iter != numeric_meta_data_.end()) {
480 return true;
481 }
482
483 return false;
484 }
485
486 inline
487 const std::vector<std::string>& DenseVectorSpace::GetStringMetaData(const std::string& tag) const
488 {
489 DBG_ASSERT(HasStringMetaData(tag));
490 StringMetaDataMapType::const_iterator iter;
491 iter = string_meta_data_.find(tag);
492 return iter->second;
493 }
494
495 inline
496 const std::vector<Index>& DenseVectorSpace::GetIntegerMetaData(const std::string& tag) const
497 {
498 DBG_ASSERT(HasIntegerMetaData(tag));
499 IntegerMetaDataMapType::const_iterator iter;
500 iter = integer_meta_data_.find(tag);
501 return iter->second;
502 }
503
504 inline
505 const std::vector<Number>& DenseVectorSpace::GetNumericMetaData(const std::string& tag) const
506 {
507 DBG_ASSERT(HasNumericMetaData(tag));
508 NumericMetaDataMapType::const_iterator iter;
509 iter = numeric_meta_data_.find(tag);
510 return iter->second;
511 }
512
513 inline
514 void DenseVectorSpace::SetStringMetaData(std::string tag, std::vector<std::string> meta_data)
515 {
516 string_meta_data_[tag] = meta_data;
517 }
518
519 inline
520 void DenseVectorSpace::SetIntegerMetaData(std::string tag, std::vector<Index> meta_data)
521 {
522 integer_meta_data_[tag] = meta_data;
523 }
524
525 inline
526 void DenseVectorSpace::SetNumericMetaData(std::string tag, std::vector<Number> meta_data)
527 {
528 numeric_meta_data_[tag] = meta_data;
529 }
530
531 inline
532 const StringMetaDataMapType& DenseVectorSpace::GetStringMetaData() const
533 {
534 return string_meta_data_;
535 }
536
537 inline
538 const IntegerMetaDataMapType& DenseVectorSpace::GetIntegerMetaData() const
539 {
540 return integer_meta_data_;
541 }
542
543 inline
544 const NumericMetaDataMapType& DenseVectorSpace::GetNumericMetaData() const
545 {
546 return numeric_meta_data_;
547 }
548
549 } // namespace Ipopt
550 #endif
Ipopt::DenseVector::initialized_
bool initialized_
Flag for Initialization.
Definition: IpDenseVector.hpp:259
Ipopt::NumericMetaDataMapType
std::map< std::string, std::vector< Number > > NumericMetaDataMapType
Definition: IpDenseVector.hpp:281
Ipopt::DenseVector::SumLogsImpl
virtual Number SumLogsImpl() const
Computes the sum of the logs of the elements of vector.
Ipopt::DenseVector::SumImpl
virtual Number SumImpl() const
Computes the sum of the lements of vector.
x
Number * x
Input: Starting point Output: Optimal solution.
Definition: IpStdCInterface.h:238
Ipopt::DenseVector::ElementWiseAbsImpl
virtual void ElementWiseAbsImpl()
take abs of the elements of the vector
Ipopt::DenseVector::ElementWiseMinImpl
virtual void ElementWiseMinImpl(const Vector &x)
Set entry to min of itself and the corresponding element in x.
IpUtils.hpp
Ipopt::DenseVector::CopyToPos
void CopyToPos(Index Pos, const Vector &x)
Copy the data in x into the subrange of this vector starting at position Pos in this vector...
Ipopt::DenseVector::set_values_from_scalar
void set_values_from_scalar()
Auxilliary method for setting explicitly all elements in values_ to the current scalar value...
Ipopt::DenseVector::Nrm2Impl
virtual Number Nrm2Impl() const
Computes the 2-norm of this vector (DNRM2)
IpVector.hpp
Ipopt::DenseVectorSpace::AllocateInternalStorage
Number * AllocateInternalStorage() const
Allocate internal storage for the DenseVector.
Definition: IpDenseVector.hpp:425
Ipopt::DenseVector::SetValues
void SetValues(const Number *x)
Set elements in the vector to the Number array x.
Ipopt::DenseVector::ParVector
friend class ParVector
Definition: IpDenseVector.hpp:220
Ipopt::DenseVectorSpace::FreeInternalStorage
void FreeInternalStorage(Number *values) const
Deallocate internal storage for the DenseVector.
Definition: IpDenseVector.hpp:436
Ipopt::DenseVector::AddVectorQuotientImpl
void AddVectorQuotientImpl(Number a, const Vector &z, const Vector &s, Number c)
Add the quotient of two vectors, y = a * z/s + c * y.
Ipopt::DenseVector::SetImpl
virtual void SetImpl(Number value)
Set each element in the vector to the scalar alpha.
Ipopt::DenseVector::IsHomogeneous
bool IsHomogeneous() const
Indicates if the vector is homogeneous (i.e., all entries have the value Scalar() ...
Definition: IpDenseVector.hpp:94
Ipopt::DenseVector::AddScalarImpl
virtual void AddScalarImpl(Number scalar)
Add scalar to every component of the vector.
Ipopt::DenseVectorSpace::MakeNewDenseVector
DenseVector * MakeNewDenseVector() const
Method for creating a new vector of this specific type.
Definition: IpDenseVector.hpp:305
Ipopt::DenseVectorSpace::SetStringMetaData
void SetStringMetaData(std::string tag, std::vector< std::string > meta_data)
Set meta data of type std::string by tag.
Definition: IpDenseVector.hpp:514
Ipopt::Number
double Number
Type of all numbers.
Definition: IpTypes.hpp:17
Ipopt::TaggedObject::ObjectChanged
void ObjectChanged()
Objects derived from TaggedObject MUST call this method every time their internal state changes to up...
Definition: IpTaggedObject.hpp:117
Ipopt::Vector
Vector Base Class.
Definition: IpVector.hpp:47
Ipopt::IntegerMetaDataMapType
std::map< std::string, std::vector< Index > > IntegerMetaDataMapType
Definition: IpDenseVector.hpp:280
Ipopt::DenseVector::ElementWiseReciprocalImpl
virtual void ElementWiseReciprocalImpl()
reciprocates the elements of the vector
Ipopt::DenseVector::AmaxImpl
virtual Number AmaxImpl() const
Computes the max-norm of this vector (based on IDAMAX)
Ipopt::DenseVector
Dense Vector Implementation.
Definition: IpDenseVector.hpp:40
Ipopt::DenseVectorSpace::GetNumericMetaData
const NumericMetaDataMapType & GetNumericMetaData() const
Get map of meta data of type Number.
Definition: IpDenseVector.hpp:544
Ipopt::DenseVector::PrintImpl
virtual void PrintImpl(const Journalist &jnlst, EJournalLevel level, EJournalCategory category, const std::string &name, Index indent, const std::string &prefix) const
Print the entire vector.
Definition: IpDenseVector.hpp:201
Ipopt::DenseVector::ExpandedValues
const Number * ExpandedValues() const
The same as the const version of Values, but we ensure that we always return a valid array...
Ipopt::EJournalLevel
EJournalLevel
Print Level Enum.
Definition: IpJournalist.hpp:51
Ipopt::DenseVector::ElementWiseSgnImpl
virtual void ElementWiseSgnImpl()
Changes each entry in the vector to its sgn value.
Ipopt::DenseVector::homogeneous_
bool homogeneous_
Flag indicating whether the vector is currently homogeneous (that is, all elements have the same valu...
Definition: IpDenseVector.hpp:265
Ipopt::DenseVectorSpace
This vectors space is the vector space for DenseVector.
Definition: IpDenseVector.hpp:285
Ipopt::DenseVector::ElementWiseDivideImpl
virtual void ElementWiseDivideImpl(const Vector &x)
Element-wise division .
Ipopt::DenseVectorSpace::string_meta_data_
StringMetaDataMapType string_meta_data_
Definition: IpDenseVector.hpp:386
Ipopt::DenseVector::ElementWiseMultiplyImpl
virtual void ElementWiseMultiplyImpl(const Vector &x)
Element-wise multiplication .
Ipopt::VectorSpace::Dim
Index Dim() const
Accessor function for the dimension of the vectors of this type.
Definition: IpVector.hpp:411
Ipopt::DenseVectorSpace::SetNumericMetaData
void SetNumericMetaData(std::string tag, std::vector< Number > meta_data)
Set meta data of type Number by tag.
Definition: IpDenseVector.hpp:526
Ipopt::DenseVectorSpace::~DenseVectorSpace
~DenseVectorSpace()
Destructor.
Definition: IpDenseVector.hpp:299
Ipopt::DenseVectorSpace::SetIntegerMetaData
void SetIntegerMetaData(std::string tag, std::vector< Index > meta_data)
Set meta data of type Index by tag.
Definition: IpDenseVector.hpp:520
Ipopt::SmartPtr
Template class for Smart Pointers.
Definition: IpSmartPtr.hpp:172
Ipopt::DenseVector::values_
Number * values_
Dense Number array of vector values.
Definition: IpDenseVector.hpp:247
Ipopt::DenseVectorSpace::MakeNew
virtual Vector * MakeNew() const
Instantiation of the generate MakeNew method for the VectorSpace base class.
Definition: IpDenseVector.hpp:313
Ipopt::DenseVector::ScalImpl
virtual void ScalImpl(Number alpha)
Scales the vector by scalar alpha (DSCAL)
Ipopt::DenseVector::DenseVector
DenseVector()
Default Constructor.
Ipopt::VectorSpace
VectorSpace base class, corresponding to the Vector base class.
Definition: IpVector.hpp:390
Ipopt::DenseVector::MaxImpl
virtual Number MaxImpl() const
Max value in the vector.
Ipopt::DenseVectorSpace::HasStringMetaData
bool HasStringMetaData(const std::string tag) const
Check if string meta exists for tag.
Definition: IpDenseVector.hpp:448
Ipopt::DenseVectorSpace::numeric_meta_data_
NumericMetaDataMapType numeric_meta_data_
Definition: IpDenseVector.hpp:388
Ipopt::DenseVector::operator=
void operator=(const DenseVector &)
Overloaded Equals Operator.
Ipopt::DenseVector::DotImpl
virtual Number DotImpl(const Vector &x) const
Computes inner product of vector x with this (DDOT)
Ipopt::DenseVector::AsumImpl
virtual Number AsumImpl() const
Computes the 1-norm of this vector (DASUM)
Ipopt::DenseVectorSpace::DenseVectorSpace
DenseVectorSpace(Index dim)
Constructor, requires dimension of all vector for this VectorSpace.
Definition: IpDenseVector.hpp:293
Ipopt::DenseVector::ElementWiseMaxImpl
virtual void ElementWiseMaxImpl(const Vector &x)
Set entry to max of itself and the corresponding element in x.
Ipopt::DenseVector::ElementWiseSqrtImpl
virtual void ElementWiseSqrtImpl()
take square-root of the elements of the vector
Ipopt::DenseVectorSpace::HasNumericMetaData
bool HasNumericMetaData(const std::string tag) const
Check if Numeric meta exists for tag.
Definition: IpDenseVector.hpp:474
Ipopt::DenseVector::owner_space_
const DenseVectorSpace * owner_space_
Copy of the owner_space ptr as a DenseVectorSpace instead of a VectorSpace.
Definition: IpDenseVector.hpp:244
Ipopt::Index
int Index
Type of all indices of vectors, matrices etc.
Definition: IpTypes.hpp:19
Ipopt::DenseVector::~DenseVector
virtual ~DenseVector()
Destructor.
DBG_ASSERT
#define DBG_ASSERT(test)
Definition: IpDebug.hpp:38
Ipopt::DenseVectorSpace::GetIntegerMetaData
const IntegerMetaDataMapType & GetIntegerMetaData() const
Get map of meta data of type Number.
Definition: IpDenseVector.hpp:538
Ipopt::DenseVector::values_allocated
Number * values_allocated()
Method of getting the internal values array, making sure that memory has been allocated.
Definition: IpDenseVector.hpp:416
Ipopt::DenseVector::FracToBoundImpl
Number FracToBoundImpl(const Vector &delta, Number tau) const
Fraction to the boundary parameter.
Ipopt::DenseVector::ExpandedValues
Number * ExpandedValues()
This is the same as Values, but we add it here so that ExpandedValues can also be used for the non-co...
Definition: IpDenseVector.hpp:87
Ipopt::DenseVector::CopyFromPos
void CopyFromPos(Index Pos, const Vector &x)
Copy a subrange of x, starting at Pos, into the full data of this vector.
Ipopt::DenseVector::AddTwoVectorsImpl
void AddTwoVectorsImpl(Number a, const Vector &v1, Number b, const Vector &v2, Number c)
Add two vectors (a * v1 + b * v2).
Ipopt::DECLARE_STD_EXCEPTION
DECLARE_STD_EXCEPTION(SUFFIX_EMPTY)
Ipopt::DenseVector::Scalar
Number Scalar() const
Scalar value of all entries in a homogeneous vector.
Definition: IpDenseVector.hpp:100
Ipopt::DenseVectorSpace::HasIntegerMetaData
bool HasIntegerMetaData(const std::string tag) const
Check if Integer meta exists for tag.
Definition: IpDenseVector.hpp:461
Ipopt::Journalist
Class responsible for all message output.
Definition: IpJournalist.hpp:134
Ipopt::DenseVector::CopyImpl
virtual void CopyImpl(const Vector &x)
Copy the data of the vector x into this vector (DCOPY).
Ipopt::DenseVectorSpace::GetStringMetaData
const StringMetaDataMapType & GetStringMetaData() const
Get map of meta data of type Number.
Definition: IpDenseVector.hpp:532
Ipopt::Vector::Dim
Index Dim() const
Dimension of the Vector.
Definition: IpVector.hpp:739
Ipopt::DenseVector::MakeNewDenseVector
SmartPtr< DenseVector > MakeNewDenseVector() const
Create a new DenseVector from same VectorSpace.
Definition: IpDenseVector.hpp:442
Ipopt::DenseVector::scalar_
Number scalar_
Homogeneous value of all elements if the vector is currently homogenous.
Definition: IpDenseVector.hpp:269
Ipopt::DenseVector::expanded_values_
Number * expanded_values_
Dense Number array pointer that is used for ExpandedValues.
Definition: IpDenseVector.hpp:250
Ipopt::EJournalCategory
EJournalCategory
Category Selection Enum.
Definition: IpJournalist.hpp:70
Ipopt::DenseVectorSpace::integer_meta_data_
IntegerMetaDataMapType integer_meta_data_
Definition: IpDenseVector.hpp:387
Ipopt::DenseVector::MinImpl
virtual Number MinImpl() const
Min value in the vector.
Ipopt::StringMetaDataMapType
std::map< std::string, std::vector< std::string > > StringMetaDataMapType
typedefs for the map variables that define meta data for the DenseVectorSpace
Definition: IpDenseVector.hpp:279
Ipopt::DenseVector::PrintImplOffset
void PrintImplOffset(const Journalist &jnlst, EJournalLevel level, EJournalCategory category, const std::string &name, Index indent, const std::string &prefix, Index offset) const
Ipopt::DenseVector::Values
Number * Values()
Obtain pointer to the internal Number array with vector elements with the indention to change the vec...
Definition: IpDenseVector.hpp:393
Ipopt::DenseVector::AxpyImpl
virtual void AxpyImpl(Number alpha, const Vector &x)
Add the multiple alpha of vector x to this vector (DAXPY)