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
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);
489 const std::vector<const TaggedObject*>& dependents,
490 const std::vector<Number>& scalar_dependents
494 DBG_START_METH(
"DependentResult<T>::DependentsIdentical", dbg_verbosity);
507 for(
Index i = 0; i < (
Index) dependents.size(); i++ )
517 for(
Index i = 0; i < (
Index) scalar_dependents.size(); i++ )
565 DBG_START_METH(
"CachedResults<T>::!CachedResults()", dbg_verbosity);
589 const std::vector<const TaggedObject*>& dependents,
590 const std::vector<Number>& scalar_dependents
594 DBG_START_METH(
"CachedResults<T>::AddCachedResult", dbg_verbosity);
630 const std::vector<const TaggedObject*>& dependents
633 std::vector<Number> scalar_dependents;
640 const std::vector<const TaggedObject*>& dependents,
641 const std::vector<Number>& scalar_dependents
645 DBG_START_METH(
"CachedResults<T>::GetCachedResult", dbg_verbosity);
655 bool retValue =
false;
657 if( (*iter)->DependentsIdentical(dependents, scalar_dependents) )
659 retResult = (*iter)->GetResult();
674 const std::vector<const TaggedObject*>& dependents
677 std::vector<Number> scalar_dependents;
688 DBG_START_METH(
"CachedResults<T>::AddCachedResult1Dep", dbg_verbosity);
691 std::vector<const TaggedObject*> dependents(1);
692 dependents[0] = dependent1;
704 DBG_START_METH(
"CachedResults<T>::GetCachedResult1Dep", dbg_verbosity);
707 std::vector<const TaggedObject*> dependents(1);
708 dependents[0] = dependent1;
722 DBG_START_METH(
"CachedResults<T>::AddCachedResult2dDep", dbg_verbosity);
725 std::vector<const TaggedObject*> dependents(2);
726 dependents[0] = dependent1;
727 dependents[1] = dependent2;
740 DBG_START_METH(
"CachedResults<T>::GetCachedResult2Dep", dbg_verbosity);
743 std::vector<const TaggedObject*> dependents(2);
744 dependents[0] = dependent1;
745 dependents[1] = dependent2;
759 DBG_START_METH(
"CachedResults<T>::AddCachedResult2dDep", dbg_verbosity);
762 std::vector<const TaggedObject*> dependents(3);
763 dependents[0] = dependent1;
764 dependents[1] = dependent2;
765 dependents[2] = dependent3;
779 DBG_START_METH(
"CachedResults<T>::GetCachedResult2Dep", dbg_verbosity);
782 std::vector<const TaggedObject*> dependents(3);
783 dependents[0] = dependent1;
784 dependents[1] = dependent2;
785 dependents[2] = dependent3;
792 const std::vector<const TaggedObject*>& dependents,
793 const std::vector<Number>& scalar_dependents
803 bool retValue =
false;
805 if( (*iter)->DependentsIdentical(dependents, scalar_dependents) )
807 (*iter)->Invalidate();
825 (*iter)->Invalidate();
844 DBG_START_METH(
"CachedResults<T>::CleanupInvalidatedResults", dbg_verbosity);
852 typename std::list<DependentResult<T>*>::iterator iter;
856 if( (*iter)->IsStale() )
858 typename std::list<DependentResult<T>*>::iterator iter_to_remove = iter++;
861 delete result_to_delete;
874 DBG_START_METH(
"CachedResults<T>::DebugPrintCachedResults", dbg_verbosity);
879 DBG_PRINT((2,
"Currentlt no cached results:\n"));
883 typename std::list< DependentResult<T>* >::const_iterator iter;
884 DBG_PRINT((2,
"Current set of cached results:\n"));
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)
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.
DependentResult(const T &result, const std::vector< const TaggedObject * > &dependents, const std::vector< Number > &scalar_dependents)
Constructor, given all information about the result.
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.
NotifyType
Enumeration specifying the type of notification.
Observer()
Default Constructor.
void RequestAttach(NotifyType notify_type, const Subject *subject)
Derived classes should call this method to request an "Attach" to a Subject.
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.