Beispiel #1
0
            inline void prepare ()
            {
                if (_options.size() != 1) {
                    _returnMsg = "configFile::commentedFile test expects 1 option to be set.";
                    setReturnCode((int) ERROR_DEVELOPMENT);
                    return ;
                }

                vector<string>::iterator it = _options.begin();

                _configObj = new configIni ((*it));

                setReturnCode((int) RETURN_SUCCESS);
            }
Beispiel #2
0
int OptCG::computeStep(ColumnVector sk)
//---------------------------------------------------------------------------- 
// 
// compute a step along the direction sk using either a backtrack line search
// or a More-Thuente search
//
//---------------------------------------------------------------------------- 
{
  int  step_type;
  int  itnmax = tol.getMaxBacktrackIter();
  real stp_length = 1.0;
  real stpmax = tol.getMaxStep();
  real stpmin = tol.getMinStep(); // 1.e-9;
  real ftol = 5.e-1;
  real xtol = 2.2e-16;
  real gtol = 5.e-1;

  step_type = linesearch(nlp, optout, sk, sx, &stp_length, stpmax, stpmin,
			   itnmax, ftol, xtol, gtol);
  if (step_type < 0) {
    setMesg("Algorithm terminated - No longer able to compute step with sufficient decrease");
    ret_code = -1;
    setReturnCode(ret_code);
    return(-1);
  }
  fcn_evals   = nlp->getFevals();
  grad_evals  = nlp->getGevals();
  step_length = stp_length;
  return(step_type);
}
Beispiel #3
0
            inline int execute ()
            {
                // test creation of insertQuery using map<string,string>.
                // if this does not work it means the data storage is
                // broken.

                map<string,string> data;
                data.insert (make_pair ("first_name", "Yannick"));
                data.insert (make_pair ("last_name", "Yannick"));
                data.insert (make_pair ("address", "Rue de l'église 37"));
                data.insert (make_pair ("zipcode", "4720"));
                data.insert (make_pair ("city", "Kelmis"));
                data.insert (make_pair ("country", "Belgium"));

                _queryObj->into ("student")
                         ->values (data);

                // make sure we inserted everything
                if (_queryObj->getValuesDispatched().size() != 6) {
                    _returnMsg = "code defines 6 field, value pairs but object returned other entries count.";
                    return setReturnCode((int) ERROR_DEVELOPMENT);
                }

                // check if all fields can be retrieved
                if (! _queryObj->hasValueForField("first_name") ||
                    ! _queryObj->hasValueForField("last_name")  ||
                    ! _queryObj->hasValueForField("address")  ||
                    ! _queryObj->hasValueForField("zipcode")  ||
                    ! _queryObj->hasValueForField("city")  ||
                    ! _queryObj->hasValueForField("country")) {

                    _returnMsg = "code defines first_name,last_name,address,zipcode,city,country but some are missing at call.";
                    return setReturnCode((int) ERROR_DEVELOPMENT);
                }

                return _returnCode;
            }
Beispiel #4
0
            inline int execute ()
            {
                jsonSingleEntry* single1 = new jsonSingleEntry("my_single1", "data");
                jsonSingleEntry* single2 = new jsonSingleEntry("my_single2", "dontknow");
                jsonSingleEntry* single3 = new jsonSingleEntry("my_single3", "one more..");
                jsonArrayEntry*  array1  = new jsonArrayEntry ("greg");
                jsonArrayEntry*  array2  = new jsonArrayEntry ("yan");

                vector<string> arrayOneData;
                arrayOneData.push_back ("Grégory");
                arrayOneData.push_back ("Saive");
                arrayOneData.push_back ("1988-08-29");

                vector<string> arrayTwoData;
                arrayTwoData.push_back ("Yannick");
                arrayTwoData.push_back ("Saive");
                arrayTwoData.push_back ("1983-12-10");

                array1->setData(arrayOneData);
                array2->setData(arrayTwoData);

                vector<jsonEntry*> entries;
                entries.push_back (single1);
                entries.push_back (single2);
                entries.push_back (array1);
                entries.push_back (array2);
                entries.push_back (single3);

                jsonObjectEntry* object = new jsonObjectEntry;
                object->setEntries (entries);

                string arrayJson = "\"my_array\":[\"key1\",\"array content\",\"should work\"]";
                jsonArrayEntry* staticArray1 = jsonArrayEntry::fromJSON (arrayJson);

                assertable<int>::assertEqual(staticArray1->getData().size(), 3);
                assertable<int>::assertEqual(object->getEntries().size(), 5);

                // void memory
                entries.clear ();
                delete single1;
                delete single2;
                delete single3;
                delete array1;
                delete array2;
                delete staticArray1;

                return setReturnCode((int) RETURN_SUCCESS);
            }
