Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ObjectiveFunction Class Referenceabstract

Base class for concrete Objective Functions ObjectiveFunction contains a pointer to a QualityMetric. If the ObjectiveFunction is associated with more than one QualityMetric (i.e., the Objective is a composite, and the composed ObjectiveFunctions are associated with different QualityMetrics), then the QualityMetric pointer is set to NULL.. More...

#include <ObjectiveFunction.hpp>

Inheritance diagram for ObjectiveFunction:
Collaboration diagram for ObjectiveFunction:

Public Types

enum  GRADIENT_TYPE { NUMERICAL_GRADIENT, ANALYTICAL_GRADIENT, NUMERICAL_GRADIENT, ANALYTICAL_GRADIENT }
 
enum  GRADIENT_TYPE { NUMERICAL_GRADIENT, ANALYTICAL_GRADIENT, NUMERICAL_GRADIENT, ANALYTICAL_GRADIENT }
 

Public Member Functions

 ObjectiveFunction ()
 
virtual ~ObjectiveFunction ()
 
virtual bool concrete_evaluate (PatchData &patch, double &fval, MsqError &err)=0
 
bool evaluate (PatchData &patch, double &fval, MsqError &err)
 
void set_gradient_type (GRADIENT_TYPE grad)
 Set gradType to either NUMERICAL_GRADIENT or ANALYTICAL_GRADIENT. More...
 
bool compute_gradient (PatchData &patch, Vector3D *const &grad, double &OF_val, MsqError &err, size_t array_size=0)
 Calls either compute_numerical_gradient or compute_analytical_gradient depending on the value of gradType. Function returns 'false' if the patch is not within a required feasible regeion. Otherwise, it returns 'true'. More...
 
bool compute_hessian (PatchData &patch, MsqHessian &hessian, Vector3D *const &grad, double &OF_val, MsqError &err)
 Calls compute_analytical_hessian. Function returns 'false' if the patch is not within a required feasible regeion. Otherwise, it returns 'true'. More...
 
QualityMetricget_quality_metric ()
 
virtual msq_std::list
< QualityMetric * > 
get_quality_metric_list ()
 
void set_quality_metric (QualityMetric *qm)
 Set the value of qMetric. More...
 
void set_negate_flag (int neg)
 Set the value of ObjectiveFunction's negateFlag. Unless composite, concrete ObjectiveFunctions should set this flag to to the value of the associated QualityMetric's negateFLag. More...
 
int get_negate_flag ()
 Returns negateFlag. More...
 
 ObjectiveFunction ()
 
virtual ~ObjectiveFunction ()
 
virtual bool concrete_evaluate (PatchData &patch, double &fval, MsqError &err)=0
 
bool evaluate (PatchData &patch, double &fval, MsqError &err)
 
void set_gradient_type (GRADIENT_TYPE grad)
 Set gradType to either NUMERICAL_GRADIENT or ANALYTICAL_GRADIENT. More...
 
bool compute_gradient (PatchData &patch, Vector3D *const &grad, double &OF_val, MsqError &err, size_t array_size=0)
 Calls either compute_numerical_gradient or compute_analytical_gradient depending on the value of gradType. Function returns 'false' if the patch is not within a required feasible regeion. Otherwise, it returns 'true'. More...
 
bool compute_hessian (PatchData &patch, MsqHessian &hessian, Vector3D *const &grad, double &OF_val, MsqError &err)
 Calls compute_analytical_hessian. Function returns 'false' if the patch is not within a required feasible regeion. Otherwise, it returns 'true'. More...
 
QualityMetricget_quality_metric ()
 
virtual msq_std::list
< QualityMetric * > 
get_quality_metric_list ()
 
void set_quality_metric (QualityMetric *qm)
 Set the value of qMetric. More...
 
void set_negate_flag (int neg)
 Set the value of ObjectiveFunction's negateFlag. Unless composite, concrete ObjectiveFunctions should set this flag to to the value of the associated QualityMetric's negateFLag. More...
 
int get_negate_flag ()
 Returns negateFlag. More...
 

Protected Member Functions

bool compute_numerical_gradient (PatchData &patch, Vector3D *const &grad, double &OF_val, MsqError &err, size_t array_size)
 Non-virtual function which numerically computes the gradient of the Objective Function. Function returns 'false' if the patch is not within a required feasible regeion. Otherwise, it returns 'true'. More...
 
