Ipopt Documentation  
 
Loading...
Searching...
No Matches
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
14namespace Ipopt
15{
16
17/* forward declarations */
18class DenseVectorSpace;
19
22DECLARE_STD_EXCEPTION(METADATA_ERROR);
24
41{
42public:
45
48 const DenseVectorSpace* owner_space
49 );
50
53 virtual ~DenseVector();
55
58
59 SmartPtr<DenseVector> MakeNewDenseVector() const;
60
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
110 {
111 DBG_ASSERT(homogeneous_);
112 return scalar_;
113 }
115
118
124 Index Pos,
125 const Vector& x
126 );
127
134 Index Pos,
135 const Vector& x
136 );
138
139protected:
142 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
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
170 const Vector& x
171 );
172
174 const Vector& x
175 );
176
177 virtual void ElementWiseMaxImpl(
178 const Vector& x
179 );
180
181 virtual void ElementWiseMinImpl(
182 const Vector& x
183 );
184
186
187 virtual void ElementWiseAbsImpl();
188
189 virtual void ElementWiseSqrtImpl();
190
191 virtual void ElementWiseSgnImpl();
192
193 virtual void AddScalarImpl(
194 Number scalar
195 );
196
197 virtual Number MaxImpl() const;
198
199 virtual Number MinImpl() const;
200
201 virtual Number SumImpl() const;
202
203 virtual Number SumLogsImpl() const;
205
208
213 Number a,
214 const Vector& v1,
215 Number b,
216 const Vector& v2,
217 Number c
218 );
219
222 const Vector& delta,
223 Number tau
224 ) const;
225
228 Number a,
229 const Vector& z,
230 const Vector& s,
231 Number c
232 );
234
237 virtual void PrintImpl(
238 const Journalist& jnlst,
239 EJournalLevel level,
240 EJournalCategory category,
241 const std::string& name,
242 Index indent,
243 const std::string& prefix
244 ) const
245 {
246 PrintImplOffset(jnlst, level, category, name, indent, prefix, 1);
247 }
248
249 /* Print the entire vector with padding, and start counting with an offset. */
251 const Journalist& jnlst,
252 EJournalLevel level,
253 EJournalCategory category,
254 const std::string& name,
255 Index indent,
256 const std::string& prefix,
257 Index offset
258 ) const;
260
261 friend class ParVector;
262
263private:
272
274
277 const DenseVector&
278 );
279
282 const DenseVector&
283 );
285
288
291
294
296 inline Number* values_allocated();
297
303
311
314
319};
320
323typedef std::map<std::string, std::vector<std::string> > StringMetaDataMapType;
324typedef std::map<std::string, std::vector<Index> > IntegerMetaDataMapType;
325typedef std::map<std::string, std::vector<Number> > NumericMetaDataMapType;
327
330{
331public:
334
336 Index dim
337 )
338 : VectorSpace(dim)
339 { }
340
343 { }
345
348 {
349 return new DenseVector(this);
350 }
351
352 virtual Vector* MakeNew() const
353 {
354 return MakeNewDenseVector();
355 }
356
363
364 inline Number* AllocateInternalStorage() const;
365
367 inline void FreeInternalStorage(
368 Number* values
369 ) const;
371
375
376 inline
377 bool HasStringMetaData(
378 const std::string tag
379 ) const;
380
382 inline
383 bool HasIntegerMetaData(
384 const std::string tag
385 ) const;
386
388 inline
389 bool HasNumericMetaData(
390 const std::string tag
391 ) const;
392
394 inline const std::vector<std::string>& GetStringMetaData(
395 const std::string& tag
396 ) const;
397
399 inline const std::vector<Index>& GetIntegerMetaData(
400 const std::string& tag
401 ) const;
402
404 inline const std::vector<Number>& GetNumericMetaData(
405 const std::string& tag
406 ) const;
407
409 inline void SetStringMetaData(
410 std::string tag,
411 std::vector<std::string> meta_data
412 );
413
415 inline void SetIntegerMetaData(
416 std::string tag,
417 std::vector<Index> meta_data
418 );
419
421 inline void SetNumericMetaData(
422 std::string tag,
423 std::vector<Number> meta_data
424 );
425
427 inline const StringMetaDataMapType& GetStringMetaData() const;
428
430 inline const IntegerMetaDataMapType& GetIntegerMetaData() const;
431
433 inline const NumericMetaDataMapType& GetNumericMetaData() const;
435
436private:
437 // variables to store vector meta data
441};
442
443// inline functions
445{
446 // Here we assume that every time someone requests this direct raw
447 // pointer, the data is going to change and the Tag for this
448 // vector has to be updated.
449
451 {
452 // If currently the vector is a homogeneous vector, set all elements
453 // explicitly to this value
455 }
457 initialized_ = true;
458 homogeneous_ = false;
459 return values_allocated();
460}
461
462inline const Number* DenseVector::Values() const
463{
464 DBG_ASSERT(initialized_ && (Dim() == 0 || values_));
465 return values_;
466}
467
469{
470 if( values_ == NULL )
471 {
473 }
474 return values_;
475}
476
478{
479 if( Dim() > 0 )
480 {
481 return new Number[Dim()];
482 }
483 else
484 {
485 return NULL;
486 }
487}
488
489inline
491 Number* values
492) const
493{
494 delete[] values;
495}
496
498{
500}
501
502inline
504 const std::string tag
505) const
506{
507 StringMetaDataMapType::const_iterator iter;
508 iter = string_meta_data_.find(tag);
509
510 if( iter != string_meta_data_.end() )
511 {
512 return true;
513 }
514
515 return false;
516}
517
518inline
520 const std::string tag
521) const
522{
523 IntegerMetaDataMapType::const_iterator iter;
524 iter = integer_meta_data_.find(tag);
525
526 if( iter != integer_meta_data_.end() )
527 {
528 return true;
529 }
530
531 return false;
532}
533
534inline
536 const std::string tag
537) const
538{
539 NumericMetaDataMapType::const_iterator iter;
540 iter = numeric_meta_data_.find(tag);
541
542 if( iter != numeric_meta_data_.end() )
543 {
544 return true;
545 }
546
547 return false;
548}
549
550inline const std::vector<std::string>& DenseVectorSpace::GetStringMetaData(
551 const std::string& tag
552) const
553{
555 StringMetaDataMapType::const_iterator iter;
556 iter = string_meta_data_.find(tag);
557 return iter->second;
558}
559
560inline const std::vector<Index>& DenseVectorSpace::GetIntegerMetaData(
561 const std::string& tag
562) const
563{
565 IntegerMetaDataMapType::const_iterator iter;
566 iter = integer_meta_data_.find(tag);
567 return iter->second;
568}
569
570inline const std::vector<Number>& DenseVectorSpace::GetNumericMetaData(
571 const std::string& tag
572) const
573{
575 NumericMetaDataMapType::const_iterator iter;
576 iter = numeric_meta_data_.find(tag);
577 return iter->second;
578}
579
581 std::string tag,
582 std::vector<std::string> meta_data
583)
584{
585 string_meta_data_[tag] = meta_data;
586}
587
589 std::string tag,
590 std::vector<Index> meta_data
591)
592{
593 integer_meta_data_[tag] = meta_data;
594}
595
597 std::string tag,
598 std::vector<Number> meta_data
599)
600{
601 numeric_meta_data_[tag] = meta_data;
602}
603
605{
606 return string_meta_data_;
607}
608
610{
611 return integer_meta_data_;
612}
613
615{
616 return numeric_meta_data_;
617}
618
619} // namespace Ipopt
620#endif
#define DBG_ASSERT(test)
Definition: IpDebug.hpp:27
#define DECLARE_STD_EXCEPTION(__except_type)
This vectors space is the vector space for DenseVector.
Number * AllocateInternalStorage() const
Allocate internal storage for the DenseVector.
const NumericMetaDataMapType & GetNumericMetaData() const
Get map of meta data of type Number.
bool HasIntegerMetaData(const std::string tag) const
Check if Integer meta exists for tag.
void SetStringMetaData(std::string tag, std::vector< std::string > meta_data)
Set meta data of type std::string by tag.
const StringMetaDataMapType & GetStringMetaData() const
Get map of meta data of type Number.
StringMetaDataMapType string_meta_data_
bool HasStringMetaData(const std::string tag) const
Check if string meta exists for tag.
NumericMetaDataMapType numeric_meta_data_
bool HasNumericMetaData(const std::string tag) const
Check if Numeric meta exists for tag.
DenseVectorSpace(Index dim)
Constructor, requires dimension of all vector for this VectorSpace.
void SetIntegerMetaData(std::string tag, std::vector< Index > meta_data)
Set meta data of type Index by tag.
IntegerMetaDataMapType integer_meta_data_
void SetNumericMetaData(std::string tag, std::vector< Number > meta_data)
Set meta data of type Number by tag.
void FreeInternalStorage(Number *values) const
Deallocate internal storage for the DenseVector.
~DenseVectorSpace()
Destructor.
DenseVector * MakeNewDenseVector() const
Method for creating a new vector of this specific type.
const IntegerMetaDataMapType & GetIntegerMetaData() const
Get map of meta data of type Number.
virtual Vector * MakeNew() const
Pure virtual method for creating a new Vector of the corresponding type.
Dense Vector Implementation.
virtual Number DotImpl(const Vector &x) const
Computes inner product of vector x with this (DDOT)
void AddVectorQuotientImpl(Number a, const Vector &z, const Vector &s, Number c)
Add the quotient of two vectors, y = a * z/s + c * y.
void SetValues(const Number *x)
Set elements in the vector to the Number array x.
virtual void AxpyImpl(Number alpha, const Vector &x)
Add the multiple alpha of vector x to this vector (DAXPY)
Number * ExpandedValues()
This is the same as Values, but we add it here so that ExpandedValues can also be used for the non-co...
bool initialized_
Flag for Initialization.
void operator=(const DenseVector &)
Default Assignment Operator.
const DenseVectorSpace * owner_space_
Copy of the owner_space ptr as a DenseVectorSpace instead of a VectorSpace.
Number * values_allocated()
Get the internal values array, making sure that memory has been allocated.
bool IsHomogeneous() const
Indicates if the vector is homogeneous (i.e., all entries have the value Scalar().
virtual void ElementWiseSgnImpl()
Replaces entries with sgn of the entry.
Number * expanded_values_
Dense Number array pointer that is used for ExpandedValues.
virtual void ElementWiseDivideImpl(const Vector &x)
Element-wise division .
DenseVector(const DenseVectorSpace *owner_space)
Default Constructor.
virtual void ElementWiseSqrtImpl()
Take elementwise square-root of the elements of the vector.
virtual void SetImpl(Number value)
Set each element in the vector to the scalar alpha.
const Number * ExpandedValues() const
The same as the const version of Values, but we ensure that we always return a valid array,...
void AddTwoVectorsImpl(Number a, const Vector &v1, Number b, const Vector &v2, Number c)
Add two vectors (a * v1 + b * v2).
void PrintImplOffset(const Journalist &jnlst, EJournalLevel level, EJournalCategory category, const std::string &name, Index indent, const std::string &prefix, Index offset) const
void set_values_from_scalar()
Auxiliary method for setting explicitly all elements in values_ to the current scalar value.
Number FracToBoundImpl(const Vector &delta, Number tau) const
Fraction to the boundary parameter.
virtual Number Nrm2Impl() const
Computes the 2-norm of this vector (DNRM2)
void CopyFromPos(Index Pos, const Vector &x)
Copy a subrange of x, starting at Pos, into the full data of this vector.
virtual Number MinImpl() const
Min number in the vector.
virtual void ScalImpl(Number alpha)
Scales the vector by scalar alpha (DSCAL)
virtual ~DenseVector()
Destructor.
virtual void CopyImpl(const Vector &x)
Copy the data of the vector x into this vector (DCOPY).
bool homogeneous_
Flag indicating whether the vector is currently homogeneous (that is, all elements have the same valu...
virtual Number AmaxImpl() const
Computes the max-norm of this vector (based on IDAMAX)
virtual void ElementWiseReciprocalImpl()
Reciprocates the elements of the vector.
Number scalar_
Homogeneous value of all elements if the vector is currently homogeneous.
DenseVector(const DenseVector &)
Copy Constructor.
SmartPtr< DenseVector > MakeNewDenseVector() const
Create a new DenseVector from same VectorSpace.
virtual void ElementWiseAbsImpl()
Take elementwise absolute values of the elements of the vector.
virtual Number MaxImpl() const
Max value in the vector.
virtual void ElementWiseMultiplyImpl(const Vector &x)
Element-wise multiplication .
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.
virtual void AddScalarImpl(Number scalar)
Add scalar to every component of vector.
Number Scalar() const
Scalar value of all entries in a homogeneous vector.
virtual Number SumLogsImpl() const
Sum of logs of entries in the vector.
virtual void ElementWiseMaxImpl(const Vector &x)
Element-wise max against entries in x.
virtual Number AsumImpl() const
Computes the 1-norm of this vector (DASUM)
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.
virtual Number SumImpl() const
Sum of entries in the vector.
Number * Values()
Obtain pointer to the internal Number array with vector elements with the intention to change the vec...
DenseVector()
Default Constructor.
virtual void ElementWiseMinImpl(const Vector &x)
Element-wise min against entries in x.
Number * values_
Dense Number array of vector values.
Class responsible for all message output.
Template class for Smart Pointers.
Definition: IpSmartPtr.hpp:172
void ObjectChanged()
Objects derived from TaggedObject MUST call this method every time their internal state changes to up...
VectorSpace base class, corresponding to the Vector base class.
Definition: IpVector.hpp:459
Index Dim() const
Accessor function for the dimension of the vectors of this type.
Definition: IpVector.hpp:481
Vector Base Class.
Definition: IpVector.hpp:48
Index Dim() const
Dimension of the Vector.
Definition: IpVector.hpp:836
#define IPOPTLIB_EXPORT
This file contains a base class for all exceptions and a set of macros to help with exceptions.
std::map< std::string, std::vector< Number > > NumericMetaDataMapType
EJournalCategory
Category Selection Enum.
std::map< std::string, std::vector< Index > > IntegerMetaDataMapType
int Index
Type of all indices of vectors, matrices etc.
Definition: IpTypes.hpp:17
std::map< std::string, std::vector< std::string > > StringMetaDataMapType
EJournalLevel
Print Level Enum.
double Number
Type of all numbers.
Definition: IpTypes.hpp:15