7#ifndef __IPCACHEDRESULTS_HPP__
8#define __IPCACHEDRESULTS_HPP__
19#if IPOPT_CHECKLEVEL > 2
20# define IP_DEBUG_CACHE
73 static const Index dbg_verbosity;
94 const std::vector<const TaggedObject*>& dependents,
95 const std::vector<Number>& scalar_dependents
104 const std::vector<const TaggedObject*>& dependents,
105 const std::vector<Number>& scalar_dependents
111 const std::vector<const TaggedObject*>& dependents
117 const std::vector<const TaggedObject*>& dependents
242 const std::vector<const TaggedObject*>& dependents,
243 const std::vector<Number>& scalar_dependents
306 static const Index dbg_verbosity;
314 const std::vector<const TaggedObject*>& dependents,
315 const std::vector<Number>& scalar_dependents
339 const std::vector<const TaggedObject*>& dependents,
340 const std::vector<Number>& scalar_dependents
412 const std::vector<const TaggedObject*>& dependents,
413 const std::vector<Number>& scalar_dependents
417 dependent_tags_(dependents.size()),
418 scalar_dependents_(scalar_dependents)
421 DBG_START_METH(
"DependentResult<T>::DependentResult()", dbg_verbosity);
424 for(
Index i = 0; i < (
Index) dependents.size(); ++i )
449 DBG_START_METH(
"DependentResult<T>::~DependentResult()", dbg_verbosity);
476 DBG_START_METH(
"DependentResult<T>::ReceiveNotification", dbg_verbosity);
479 if( notify_type == NT_Changed || notify_type == NT_BeingDestroyed )
489 const std::vector<const TaggedObject*>& dependents,
490 const std::vector<Number>& scalar_dependents
494 DBG_START_METH(
"DependentResult<T>::DependentsIdentical", dbg_verbosity);
496 DBG_ASSERT(dependents.size() == dependent_tags_.size());
501 if( dependents.size() != dependent_tags_.size() || scalar_dependents.size() != scalar_dependents_.size() )
507 for(
Index i = 0; i < (
Index) dependents.size(); i++ )
509 if( ( dependents[i] && dependents[i]->GetTag() != dependent_tags_[i])
510 || (!dependents[i] && dependent_tags_[i] != 0) )
517 for(
Index i = 0; i < (
Index) scalar_dependents.size(); i++ )
518 if( scalar_dependents[i] != scalar_dependents_[i] )
552 : max_cache_size_(max_cache_size),
553 cached_results_(NULL)
565 DBG_START_METH(
"CachedResults<T>::!CachedResults()", dbg_verbosity);
568 if( cached_results_ )
570 for(
typename std::list<
DependentResult<T>*>::iterator iter = cached_results_->begin(); iter != cached_results_->end(); ++iter )
575 delete cached_results_;
589 const std::vector<const TaggedObject*>& dependents,
590 const std::vector<Number>& scalar_dependents
594 DBG_START_METH(
"CachedResults<T>::AddCachedResult", dbg_verbosity);
597 CleanupInvalidatedResults();
601 if( !cached_results_ )
603 cached_results_ =
new std::list<DependentResult<T>*>;
609 if( max_cache_size_ >= 0 )
613 DBG_ASSERT(cached_results_->size() <= (
size_t)max_cache_size_ + 1);
614 if( cached_results_->size() > (
size_t)max_cache_size_ )
616 delete cached_results_->back();
617 cached_results_->pop_back();
622 DBG_EXEC(2, DebugPrintCachedResults());
630 const std::vector<const TaggedObject*>&
dependents
640 const std::vector<const TaggedObject*>&
dependents,
648 if( !cached_results_ )
653 CleanupInvalidatedResults();
665 DBG_EXEC(2, DebugPrintCachedResults());
674 const std::vector<const TaggedObject*>&
dependents
691 std::vector<const TaggedObject*>
dependents(1);
707 std::vector<const TaggedObject*>
dependents(1);
725 std::vector<const TaggedObject*>
dependents(2);
743 std::vector<const TaggedObject*>
dependents(2);
762 std::vector<const TaggedObject*>
dependents(3);
782 std::vector<const TaggedObject*>
dependents(3);
792 const std::vector<const TaggedObject*>&
dependents,
796 if( !cached_results_ )
801 CleanupInvalidatedResults();
818 if( !cached_results_ )
828 CleanupInvalidatedResults();
847 if( !cached_results_ )
852 typename std::list<DependentResult<T>*>
::iterator iter;
853 iter = cached_results_->begin();
854 while( iter != cached_results_->end() )
856 if( (*iter)->IsStale() )
877 if (!cached_results_)
879 DBG_PRINT((2,
"Currentlt no cached results:\n"));
884 DBG_PRINT((2,
"Current set of cached results:\n"));
885 for (iter = cached_results_->begin(); iter != cached_results_->end(); ++iter)
887 DBG_PRINT((2,
" DependentResult: %p\n", (
void*)*iter));
#define DBG_PRINT(__printf_args)
#define DBG_START_METH(__func_name, __verbose_level)
#define DBG_EXEC(__verbosity, __cmd)
Templated class for Cached Results.
CachedResults()
Default Constructor.
void operator=(const CachedResults &)
Default Assignment Operator.
std::list< DependentResult< T > * > * cached_results_
list of currently cached results.
void Clear()
Invalidates all cached results.
void DebugPrintCachedResults() const
Print list of currently cached results.
void AddCachedResult2Dep(const T &result, const TaggedObject *dependent1, const TaggedObject *dependent2)
Method for adding a result to the cache, proving two dependencies as a TaggedObject explicitly.
void AddCachedResult1Dep(const T &result, const TaggedObject *dependent1)
Method for adding a result to the cache, proving one dependency as a TaggedObject explicitly.
bool GetCachedResult2Dep(T &retResult, const TaggedObject &dependent1, const TaggedObject &dependent2)
bool GetCachedResult1Dep(T &retResult, const TaggedObject *dependent1)
Method for retrieving a cached result, proving one dependency as a TaggedObject explicitly.
bool InvalidateResult(const std::vector< const TaggedObject * > &dependents, const std::vector< Number > &scalar_dependents)
Invalidates the result for given dependencies.
CachedResults(const CachedResults &)
Copy Constructor.
bool GetCachedResult(T &retResult, const std::vector< const TaggedObject * > &dependents) const
Method for retrieving a cached result, providing only a std::vector of TaggedObjects.
bool GetCachedResult(T &retResult, const std::vector< const TaggedObject * > &dependents, const std::vector< Number > &scalar_dependents) const
Generic method for retrieving a cached results, given the dependencies as a std::vector of TaggesObje...
void AddCachedResult3Dep(const T &result, const TaggedObject &dependent1, const TaggedObject &dependent2, const TaggedObject &dependent3)
bool GetCachedResult3Dep(T &retResult, const TaggedObject *dependent1, const TaggedObject *dependent2, const TaggedObject *dependent3)
Method for retrieving a cached result, proving three dependencies as a TaggedObject explicitly.
void CleanupInvalidatedResults() const
internal method for removing stale DependentResults from the list
void AddCachedResult(const T &result, const std::vector< const TaggedObject * > &dependents)
Method for adding a result, providing only a std::vector of TaggedObjects.
int max_cache_size_
maximum number of cached results
CachedResults(int max_cache_size)
Constructor.
void Clear(int max_cache_size)
Invalidate all cached results and changes max_cache_size.
bool GetCachedResult2Dep(T &retResult, const TaggedObject *dependent1, const TaggedObject *dependent2)
Method for retrieving a cached result, proving two dependencies as a TaggedObject explicitly.
virtual ~CachedResults()
Destructor.
void AddCachedResult1Dep(const T &result, const TaggedObject &dependent1)
void AddCachedResult3Dep(const T &result, const TaggedObject *dependent1, const TaggedObject *dependent2, const TaggedObject *dependent3)
Method for adding a result to the cache, proving three dependencies as a TaggedObject explicitly.
bool GetCachedResult1Dep(T &retResult, const TaggedObject &dependent1)
bool GetCachedResult3Dep(T &retResult, const TaggedObject &dependent1, const TaggedObject &dependent2, const TaggedObject &dependent3)
void AddCachedResult2Dep(const T &result, const TaggedObject &dependent1, const TaggedObject &dependent2)
void AddCachedResult(const T &result, const std::vector< const TaggedObject * > &dependents, const std::vector< Number > &scalar_dependents)
Generic method for adding a result to the cache, given a std::vector of TaggesObjects and a std::vect...
Templated class which stores one entry for the CachedResult class.
void DebugPrint() const
Print information about this DependentResults.
const T & GetResult() const
Returns the cached result.
DependentResult()
Default Constructor.
DependentResult(const DependentResult &)
Copy Constructor.
std::vector< TaggedObject::Tag > dependent_tags_
Dependencies in form of TaggedObjects.
const T result_
The value of the dependent results.
bool stale_
Flag indicating, if the cached result is still valid.
std::vector< Number > scalar_dependents_
Dependencies in form a Numbers.
virtual void ReceiveNotification(NotifyType notify_type, const Subject *subject)
Notification Receiver Method.
void Invalidate()
Invalidates the cached result.
bool DependentsIdentical(const std::vector< const TaggedObject * > &dependents, const std::vector< Number > &scalar_dependents) const
This method returns true if the dependencies provided to this function are identical to the ones stor...
~DependentResult()
Destructor.
bool IsStale() const
Indicates, whether the DependentResult is no longer valid.
void operator=(const DependentResult &)
Default Assignment Operator.
Slight Variation of the Observer Design Pattern.
NotifyType
Enumeration specifying the type of notification.
void RequestAttach(NotifyType notify_type, const Subject *subject)
Derived classes should call this method to request an "Attach" to a Subject.
Slight Variation of the Observer Design Pattern (Subject part).
This file contains a base class for all exceptions and a set of macros to help with exceptions.
ipindex Index
Type of all indices of vectors, matrices etc.