Actual source code: asils.c
1: #include <../src/tao/complementarity/impls/ssls/ssls.h>
2: /*
3: Context for ASXLS
4: -- active-set - reduced matrices formed
5: - inherit properties of original system
6: -- semismooth (S) - function not differentiable
7: - merit function continuously differentiable
8: - Fischer-Burmeister reformulation of complementarity
9: - Billups composition for two finite bounds
10: -- infeasible (I) - iterates not guaranteed to remain within bounds
11: -- feasible (F) - iterates guaranteed to remain within bounds
12: -- linesearch (LS) - Armijo rule on direction
14: Many other reformulations are possible and combinations of
15: feasible/infeasible and linesearch/trust region are possible.
17: Basic theory
18: Fischer-Burmeister reformulation is semismooth with a continuously
19: differentiable merit function and strongly semismooth if the F has
20: lipschitz continuous derivatives.
22: Every accumulation point generated by the algorithm is a stationary
23: point for the merit function. Stationary points of the merit function
24: are solutions of the complementarity problem if
25: a. the stationary point has a BD-regular subdifferential, or
26: b. the Schur complement F'/F'_ff is a P_0-matrix where ff is the
27: index set corresponding to the free variables.
29: If one of the accumulation points has a BD-regular subdifferential then
30: a. the entire sequence converges to this accumulation point at
31: a local q-superlinear rate
32: b. if in addition the reformulation is strongly semismooth near
33: this accumulation point, then the algorithm converges at a
34: local q-quadratic rate.
36: The theory for the feasible version follows from the feasible descent
37: algorithm framework.
39: References:
40: Billups, "Algorithms for Complementarity Problems and Generalized
41: Equations," Ph.D thesis, University of Wisconsin Madison, 1995.
42: De Luca, Facchinei, Kanzow, "A Semismooth Equation Approach to the
43: Solution of Nonlinear Complementarity Problems," Mathematical
44: Programming, 75, 1996.
45: Ferris, Kanzow, Munson, "Feasible Descent Algorithms for Mixed
46: Complementarity Problems," Mathematical Programming, 86,
47: 1999.
48: Fischer, "A Special Newton type Optimization Method," Optimization,
49: 24, 1992
50: Munson, Facchinei, Ferris, Fischer, Kanzow, "The Semismooth Algorithm
51: for Large Scale Complementarity Problems," Technical Report,
52: University of Wisconsin Madison, 1999.
53: */
55: static PetscErrorCode TaoSetUp_ASILS(Tao tao)
56: {
57: TAO_SSLS *asls = (TAO_SSLS *)tao->data;
61: VecDuplicate(tao->solution,&tao->gradient);
62: VecDuplicate(tao->solution,&tao->stepdirection);
63: VecDuplicate(tao->solution,&asls->ff);
64: VecDuplicate(tao->solution,&asls->dpsi);
65: VecDuplicate(tao->solution,&asls->da);
66: VecDuplicate(tao->solution,&asls->db);
67: VecDuplicate(tao->solution,&asls->t1);
68: VecDuplicate(tao->solution,&asls->t2);
69: asls->fixed = NULL;
70: asls->free = NULL;
71: asls->J_sub = NULL;
72: asls->Jpre_sub = NULL;
73: asls->w = NULL;
74: asls->r1 = NULL;
75: asls->r2 = NULL;
76: asls->r3 = NULL;
77: asls->dxfree = NULL;
78: return(0);
79: }
81: static PetscErrorCode Tao_ASLS_FunctionGradient(TaoLineSearch ls, Vec X, PetscReal *fcn, Vec G, void *ptr)
82: {
83: Tao tao = (Tao)ptr;
84: TAO_SSLS *asls = (TAO_SSLS *)tao->data;
88: TaoComputeConstraints(tao, X, tao->constraints);
89: VecFischer(X,tao->constraints,tao->XL,tao->XU,asls->ff);
90: VecNorm(asls->ff,NORM_2,&asls->merit);
91: *fcn = 0.5*asls->merit*asls->merit;
93: TaoComputeJacobian(tao,tao->solution,tao->jacobian,tao->jacobian_pre);
94: MatDFischer(tao->jacobian, tao->solution, tao->constraints,tao->XL, tao->XU, asls->t1, asls->t2,asls->da, asls->db);
95: VecPointwiseMult(asls->t1, asls->ff, asls->db);
96: MatMultTranspose(tao->jacobian,asls->t1,G);
97: VecPointwiseMult(asls->t1, asls->ff, asls->da);
98: VecAXPY(G,1.0,asls->t1);
99: return(0);
100: }
102: static PetscErrorCode TaoDestroy_ASILS(Tao tao)
103: {
104: TAO_SSLS *ssls = (TAO_SSLS *)tao->data;
108: VecDestroy(&ssls->ff);
109: VecDestroy(&ssls->dpsi);
110: VecDestroy(&ssls->da);
111: VecDestroy(&ssls->db);
112: VecDestroy(&ssls->w);
113: VecDestroy(&ssls->t1);
114: VecDestroy(&ssls->t2);
115: VecDestroy(&ssls->r1);
116: VecDestroy(&ssls->r2);
117: VecDestroy(&ssls->r3);
118: VecDestroy(&ssls->dxfree);
119: MatDestroy(&ssls->J_sub);
120: MatDestroy(&ssls->Jpre_sub);
121: ISDestroy(&ssls->fixed);
122: ISDestroy(&ssls->free);
123: PetscFree(tao->data);
124: return(0);
125: }
127: static PetscErrorCode TaoSolve_ASILS(Tao tao)
128: {
129: TAO_SSLS *asls = (TAO_SSLS *)tao->data;
130: PetscReal psi,ndpsi, normd, innerd, t=0;
131: PetscInt nf;
132: PetscErrorCode ierr;
133: TaoLineSearchConvergedReason ls_reason;
136: /* Assume that Setup has been called!
137: Set the structure for the Jacobian and create a linear solver. */
139: TaoComputeVariableBounds(tao);
140: TaoLineSearchSetObjectiveAndGradientRoutine(tao->linesearch,Tao_ASLS_FunctionGradient,tao);
141: TaoLineSearchSetObjectiveRoutine(tao->linesearch,Tao_SSLS_Function,tao);
143: /* Calculate the function value and fischer function value at the
144: current iterate */
145: TaoLineSearchComputeObjectiveAndGradient(tao->linesearch,tao->solution,&psi,asls->dpsi);
146: VecNorm(asls->dpsi,NORM_2,&ndpsi);
148: tao->reason = TAO_CONTINUE_ITERATING;
149: while (1) {
150: /* Check the termination criteria */
151: PetscInfo3(tao,"iter %D, merit: %g, ||dpsi||: %g\n",tao->niter, (double)asls->merit, (double)ndpsi);
152: TaoLogConvergenceHistory(tao,asls->merit,ndpsi,0.0,tao->ksp_its);
153: TaoMonitor(tao,tao->niter,asls->merit,ndpsi,0.0,t);
154: (*tao->ops->convergencetest)(tao,tao->cnvP);
155: if (TAO_CONTINUE_ITERATING != tao->reason) break;
157: /* Call general purpose update function */
158: if (tao->ops->update) {
159: (*tao->ops->update)(tao, tao->niter, tao->user_update);
160: }
161: tao->niter++;
163: /* We are going to solve a linear system of equations. We need to
164: set the tolerances for the solve so that we maintain an asymptotic
165: rate of convergence that is superlinear.
166: Note: these tolerances are for the reduced system. We really need
167: to make sure that the full system satisfies the full-space conditions.
169: This rule gives superlinear asymptotic convergence
170: asls->atol = min(0.5, asls->merit*sqrt(asls->merit));
171: asls->rtol = 0.0;
173: This rule gives quadratic asymptotic convergence
174: asls->atol = min(0.5, asls->merit*asls->merit);
175: asls->rtol = 0.0;
177: Calculate a free and fixed set of variables. The fixed set of
178: variables are those for the d_b is approximately equal to zero.
179: The definition of approximately changes as we approach the solution
180: to the problem.
182: No one rule is guaranteed to work in all cases. The following
183: definition is based on the norm of the Jacobian matrix. If the
184: norm is large, the tolerance becomes smaller. */
185: MatNorm(tao->jacobian,NORM_1,&asls->identifier);
186: asls->identifier = PetscMin(asls->merit, 1e-2) / (1 + asls->identifier);
188: VecSet(asls->t1,-asls->identifier);
189: VecSet(asls->t2, asls->identifier);
191: ISDestroy(&asls->fixed);
192: ISDestroy(&asls->free);
193: VecWhichBetweenOrEqual(asls->t1, asls->db, asls->t2, &asls->fixed);
194: ISComplementVec(asls->fixed,asls->t1, &asls->free);
196: ISGetSize(asls->fixed,&nf);
197: PetscInfo1(tao,"Number of fixed variables: %D\n", nf);
199: /* We now have our partition. Now calculate the direction in the
200: fixed variable space. */
201: TaoVecGetSubVec(asls->ff, asls->fixed, tao->subset_type, 0.0, &asls->r1);
202: TaoVecGetSubVec(asls->da, asls->fixed, tao->subset_type, 1.0, &asls->r2);
203: VecPointwiseDivide(asls->r1,asls->r1,asls->r2);
204: VecSet(tao->stepdirection,0.0);
205: VecISAXPY(tao->stepdirection, asls->fixed,1.0,asls->r1);
207: /* Our direction in the Fixed Variable Set is fixed. Calculate the
208: information needed for the step in the Free Variable Set. To
209: do this, we need to know the diagonal perturbation and the
210: right hand side. */
212: TaoVecGetSubVec(asls->da, asls->free, tao->subset_type, 0.0, &asls->r1);
213: TaoVecGetSubVec(asls->ff, asls->free, tao->subset_type, 0.0, &asls->r2);
214: TaoVecGetSubVec(asls->db, asls->free, tao->subset_type, 1.0, &asls->r3);
215: VecPointwiseDivide(asls->r1,asls->r1, asls->r3);
216: VecPointwiseDivide(asls->r2,asls->r2, asls->r3);
218: /* r1 is the diagonal perturbation
219: r2 is the right hand side
220: r3 is no longer needed
222: Now need to modify r2 for our direction choice in the fixed
223: variable set: calculate t1 = J*d, take the reduced vector
224: of t1 and modify r2. */
226: MatMult(tao->jacobian, tao->stepdirection, asls->t1);
227: TaoVecGetSubVec(asls->t1,asls->free,tao->subset_type,0.0,&asls->r3);
228: VecAXPY(asls->r2, -1.0, asls->r3);
230: /* Calculate the reduced problem matrix and the direction */
231: if (!asls->w && (tao->subset_type == TAO_SUBSET_MASK || tao->subset_type == TAO_SUBSET_MATRIXFREE)) {
232: VecDuplicate(tao->solution, &asls->w);
233: }
234: TaoMatGetSubMat(tao->jacobian, asls->free, asls->w, tao->subset_type,&asls->J_sub);
235: if (tao->jacobian != tao->jacobian_pre) {
236: TaoMatGetSubMat(tao->jacobian_pre, asls->free, asls->w, tao->subset_type, &asls->Jpre_sub);
237: } else {
238: MatDestroy(&asls->Jpre_sub);
239: asls->Jpre_sub = asls->J_sub;
240: PetscObjectReference((PetscObject)(asls->Jpre_sub));
241: }
242: MatDiagonalSet(asls->J_sub, asls->r1,ADD_VALUES);
243: TaoVecGetSubVec(tao->stepdirection, asls->free, tao->subset_type, 0.0, &asls->dxfree);
244: VecSet(asls->dxfree, 0.0);
246: /* Calculate the reduced direction. (Really negative of Newton
247: direction. Therefore, rest of the code uses -d.) */
248: KSPReset(tao->ksp);
249: KSPSetOperators(tao->ksp, asls->J_sub, asls->Jpre_sub);
250: KSPSolve(tao->ksp, asls->r2, asls->dxfree);
251: KSPGetIterationNumber(tao->ksp,&tao->ksp_its);
252: tao->ksp_tot_its+=tao->ksp_its;
254: /* Add the direction in the free variables back into the real direction. */
255: VecISAXPY(tao->stepdirection, asls->free, 1.0,asls->dxfree);
257: /* Check the real direction for descent and if not, use the negative
258: gradient direction. */
259: VecNorm(tao->stepdirection, NORM_2, &normd);
260: VecDot(tao->stepdirection, asls->dpsi, &innerd);
262: if (innerd <= asls->delta*PetscPowReal(normd, asls->rho)) {
263: PetscInfo1(tao,"Gradient direction: %5.4e.\n", (double)innerd);
264: PetscInfo1(tao, "Iteration %D: newton direction not descent\n", tao->niter);
265: VecCopy(asls->dpsi, tao->stepdirection);
266: VecDot(asls->dpsi, tao->stepdirection, &innerd);
267: }
269: VecScale(tao->stepdirection, -1.0);
270: innerd = -innerd;
272: /* We now have a correct descent direction. Apply a linesearch to
273: find the new iterate. */
274: TaoLineSearchSetInitialStepLength(tao->linesearch, 1.0);
275: TaoLineSearchApply(tao->linesearch, tao->solution, &psi,asls->dpsi, tao->stepdirection, &t, &ls_reason);
276: VecNorm(asls->dpsi, NORM_2, &ndpsi);
277: }
278: return(0);
279: }
281: /* ---------------------------------------------------------- */
282: /*MC
283: TAOASILS - Active-set infeasible linesearch algorithm for solving
284: complementarity constraints
286: Options Database Keys:
287: + -tao_ssls_delta - descent test fraction
288: - -tao_ssls_rho - descent test power
290: Level: beginner
291: M*/
292: PETSC_EXTERN PetscErrorCode TaoCreate_ASILS(Tao tao)
293: {
294: TAO_SSLS *asls;
296: const char *armijo_type = TAOLINESEARCHARMIJO;
299: PetscNewLog(tao,&asls);
300: tao->data = (void*)asls;
301: tao->ops->solve = TaoSolve_ASILS;
302: tao->ops->setup = TaoSetUp_ASILS;
303: tao->ops->view = TaoView_SSLS;
304: tao->ops->setfromoptions = TaoSetFromOptions_SSLS;
305: tao->ops->destroy = TaoDestroy_ASILS;
306: tao->subset_type = TAO_SUBSET_SUBVEC;
307: asls->delta = 1e-10;
308: asls->rho = 2.1;
309: asls->fixed = NULL;
310: asls->free = NULL;
311: asls->J_sub = NULL;
312: asls->Jpre_sub = NULL;
313: asls->w = NULL;
314: asls->r1 = NULL;
315: asls->r2 = NULL;
316: asls->r3 = NULL;
317: asls->t1 = NULL;
318: asls->t2 = NULL;
319: asls->dxfree = NULL;
321: asls->identifier = 1e-5;
323: TaoLineSearchCreate(((PetscObject)tao)->comm, &tao->linesearch);
324: PetscObjectIncrementTabLevel((PetscObject)tao->linesearch, (PetscObject)tao, 1);
325: TaoLineSearchSetType(tao->linesearch, armijo_type);
326: TaoLineSearchSetOptionsPrefix(tao->linesearch,tao->hdr.prefix);
327: TaoLineSearchSetFromOptions(tao->linesearch);
329: KSPCreate(((PetscObject)tao)->comm, &tao->ksp);
330: PetscObjectIncrementTabLevel((PetscObject)tao->ksp, (PetscObject)tao, 1);
331: KSPSetOptionsPrefix(tao->ksp,tao->hdr.prefix);
332: KSPSetFromOptions(tao->ksp);
334: /* Override default settings (unless already changed) */
335: if (!tao->max_it_changed) tao->max_it = 2000;
336: if (!tao->max_funcs_changed) tao->max_funcs = 4000;
337: if (!tao->gttol_changed) tao->gttol = 0;
338: if (!tao->grtol_changed) tao->grtol = 0;
339: #if defined(PETSC_USE_REAL_SINGLE)
340: if (!tao->gatol_changed) tao->gatol = 1.0e-6;
341: if (!tao->fmin_changed) tao->fmin = 1.0e-4;
342: #else
343: if (!tao->gatol_changed) tao->gatol = 1.0e-16;
344: if (!tao->fmin_changed) tao->fmin = 1.0e-8;
345: #endif
346: return(0);
347: }