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
Detect convergence of the solver from the duality gap and step sizes.
Internal structures for the DSDP solver.
Definition dsdp.h:65