virtual bool compute_analytical_gradient (PatchData &patch, Vector3D *const &grad, double &OF_val, MsqError &err, size_t array_size)
 
virtual bool compute_analytical_hessian (PatchData &, MsqHessian &, Vector3D *const &, double &, MsqError &)
 
double get_eps (PatchData &pd, double &local_val, int k, MsqVertex *vertex, MsqError &err)
 Returns eps used in the numerical gradient calculation. More...
 
void set_use_local_gradient (bool new_bool)
 Sets useLocalGradient This variable determines whether compute_numercial_gradient can use the most efficient gradient calculation. More...
 
bool compute_numerical_gradient (PatchData &patch, Vector3D *const &grad, double &OF_val, MsqError &err, size_t array_size)
 Non-virtual function which numerically computes the gradient of the Objective Function. Function returns 'false' if the patch is not within a required feasible regeion. Otherwise, it returns 'true'. More...
 
virtual bool compute_analytical_gradient (PatchData &patch, Vector3D *const &grad, double &OF_val, MsqError &err, size_t array_size)
 
virtual bool compute_analytical_hessian (PatchData &, MsqHessian &, Vector3D *const &, double &, MsqError &)
 
double get_eps (PatchData &pd, double &local_val, int k, MsqVertex *vertex, MsqError &err)
 Returns eps used in the numerical gradient calculation. More...
 
void set_use_local_gradient (bool new_bool)
 Sets useLocalGradient This variable determines whether compute_numercial_gradient can use the most efficient gradient calculation. More...
 

Private Attributes

enum GRADIENT_TYPE gradType
 
QualityMetricqMetric
 Flag for numerical or analytical gradient. More...
 
int negateFlag
 Pointer to associated QualityMetric. More...
 
bool useLocalGradient
 

Detailed Description

Base class for concrete Objective Functions ObjectiveFunction contains a pointer to a QualityMetric. If the ObjectiveFunction is associated with more than one QualityMetric (i.e., the Objective is a composite, and the composed ObjectiveFunctions are associated with different QualityMetrics), then the QualityMetric pointer is set to NULL..

Definition at line 67 of file includeLinks/ObjectiveFunction.hpp.

Member Enumeration Documentation

Enumerator
NUMERICAL_GRADIENT 

can be very slow. Should be for tests only.

ANALYTICAL_GRADIENT 

every differentiable function should have an analytical gradient implemented.

NUMERICAL_GRADIENT 

can be very slow. Should be for tests only.

ANALYTICAL_GRADIENT 

every differentiable function should have an analytical gradient implemented.

Definition at line 102 of file includeLinks/ObjectiveFunction.hpp.

103  {
106  };
every differentiable function should have an analytical gradient implemented.
Enumerator
NUMERICAL_GRADIENT 

can be very slow. Should be for tests only.

ANALYTICAL_GRADIENT 

every differentiable function should have an analytical gradient implemented.

NUMERICAL_GRADIENT 

can be very slow. Should be for tests only.

ANALYTICAL_GRADIENT 

every differentiable function should have an analytical gradient implemented.

Definition at line 102 of file src/ObjectiveFunction/ObjectiveFunction.hpp.

103  {
106  };
every differentiable function should have an analytical gradient implemented.

Constructor & Destructor Documentation

ObjectiveFunction ( )
inline

Definition at line 70 of file includeLinks/ObjectiveFunction.hpp.

virtual ~ObjectiveFunction ( )
inlinevirtual

Definition at line 76 of file includeLinks/ObjectiveFunction.hpp.

77  {};
virtual ~ObjectiveFunction ( )
inlinevirtual

Definition at line 76 of file src/ObjectiveFunction/ObjectiveFunction.hpp.

77  {};

Member Function Documentation

bool compute_analytical_gradient ( PatchData patch,
Vector3D *const &  grad,
double &  OF_val,
MsqError err,
size_t  array_size 
)
protectedvirtual

Fills an array of Vector3D, grad, with the gradient of the objective function computed using the gradient of the quality metric. If the function has not been over-riden in the concrete Objective Function, the base class implementation prints a warning and then defaults to numerical gradient. Function returns 'false' if the patch is not within a required feasible regeion. Otherwise, it returns 'true'.

Parameters
patchThe PatchData object for which the objective function gradient is computed.
gradAn array of Vector3D, at least the size of the number of vertices in the patch.
OF_valis set to the value of the objective function.
array_sizeis the size of the grad Vector3D[] array and must correspond to the number of vertices in the patch.

