Actual source code: ssls.c

      1: #include "src/complementarity/impls/ssls/ssls.h"

      3: /* ---------------------------------------------------------- */
      6: int TaoSetUp_SSLS(TAO_SOLVER tao, void *solver)
      7: {
      8:   TAO_SSLS *ssls = (TAO_SSLS *)solver;
      9:   TaoVec *x;
     10:   TaoMat *J;
     11:   TaoLinearSolver *ksp;
     12:   int n, info;

     14:   TaoFunctionBegin;

     16:   info = TaoGetSolution(tao, &x); CHKERRQ(info);
     17:   info = TaoGetJacobian(tao, &J); CHKERRQ(info);

     19:   info = x->GetDimension(&n); CHKERRQ(info);

     21:   info = x->Clone(&(ssls->f)); CHKERRQ(info);
     22:   info = x->Clone(&(ssls->g)); CHKERRQ(info);
     23:   info = x->Clone(&(ssls->ff)); CHKERRQ(info);
     24:   info = x->Clone(&(ssls->dpsi)); CHKERRQ(info);
     25:   info = x->Clone(&(ssls->d)); CHKERRQ(info);
     26:   info = x->Clone(&(ssls->w)); CHKERRQ(info);
     27:   info = x->Clone(&(ssls->da)); CHKERRQ(info);
     28:   info = x->Clone(&(ssls->db)); CHKERRQ(info);
     29:   info = x->Clone(&(ssls->t1)); CHKERRQ(info);
     30:   info = x->Clone(&(ssls->t2)); CHKERRQ(info);
     31:   info = x->Clone(&(ssls->xl)); CHKERRQ(info);
     32:   info = x->Clone(&(ssls->xu)); CHKERRQ(info);

     34:   info = TaoSetVariableBounds(tao,ssls->xl,ssls->xu); CHKERRQ(info);
     35:   info = TaoCheckBounds(tao); CHKERRQ(info);

     37:   info = TaoSetStepDirectionVector(tao,ssls->d);CHKERRQ(info);
     38:   info = TaoSetLagrangianGradientVector(tao,ssls->g);CHKERRQ(info);

     40:   info = TaoCreateLinearSolver(tao,J,21,0); CHKERRQ(info);
     41:   info = TaoGetLinearSolver(tao,&ksp); CHKERRQ(info);
     42:   info = x->GetDimension(&n);CHKERRQ(info);
     43:   n = int(5*sqrt(1.0*n));
     44:   info = ksp->SetTolerances(1e-16,1e-16,1e30,n);CHKERRQ(info);

     46:   info = TaoLineSearchSetUp(tao);CHKERRQ(info);
     47:   TaoFunctionReturn(0);
     48: }

     50: /* ---------------------------------------------------------- */
     53: int TaoSetDown_SSLS(TAO_SOLVER tao, void *solver)
     54: {
     55:   TAO_SSLS *ssls = (TAO_SSLS *)solver;
     56:   int info;

     58:   TaoFunctionBegin;

     60:   info=TaoVecDestroy(ssls->f); CHKERRQ(info);
     61:   info=TaoVecDestroy(ssls->g); CHKERRQ(info);
     62:   info=TaoVecDestroy(ssls->ff); CHKERRQ(info);
     63:   info=TaoVecDestroy(ssls->dpsi); CHKERRQ(info);
     64:   info=TaoVecDestroy(ssls->d); CHKERRQ(info);
     65:   info=TaoVecDestroy(ssls->w); CHKERRQ(info);
     66:   info=TaoVecDestroy(ssls->da); CHKERRQ(info);
     67:   info=TaoVecDestroy(ssls->db); CHKERRQ(info);
     68:   info=TaoVecDestroy(ssls->t1); CHKERRQ(info);
     69:   info=TaoVecDestroy(ssls->t2); CHKERRQ(info);
     70:   info=TaoVecDestroy(ssls->xl); CHKERRQ(info);
     71:   info=TaoVecDestroy(ssls->xu); CHKERRQ(info);

     73:   info = TaoDestroyLinearSolver(tao);CHKERRQ(info);

     75:   TaoFunctionReturn(0);
     76: }

     78: /*------------------------------------------------------------*/
     81: int TaoSetOptions_SSLS(TAO_SOLVER tao, void *solver)
     82: {
     83:   TAO_SSLS *ssls = (TAO_SSLS *)solver;
     84:   int info;
     85:   TaoTruth flg;

     87:   TaoFunctionBegin;
     88:   info = TaoOptionsHead("Semismooth method with a linesearch for "
     89:                           "complementarity problems"); CHKERRQ(info);
     90:   info = TaoOptionDouble("-ssls_delta", "descent test fraction", "",
     91:                          ssls->delta, &(ssls->delta), &flg);CHKERRQ(info);
     92:   info = TaoOptionDouble("-ssls_rho", "descent test power", "",
     93:                          ssls->rho, &(ssls->rho), &flg);CHKERRQ(info);
     94:   info = TaoLineSearchSetFromOptions(tao);CHKERRQ(info);
     95:   info = TaoOptionsTail(); CHKERRQ(info);
     96:   TaoFunctionReturn(0);
     97: }

     99: /*------------------------------------------------------------*/
    102: int TaoView_SSLS(TAO_SOLVER tao, void *solver)
    103: {
    104:   int info;

    106:   TaoFunctionBegin;
    107:   info = TaoLineSearchView(tao); CHKERRQ(info);
    108:   TaoFunctionReturn(0);
    109: }

    111: /*------------------------------------------------------------*/
    114: int Tao_SSLS_Function(TAO_SOLVER tao, TaoVec *X, double *fcn, void *solver)
    115: {
    116:   TAO_SSLS *ssls = (TAO_SSLS *)solver;
    117:   TaoVec *f, *l, *u, *ff;
    118:   int info;

    120:   TaoFunctionBegin;
    121:   info = TaoGetVariableBounds(tao, &l, &u); CHKERRQ(info);
    122:   f  = ssls->f;
    123:   ff = ssls->ff;
    124:
    125:   info = TaoComputeConstraints(tao, X, f); CHKERRQ(info);
    126:   info = ff->Fischer(X, f, l, u); CHKERRQ(info);
    127:   info = ff->Norm2(&ssls->merit); CHKERRQ(info);
    128:   *fcn = 0.5*ssls->merit*ssls->merit;
    129:   TaoFunctionReturn(0);
    130: }

    132: /*------------------------------------------------------------*/
    135: int Tao_SSLS_FunctionGradient(TAO_SOLVER tao, TaoVec *X, double *fcn,
    136:                               TaoVec *G, void *solver)
    137: {
    138:   TAO_SSLS *ssls = (TAO_SSLS *)solver;
    139:   TaoVec *f, *l, *u, *ff, *da, *db, *t1, *t2;
    140:   TaoMat *J;
    141:   int info;

    143:   TaoFunctionBegin;
    144:   info = TaoGetVariableBounds(tao, &l, &u); CHKERRQ(info);
    145:   info = TaoGetJacobian(tao, &J); CHKERRQ(info);
    146:   f  = ssls->f;
    147:   ff = ssls->ff;
    148:   da = ssls->da;
    149:   db = ssls->db;
    150:   t1 = ssls->t1;
    151:   t2 = ssls->t2;

    153:   info = TaoComputeConstraints(tao, X, f); CHKERRQ(info);
    154:   info = ff->Fischer(X, f, l, u); CHKERRQ(info);
    155:   info = ff->Norm2(&ssls->merit); CHKERRQ(info);
    156:   *fcn = 0.5*ssls->merit*ssls->merit;

    158:   info = TaoComputeJacobian(tao, X, J); CHKERRQ(info);
    159:   info = J->D_Fischer(X, f, l, u, t1, t2, da, db); CHKERRQ(info);
    160:   info = J->RowScale(db); CHKERRQ(info);
    161:   info = J->AddDiagonal(da); CHKERRQ(info);
    162:   info = J->MultiplyTranspose(ff, G); CHKERRQ(info);
    163:   TaoFunctionReturn(0);
    164: }

    166: /*------------------------------------------------------------*/
    169: int Tao_ASLS_FunctionGradient(TAO_SOLVER tao, TaoVec *X, double *fcn,
    170:                               TaoVec *G, void *solver)
    171: {
    172:   TAO_SSLS *asls = (TAO_SSLS *)solver;
    173:   TaoVec *f, *l, *u, *ff, *da, *db, *t1, *t2;
    174:   TaoMat *J;
    175:   int info;

    177:   TaoFunctionBegin;
    178:   info = TaoGetVariableBounds(tao, &l, &u); CHKERRQ(info);
    179:   info = TaoGetJacobian(tao, &J); CHKERRQ(info);
    180:   f  = asls->f;
    181:   ff = asls->ff;
    182:   da = asls->da;
    183:   db = asls->db;
    184:   t1 = asls->t1;
    185:   t2 = asls->t2;

    187:   info = TaoComputeConstraints(tao, X, f); CHKERRQ(info);
    188:   info = ff->Fischer(X, f, l, u); CHKERRQ(info);
    189:   info = ff->Norm2(&asls->merit); CHKERRQ(info);
    190:   *fcn = 0.5*asls->merit*asls->merit;

    192:   info = TaoComputeJacobian(tao, X, J); CHKERRQ(info);
    193:   info = J->D_Fischer(X, f, l, u, t1, t2, da, db); CHKERRQ(info);
    194:   info = t1->PointwiseMultiply(ff, db);
    195:   info = J->MultiplyTranspose(t1, G); CHKERRQ(info);
    196:   info = t1->PointwiseMultiply(ff, da); CHKERRQ(info);
    197:   info = G->Axpy(1.0, t1); CHKERRQ(info);
    198:   TaoFunctionReturn(0);
    199: }