//------------------------------------------------------------------------ // Initialization subroutine //------------------------------------------------------------------------ void OptBCEllipsoid::initOpt() { NLP1 *nlp = nlprob(); int i,n = nlp->getDim(); double dtmp=0.0; time_t t; char *c; // Get date and print out header t = time(NULL); c = asctime(localtime(&t)); *optout << "**********************************************************\n"; *optout << "OPT++ version " << OPT_GLOBALS::OPT_VERSION << "\n"; *optout << "Job run at " << c << "\n"; copyright(); *optout << "**********************************************************\n"; // Read in OPT++ input file if it exists. Be aware that anything in // the input file will override any variable set so far nlp->initFcn(); SerialDenseVector<int,double> xc(nlp->getXc().length()); xc = nlp->getXc(); readOptInput(); if (debug_) nlp->setDebug(); ret_code = 0; if(nlp->hasConstraints()){ CompoundConstraint* constraints = nlp->getConstraints(); SerialDenseVector<int,double> xstart(nlp->getXc().length()); xstart = nlp->getXc(); double feas_tol = tol.getCTol(); bool feasible = constraints->amIFeasible(xstart, feas_tol); if (!feasible) { *optout << "OptBCEllipsoid WARNING: Initial guess not feasible.\n" << "Ellipsoid may be unable to make progress." << endl; } } if (ret_code == 0) { nlp->evalF(); // if initial radius of ellipsoid is not specified, set it to something if (initial_radius < 0.0e0) { for (i=1; i<=n; i++) dtmp = max(dtmp, fabs(xc(i))); initial_radius = 1.0e1 * dtmp + 1.0e5; } *optout << "\n Iter F(x) Steplength " << "fevals gevals\n\n"; if(debug_) *optout << "Radius of initial ellipsoid = " << initial_radius << "\n"; } }
void OptCG::initOpt() { time_t t; char *c; // get date and print out header t = time(NULL); c = asctime(localtime(&t)); *optout << "************************************************************\n"; *optout << "OPT++ version " << OPT_GLOBALS::OPT_VERSION << "\n"; *optout << "Job run at " << c << "\n"; copyright(); *optout << "************************************************************\n"; if (debug_) nlp->setDebug(); nlp->initFcn(); ret_code = 0; if(nlp->hasConstraints()){ CompoundConstraint* constraints = nlp->getConstraints(); ColumnVector xstart = nlp->getXc(); double feas_tol = tol.getCTol(); bool feasible = constraints->amIFeasible(xstart, feas_tol); if (!feasible) { *optout << "OptCG WARNING: Initial guess not feasible.\n" << "CG may be unable to make progress." << endl; } //cerr << "Error: OptCG does not support bound, linear, or nonlinear " // << "constraints.\n Please select a different method for " // << "constrained problems." << endl; //abort_handler(-1); } if (ret_code == 0) { double fvalue, gnorm; int n = nlp->getDim(); nlp->eval(); fvalue = nlp->getF(); fprev = fvalue; xprev = nlp->getXc(); gprev = nlp->getGrad(); gnorm = Norm2(gprev); *optout << "\n\t\t\t\tNonlinear CG" << "\n Iter F(x) ||grad|| " << "||step|| beta gtp fcn\n\n" << d(0,5) << " " << e(fvalue,12,4) << " " << e(gnorm,12,4) << endl; if (debug_) { nlp->fPrintState(optout, "qnewton: Initial Guess"); *optout << "xc, grad, step\n"; for(int i=1; i<=n; i++) *optout << d(i,6) << e(xprev(i),24,16) << e(gprev(i),24,16) << "\n"; } } }