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

Multiplies two ObjectiveFunction values together. More...

#include <CompositeOFMultiply.hpp>

Inheritance diagram for CompositeOFMultiply:
Collaboration diagram for CompositeOFMultiply:

Public Member Functions

 CompositeOFMultiply (ObjectiveFunction *, ObjectiveFunction *)
 
virtual ~CompositeOFMultiply ()
 
virtual bool concrete_evaluate (PatchData &patch, double &fval, MsqError &err)
 
virtual msq_std::list
< QualityMetric * > 
get_quality_metric_list ()
 
 CompositeOFMultiply (ObjectiveFunction *, ObjectiveFunction *)
 
virtual ~CompositeOFMultiply ()
 
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

ObjectiveFunctionobjFunc1
 
ObjectiveFunctionobjFunc2
 

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

Multiplies two ObjectiveFunction values together.

Definition at line 51 of file includeLinks/CompositeOFMultiply.hpp.

Constructor & Destructor Documentation

Sets the QualityMetric pointer to the metric associated with Obj1 and Obj2 if Obj1 and Obj2 are associated with the same metric. Otherwise, it sets the QualityMetric pointer to NULL. The new ObjectiveFunction's negateFlag is set to negative one only if both Obj1 and Obj2's negateFlag are negative one (because obj1 and obj2's evaluate function multiply their return values by negative one if their respective function needs to be maximized. If both of these functions needed to be maximized, then the negative ones will have cancelled out). Otherwise, the negateFlag is set to one. Defaults to the analytical gradient.

Parameters
Obj1(ObjectiveFunction*)
Obj2(ObjectiveFunction*)

Definition at line 56 of file ObjectiveFunction/CompositeOFMultiply.cpp.

References ObjectiveFunction::ANALYTICAL_GRADIENT, ObjectiveFunction::get_negate_flag(), ObjectiveFunction::get_quality_metric(), CompositeOFMultiply::objFunc1, CompositeOFMultiply::objFunc2, ObjectiveFunction::set_gradient_type(), ObjectiveFunction::set_negate_flag(), and ObjectiveFunction::set_quality_metric().

56  {
57  if(Obj1->get_quality_metric()==Obj2->get_quality_metric()){
58  set_quality_metric(Obj1->get_quality_metric());
59  }
60  else
61  set_quality_metric(NULL);
62  objFunc1=Obj1;
63  objFunc2=Obj2;
64  //if both obj1 and ob2 have been negated
65  if(Obj1->get_negate_flag()-Obj2->get_negate_flag()==-2)
66  set_negate_flag(-1);
67  else
68  set_negate_flag(1);
70 }
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...

Here is the call graph for this function:

~CompositeOFMultiply ( )
virtual

Definition at line 73 of file ObjectiveFunction/CompositeOFMultiply.cpp.

73  {
74 
75 }
virtual ~CompositeOFMultiply ( )
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, using the multiplication rule. by scaling the gradient returned objFunc->compute_gradient().

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 128 of file ObjectiveFunction/CompositeOFMultiply.cpp.

References ObjectiveFunction::compute_gradient(), i, MSQ_ERRZERO, MSQ_FUNCTION_TIMER, PatchData::num_vertices(), CompositeOFMultiply::objFunc1, and CompositeOFMultiply::objFunc2.

133 {
134  MSQ_FUNCTION_TIMER( "CompositeOFMultiply::compute_analytical_gradient" );
135 
136  double obj_2_val=0.0;
137  //get the first gradient and objective function value
138  bool rval=objFunc1->compute_gradient(patch, grad, OF_val, err, array_size); MSQ_ERRZERO(err);
139  //if the above is valid, get the second gradient
140  if(rval){
141  int num_vert=patch.num_vertices();
142  Vector3D* second_grad = new Vector3D[num_vert];
143  //get second objective function's gradient
144  rval=objFunc2->compute_gradient(patch, second_grad,obj_2_val,
145  err, num_vert);
146  //if both objective functions gradients were successfully computed,
147  //use the multiplaction rule to get the complete gradient.
148  if(rval){
149  int i=0;
150  for(i=0;i<num_vert;++i){
151  grad[i]*=obj_2_val;
152  grad[i]+=(second_grad[i]*OF_val);
153  }
154  }
155  //delete the dynamically allocated space for the second gradient
156  delete []second_grad;
157  }
158 
159  //true if both gradient and both evaluate were successful.
160  //compute the objective function value by mulitiplying
161  //OF_val and obj_2_val
162  if(rval)
163  OF_val*=obj_2_val;
164  else
165  OF_val=0.0;
166  return rval;
167 }
#define MSQ_ERRZERO(err)
Return zero/NULL on error.
Definition: patch.h:74
NVec< 3, double > Vector3D
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= objFunc1->evaluate(patch,err)*objFunc2->evaluate(patch,err). Note that since objFunc1 and objFunc2's evaluate() functions are called (as opposed to their concrete_evaluates) the returned values have already been multiplied by the respective negateFlag (that is, if objFunc1 (or objFunc2) needed to be maximized then the value has been multiplied by negative one so that it may be minimized instead.) Function returns `false' if either objFunc1->evaluate() or objFunc2->evaluate() returns `false'; otherwise function returns `true'.

Implements ObjectiveFunction.

Definition at line 99 of file ObjectiveFunction/CompositeOFMultiply.cpp.

References ObjectiveFunction::evaluate(), MSQ_CHKERR, CompositeOFMultiply::objFunc1, and CompositeOFMultiply::objFunc2.

100  {
101  double second_val;
102  //if invalid, return false without calculating fval.
103  bool b = objFunc1->evaluate(patch, fval, err);
104  if(MSQ_CHKERR(err) || !b){
105  fval=0.0;
106  return false;
107  }
108 
109  b = objFunc2->evaluate(patch, second_val, err);
110  if(MSQ_CHKERR(err) || !b){
111  fval=0.0;
112  return false;
113  }
114  fval*=second_val;
115  return true;
116 }
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 associated with objFunc1 merged with the QualityMetric list associated with objFunc2. The entries in this merged list may not be unique.

Reimplemented from ObjectiveFunction.

Definition at line 81 of file ObjectiveFunction/CompositeOFMultiply.cpp.

References ObjectiveFunction::get_quality_metric_list(), CompositeOFMultiply::objFunc1, and CompositeOFMultiply::objFunc2.

82 {
83  msq_std::list<QualityMetric*> temp_list=objFunc1->get_quality_metric_list();
84  msq_std::list<QualityMetric*> temp_list2=objFunc2->get_quality_metric_list();
85  temp_list.merge(temp_list2);
86  return temp_list;
87 }
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: