Sandia Home Sandia Home
Main Page | Publications | Downloads | Configuration | Running the Code | Solver Parameters | FAQ | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

cev_evaluator.cpp

Go to the documentation of this file.
00001 // $Id: cev_evaluator.cpp,v 1.3 2006/06/30 19:14:31 tgkolda Exp $ 
00002 // $Source: /space/CVS-Acro/acro/packages/appspack/appspack/example-custom-evaluator/cev_evaluator.cpp,v $ 
00003 
00004 #include "cev_evaluator.hpp"
00005 
00013 CustomEvaluator::CustomEvaluator(): cnt(0)
00014 {
00015 }
00016 
00017 CustomEvaluator::~CustomEvaluator()
00018 {
00019   print();
00020 }
00021 
00022 void CustomEvaluator::operator()(int tag_in, const APPSPACK::Vector& x_in, 
00023                                  APPSPACK::Vector& f_out, string& msg_out)
00024 {
00025   if (constraint(x_in))
00026   {
00027     f_out.resize(1);            // Only a single function value
00028     f_out[0] = feval(x_in);     // Record the single function value
00029     msg_out = "Success";
00030   }
00031   else
00032   {
00033     f_out.resize(0);            // Empty function value
00034     msg_out = "Constraint Violation";
00035   }
00036   cnt ++;
00037   return;
00038 }
00039 
00040 void CustomEvaluator::print() const
00041 {
00042   cout << "Number of evaluations is: " << cnt << endl;
00043 }
00044 
00045 double CustomEvaluator::feval(const APPSPACK::Vector& x)
00046 {
00047   double f = 0;
00048 
00049   for (int i = 0; i < x.size(); i ++)
00050     f += (i + 1) * x[i] * x[i];
00051 
00052   return(f);
00053 } 
00054 
00055 bool CustomEvaluator::constraint(const APPSPACK::Vector& x)
00056 {
00057   double tmp = 0;
00058 
00059   for (int i = 0; i < x.size(); i ++)
00060     tmp += x[i] * x[i];
00061 
00062   return (tmp >= 1.0);
00063 } 

 

© Sandia Corporation | Site Contact | Privacy and Security

Generated on Fri Feb 16 10:33:35 2007 for APPSPACK 5.0.1 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2002