Beispiel #5
0
            inline int execute ()
            {
                if (! (bool) _returnCode)
                    return _returnCode;

                _configObj->parse();

                assertable<bool>::assertEqual(_configObj->state(), true);

                // the configuration file has two sections (workSection & workSection2) and
                // one commented section. The first has 3 entries, the second has no.
                // check if comments work without messing up the entries attachments.

                iniSection sectionOne = _configObj->getSection("workSection");
                iniSection sectionTwo = _configObj->getSection("workSection2");
                iniSection sectionOut = _configObj->getSection("commentedSection");

                assertable<int>::assertEqual(sectionOne.getPairs().size(), 3);
                assertable<int>::assertEqual(sectionTwo.getPairs().size(), 0);
                assertable<string>::assertEqual(sectionTwo.getLabel(), "workSection2");

                return setReturnCode((int) RETURN_SUCCESS);
            }
Beispiel #6
0
            inline int execute ()
            {
                string jsonObjectGreg = "\"json.user\"={\"first_name\":\"Grégory\",\"last_name\":\"Saive\",\"address\":[\"rue de l'église\",\"37\",\"4720\",\"Kelmis\"]}";

                jsonObjectEntry* objectGreg = new jsonObjectEntry ("student.greg");

                jsonSingleEntry* firstNameGreg  = new jsonSingleEntry ("first_name", "Grégory");
                jsonSingleEntry* lastNameGreg   = new jsonSingleEntry ("last_name", "Saive");
                jsonArrayEntry*  addressGreg    = new jsonArrayEntry  ("address");

                vector<string> addrData;
                addrData.push_back ("rue de l'église");
                addrData.push_back ("37");
                addrData.push_back ("4720");
                addrData.push_back ("Kelmis");

                // set address data
                addressGreg->setData (addrData);

                vector<jsonEntry*> entriesForObject;
                entriesForObject.push_back (firstNameGreg);
                entriesForObject.push_back (lastNameGreg);
                entriesForObject.push_back (addressGreg);

                // set object data
                objectGreg->setEntries (entriesForObject);

                assertable<int>::assertEqual(objectGreg->getEntries().size(), 3);

                // free
                delete objectGreg;
                delete firstNameGreg;
                delete lastNameGreg;
                delete addressGreg;

                return setReturnCode((int) RETURN_SUCCESS);
            }
Beispiel #7
0
            inline void prepare ()
            {
                _queryObj = new insertQuery;

                setReturnCode((int) RETURN_SUCCESS);
            }
Beispiel #8
0
 inline void prepare ()
 {
     setReturnCode((int) RETURN_SUCCESS);
 }
