DSDP
dsdpconverge.c
Go to the documentation of this file.
1#include "dsdp5.h"
2#include "dsdpconverge.h"
9extern int DSDPGetConvergenceMonitor(DSDP, ConvergenceMonitor**);
10
24#undef __FUNCT__
25#define __FUNCT__ "DSDPCheckConvergence"
26int DSDPDefaultConvergence(DSDP dsdp,void *ctx){
27
28 ConvergenceMonitor *conv=(ConvergenceMonitor*)ctx;
29 int info,i,iter;
30 double mu,mu2;
31 double rgap,rgap2,rgaptol=conv->rgaptol;
32 double infeastol=0;
33 double pnorm,dstep,pstep,steptol=conv->steptol,pnormtol=conv->pnormtol;
34 double ppobj,ddobj, gap, dualbound=conv->dualbound;
35 double res,np;
37
38 DSDPFunctionBegin;
39 info = DSDPGetStepLengths(dsdp,&pstep,&dstep); DSDPCHKERR(info);
40 info = DSDPGetPnorm(dsdp,&pnorm); DSDPCHKERR(info);
41 info = DSDPGetIts(dsdp,&iter); DSDPCHKERR(info);
42 info = DSDPGetDDObjective(dsdp,&ddobj); DSDPCHKERR(info);
43 info = DSDPGetPPObjective(dsdp,&ppobj); DSDPCHKERR(info);
44 info = DSDPGetR(dsdp,&res); DSDPCHKERR(info);
45 info = DSDPGetBarrierParameter(dsdp,&mu); DSDPCHKERR(info);
46 info = DSDPGetDimension(dsdp,&np); DSDPCHKERR(info);
47 info = DSDPStopReason(dsdp,&reason); DSDPCHKERR(info);
48 info = DSDPGetRTolerance(dsdp,&infeastol); DSDPCHKERR(info);
49 info = DSDPGetDualityGap(dsdp,&gap); DSDPCHKERR(info);
50 rgap=(gap)/(1.0+fabs(ddobj)/2+fabs(ppobj)/2);
51 rgap2=(mu*np)/(1.0+fabs(ddobj)/2+fabs(ppobj)/2);
52 if (iter==0){
53 conv->history = DSDPHistory;
54 for (i=0; i<DSDPHistory; i++){
55 conv->alpha[i] = 0.0;
56 conv->gaphist[i] = 0.0;
57 conv->infhist[i] = 0.0;
58 }
59 }
60 if (iter<conv->history && iter>0){
61 conv->gaphist[iter-1]=(ppobj-ddobj);
62 conv->infhist[iter-1]=res;
63 }
64
65 if ( 0==1 ){
66
67 } else if ( ddobj!=ddobj || pnorm < 0){
68 reason = DSDP_NUMERICAL_ERROR;
69 DSDPLogInfo(0,2,"Stop due to Numerical Error\n");
70 } else if ( rgap <=rgaptol/1.01 && res<=infeastol ){
71 if (pnorm>pnormtol){
72 mu2=gap/np;
73 info = DSDPSetBarrierParameter(dsdp,mu2); DSDPCHKERR(info);
74 } else {
75 reason = DSDP_CONVERGED;
76 DSDPLogInfo(0,2,"DSDP Converged: Relative Duality Gap %4.2e < %4.2e, Primal Feasible, Dual Infeasiblity %4.2e < %4.2e \n",rgap,rgaptol,res,infeastol);
77 }
78 } else if ( rgap2 <=rgaptol/100 && rgap<0.01){
79 reason = DSDP_CONVERGED;
80 DSDPLogInfo(0,2,"DSDP Converged: Relative Duality Gap %4.2e < %4.2e. Check Feasiblity \n",rgap,rgaptol);
81 } else if ( ddobj > dualbound && res<=infeastol){
82 reason = DSDP_UPPERBOUND;
83 DSDPLogInfo(0,2,"DSDP Converged: Dual Objective: %4.2e > upper bound %4.2e\n",pnorm,dualbound);
84 } else if ( iter > 5 && dstep<steptol && dstep*pnorm< steptol && rgap <= 1.0e-3 ) {
85 reason = DSDP_SMALL_STEPS;
86 DSDPLogInfo(0,2,"DSDP Terminated: Small relative gap and small steps detected (3)\n");
87 }
88
89 info=DSDPSetConvergenceFlag(dsdp,reason); DSDPCHKERR(info);
90
91 DSDPFunctionReturn(0);
92}
93
108#undef __FUNCT__
109#define __FUNCT__ "DSDPSetGapTolerance"
110int DSDPSetGapTolerance(DSDP dsdp,double gaptol){
111 int info;
112 ConvergenceMonitor *conv;
113 DSDPFunctionBegin;
114 info=DSDPGetConvergenceMonitor(dsdp,&conv); DSDPCHKERR(info);
115 if (gaptol > 0) conv->rgaptol = gaptol;
116 DSDPLogInfo(0,2,"Set Relative Gap Tolerance: %4.4e\n",gaptol);
117 DSDPFunctionReturn(0);
118}
119
130#undef __FUNCT__
131#define __FUNCT__ "DSDPGetGapTolerance"
132int DSDPGetGapTolerance(DSDP dsdp,double *gaptol){
133 int info;
134 ConvergenceMonitor *conv;
135 DSDPFunctionBegin;
136 info=DSDPGetConvergenceMonitor(dsdp,&conv); DSDPCHKERR(info);
137 DSDPFunctionBegin;
138 *gaptol=conv->rgaptol;
139 DSDPFunctionReturn(0);
140}
141
156#undef __FUNCT__
157#define __FUNCT__ "DSDPSetPNormTolerance"
158int DSDPSetPNormTolerance(DSDP dsdp,double ptol){
159 int info;
160 ConvergenceMonitor *conv;
161 DSDPFunctionBegin;
162 info=DSDPGetConvergenceMonitor(dsdp,&conv); DSDPCHKERR(info);
163 if (ptol > 0) conv->pnormtol = ptol;
164 DSDPLogInfo(0,2,"Set Relative PNorm Tolerance: %4.4e\n",ptol);
165 DSDPFunctionReturn(0);
166}
167
178#undef __FUNCT__
179#define __FUNCT__ "DSDPGetPNormTolerance"
180int DSDPGetPNormTolerance(DSDP dsdp,double *ptol){
181 int info;
182 ConvergenceMonitor *conv;
183 DSDPFunctionBegin;
184 info=DSDPGetConvergenceMonitor(dsdp,&conv); DSDPCHKERR(info);
185 DSDPFunctionBegin;
186 *ptol=conv->pnormtol;
187 DSDPFunctionReturn(0);
188}
189
203#undef __FUNCT__
204#define __FUNCT__ "DSDPSetDualBound"
205int DSDPSetDualBound(DSDP dsdp,double dbound){
206 int info;
207 ConvergenceMonitor *conv;
208 DSDPFunctionBegin;
209 info=DSDPGetConvergenceMonitor(dsdp,&conv); DSDPCHKERR(info);
210 conv->dualbound=dbound;
211 DSDPLogInfo(0,2,"Set DualBound of %4.4e \n",dbound);
212 DSDPFunctionReturn(0);
213}
214
225#undef __FUNCT__
226#define __FUNCT__ "DSDPGetDualBound"
227int DSDPGetDualBound(DSDP dsdp,double *dbound){
228 int info;
229 ConvergenceMonitor *conv;
230 DSDPFunctionBegin;
231 info=DSDPGetConvergenceMonitor(dsdp,&conv); DSDPCHKERR(info);
232 *dbound=conv->dualbound;
233 DSDPFunctionReturn(0);
234}
235
250#undef __FUNCT__
251#define __FUNCT__ "DSDPSetStepTolerance"
252int DSDPSetStepTolerance(DSDP dsdp,double steptol){
253 int info;
254 ConvergenceMonitor *conv;
255 DSDPFunctionBegin;
256 info=DSDPGetConvergenceMonitor(dsdp,&conv); DSDPCHKERR(info);
257 if (steptol > 0) conv->steptol = steptol;
258 DSDPFunctionReturn(0);
259}
260
271#undef __FUNCT__
272#define __FUNCT__ "DSDPGetStepTolerance"
273int DSDPGetStepTolerance(DSDP dsdp,double *steptol){
274 int info;
275 ConvergenceMonitor *conv;
276 DSDPFunctionBegin;
277 info=DSDPGetConvergenceMonitor(dsdp,&conv); DSDPCHKERR(info);
278 *steptol=conv->steptol;
279 DSDPFunctionReturn(0);
280}
281
296#undef __FUNCT__
297#define __FUNCT__ "DSDPGetRHistory"
298int DSDPGetRHistory(DSDP dsdp, double hist[], int length){
299 int i,info;
300 ConvergenceMonitor *conv;
301 DSDPFunctionBegin;
302 info=DSDPGetConvergenceMonitor(dsdp,&conv); DSDPCHKERR(info);
303 for (i=0;i<length;i++) hist[i]=0.0;
304 for (i=0;i<DSDPMin(length,DSDPHistory);i++) hist[i]=conv->infhist[i];
305 DSDPFunctionReturn(0);
306}
307
319#undef __FUNCT__
320#define __FUNCT__ "DSDPGetGapHistory"
321int DSDPGetGapHistory(DSDP dsdp, double hist[], int length){
322 int i,info;
323 ConvergenceMonitor *conv;
324 DSDPFunctionBegin;
325 info=DSDPGetConvergenceMonitor(dsdp,&conv); DSDPCHKERR(info);
326 for (i=0;i<length;i++) hist[i]=0.0;
327 for (i=0;i<DSDPMin(length,DSDPHistory);i++) hist[i]=conv->gaphist[i];
328 DSDPFunctionReturn(0);
329}
330
The API to DSDP for those applications using DSDP as a subroutine library.
DSDPTerminationReason
There are many reasons to terminate the solver.
@ DSDP_UPPERBOUND
@ DSDP_CONVERGED
@ DSDP_SMALL_STEPS
@ DSDP_NUMERICAL_ERROR
int DSDPGetConvergenceMonitor(DSDP, ConvergenceMonitor **)
Get the structure containing convergence parameters.
Definition: dsdpsetup.c:268
Detect convergence of the solver from the duality gap and step sizes.
int DSDPGetRHistory(DSDP dsdp, double hist[], int length)
Copy a history of the infeasibility in (D) into an array.
Definition: dsdpconverge.c:298
int DSDPDefaultConvergence(DSDP dsdp, void *ctx)
Check for Convergence.
Definition: dsdpconverge.c:26
int DSDPSetConvergenceFlag(DSDP dsdp, DSDPTerminationReason reason)
Monitor each iteration of the solver.
Definition: dsdpsetdata.c:968
int DSDPGetPNormTolerance(DSDP dsdp, double *ptol)
Get the termination tolerance.
Definition: dsdpconverge.c:180
int DSDPGetRTolerance(DSDP dsdp, double *inftol)
Copy the maximum infeasibility allowed (D).
Definition: dsdpx.c:434
int DSDPSetGapTolerance(DSDP dsdp, double gaptol)
Terminate the solver when the relative duality gap is less than this tolerance.
Definition: dsdpconverge.c:110
int DSDPSetPNormTolerance(DSDP dsdp, double ptol)
Terminate the solver when the relative duality gap is suffiently small and the PNorm is less than thi...
Definition: dsdpconverge.c:158
int DSDPStopReason(DSDP dsdp, DSDPTerminationReason *reason)
Copy the reason why the solver terminated.
Definition: dsdpsetdata.c:582
int DSDPGetGapHistory(DSDP dsdp, double hist[], int length)
Copy a history of the duality gap into an array.
Definition: dsdpconverge.c:321
int DSDPGetGapTolerance(DSDP dsdp, double *gaptol)
Get the termination tolerance.
Definition: dsdpconverge.c:132
int DSDPSetStepTolerance(DSDP dsdp, double steptol)
Terminate the solver if the step length in (DD) is below this tolerance.
Definition: dsdpconverge.c:252
int DSDPSetDualBound(DSDP dsdp, double dbound)
Terminate the solver if the objective value in (DD) is greater than this tolerance.
Definition: dsdpconverge.c:205
int DSDPGetDualBound(DSDP dsdp, double *dbound)
Get the termination parameter.
Definition: dsdpconverge.c:227
int DSDPGetIts(DSDP dsdp, int *its)
Copy the current iteration number.
Definition: dsdpsetdata.c:564
int DSDPGetStepTolerance(DSDP dsdp, double *steptol)
Get the current tolerance.
Definition: dsdpconverge.c:273
int DSDPGetDimension(DSDP dsdp, double *n)
Copy the dimension of the cones, or the number of constraints in (D).
Definition: dsdpsetdata.c:661
int DSDPGetPnorm(DSDP dsdp, double *pnorm)
Copy the proximity of the solution to the central path.
Definition: dsdpsetdata.c:724
int DSDPGetR(DSDP dsdp, double *res)
Copy the infeasibility in (D), or the variable r in (DD).
Definition: dsdpsetdata.c:601
int DSDPGetPPObjective(DSDP dsdp, double *ppobj)
Copy the objective value (PP).
Definition: dsdpsetdata.c:479
int DSDPGetDDObjective(DSDP dsdp, double *ddobj)
Copy the objective value (DD).
Definition: dsdpsetdata.c:523
int DSDPGetStepLengths(DSDP dsdp, double *pstep, double *dstep)
Copy the step sizes in the current iteration.
Definition: dsdpsetdata.c:742
int DSDPGetDualityGap(DSDP dsdp, double *dgap)
Copy the difference between the objective values.
Definition: dsdpsetdata.c:545
int DSDPGetBarrierParameter(DSDP dsdp, double *mu)
Copy the current barrier parameter.
Definition: dsdpsetdata.c:364
int DSDPSetBarrierParameter(DSDP dsdp, double mu)
Set the current barrier parameter.
Definition: dsdpsetdata.c:340
Internal structures for the DSDP solver.
Definition: dsdp.h:65