Ipopt Documentation  
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 // Authors: Carl Laird, Andreas Waechter IBM 2004-08-13
6 
7 #ifndef __IPDENSEVECTOR_HPP__
8 #define __IPDENSEVECTOR_HPP__
9 
10 #include "IpUtils.hpp"
11 #include "IpVector.hpp"
12 #include <map>
13 
14 namespace Ipopt
15 {
16 
17 /* forward declarations */
18 class DenseVectorSpace;
19 
21 DECLARE_STD_EXCEPTION(METADATA_ERROR);
24 
41 {
42 public:
44 
48  const DenseVectorSpace* owner_space
49  );
50 
53  virtual ~DenseVector();
55 
57 
59  SmartPtr<DenseVector> MakeNewDenseVector() const;
60 
62  void SetValues(
63  const Number* x
64  );
65 
71  inline Number* Values();
72 
84  inline const Number* Values() const;
85 
90  const Number* ExpandedValues() const;
91 
96  {
97  return Values();
98  }
99 
103  bool IsHomogeneous() const
104  {
105  return homogeneous_;
106  }
107 
109  Number Scalar() const
110  {
111  DBG_ASSERT(homogeneous_);
112  return scalar_;
113  }
115 
117 
123  void CopyToPos(
124  Index Pos,
125  const Vector& x
126  );
127 
134  Index Pos,
135  const Vector& x
136  );
138 
139 protected:
141  virtual void CopyImpl(
143  const Vector& x
144  );
145 
146  virtual void ScalImpl(
147  Number alpha
148  );
149 
150  virtual void AxpyImpl(
151  Number alpha,
152  const Vector& x
153  );
154 
155  virtual Number DotImpl(
156  const Vector& x
157  ) const;
158 
159  virtual Number Nrm2Impl() const;
160 
161  virtual Number AsumImpl() const;
162 
163  virtual Number AmaxImpl() const;
164 
165  virtual void SetImpl(
166  Number value
167  );
168 
169  virtual void ElementWiseDivideImpl(
170  const Vector& x
171  );
172 
174  const Vector& x
175  );
176 
177  virtual void ElementWiseSelectImpl(
178  const Vector& x
179  );
180 
181  virtual void ElementWiseMaxImpl(
182  const Vector& x
183  );
184 
185  virtual void ElementWiseMinImpl(
186  const Vector& x
187  );
188 
190 
191  virtual void ElementWiseAbsImpl();
192 
193  virtual void ElementWiseSqrtImpl();
194 
195  virtual void ElementWiseSgnImpl();
196 
197  virtual void AddScalarImpl(
198  Number scalar
199  );
200 
201  virtual Number MaxImpl() const;
202 
203  virtual Number MinImpl() const;
204 
205  virtual Number SumImpl() const;
206 
207  virtual Number SumLogsImpl() const;
209 
211 
217  Number a,
218  const Vector& v1,
219  Number b,
220  const Vector& v2,
221  Number c
222  );
223 
226  const Vector& delta,
227  Number tau
228  ) const;
229 
232  Number a,
233  const Vector& z,
234  const Vector& s,
235  Number c
236  );
238 
240  virtual void PrintImpl(
242  const Journalist& jnlst,
243  EJournalLevel level,
244  EJournalCategory category,
245  const std::string& name,
246  Index indent,
247  const std::string& prefix
248  ) const
249  {
250  PrintImplOffset(jnlst, level, category, name, indent, prefix, 1);
251  }
252 
253  /* Print the entire vector with padding, and start counting with an offset. */
255  const Journalist& jnlst,
256  EJournalLevel level,
257  EJournalCategory category,
258  const std::string& name,
259  Index indent,
260  const std::string& prefix,
261  Index offset
262  ) const;
264 
265  friend class ParVector;
266 
267 private:
275 
278 
281  const DenseVector&
282  );
283 
285  void operator=(
286  const DenseVector&
287  );
289 
292 
295 
298 
300  inline Number* values_allocated();
301 
307 
315 
318 
323 };
324 
326 typedef std::map<std::string, std::vector<std::string> > StringMetaDataMapType;
328 typedef std::map<std::string, std::vector<Index> > IntegerMetaDataMapType;
329 typedef std::map<std::string, std::vector<Number> > NumericMetaDataMapType;
331 
334 {
335 public:
337 
340  Index dim
341  )
342  : VectorSpace(dim)
343  { }
344 
347  { }
349 
352  {
353  return new DenseVector(this);
354  }
355 
356  virtual Vector* MakeNew() const
357  {
358  return MakeNewDenseVector();
359  }
360 
366 
368  inline Number* AllocateInternalStorage() const;
369 
371  inline void FreeInternalStorage(
372  Number* values
373  ) const;
375 
378 
380  inline
381  bool HasStringMetaData(
382  const std::string& tag
383  ) const;
384 
386  inline
387  bool HasIntegerMetaData(
388  const std::string& tag
389  ) const;
390 
392  inline
393  bool HasNumericMetaData(
394  const std::string& tag
395  ) const;
396 
398  inline const std::vector<std::string>& GetStringMetaData(
399  const std::string& tag
400  ) const;
401 
403  inline const std::vector<Index>& GetIntegerMetaData(
404  const std::string& tag
405  ) const;
406 
408  inline const std::vector<Number>& GetNumericMetaData(
409  const std::string& tag
410  ) const;
411 
413  inline void SetStringMetaData(
414  const std::string& tag,
415  const std::vector<std::string>& meta_data
416  );
417 
419  inline void SetIntegerMetaData(
420  const std::string& tag,
421  const std::vector<Index>& meta_data
422  );
423 
425  inline void SetNumericMetaData(
426  const std::string& tag,
427  const std::vector<Number>& meta_data
428  );
429 
431  inline const StringMetaDataMapType& GetStringMetaData() const;
432 
434  inline const IntegerMetaDataMapType& GetIntegerMetaData() const;
435 
437  inline const NumericMetaDataMapType& GetNumericMetaData() const;
439 
440 private:
441  // variables to store vector meta data
445 };
446 
447 // inline functions
449 {
450  // Here we assume that every time someone requests this direct raw
451  // pointer, the data is going to change and the Tag for this
452  // vector has to be updated.
453 
454  if( initialized_ && homogeneous_ )
455  {
456  // If currently the vector is a homogeneous vector, set all elements
457  // explicitly to this value
459  }
460  ObjectChanged();
461  initialized_ = true;
462  homogeneous_ = false;
464  DBG_ASSERT(Dim() == 0 || values_ != NULL);
465  return values_;
466 }
467 
468 inline const Number* DenseVector::Values() const
469 {
470  DBG_ASSERT(initialized_ && (Dim() == 0 || values_));
471  return values_;
472 }
473 
475 {
476  if( values_ == NULL )
477  {
479  }
480  return values_;
481 }
482 
484 {
485  if( Dim() > 0 )
486  {
487  return new Number[Dim()];
488  }
489  else
490  {
491  return NULL;
492  }
493 }
494 
495 inline
497  Number* values
498 ) const
499 {
500  delete[] values;
501 }
502 
504 {
506 }
507 
508 inline
510  const std::string& tag
511 ) const
512 {
513  StringMetaDataMapType::const_iterator iter;
514  iter = string_meta_data_.find(tag);
515 
516  if( iter != string_meta_data_.end() )
517  {
518  return true;
519  }
520 
521  return false;
522 }
523 
524 inline
526  const std::string& tag
527 ) const
528 {
529  IntegerMetaDataMapType::const_iterator iter;
530  iter = integer_meta_data_.find(tag);
531 
532  if( iter != integer_meta_data_.end() )
533  {
534  return true;
535  }
536 
537  return false;
538 }
539 
540 inline
542  const std::string& tag
543 ) const
544 {
545  NumericMetaDataMapType::const_iterator iter;
546  iter = numeric_meta_data_.find(tag);
547 
548  if( iter != numeric_meta_data_.end() )
549  {
550  return true;
551  }
552 
553  return false;
554 }
555 
556 inline const std::vector<std::string>& DenseVectorSpace::GetStringMetaData(
557  const std::string& tag
558 ) const
559 {
561  StringMetaDataMapType::const_iterator iter;
562  iter = string_meta_data_.find(tag);
563  return iter->second;
564 }
565 
566 inline const std::vector<Index>& DenseVectorSpace::GetIntegerMetaData(
567  const std::string& tag
568 ) const
569 {
571  IntegerMetaDataMapType::const_iterator iter;
572  iter = integer_meta_data_.find(tag);
573  return iter->second;
574 }
575 
576 inline const std::vector<Number>& DenseVectorSpace::GetNumericMetaData(
577  const std::string& tag
578 ) const
579 {
581  NumericMetaDataMapType::const_iterator iter;
582  iter = numeric_meta_data_.find(tag);
583  return iter->second;
584 }
585 
587  const std::string& tag,
588  const std::vector<std::string>& meta_data
589 )
590 {
591  string_meta_data_[tag] = meta_data;
592 }
593 
595  const std::string& tag,
596  const std::vector<Index>& meta_data
597 )
598 {
599  integer_meta_data_[tag] = meta_data;
600 }
601 
603  const std::string& tag,
604  const std::vector<Number>& meta_data
605 )
606 {
607  numeric_meta_data_[tag] = meta_data;
608 }
609 
611 {
612  return string_meta_data_;
613 }
614 
616 {
617  return integer_meta_data_;
618 }
619 
621 {
622  return numeric_meta_data_;
623 }
624 
625 } // namespace Ipopt
626 #endif
Ipopt::DenseVector::values_
Number * values_
Dense Number array of vector values.
Definition: IpDenseVector.hpp:294
IpUtils.hpp
Ipopt::DenseVectorSpace::GetNumericMetaData
const NumericMetaDataMapType & GetNumericMetaData() const
Get map of meta data of type Number.
Definition: IpDenseVector.hpp:620
Ipopt::DenseVector::DenseVector
DenseVector(const DenseVector &)
Copy Constructor.
Ipopt::DenseVector::~DenseVector
virtual ~DenseVector()
Destructor.
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::Nrm2Impl
virtual Number Nrm2Impl() const
Computes the 2-norm of this vector (DNRM2)
Ipopt::DenseVector::operator=
void operator=(const DenseVector &)
Default Assignment Operator.
Ipopt::DenseVector::set_values_from_scalar
void set_values_from_scalar()
Auxiliary method for setting explicitly all elements in values_ to the current scalar value.
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::MinImpl
virtual Number MinImpl() const
Min number in the vector.
Ipopt::DenseVector::DenseVector
DenseVector(const DenseVectorSpace *owner_space)
Default Constructor.
Ipopt::DenseVector::AmaxImpl
virtual Number AmaxImpl() const
Computes the max-norm of this vector (based on IDAMAX)
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::DenseVector::Values
Number * Values()
Obtain pointer to the internal Number array with vector elements with the intention to change the vec...
Definition: IpDenseVector.hpp:448
Ipopt::DenseVector::MaxImpl
virtual Number MaxImpl() const
Max value in the vector.
Ipopt::DenseVectorSpace::MakeNewDenseVector
DenseVector * MakeNewDenseVector() const
Method for creating a new vector of this specific type.
Definition: IpDenseVector.hpp:351
Ipopt
This file contains a base class for all exceptions and a set of macros to help with exceptions.
Definition: IpInexactAlgBuilder.hpp:14
Ipopt::NumericMetaDataMapType
std::map< std::string, std::vector< Number > > NumericMetaDataMapType
Definition: IpDenseVector.hpp:329
Ipopt::DenseVector::DotImpl
virtual Number DotImpl(const Vector &x) const
Computes inner product of vector x with this (DDOT)
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::ElementWiseSelectImpl
virtual void ElementWiseSelectImpl(const Vector &x)
Element-wise selection .
Ipopt::DenseVector::ElementWiseAbsImpl
virtual void ElementWiseAbsImpl()
Take elementwise absolute values of the elements of the vector.
Ipopt::TaggedObject::ObjectChanged
void ObjectChanged()
Objects derived from TaggedObject MUST call this method every time their internal state changes to up...
Ipopt::DenseVector::ElementWiseMultiplyImpl
virtual void ElementWiseMultiplyImpl(const Vector &x)
Element-wise multiplication .
Ipopt::EJournalLevel
EJournalLevel
Print Level Enum.
Definition: IpJournalist.hpp:32
Ipopt::DenseVectorSpace::GetStringMetaData
const StringMetaDataMapType & GetStringMetaData() const
Get map of meta data of type Number.
Definition: IpDenseVector.hpp:610
IPOPTLIB_EXPORT
#define IPOPTLIB_EXPORT
Definition: config_default.h:10
Ipopt::DenseVectorSpace::numeric_meta_data_
NumericMetaDataMapType numeric_meta_data_
Definition: IpDenseVector.hpp:444
Ipopt::DenseVectorSpace::DenseVectorSpace
DenseVectorSpace(Index dim)
Constructor, requires dimension of all vector for this VectorSpace.
Definition: IpDenseVector.hpp:339
Ipopt::DenseVectorSpace
This vectors space is the vector space for DenseVector.
Definition: IpDenseVector.hpp:334
Ipopt::DenseVector::SumLogsImpl
virtual Number SumLogsImpl() const
Sum of logs of entries in the vector.
Ipopt::DenseVectorSpace::FreeInternalStorage
void FreeInternalStorage(Number *values) const
Deallocate internal storage for the DenseVector.
Definition: IpDenseVector.hpp:496
Ipopt::DenseVectorSpace::HasStringMetaData
bool HasStringMetaData(const std::string &tag) const
Check if string meta exists for tag.
Definition: IpDenseVector.hpp:509
Ipopt::DenseVectorSpace::GetIntegerMetaData
const IntegerMetaDataMapType & GetIntegerMetaData() const
Get map of meta data of type Number.
Definition: IpDenseVector.hpp:615
Ipopt::DenseVector::SetValues
void SetValues(const Number *x)
Set elements in the vector to the Number array x.
Ipopt::DenseVector::IsHomogeneous
bool IsHomogeneous() const
Indicates if the vector is homogeneous (i.e., all entries have the value Scalar().
Definition: IpDenseVector.hpp:103
Ipopt::DenseVectorSpace::~DenseVectorSpace
~DenseVectorSpace()
Destructor.
Definition: IpDenseVector.hpp:346
Ipopt::DenseVector::expanded_values_
Number * expanded_values_
Dense Number array pointer that is used for ExpandedValues.
Definition: IpDenseVector.hpp:297
Ipopt::IntegerMetaDataMapType
std::map< std::string, std::vector< Index > > IntegerMetaDataMapType
Definition: IpDenseVector.hpp:328
Ipopt::SmartPtr
Template class for Smart Pointers.
Definition: IpSmartPtr.hpp:165
Ipopt::DenseVector::SetImpl
virtual void SetImpl(Number value)
Set each element in the vector to the scalar alpha.
Ipopt::EJournalCategory
EJournalCategory
Category Selection Enum.
Definition: IpJournalist.hpp:52
Ipopt::DenseVector::owner_space_
const DenseVectorSpace * owner_space_
Copy of the owner_space ptr as a DenseVectorSpace instead of a VectorSpace.
Definition: IpDenseVector.hpp:291
Ipopt::DenseVector::scalar_
Number scalar_
Homogeneous value of all elements if the vector is currently homogeneous.
Definition: IpDenseVector.hpp:317
Ipopt::DenseVector::ElementWiseMinImpl
virtual void ElementWiseMinImpl(const Vector &x)
Element-wise min against entries in x.
Ipopt::DenseVectorSpace::HasNumericMetaData
bool HasNumericMetaData(const std::string &tag) const
Check if Numeric meta exists for tag.
Definition: IpDenseVector.hpp:541
Ipopt::Index
ipindex Index
Type of all indices of vectors, matrices etc.
Definition: IpTypes.hpp:20
Ipopt::Number
ipnumber Number
Type of all numbers.
Definition: IpTypes.hpp:17
Ipopt::DenseVector::initialized_
bool initialized_
Flag for Initialization.
Definition: IpDenseVector.hpp:306
Ipopt::DenseVector::AsumImpl
virtual Number AsumImpl() const
Computes the 1-norm of this vector (DASUM)
Ipopt::DenseVector::ElementWiseMaxImpl
virtual void ElementWiseMaxImpl(const Vector &x)
Element-wise max against entries in x.
Ipopt::DenseVectorSpace::SetNumericMetaData
void SetNumericMetaData(const std::string &tag, const std::vector< Number > &meta_data)
Set meta data of type Number by tag.
Definition: IpDenseVector.hpp:602
Ipopt::DenseVector::ElementWiseReciprocalImpl
virtual void ElementWiseReciprocalImpl()
Reciprocates the elements of the vector.
Ipopt::Journalist
Class responsible for all message output.
Definition: IpJournalist.hpp:117
Ipopt::DenseVector::values_allocated
Number * values_allocated()
Get the internal values array, making sure that memory has been allocated.
Definition: IpDenseVector.hpp:474
Ipopt::DenseVectorSpace::integer_meta_data_
IntegerMetaDataMapType integer_meta_data_
Definition: IpDenseVector.hpp:443
Ipopt::DenseVector::homogeneous_
bool homogeneous_
Flag indicating whether the vector is currently homogeneous (that is, all elements have the same valu...
Definition: IpDenseVector.hpp:314
Ipopt::DenseVector::FracToBoundImpl
Number FracToBoundImpl(const Vector &delta, Number tau) const
Fraction to the boundary parameter.
Ipopt::DenseVector::ElementWiseSqrtImpl
virtual void ElementWiseSqrtImpl()
Take elementwise square-root of the elements of the vector.
Ipopt::VectorSpace
VectorSpace base class, corresponding to the Vector base class.
Definition: IpVector.hpp:473
Ipopt::StringMetaDataMapType
std::map< std::string, std::vector< std::string > > StringMetaDataMapType
Definition: IpDenseVector.hpp:327
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,...
IpVector.hpp
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:95
Ipopt::DenseVector
Dense Vector Implementation.
Definition: IpDenseVector.hpp:41
Ipopt::DenseVectorSpace::SetIntegerMetaData
void SetIntegerMetaData(const std::string &tag, const std::vector< Index > &meta_data)
Set meta data of type Index by tag.
Definition: IpDenseVector.hpp:594
Ipopt::DenseVectorSpace::MakeNew
virtual Vector * MakeNew() const
Pure virtual method for creating a new Vector of the corresponding type.
Definition: IpDenseVector.hpp:356
Ipopt::DenseVectorSpace::HasIntegerMetaData
bool HasIntegerMetaData(const std::string &tag) const
Check if Integer meta exists for tag.
Definition: IpDenseVector.hpp:525
Ipopt::DenseVectorSpace::SetStringMetaData
void SetStringMetaData(const std::string &tag, const std::vector< std::string > &meta_data)
Set meta data of type std::string by tag.
Definition: IpDenseVector.hpp:586
Ipopt::DenseVector::ScalImpl
virtual void ScalImpl(Number alpha)
Scales the vector by scalar alpha (DSCAL)
Ipopt::DenseVector::SumImpl
virtual Number SumImpl() const
Sum of entries in the vector.
Ipopt::DenseVectorSpace::AllocateInternalStorage
Number * AllocateInternalStorage() const
Allocate internal storage for the DenseVector.
Definition: IpDenseVector.hpp:483
Ipopt::Vector::Dim
Index Dim() const
Dimension of the Vector.
Definition: IpVector.hpp:858
Ipopt::DenseVector::MakeNewDenseVector
SmartPtr< DenseVector > MakeNewDenseVector() const
Create a new DenseVector from same VectorSpace.
Definition: IpDenseVector.hpp:503
Ipopt::DenseVector::AddScalarImpl
virtual void AddScalarImpl(Number scalar)
Add scalar to every component of vector.
Ipopt::DenseVector::ElementWiseDivideImpl
virtual void ElementWiseDivideImpl(const Vector &x)
Element-wise division .
Ipopt::DenseVector::AxpyImpl
virtual void AxpyImpl(Number alpha, const Vector &x)
Add the multiple alpha of vector x to this vector (DAXPY)
Ipopt::DECLARE_STD_EXCEPTION
DECLARE_STD_EXCEPTION(FATAL_ERROR_IN_LINEAR_SOLVER)
Ipopt::DenseVector::ElementWiseSgnImpl
virtual void ElementWiseSgnImpl()
Replaces entries with sgn of the entry.
DBG_ASSERT
#define DBG_ASSERT(test)
Definition: IpDebug.hpp:27
Ipopt::DenseVector::Scalar
Number Scalar() const
Scalar value of all entries in a homogeneous vector.
Definition: IpDenseVector.hpp:109
Ipopt::DenseVectorSpace::string_meta_data_
StringMetaDataMapType string_meta_data_
Definition: IpDenseVector.hpp:442
Ipopt::DenseVector::DenseVector
DenseVector()
Default Constructor.
Ipopt::VectorSpace::Dim
Index Dim() const
Accessor function for the dimension of the vectors of this type.
Definition: IpVector.hpp:495
Ipopt::Vector
Vector Base Class.
Definition: IpVector.hpp:48
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