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

Scales a given an ObjectiveFunction. More...

#include <CompositeOFScalarMultiply.hpp>

Inheritance diagram for CompositeOFScalarMultiply:
Collaboration diagram for CompositeOFScalarMultiply:

Public Member Functions

 CompositeOFScalarMultiply (double, ObjectiveFunction *)
 
virtual ~CompositeOFScalarMultiply ()
 
virtual bool concrete_evaluate (PatchData &patch, double &fval, MsqError &err)
 
virtual msq_std::list
< QualityMetric * > 
get_quality_metric_list ()
 Returns the QualityMetric list assossiated with objFunc. More...
 
 CompositeOFScalarMultiply (double, ObjectiveFunction *)
 
virtual ~CompositeOFScalarMultiply ()
 
virtual bool concrete_evaluate (PatchData &patch, double &fval, MsqError &err)
 
virtual msq_std::list
< QualityMetric * > 
get_quality_metric_list ()
 
- Public Member Functions inherited from ObjectiveFunction
 ObjectiveFunction ()
 
virtual ~ObjectiveFunction ()
 
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 ()
 
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 ()
 
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 ()
 
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_analytical_gradient (PatchData &patch, Vector3D *const &grad, double &OF_val, MsqError &err, size_t array_size)
 Implement the scalar multiply analytic gradient. More...
 
bool compute_analytical_gradient (PatchData &patch, Vector3D *const &grad, double &OF_val, MsqError &err, size_t array_size)
 Implement the scalar multiply analytic gradient. More...
 
- Protected Member Functions inherited from ObjectiveFunction
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_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_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

ObjectiveFunctionobjFunc
 
double mAlpha
 

Additional Inherited Members

- Public Types inherited from ObjectiveFunction
enum  GRADIENT_TYPE { NUMERICAL_GRADIENT, ANALYTICAL_GRADIENT, NUMERICAL_GRADIENT, ANALYTICAL_GRADIENT }
 
enum  GRADIENT_TYPE { NUMERICAL_GRADIENT, ANALYTICAL_GRADIENT, NUMERICAL_GRADIENT, ANALYTICAL_GRADIENT }
 

Detailed Description

Scales a given an ObjectiveFunction.

Definition at line 53 of file includeLinks/CompositeOFScalarMultiply.hpp.

Constructor & Destructor Documentation

CompositeOFScalarMultiply ( double  alp,
ObjectiveFunction Obj 
)

Sets the QualityMetric pointer to the metric associated with Obj. However, if alp is less than zero, the new ObjectiveFunction's negateFlag is the opposite of Obj's. This objective function defaults to the analytical gradient.

Parameters
alp(double)
Obj(ObjectiveFunction*)

Definition at line 53 of file ObjectiveFunction/CompositeOFScalarMultiply.cpp.

References ObjectiveFunction::ANALYTICAL_GRADIENT, ObjectiveFunction::get_quality_metric(), CompositeOFScalarMultiply::mAlpha, MSQ_DBGOUT, CompositeOFScalarMultiply::objFunc, ObjectiveFunction::set_gradient_type(), ObjectiveFunction::set_negate_flag(), and ObjectiveFunction::set_quality_metric().

53  {
54 
55  set_quality_metric(Obj->get_quality_metric());
56  objFunc=Obj;
57  mAlpha=alp;
58  if(alp<0)
59  set_negate_flag(-1);
60  else if (alp>0)
61  set_negate_flag(1);
62  else
63  MSQ_DBGOUT(1) << "ObjectiveFunction being scaled by zero.";
65 }
void set_gradient_type(GRADIENT_TYPE grad)
Set gradType to either NUMERICAL_GRADIENT or ANALYTICAL_GRADIENT.
void set_quality_metric(QualityMetric *qm)
Set the value of qMetric.
every differentiable function should have an analytical gradient implemented.
void set_negate_flag(int neg)
Set the value of ObjectiveFunction&#39;s negateFlag. Unless composite, concrete ObjectiveFunctions should...
#define MSQ_DBGOUT(flag)
Check debug flag and return ostream associated with flag.

