Templated class for Cached Results. More...
#include <IpCachedResults.hpp>
Public Member Functions | |
bool | InvalidateResult (const std::vector< const TaggedObject * > &dependents, const std::vector< Number > &scalar_dependents) |
Invalidates the result for given dependencies. | |
void | Clear () |
Invalidates all cached results. | |
void | Clear (int max_cache_size) |
Invalidate all cached results and changes max_cache_size. | |
Constructors and Destructors. | |
CachedResults (int max_cache_size) | |
Constructor. | |
virtual | ~CachedResults () |
Destructor. | |
Generic methods for adding and retrieving cached results. | |
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::vector of Numbers. | |
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 TaggesObjects and a std::vector of Numbers. | |
void | AddCachedResult (const T &result, const std::vector< const TaggedObject * > &dependents) |
Method for adding a result, providing only a std::vector of TaggedObjects. | |
bool | GetCachedResult (T &retResult, const std::vector< const TaggedObject * > &dependents) const |
Method for retrieving a cached result, providing only a std::vector of TaggedObjects. | |
Pointer-based methods for adding and retrieving cached | |
results, providing dependencies 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 | GetCachedResult1Dep (T &retResult, const TaggedObject *dependent1) |
Method for retrieving a cached result, proving one dependency as a TaggedObject explicitly. | |
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. | |
bool | GetCachedResult2Dep (T &retResult, const TaggedObject *dependent1, const TaggedObject *dependent2) |
Method for retrieving a cached result, proving two dependencies as a TaggedObject explicitly. | |
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 | 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. | |
Pointer-free version of the Add and Get methods | |
bool | GetCachedResult1Dep (T &retResult, const TaggedObject &dependent1) |
bool | GetCachedResult2Dep (T &retResult, const TaggedObject &dependent1, const TaggedObject &dependent2) |
bool | GetCachedResult3Dep (T &retResult, const TaggedObject &dependent1, const TaggedObject &dependent2, const TaggedObject &dependent3) |
void | AddCachedResult1Dep (const T &result, const TaggedObject &dependent1) |
void | AddCachedResult2Dep (const T &result, const TaggedObject &dependent1, const TaggedObject &dependent2) |
void | AddCachedResult3Dep (const T &result, const TaggedObject &dependent1, const TaggedObject &dependent2, const TaggedObject &dependent3) |
Private Member Functions | |
void | CleanupInvalidatedResults () const |
internal method for removing stale DependentResults from the list | |
void | DebugPrintCachedResults () const |
Print list of currently cached results. | |
Default Compiler Generated Methods | |
(Hidden to avoid implicit creation/calling). These methods are not implemented and we do not want the compiler to implement them for us, so we declare them private and do not define them. This ensures that they will not be implicitly created/called. | |
CachedResults () | |
Default Constructor. | |
CachedResults (const CachedResults &) | |
Copy Constructor. | |
void | operator= (const CachedResults &) |
Default Assignment Operator. | |
Private Attributes | |
int | max_cache_size_ |
maximum number of cached results | |
std::list< DependentResult< T > * > * | cached_results_ |
list of currently cached results. | |
Templated class for Cached Results.
This class stores up to a given number of "results", entities that are stored here together with identifiers, that can be used to later retrieve the information again.
Typically, T is a SmartPtr for some calculated quantity that should be stored (such as a Vector). The identifiers (or dependencies) are a (possibly varying) number of Tags from TaggedObjects, and a number of Numbers. Results are added to the cache using the AddCachedResults methods, and the can be retrieved with the GetCachedResults methods. The second set of methods checks whether a result has been cached for the given identifiers. If a corresponding result is found, a copy of it is returned and the method evaluates to true, otherwise it evaluates to false.
Note that cached results can become "stale", namely when a TaggedObject that is used to identify this CachedResult is changed. When this happens, the cached result can never be asked for again, so that there is no point in storing it any longer. For this purpose, a cached result, which is stored as a DependentResult, inherits off an Observer. This Observer retrieves notification whenever a TaggedObject dependency has changed. Stale results are later removed from the cache.
Definition at line 68 of file IpCachedResults.hpp.
Ipopt::CachedResults< T >::CachedResults | ( | int | max_cache_size | ) |
Constructor.
max_cache_size | maximal number of results that should be cached, negative for infinity |
Definition at line 549 of file IpCachedResults.hpp.
|
virtual |
Destructor.
Definition at line 562 of file IpCachedResults.hpp.
|
private |
Default Constructor.
|
private |
Copy Constructor.
void Ipopt::CachedResults< T >::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::vector of Numbers.
Definition at line 587 of file IpCachedResults.hpp.
bool Ipopt::CachedResults< T >::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 TaggesObjects and a std::vector of Numbers.
Definition at line 638 of file IpCachedResults.hpp.
void Ipopt::CachedResults< T >::AddCachedResult | ( | const T & | result, |
const std::vector< const TaggedObject * > & | dependents | ||
) |
Method for adding a result, providing only a std::vector of TaggedObjects.
Definition at line 628 of file IpCachedResults.hpp.
bool Ipopt::CachedResults< T >::GetCachedResult | ( | T & | retResult, |
const std::vector< const TaggedObject * > & | dependents | ||
) | const |
Method for retrieving a cached result, providing only a std::vector of TaggedObjects.
Definition at line 672 of file IpCachedResults.hpp.
void Ipopt::CachedResults< T >::AddCachedResult1Dep | ( | const T & | result, |
const TaggedObject * | dependent1 | ||
) |
Method for adding a result to the cache, proving one dependency as a TaggedObject explicitly.
Definition at line 682 of file IpCachedResults.hpp.
bool Ipopt::CachedResults< T >::GetCachedResult1Dep | ( | T & | retResult, |
const TaggedObject * | dependent1 | ||
) |
Method for retrieving a cached result, proving one dependency as a TaggedObject explicitly.
Definition at line 698 of file IpCachedResults.hpp.
void Ipopt::CachedResults< T >::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.
Definition at line 714 of file IpCachedResults.hpp.
bool Ipopt::CachedResults< T >::GetCachedResult2Dep | ( | T & | retResult, |
const TaggedObject * | dependent1, | ||
const TaggedObject * | dependent2 | ||
) |
Method for retrieving a cached result, proving two dependencies as a TaggedObject explicitly.
Definition at line 733 of file IpCachedResults.hpp.
void Ipopt::CachedResults< T >::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.
Definition at line 751 of file IpCachedResults.hpp.
bool Ipopt::CachedResults< T >::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.
Definition at line 771 of file IpCachedResults.hpp.
|
inline |
Definition at line 181 of file IpCachedResults.hpp.
|
inline |
Definition at line 189 of file IpCachedResults.hpp.
|
inline |
Definition at line 198 of file IpCachedResults.hpp.
|
inline |
Definition at line 207 of file IpCachedResults.hpp.
|
inline |
Definition at line 215 of file IpCachedResults.hpp.
|
inline |
Definition at line 224 of file IpCachedResults.hpp.
bool Ipopt::CachedResults< T >::InvalidateResult | ( | const std::vector< const TaggedObject * > & | dependents, |
const std::vector< Number > & | scalar_dependents | ||
) |
Invalidates the result for given dependencies.
Sets the stale flag for the corresponding cached result to true if it is found.
Definition at line 791 of file IpCachedResults.hpp.
void Ipopt::CachedResults< T >::Clear | ( | ) |
Invalidates all cached results.
Definition at line 816 of file IpCachedResults.hpp.
Invalidate all cached results and changes max_cache_size.
Definition at line 832 of file IpCachedResults.hpp.
|
private |
Default Assignment Operator.
|
private |
internal method for removing stale DependentResults from the list
It is called at the beginning of every GetDependentResult method.
Definition at line 841 of file IpCachedResults.hpp.
|
private |
Print list of currently cached results.
Definition at line 871 of file IpCachedResults.hpp.
|
private |
maximum number of cached results
Definition at line 280 of file IpCachedResults.hpp.
|
mutableprivate |
list of currently cached results.
Definition at line 283 of file IpCachedResults.hpp.