Changeset 17896


Ignore:
Timestamp:
04/30/14 14:30:03 (11 years ago)
Author:
Mathieu Morlighem
Message:

CHG: making the code a little more flexible

File:
1 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/c/cores/controlm1qn3_core.cpp

    r17895 r17896  
    3232
    3333void controlm1qn3_core(FemModel* femmodel){
     34
     35        /*Intermediaries*/
     36        long   omode; /*m1qn3 output flag*/
     37        double f;     /*cost function value*/
     38
    3439        if(VerboseControl())_printf0_("   Initialize M1QN3 parameters\n");
    35 
    36         const int pbdim = 2;
    37 
    38         /*Solution parameters*/
    39         double c = 10.;
    40 
    41         /*output*/
    42         long omode;
    43 
    44         /*Function evaluation and gradient*/
    45         double f;
    46         double g[2]; /**/
    47 
    48         /*m1qn3 parameters*/
    4940        SimulFunc costfuncion  = &simul;    /*Cost function address*/
    5041        void**    prosca       = &euclid_;  /*Dot product function (euclid is the default)*/
    51         char      normtype[3];              /*Norm type: dfn = scalar product defined by prosca*/
    52         strcpy(normtype, "dfn");
     42        char      normtype[3];              /*Norm type: dfn = scalar product defined by prosca*/ strcpy(normtype, "dfn");
     43        double    dzs[1];                   /*Arrays used by m1qn3 subroutines*/
     44        long      izs[5];                   /*Arrays used by m1qn3 subroutines*/
     45        float     rzs[1];                   /*Arrays used by m1qn3 subroutines*/
    5346        long      impres       = 0;         /*verbosity level*/
    54         long      imode[3]     = {0};
     47        long      imode[3]     = {0};       /*scaling and starting mode, 0 by default*/
    5548        long      indic        = 4;         /*compute f and g*/
    56         long      reverse      = 0;
    57         long      ndz          = 20000; /*Dimension of the working area*/
    58         double    dz[20000];            /*Working array*/
    59         long      iz[5];
    60         double    dxmin        = 1.e-10; /*Resolution for the solution x*/
    61         double    epsrel       = 1.e-5;  /*Gradient stopping criterion in ]0 1[ -> |gk|/|g1| < epsrel*/
    62         long      niter        = 200;    /*Maximum number of iterations*/
    63         long      nsim         = 200;    /*Maximum number of function calls*/
    64         long      io           = 6;      /*Channel number for the output*/
    65         /*Arrayes used by m1qn3 subroutines*/
    66         double    dzs[1];
    67         long      izs[5];
    68         float     rzs[1];
     49        long      reverse      = 0;         /*reverse or direct mode*/
     50        long      ndz          = 20000;     /*Dimension of the working area*/
     51        double    dz[20000];                /*Working array*/
     52        long      iz[5];                    /*Integer m1qn3 working array of size 5*/
     53        long      niter        = 200;       /*Maximum number of iterations*/
     54        long      nsim         = 200;       /*Maximum number of function calls*/
     55        long      io           = 6;         /*Channel number for the output*/
    6956
     57        /*Optimization criterions*/
     58        double    dxmin        = 1.e-10;    /*Resolution for the solution x*/
     59        double    epsrel       = 1.e-5;     /*Gradient stopping criterion in ]0 1[ -> |gk|/|g1| < epsrel*/
    7060
    71         /*Prepare initial guess*/
    72         long      n = pbdim;
    73         double    x[pbdim];
     61        /*Get problem dimension and initialize gradient and initial guess*/
     62        long    n = 2;
     63        double* g = xNew<double>(n);
     64        double* x = xNew<double>(n);
    7465        for(int i=0;i<n;i++) x[i]=5.;
    75         dzs[0] = c;
     66        dzs[0] = 10; //c = 10 function parameter
    7667
    7768        if(VerboseControl())_printf0_("   Computing initial solution\n");
     
    9788
    9889        _printf0_(" == Final cost function = "<< f <<"\n");
    99         _printf0_(" == Final x = ["<<x[0]<<" "<<x[1]<<"]\n");
     90        //_printf0_(" == Final x = ["<<x[0]<<" "<<x[1]<<"]\n");
     91
     92        /*Clean-up and return*/
     93        xDelete<double>(g);
     94        xDelete<double>(x);
    10095}
    10196#else
Note: See TracChangeset for help on using the changeset viewer.