Here is the call graph for this function:

Definition at line 68 of file ObjectiveFunction/CompositeOFScalarMultiply.cpp.

68  {
69 
70 }
virtual ~CompositeOFScalarMultiply ( )
virtual

Member Function Documentation

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

Implement the scalar multiply analytic gradient.

Analytically computes the composite objective function's gradient by scaling the gradient returned objFunc->compute_gradient(). If mAlpha is less than zero, the gradient is scaled by negatvie mAlpha because the ObjectiveFunction is multiplied by negative one so that it may be minimized.

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.
array_sizeis the size of the grad Vector3D[] array and must correspond to the number of vertices in the patch.

Reimplemented from ObjectiveFunction.

Definition at line 110 of file ObjectiveFunction/CompositeOFScalarMultiply.cpp.

References ObjectiveFunction::compute_gradient(), ObjectiveFunction::get_negate_flag(), i, CompositeOFScalarMultiply::mAlpha, MSQ_ERRZERO, MSQ_FUNCTION_TIMER, PatchData::num_vertices(), and CompositeOFScalarMultiply::objFunc.

116 {
117  MSQ_FUNCTION_TIMER( "CompositeOFScalarMultiply::compute_analytical_gradient" );
118 
119  double scale_factor=(get_negate_flag()*mAlpha);
120  bool rval=objFunc->compute_gradient(patch, grad, OF_val, err, array_size); MSQ_ERRZERO(err);
121  int num_vert=patch.num_vertices();
122  int i=0;
123  //If the objFunc was successful in calculating the gradient
124  if(rval){
125  //scale the gradient by alpha
126  for(i=0;i<num_vert;++i){
127  grad[i]*=scale_factor;
128  }
129  //scale the OF_val
130  OF_val*=mAlpha;
131  }
132  else{
133  OF_val=0.0;
134  }
135  return rval;
136 }
#define MSQ_ERRZERO(err)
Return zero/NULL on error.
Definition: patch.h:74
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 grad...
blockLoc i
Definition: read.cpp:79

Here is the call graph for this function:

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

Implement the scalar multiply analytic gradient.

Reimplemented from ObjectiveFunction.

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

Evaluate the objective function on a given patch.

Implements ObjectiveFunction.

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

Computes fval= mAlpha*objFunc->evaluate(patch,err). Note that since Obj's evaluate() function is called (as opposed to its concrete_evaluate) the returned value has been multiplied by objFunc's negateFlag (that is, if objFunc needed to be maximized then the value has been multiplied by negative one so that it may be minimized instead.) Function returns `false' if and only if objFunc->evaluate() returns `false'.

Implements ObjectiveFunction.

Definition at line 79 of file ObjectiveFunction/CompositeOFScalarMultiply.cpp.

References ObjectiveFunction::evaluate(), CompositeOFScalarMultiply::mAlpha, MSQ_CHKERR, and CompositeOFScalarMultiply::objFunc.

80  {
81  //if invalid return false without calculating fval
82  bool b = objFunc->evaluate(patch, fval, err);
83  if (MSQ_CHKERR(err) || !b){
84  fval = 0.0;
85  return false;
86 
87  }
88  fval*=mAlpha;
89  return true;
90 }
bool evaluate(PatchData &patch, double &fval, MsqError &err)
Definition: patch.h:74
#define MSQ_CHKERR(err)
Mesquite&#39;s Error Checking macro.

Here is the call graph for this function:

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

Returns the QualityMetric list assossiated with objFunc.

Reimplemented from ObjectiveFunction.

Definition at line 93 of file ObjectiveFunction/CompositeOFScalarMultiply.cpp.

References ObjectiveFunction::get_quality_metric_list(), and CompositeOFScalarMultiply::objFunc.

93  {
95 }
virtual msq_std::list< QualityMetric * > get_quality_metric_list()

Here is the call graph for this function:

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

returns a list of all associated metrics;

Reimplemented from ObjectiveFunction.

Member Data Documentation


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