NLP interface class that adds gradient information for the objective function {abstract}. More...
#include <NLPInterfacePack_NLPObjGrad.hpp>
Classes | |
struct | ObjGradInfo |
Struct for gradient (objective), objective and constriants (pointers). More... | |
Protected Member Functions | |
const ObjGradInfo | obj_grad_info () const |
Return objective gradient and zero order information. | |
Constructors | |
| |
NLPObjGrad () | |
Initialize to no reference set to calculation quanities. | |
NLP initialization | |
| |
void | initialize (bool test_setup) |
Initialize the NLP for its first use. | |
Information | |
| |
virtual bool | supports_Gf () const |
Determine if the objective gradient is supported or not. | |
virtual bool | supports_Gf_prod () const |
Determine if the objective gradient product is supported or not. | |
<<std aggr>> members for the gradient of the objective function Gf(x) | |
| |
virtual void | set_Gf (VectorMutable *Gf) |
Set a pointer to a vector to be updated when this->calc_Gf() is called. | |
virtual VectorMutable * | get_Gf () |
Return pointer passed to this->set_Gf() . | |
virtual VectorMutable & | Gf () |
Returns non-const *this->get_Gf() . | |
virtual const Vector & | Gf () const |
Returns const *this->get_Gf() . | |
Unset calculation quantities | |
| |
void | unset_quantities () |
Call to unset all storage quantities (both in this class and all subclasses). | |
Calculation Members | |
| |
virtual void | calc_Gf (const Vector &x, bool newx=true) const |
Update the vector for Gf at the point x and put it in the stored reference. | |
virtual value_type | calc_Gf_prod (const Vector &x, const Vector &d, bool newx=true) const |
Calculate the inner product Gf(x)'*d at the point x and put it in the stored reference. | |
Function evaluation counts. | |
| |
virtual size_type | num_Gf_evals () const |
Objective gradient evaluations count. | |
Protected methods to be overridden by subclasses | |
| |
virtual void | imp_calc_Gf (const Vector &x, bool newx, const ObjGradInfo &obj_grad_info) const =0 |
Overridden to compute f(x) and perhaps c(x) (if multiple calculaiton = true). |
NLP interface class that adds gradient information for the objective function {abstract}.
Overview:
This class adds the ability to compute the gradient of the objective function Gf(x)
to the basic information given in the NLP
interface class. Note that Gf
is in the vector space space_x()
.
Client Usage:
As with the NLP
base interface, the initialize()
method must be called before the NLP object can be used. The method set_Gf()
is used to set a pointer to a vector to update when the gradient of the objective Gf
is computed when calc_Gf()
is called.
The number of evaluations of Gf
using calc_Gf()
is returned by num_Gf_evals()
.
Subclass developer's notes:
In addition to the methods that must be overridden by the NLP
interface (see) the following methods must also be overridden: imp_calc_Gf()
.
In addition to the methods that should be overridden from NLP
by most subclasses (see), the following additional methods should be overridden: initialize()
.
The following methods should never have to be overridden by most subclasses except in some very strange situations: set_Gf()
, get_Gf()
, Gf()
, num_Gf_evals()
.
Definition at line 66 of file NLPInterfacePack_NLPObjGrad.hpp.
NLPInterfacePack::NLPObjGrad::NLPObjGrad | ( | ) |
Initialize to no reference set to calculation quanities.
Definition at line 40 of file NLPInterfacePack_NLPObjGrad.cpp.
void NLPInterfacePack::NLPObjGrad::initialize | ( | bool | test_setup | ) | [virtual] |
Initialize the NLP for its first use.
This function implementation should be called by subclass implementations in order to reset counts for f(x)
, c(x)
, h(x)
and Gf(x)
evaluations. This implementation calls this->NLP::initialize()
Postconditions:
NLP::initialize()
this->num_Gf_evals() == 0
Reimplemented from NLPInterfacePack::NLP.
Reimplemented in NLPInterfacePack::NLPDirect, NLPInterfacePack::NLPFirstOrder, NLPInterfacePack::NLPSecondOrder, NLPInterfacePack::NLPBarrier, NLPInterfacePack::NLPSerialPreprocess, and NLPInterfacePack::NLPSerialPreprocessExplJac.
Definition at line 44 of file NLPInterfacePack_NLPObjGrad.cpp.
bool NLPInterfacePack::NLPObjGrad::supports_Gf | ( | ) | const [virtual] |
Determine if the objective gradient is supported or not.
The default implementation returns true
.
Definition at line 51 of file NLPInterfacePack_NLPObjGrad.cpp.
bool NLPInterfacePack::NLPObjGrad::supports_Gf_prod | ( | ) | const [virtual] |
Determine if the objective gradient product is supported or not.
The default implementation returns true
.
Definition at line 56 of file NLPInterfacePack_NLPObjGrad.cpp.
void NLPInterfacePack::NLPObjGrad::set_Gf | ( | VectorMutable * | Gf | ) | [virtual] |
Set a pointer to a vector to be updated when this->calc_Gf()
is called.
Gf | [in] Pointer to gradient vector. May be NULL . |
Preconditions:
this->is_initialized() == true
(throw NotInitialized
) this->supports_Gf()
Gf != NULL
] Gf->space().is_compatible(*this->space_x()) == true
(throw VectorSpace::IncompatibleVectorSpaces
) Postconditions:
this->get_Gf() == Gf
Reimplemented in NLPInterfacePack::NLPBarrier.
Definition at line 63 of file NLPInterfacePack_NLPObjGrad.cpp.
AbstractLinAlgPack::VectorMutable * NLPInterfacePack::NLPObjGrad::get_Gf | ( | ) | [virtual] |
Return pointer passed to this->set_Gf()
.
Preconditions:
this->is_initialized() == true
(throw NotInitialized
) this->supports_Gf()
Reimplemented in NLPInterfacePack::NLPBarrier.
Definition at line 68 of file NLPInterfacePack_NLPObjGrad.cpp.
AbstractLinAlgPack::VectorMutable & NLPInterfacePack::NLPObjGrad::Gf | ( | ) | [virtual] |
Returns non-const
*this->get_Gf()
.
Preconditions:
this->is_initialized() == true
(throw NotInitialized
) this->supports_Gf()
this->get_Gf() != NULL
(throw NoRefSet
) Reimplemented in NLPInterfacePack::NLPBarrier.
Definition at line 73 of file NLPInterfacePack_NLPObjGrad.cpp.
const AbstractLinAlgPack::Vector & NLPInterfacePack::NLPObjGrad::Gf | ( | ) | const [virtual] |
Returns const
*this->get_Gf()
.
Preconditions:
this->is_initialized() == true
(throw NotInitialized
) this->supports_Gf()
this->get_Gf() != NULL
(throw NoRefSet
) Reimplemented in NLPInterfacePack::NLPBarrier.
Definition at line 78 of file NLPInterfacePack_NLPObjGrad.cpp.
void NLPInterfacePack::NLPObjGrad::unset_quantities | ( | ) | [virtual] |
Call to unset all storage quantities (both in this class and all subclasses).
Preconditions:
this->is_initialized() == true
(throw NotInitialized
) Postconditions:
NLP::unset_quantities()
this->get_Gf() == NULL
This method must be called by all subclasses that override it.
Reimplemented from NLPInterfacePack::NLP.
Reimplemented in NLPInterfacePack::NLPFirstOrder, and NLPInterfacePack::NLPSecondOrder.
Definition at line 83 of file NLPInterfacePack_NLPObjGrad.cpp.
Update the vector for Gf
at the point x
and put it in the stored reference.
x | [in] Point at which to calculate the gradient of the objective Gf(x) . | |
newx | [in] (default true ) If false , the values in x are assumed to be the same as the last call to a this->calc_*(x,newx) member. If true , the values in x are assumed to not be the same as the last call to a this->calc_*(x,newx) member. |
Preconditions:
this->is_initialized() == true
(throw NotInitialized
) this->supports_Gf()
x.space().is_compatible(*this->space_x()) == true
(throw VectorSpace::IncompatibleVectorSpaces
) this->get_Gf() != NULL
(throw NoRefSet
) Postconditions:
this->Gf()
is updated to Gf(x)
If set_multi_calc(true)
was called then referenced storage for f
and/or c
may also be updated but are not guaranteed to be. But no other quanities from possible subclasses are allowed to be updated as a side effect (i.e. no higher order derivatives).
Reimplemented in NLPInterfacePack::NLPBarrier.
Definition at line 91 of file NLPInterfacePack_NLPObjGrad.cpp.
value_type NLPInterfacePack::NLPObjGrad::calc_Gf_prod | ( | const Vector & | x, | |
const Vector & | d, | |||
bool | newx = true | |||
) | const [virtual] |
Calculate the inner product Gf(x)'*d
at the point x
and put it in the stored reference.
x | [in] Base point | |
d | [in] Direction to compute the product along. | |
newx | [in] (default true ) If false , the values in x are assumed to be the same as the last call to a this->calc_*(x,newx) member. If true , the values in x are assumed to not be the same as the last call to a this->calc_*(x,newx) member. |
Preconditions:
this->is_initialized() == true
(throw NotInitialized
) this->supports_Gf()
x.space().is_compatible(*this->space_x()) == true
(throw VectorSpace::IncompatibleVectorSpaces
) Postconditions:
return
gives the desired product. If set_multi_calc(true)
was called then referenced storage for f
and/or c
may also be updated but are not guaranteed to be. But no other quanities from possible subclasses are allowed to be updated as a side effect (i.e. no higher order derivatives).
Definition at line 98 of file NLPInterfacePack_NLPObjGrad.cpp.
size_type NLPInterfacePack::NLPObjGrad::num_Gf_evals | ( | ) | const [virtual] |
Objective gradient evaluations count.
This function can be called to find out how many evaluations this->calc_Gf()
the client requested since this->initialize()
was called.
Reimplemented in NLPInterfacePack::NLPBarrier.
Definition at line 115 of file NLPInterfacePack_NLPObjGrad.cpp.
const NLPObjGrad::ObjGradInfo NLPInterfacePack::NLPObjGrad::obj_grad_info | ( | ) | const [inline, protected] |
Return objective gradient and zero order information.
Definition at line 319 of file NLPInterfacePack_NLPObjGrad.hpp.
virtual void NLPInterfacePack::NLPObjGrad::imp_calc_Gf | ( | const Vector & | x, | |
bool | newx, | |||
const ObjGradInfo & | obj_grad_info | |||
) | const [protected, pure virtual] |
Overridden to compute f(x) and perhaps c(x) (if multiple calculaiton = true).
Preconditions:
x.space().is_compatible(*this->space_x())
(throw IncompatibleType
) obj_grad_info.Gf != NULL
(throw std::invalid_argument
) Postconditions:
*obj_grad_info.Gf
is updated to Gf(x). x | [in] Unknown vector (size n). | |
newx | [in] (default true ) If false , the values in x are assumed to be the same as the last call to a this->imp_calc_*(x,newx) member. If true , the values in x are assumed to not be the same as the last call to a this->imp_calc_*(x,newx) member. | |
obj_grad_info | [out] Pointers to f , c and Gf . On output *obj_grad_info.Gf is updated to Gf(x). Any of the other objects pointed to in obj_grad_info may be set if this->multi_calc() == true but are now guaranteed to be. |
Implemented in NLPInterfacePack::NLPBarrier, and NLPInterfacePack::NLPSerialPreprocess.