Reimplemented in LPtoPTemplate, LPtoPTemplate, MaxTemplate, MaxTemplate, CompositeOFScalarMultiply, LInfTemplate, CompositeOFScalarMultiply, LInfTemplate, CompositeOFAdd, CompositeOFScalarAdd, CompositeOFAdd, CompositeOFScalarAdd, CompositeOFMultiply, and CompositeOFMultiply.

Definition at line 152 of file ObjectiveFunction/ObjectiveFunction.cpp.

References ObjectiveFunction::compute_numerical_gradient(), MSQ_CHKERR, ObjectiveFunction::NUMERICAL_GRADIENT, and ObjectiveFunction::set_gradient_type().

Referenced by ObjectiveFunction::compute_gradient().

155  {
157  bool result = compute_numerical_gradient(patch, grad, OF_val, err, array_size);
158  return !MSQ_CHKERR(err) && result;
159  }
void set_gradient_type(GRADIENT_TYPE grad)
Set gradType to either NUMERICAL_GRADIENT or ANALYTICAL_GRADIENT.
bool compute_numerical_gradient(PatchData &patch, Vector3D *const &grad, double &OF_val, MsqError &err, size_t array_size)
Non-virtual function which numerically computes the gradient of the Objective Function. Function returns &#39;false&#39; if the patch is not within a required feasible regeion. Otherwise, it returns &#39;true&#39;.
Definition: patch.h:74
#define MSQ_CHKERR(err)
Mesquite&#39;s Error Checking macro.

Here is the call graph for this function:

Here is the caller graph for this function:

virtual bool compute_analytical_gradient ( PatchData patch,
Vector3D *const &  grad,
double &  OF_val,
MsqError err,
size_t  array_size 
)
protectedvirtual

Fills an array of Vector3D, grad, with the gradient of the objective function computed using the gradient of the quality metric. If the function has not been over-riden in the concrete Objective Function, the base class implementation prints a warning and then defaults to numerical gradient. Function returns 'false' if the patch is not within a required feasible regeion. Otherwise, it returns 'true'.

Parameters
patchThe PatchData object for which the objective function gradient is computed.
gradAn array of Vector3D, at least the size of the number of vertices in the patch.
OF_valis set to the value of the objective function.
array_sizeis the size of the grad Vector3D[] array and must correspond to the number of vertices in the patch.

Reimplemented in LPtoPTemplate, LPtoPTemplate, MaxTemplate, MaxTemplate, CompositeOFScalarMultiply, LInfTemplate, CompositeOFScalarMultiply, LInfTemplate, CompositeOFAdd, CompositeOFScalarAdd, CompositeOFAdd, CompositeOFScalarAdd, CompositeOFMultiply, and CompositeOFMultiply.

bool compute_analytical_hessian ( PatchData ,
MsqHessian ,
Vector3D *const &  ,
double &  ,
MsqError err 
)
protectedvirtual

Fills a MsqHessian object with the Hessian of the objective function computed using the hessian of the quality metric. If the function has not been over-riden in the concrete Objective Function, the base class implementation prints a warning and returns false. Function returns 'false' if the patch is not within a required feasible regeion. Otherwise, it returns 'true'.

Reimplemented in LPtoPTemplate, and LPtoPTemplate.

Definition at line 161 of file ObjectiveFunction/ObjectiveFunction.cpp.

References MsqError::INVALID_STATE, and MSQ_SETERR.

Referenced by ObjectiveFunction::compute_hessian().

