コード例 #1
0
void
nlf1(int mode, int ndim, NEWMAT::ColumnVector const & x, OPTPP::real & fx, NEWMAT::ColumnVector & gx, int & result, void * data)
{
  result = OPTPP::NLPNoOp;

  if (mode & OPTPP::NLPFunction)
    nlf0(ndim, x, fx, result, data);

  if (mode & OPTPP::NLPGradient)
  {
    ScalarFunction const * func = static_cast<ScalarFunction *>(data);
    AnalyticD1ScalarFunction const * func1 = dynamic_cast<AnalyticD1ScalarFunction const *>(func);
    alwaysAssertM(func1, "OPTPPNumericalOptimizer: Function does not have analytical first derivative");

    gx.ReSize(ndim);
    func1->gradientAt(x.data(), gx.data());
    result |= OPTPP::NLPGradient;
  }
}
コード例 #2
0
void
nlf2(int mode, int ndim, NEWMAT::ColumnVector const & x, OPTPP::real & fx, NEWMAT::ColumnVector & gx,
     NEWMAT::SymmetricMatrix & Hx, int & result, void * data)
{
  result = OPTPP::NLPNoOp;

  if (mode & OPTPP::NLPFunction || mode & OPTPP::NLPGradient)
    nlf1(mode, ndim, x, fx, gx, result, data);

  if (mode & OPTPP::NLPHessian)
  {
    ScalarFunction const * func = static_cast<ScalarFunction *>(data);
    AnalyticD2ScalarFunction const * func2 = dynamic_cast<AnalyticD2ScalarFunction const *>(func);
    alwaysAssertM(func2, "OPTPPNumericalOptimizer: Function does not have analytical second derivative");

    Hx.ReSize(ndim);
    OPTPPSymMatWrapper Hwrapper(&Hx);
    func2->hessianAt(x.data(), Hwrapper);
    result |= OPTPP::NLPHessian;
  }
}