Beispiel #9
0
void OptCG::optimize()
//------------------------------------------------------------------------
// Nonlinear Preconditioned Conjugate Gradient
// 
// Given a nonlinear operator objfcn find the minimizer using a
// nonlinear conjugate gradient method
// This version uses the Polak-Ribiere formula.
// and a line search routine due to More and Thuente as implemented
// in the routines mcsrch and mcstep
//
// Notes: The parameters ftol and gtol should be set so that
//        0 < ftol < gtol < 0.5
//        Default values: ftol = 1.e-1, gtol = 5.e-1
//        This results in a fairly accurate line search
//
// Here is the mathematical description of the algorithm
// (g = grad f).
//                     -1
//        1.  set z = M  g, search = -z; 
//
//        2.  for i=0 until convergence
//
//                 find alpha that minimizes f(x + alpha*search)
//                 subject to the strong Wolfe conditions
//
//                 Test for convergence
//
//
//                 beta = -( g  ,  (z     - z ) ) / ( g  , z  )
//                            i+1    i + 1   i         i    i
//
//                 search     =  - z     +   beta * search
//                       i+1        i+1                   i
//
//----------------------------------------------------------------------------
     
{

  int i, nlcg_iter;
  int convgd = 0;
  int step_type;

  double beta;
  double delta, delta_old, delta_mid, delta_new;
  double slope, gnorm;

  double step;
  double zero = 0.;
  
// Allocate local vectors 

  int n = dim;
  int maxiter;
  double fvalue;
  ColumnVector search(n), grad(n), z(n), diag(n), xc(n);

// Initialize iteration

  maxiter = tol.getMaxIter();

  initOpt();

  if (ret_code == 0) {
    //  compute preconditioned gradient

    diag = getFcnScale();
    grad = nlp->getGrad();
    for (i=1; i<=n; i++) z(i) = grad(i)/diag(i);

    search    = -z;
    delta_old = delta_new = Dot(grad,z);
    gnorm     = sqrt(Dot(grad,grad));

    step    = 1.0/gnorm;

//---------------------------------------------------------------------------
//
//
//
//
//---------------------------------------------------------------------------

    for (nlcg_iter=1; nlcg_iter <= maxiter; nlcg_iter++) {

      iter_taken = nlcg_iter;

      //  compute a step along the direction search 

      if ((step_type = computeStep(search)) < 0) {
	setMesg("Algorithm terminated - No longer able to compute step with sufficient decrease");
	ret_code = step_type;
        setReturnCode(ret_code);
	return;
      }
    
      //  Accept this step and update the nonlinear model

      acceptStep(nlcg_iter, step_type);
      updateModel(nlcg_iter, n, xprev);

      xc         = nlp->getXc();
      mem_step   = xc - xprev;
      step       = Norm2(mem_step);

      fvalue     = nlp->getF();
      grad       = nlp->getGrad();
      gnorm      = sqrt(Dot(grad,grad));
      slope      = Dot(grad,search);

      //  Test for Convergence

      convgd = checkConvg();
      if (convgd > 0) {
	ret_code = convgd;
        setReturnCode(ret_code);
	*optout  << d(nlcg_iter,5) << " " << e(fvalue,12,4)  << " "
		 << e(gnorm,12,4)  << e(step,12,4) << "\n";
	return;
      }

      //
      //  compute a new search direction
      //  1. compute preconditioned gradient,  z = grad;
      //  2. beta is computed using Polak-Ribiere Formula constrained 
      //     so that beta > 0
      //  3  Update search direction and norms 
  
      delta_old = delta_new; delta_mid = Dot(grad,z);

      for (i=1; i<=n; i++) z(i) = grad(i)/diag(i);

      delta_new = Dot(grad,z);
      delta     = delta_new - delta_mid;
      beta      = max(zero,delta/delta_old);

      search = -z + search*beta;

      xprev  = nlp->getXc();
      fprev  = fvalue;
      gprev  = grad;

      *optout 
	<< d(nlcg_iter,5) << " " << e(fvalue,12,4) << " " << e(gnorm,12,4) 
	<< e(step,12,4)   << " " << e(beta,12,4)   << " " << e(slope,12,4) 
	<< d(fcn_evals,4) << " " << d(grad_evals,4) << endl;
    }

    setMesg("Algorithm terminated - Number of iterations exceeds the specified limit");
    ret_code = 4;
    setReturnCode(ret_code);
  }
}