165  {
166  MSQ_SETERR(err)("Analytic hessian not implemented for this Objective "
167  "Function. Feasible Newton algorythm cannot be used.\n",
169  return false;
170  }
#define MSQ_SETERR(err)
Macro to set error - use err.clear() to clear.
object is in an invalid state

Here is the caller graph for this function:

virtual bool compute_analytical_hessian ( PatchData ,
MsqHessian ,
Vector3D *const &  ,
double &  ,
MsqError  
)
protectedvirtual

Fills a MsqHessian object with the Hessian of the objective function computed using the hessian of the quality metric. If the function has not been over-riden in the concrete Objective Function, the base class implementation prints a warning and returns false. Function returns 'false' if the patch is not within a required feasible regeion. Otherwise, it returns 'true'.

Reimplemented in LPtoPTemplate, and LPtoPTemplate.

bool compute_gradient ( PatchData patch,
Vector3D *const &  grad,
double &  OF_val,
MsqError err,
size_t  array_size = 0 
)

Calls either compute_numerical_gradient or compute_analytical_gradient depending on the value of gradType. Function returns 'false' if the patch is not within a required feasible regeion. Otherwise, it returns 'true'.

bool compute_gradient ( PatchData patch,
Vector3D *const &  grad,
double &  OF_val,
MsqError err,
size_t  array_size = 0 
)
inline

Calls either compute_numerical_gradient or compute_analytical_gradient depending on the value of gradType. Function returns 'false' if the patch is not within a required feasible regeion. Otherwise, it returns 'true'.

Calls either compute_numerical_gradient or compute_analytical_gradient depending on the value of gradType.

Definition at line 257 of file includeLinks/ObjectiveFunction.hpp.

References ObjectiveFunction::ANALYTICAL_GRADIENT, ObjectiveFunction::compute_analytical_gradient(), ObjectiveFunction::compute_numerical_gradient(), ObjectiveFunction::gradType, MSQ_CHKERR, and ObjectiveFunction::NUMERICAL_GRADIENT.

Referenced by TerminationCriterion::accumulate_inner(), CompositeOFMultiply::compute_analytical_gradient(), CompositeOFAdd::compute_analytical_gradient(), CompositeOFScalarAdd::compute_analytical_gradient(), CompositeOFScalarMultiply::compute_analytical_gradient(), ConjugateGradient::optimize_vertex_positions(), SteepestDescent::optimize_vertex_positions(), FeasibleNewton::optimize_vertex_positions(), and TerminationCriterion::reset_inner().

262  {
263  bool obj_bool = false;
264  switch(gradType){
265  case NUMERICAL_GRADIENT:
266  obj_bool=compute_numerical_gradient(patch, grad, OF_val,
267  err, array_size);
268  break;
269  case ANALYTICAL_GRADIENT:
270  obj_bool=compute_analytical_gradient(patch, grad, OF_val,
271  err, array_size);
272  break;
273  }
274  return !MSQ_CHKERR(err) && obj_bool;
275  }
every differentiable function should have an analytical gradient implemented.
bool compute_numerical_gradient(PatchData &patch, Vector3D *const &grad, double &OF_val, MsqError &err, size_t array_size)
Non-virtual function which numerically computes the gradient of the Objective Function. Function returns &#39;false&#39; if the patch is not within a required feasible regeion. Otherwise, it returns &#39;true&#39;.
virtual bool compute_analytical_gradient(PatchData &patch, Vector3D *const &grad, double &OF_val, MsqError &err, size_t array_size)
Definition: patch.h:74
#define MSQ_CHKERR(err)
Mesquite&#39;s Error Checking macro.

Here is the call graph for this function:

Here is the caller graph for this function:

bool compute_hessian ( PatchData patch,
MsqHessian hessian,
Vector3D *const &  grad,
double &  OF_val,
MsqError err 
)
inline

Calls compute_analytical_hessian. Function returns 'false' if the patch is not within a required feasible regeion. Otherwise, it returns 'true'.

Calls compute_analytical_hessian. Numerical objective function hessians are only used for test purposes.

Definition at line 282 of file includeLinks/ObjectiveFunction.hpp.

References ObjectiveFunction::compute_analytical_hessian(), and MSQ_CHKERR.

Referenced by FeasibleNewton::optimize_vertex_positions().

287  {
288  bool result = compute_analytical_hessian(patch, hessian,
289  grad, OF_val, err);
290  return !MSQ_CHKERR(err) && result;
291  }
virtual bool compute_analytical_hessian(PatchData &, MsqHessian &, Vector3D *const &, double &, MsqError &)
Definition: patch.h:74
#define MSQ_CHKERR(err)
Mesquite&#39;s Error Checking macro.

Here is the call graph for this function:

Here is the caller graph for this function:

bool compute_hessian ( PatchData patch,
MsqHessian hessian,
Vector3D *const &  grad,
double &  OF_val,
MsqError err 
)

Calls compute_analytical_hessian. Function returns 'false' if the patch is not within a required feasible regeion. Otherwise, it returns 'true'.

bool compute_numerical_gradient ( Mesquite::PatchData pd,
Vector3D *const &  grad,
double &  OF_val,
MsqError err,
size_t  array_size 
)
protected

Non-virtual function which numerically computes the gradient of the Objective Function. Function returns 'false' if the patch is not within a required feasible regeion. Otherwise, it returns 'true'.

Numerically Calculates the gradient of the ObjectiveFunction for the free vertices in the patch. Returns 'false' if the patch is outside of a required feasible region, returns 'ture' otherwise. The behavior of the function depends on the value of the boolean useLocalGradient. If useLocalGradient is set to 'true', compute_numerical_gradient creates a sub-patch around a free vertex, and then perturbs that vertex in one of the coordinate directions. Only the ObjectiveFunction value on the local sub-patch is used in the computation of the gradient. Therefore, useLocalGradient should only be set to 'true' for ObjectiveFunctions which can use this method. Unless the concrete ObjectiveFunction sets useLocalGradient to 'true' in its constructor, the value will be 'false'. In this case, the objective function value for the entire patch is used in the calculation of the gradient. This is computationally expensive, but it is numerically correct for all (C_1) functions.

Parameters
pdPatchData on which the gradient is taken.
gradArray of Vector3D of length the number of vertices used to store gradient.
OF_valwill be set to the objective function value.
array_sizeEither the length of grad or 0.

Definition at line 65 of file ObjectiveFunction/ObjectiveFunction.cpp.

References ObjectiveFunction::evaluate(), ObjectiveFunction::get_eps(), PatchData::get_subpatch(), PatchData::get_vertex_array(), MsqError::INVALID_STATE, j, MSQ_CHKERR, MSQ_DBGOUT, MSQ_ERRZERO, MSQ_SETERR, PatchData::num_vertices(), and ObjectiveFunction::useLocalGradient.

Referenced by ObjectiveFunction::compute_analytical_gradient(), and ObjectiveFunction::compute_gradient().

70 {
71  size_t num_vtx=pd.num_vertices();
72  if(num_vtx!=array_size && array_size>0)
73  MSQ_DBGOUT(1) << "\nArray size not equal to the number of vertices.\n";
74 
75  OF_val = 0.; // in case of return false.
76  MsqVertex* vertices=pd.get_vertex_array(err);
77  double flocal=0;
78  double flocald=0;
79  double eps=0;
80  size_t m=0;
81  short j;
82 
83  if(useLocalGradient){
84  //********************useLocalGradient***************************
85  //if useLocalGradient is turned on, do more efficient computation
86  PatchData sub_patch;
87  for (m=0; m<num_vtx; ++m) {
88  if (vertices[m].is_free_vertex()) {
89  pd.get_subpatch(m, sub_patch, err); MSQ_ERRZERO(err);
90  //If sub_patch is not in the feasible region, do not
91  //calculate anything. Just return false.
92  bool b = evaluate(sub_patch,flocal,err);
93  if(MSQ_CHKERR(err) || !b) {
94  return false;
95  }
96 
97  //loop over the three coords x,y,z
98  for(j=0;j<3;++j){
99  eps=get_eps(sub_patch, flocald, j, (&vertices[m]), err); MSQ_ERRZERO(err);
100  //PRINT_INFO("\nin obj num grad j=%i, eps=%20.19f",j,eps);
101  if(eps==0){
102  MSQ_SETERR(err)("Dividing by zero in Objective Functions numerical grad",
104  return false;
105  }
106  grad[m][j]=(flocald-flocal)/eps;
107  }
108  }
109  else {
110  for(j=0;j<3;++j)
111  grad[m][j] = 0.0;
112  }
113  }
114  evaluate(pd, OF_val, err); MSQ_ERRZERO(err);
115  }
116  else {
117  //********************DO NOT useLocalGradient********************
118  //if useLocalGradient is turned off, we do inefficient computation
119  for (m=0; m<num_vtx; ++m) {
120 
121  if (vertices[m].is_free_vertex()) {
122  //If pd is not in the feasible region, do not calculate anything.
123  //Just return false.
124  bool b = evaluate(pd,flocal,err);
125  if(MSQ_CHKERR(err) || !b) {
126  return false;
127  }
128  OF_val = flocal;
129  //loop over the three coords x,y,z
130  for(j=0;j<3;++j){
131  eps=get_eps(pd, flocald, j, (&vertices[m]), err); MSQ_ERRZERO(err);
132  //PRINT_INFO("\nin obj num grad j=%i, eps=%20.19f",j,eps);
133  if(eps==0){
134  MSQ_SETERR(err)("Dividing by zero in Objective Functions numerical grad",
136  return false;
137  }
138  grad[m][j]=(flocald-flocal)/eps;
139  }
140  }
141  else {
142  for(j=0;j<3;++j)
143  grad[m][j] = 0.0;
144  }
145  //PRINT_INFO(" gradx = %f, grady = %f, gradz = %f\n",grad[m][0],grad[m][1],grad[m][2]);
146  }//end loop over all vertices
147  }
148  //*****************END of DO NOT useLocalGradient*****************
149  return true;
150 }
#define MSQ_ERRZERO(err)
Return zero/NULL on error.
bool evaluate(PatchData &patch, double &fval, MsqError &err)
void get_subpatch(size_t center_vertex_index, PatchData &pd_to_fill, MsqError &err)
Fills a PatchData with the elements attached to a center vertex.
double get_eps(PatchData &pd, double &local_val, int k, MsqVertex *vertex, MsqError &err)
Returns eps used in the numerical gradient calculation.
#define MSQ_CHKERR(err)
Mesquite&#39;s Error Checking macro.
#define MSQ_SETERR(err)
Macro to set error - use err.clear() to clear.
size_t num_vertices() const
number of vertices in the patch.
const MsqVertex * get_vertex_array(MsqError &err) const
Returns a pointer to the start of the vertex array.
j indices j
Definition: Indexing.h:6
object is in an invalid state
#define MSQ_DBGOUT(flag)
Check debug flag and return ostream associated with flag.

Here is the call graph for this function:

Here is the caller graph for this function:

bool compute_numerical_gradient ( PatchData patch,
Vector3D *const &  grad,
double &  OF_val,
MsqError err,
size_t  array_size 
)
protected

Non-virtual function which numerically computes the gradient of the Objective Function. Function returns 'false' if the patch is not within a required feasible regeion. Otherwise, it returns 'true'.

virtual bool concrete_evaluate ( PatchData patch,
double &  fval,
MsqError err 
)
pure virtual
virtual bool concrete_evaluate ( PatchData patch,
double &  fval,
MsqError err 
)
pure virtual
bool evaluate ( PatchData patch,
double &  fval,
MsqError err 
)
inline

Computes the value of the objective funciton as fval*negateFlag, where fval is computed in concrete_evaluate(patch, fval, err) and negateFlag is either 1 or -1 depending on whether the function needs to be minimized or maximized, respectively. Returns the bool given as a return value from concrete_evaluate. If the bool is 'false', then the patch is not within the feasible region required by the associated QualityMetric(s).

Definition at line 94 of file includeLinks/ObjectiveFunction.hpp.

References ObjectiveFunction::concrete_evaluate(), and ObjectiveFunction::negateFlag.

Referenced by TerminationCriterion::accumulate_inner(), ObjectiveFunction::compute_numerical_gradient(), CompositeOFMultiply::concrete_evaluate(), CompositeOFAdd::concrete_evaluate(), CompositeOFScalarMultiply::concrete_evaluate(), CompositeOFScalarAdd::concrete_evaluate(), TerminationCriterion::cull_vertices(), ObjectiveFunction::get_eps(), ConjugateGradient::get_step(), SmartLaplacianSmoother::optimize_vertex_positions(), SteepestDescent::optimize_vertex_positions(), FeasibleNewton::optimize_vertex_positions(), and TerminationCriterion::reset_inner().

95  {
96  bool return_bool = concrete_evaluate(patch, fval, err);
97  fval *= negateFlag;
98  return return_bool;
99  }
Definition: patch.h:74
int negateFlag
Pointer to associated QualityMetric.
virtual bool concrete_evaluate(PatchData &patch, double &fval, MsqError &err)=0

Here is the call graph for this function:

Here is the caller graph for this function:

bool evaluate ( PatchData patch,
double &  fval,
MsqError err 
)
inline

Computes the value of the objective funciton as fval*negateFlag, where fval is computed in concrete_evaluate(patch, fval, err) and negateFlag is either 1 or -1 depending on whether the function needs to be minimized or maximized, respectively. Returns the bool given as a return value from concrete_evaluate. If the bool is 'false', then the patch is not within the feasible region required by the associated QualityMetric(s).

Definition at line 94 of file src/ObjectiveFunction/ObjectiveFunction.hpp.

References ObjectiveFunction::concrete_evaluate(), and ObjectiveFunction::negateFlag.

95  {
96  bool return_bool = concrete_evaluate(patch, fval, err);
97  fval *= negateFlag;
98  return return_bool;
99  }
Definition: patch.h:74
int negateFlag
Pointer to associated QualityMetric.
virtual bool concrete_evaluate(PatchData &patch, double &fval, MsqError &err)=0

Here is the call graph for this function:

double get_eps ( PatchData pd,
double &  local_val,
int  k,
MsqVertex vertex,
MsqError err 
)
inlineprotected

Returns eps used in the numerical gradient calculation.

double get_eps ( PatchData pd,
double &  local_val,
int  k,
MsqVertex vertex,
MsqError err 
)
inlineprotected

Returns eps used in the numerical gradient calculation.

Returns an appropiate value (eps) to use as a delta step for MsqVertex vertex in dimension k (i.e. k=0 -> x, k=1 -> y, k=2 -> z). The objective function value at the perturbed vertex position is given in local_val.

Definition at line 299 of file includeLinks/ObjectiveFunction.hpp.

References ObjectiveFunction::evaluate(), i, k, and MSQ_ERRZERO.

Referenced by ObjectiveFunction::compute_numerical_gradient().

301  {
302  double eps = 1.e-07;
303  // double rho=.5;
304  int imax=20;
305  int i=0;
306  bool feasible=false;
307  double tmp_var=0.0;
308  while (i<imax && !feasible)
309  {
310  i++;
311  //perturb kth coord val and check feas if needed
312  tmp_var=(*vertex)[k];
313  (*vertex)[k]+=eps;
314  feasible = evaluate(pd,local_val,err); MSQ_ERRZERO(err);
315  //if step was too big, shorten it
316  if(!feasible)
317  eps*=0.5;
318  //revert kth coord val
319  (*vertex)[k]=tmp_var;
320  }//end while looking for feasible eps
321  return eps;
322  }//end function get_eps
#define MSQ_ERRZERO(err)
Return zero/NULL on error.
j indices k indices k
Definition: Indexing.h:6
bool evaluate(PatchData &patch, double &fval, MsqError &err)
blockLoc i
Definition: read.cpp:79

Here is the call graph for this function:

Here is the caller graph for this function:

int get_negate_flag ( )
inline

Returns negateFlag.

Definition at line 170 of file includeLinks/ObjectiveFunction.hpp.

References ObjectiveFunction::negateFlag.

Referenced by CompositeOFMultiply::CompositeOFMultiply(), CompositeOFScalarMultiply::compute_analytical_gradient(), LPtoPTemplate::compute_analytical_gradient(), and LPtoPTemplate::compute_analytical_hessian().

171  {
172  return negateFlag;
173  }
int negateFlag
Pointer to associated QualityMetric.

Here is the caller graph for this function:

int get_negate_flag ( )
inline

Returns negateFlag.

Definition at line 170 of file src/ObjectiveFunction/ObjectiveFunction.hpp.

References ObjectiveFunction::negateFlag.

171  {
172  return negateFlag;
173  }
int negateFlag
Pointer to associated QualityMetric.
QualityMetric* get_quality_metric ( )
inline

Return the quality metric associated with this objective function. Returns null for composite functions which have multiple associated quality metrics. Use get_quality_metric_list() to retrieve all metrics.

Definition at line 139 of file src/ObjectiveFunction/ObjectiveFunction.hpp.

References ObjectiveFunction::qMetric.

139  {
140  return qMetric;
141  }
QualityMetric * qMetric
Flag for numerical or analytical gradient.
QualityMetric* get_quality_metric ( )
inline

Return the quality metric associated with this objective function. Returns null for composite functions which have multiple associated quality metrics. Use get_quality_metric_list() to retrieve all metrics.

Definition at line 139 of file includeLinks/ObjectiveFunction.hpp.

References ObjectiveFunction::qMetric.

Referenced by CompositeOFAdd::CompositeOFAdd(), CompositeOFMultiply::CompositeOFMultiply(), CompositeOFScalarAdd::CompositeOFScalarAdd(), CompositeOFScalarMultiply::CompositeOFScalarMultiply(), LPtoPTemplate::compute_analytical_gradient(), LPtoPTemplate::compute_analytical_hessian(), NonSmoothSteepestDescent::compute_function(), NonSmoothSteepestDescent::compute_gradient(), LInfTemplate::concrete_evaluate(), MaxTemplate::concrete_evaluate(), and LPtoPTemplate::concrete_evaluate().

139  {
140  return qMetric;
141  }
QualityMetric * qMetric
Flag for numerical or analytical gradient.

Here is the caller graph for this function:

virtual msq_std::list<QualityMetric*> get_quality_metric_list ( )
inlinevirtual

returns a list of all associated metrics;

Reimplemented in CompositeOFAdd, CompositeOFScalarAdd, CompositeOFScalarMultiply, CompositeOFAdd, CompositeOFScalarAdd, CompositeOFScalarMultiply, CompositeOFMultiply, and CompositeOFMultiply.

Definition at line 146 of file src/ObjectiveFunction/ObjectiveFunction.hpp.

References ObjectiveFunction::qMetric.

147  {
148  msq_std::list<QualityMetric*> temp_list;
149  temp_list.push_front(qMetric);
150  return temp_list;
151  }
QualityMetric * qMetric
Flag for numerical or analytical gradient.
virtual msq_std::list<QualityMetric*> get_quality_metric_list ( )
inlinevirtual
void set_gradient_type ( GRADIENT_TYPE  grad)
inline

Set gradType to either NUMERICAL_GRADIENT or ANALYTICAL_GRADIENT.

Definition at line 110 of file src/ObjectiveFunction/ObjectiveFunction.hpp.

References ObjectiveFunction::gradType.

111  { gradType = grad; }
void set_negate_flag ( int  neg)
inline

Set the value of ObjectiveFunction's negateFlag. Unless composite, concrete ObjectiveFunctions should set this flag to to the value of the associated QualityMetric's negateFLag.

Definition at line 164 of file includeLinks/ObjectiveFunction.hpp.

References ObjectiveFunction::negateFlag.

Referenced by CompositeOFAdd::CompositeOFAdd(), CompositeOFMultiply::CompositeOFMultiply(), CompositeOFScalarAdd::CompositeOFScalarAdd(), CompositeOFScalarMultiply::CompositeOFScalarMultiply(), LInfTemplate::LInfTemplate(), LPtoPTemplate::LPtoPTemplate(), and MaxTemplate::MaxTemplate().

165  {
166  negateFlag=neg;
167  }
int negateFlag
Pointer to associated QualityMetric.

Here is the caller graph for this function:

void set_negate_flag ( int  neg)
inline

Set the value of ObjectiveFunction's negateFlag. Unless composite, concrete ObjectiveFunctions should set this flag to to the value of the associated QualityMetric's negateFLag.

Definition at line 164 of file src/ObjectiveFunction/ObjectiveFunction.hpp.

References ObjectiveFunction::negateFlag.

165  {
166  negateFlag=neg;
167  }
int negateFlag
Pointer to associated QualityMetric.
void set_quality_metric ( QualityMetric qm)
inline
void set_quality_metric ( QualityMetric qm)
inline

Set the value of qMetric.

Definition at line 154 of file src/ObjectiveFunction/ObjectiveFunction.hpp.

References ObjectiveFunction::qMetric.

155  {
156  qMetric=qm;
157  }
QualityMetric * qMetric
Flag for numerical or analytical gradient.
void set_use_local_gradient ( bool  new_bool)
inlineprotected

Sets useLocalGradient This variable determines whether compute_numercial_gradient can use the most efficient gradient calculation.

Definition at line 230 of file src/ObjectiveFunction/ObjectiveFunction.hpp.

References ObjectiveFunction::useLocalGradient.

231  {
232  useLocalGradient=new_bool;
233  }
void set_use_local_gradient ( bool  new_bool)
inlineprotected

Sets useLocalGradient This variable determines whether compute_numercial_gradient can use the most efficient gradient calculation.

Definition at line 230 of file includeLinks/ObjectiveFunction.hpp.

References ObjectiveFunction::useLocalGradient.

231  {
232  useLocalGradient=new_bool;
233  }

Member Data Documentation

int negateFlag
private
QualityMetric * qMetric
private
bool useLocalGradient
private
          Equals one if ObjectiveFunction needs to

be minimized; equals negative one if ObjectiveFunction needs to be maximized.

Definition at line 245 of file includeLinks/ObjectiveFunction.hpp.

Referenced by ObjectiveFunction::compute_numerical_gradient(), and ObjectiveFunction::set_use_local_gradient().


The documentation for this class was generated from the following files: