00001 #include "dsdp5.h"
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00044 #undef __FUNCT__
00045 #define __FUNCT__ "DSDPSetOptions"
00046 int DSDPSetOptions(DSDP dsdp,char *runargs[],int nargs){
00047
00048 int kk, info,reuse;
00049 int maxit,rpos,drho,iloginfo;
00050 double penalty,rho,zbar,cc,r0,mu0,gaptol,dbound,dd;
00051 double ylow,yhigh,maxtrust,steptol,inftol,infptol,pnormtol;
00052
00053 DSDPFunctionBegin;
00054
00055 for (kk=0; kk<nargs-1; kk++){
00056 if (strncmp(runargs[kk],"-gaptol",5)==0){
00057 gaptol=atof(runargs[kk+1]);
00058 info=DSDPSetGapTolerance(dsdp,gaptol);DSDPCHKERR(info);
00059 } else if (strncmp(runargs[kk],"-penalty",7)==0){
00060 penalty=atof(runargs[kk+1]);
00061 info=DSDPSetPenaltyParameter(dsdp,penalty); DSDPCHKERR(info);
00062 } else if (strncmp(runargs[kk],"-bigM",5)==0){
00063 rpos=atoi(runargs[kk+1]);
00064 info=DSDPUsePenalty(dsdp,rpos); DSDPCHKERR(info);
00065 } else if (strncmp(runargs[kk],"-maxit",6)==0){
00066 maxit=atoi(runargs[kk+1]);
00067 info=DSDPSetMaxIts(dsdp,maxit); DSDPCHKERR(info);
00068 } else if (strncmp(runargs[kk],"-r0",3)==0){
00069 r0=atof(runargs[kk+1]);
00070 info=DSDPSetR0(dsdp,r0); DSDPCHKERR(info);
00071 } else if (strncmp(runargs[kk],"-zbar",5)==0){
00072 zbar=atof(runargs[kk+1]);
00073 info=DSDPSetZBar(dsdp,zbar);DSDPCHKERR(info);
00074 } else if (strncmp(runargs[kk],"-infdtol",7)==0){
00075 inftol=atof(runargs[kk+1]);
00076 info=DSDPSetRTolerance(dsdp,inftol);DSDPCHKERR(info);
00077 } else if (strncmp(runargs[kk],"-infptol",7)==0){
00078 infptol=atof(runargs[kk+1]);
00079 info=DSDPSetPTolerance(dsdp,infptol);DSDPCHKERR(info);
00080 } else if (strncmp(runargs[kk],"-rho",4)==0){
00081 rho=atof(runargs[kk+1]);
00082 info=DSDPSetPotentialParameter(dsdp,rho); DSDPCHKERR(info);
00083 } else if (strncmp(runargs[kk],"-drho",5)==0){
00084 drho=atoi(runargs[kk+1]);
00085 info=DSDPUseDynamicRho(dsdp,drho);DSDPCHKERR(info);
00086 } else if (strncmp(runargs[kk],"-mu0",4)==0){
00087 mu0=atof(runargs[kk+1]);
00088 info=DSDPSetBarrierParameter(dsdp,mu0);DSDPCHKERR(info);
00089 } else if (strncmp(runargs[kk],"-maxtrustradius",7)==0){
00090 maxtrust=atof(runargs[kk+1]);
00091 info=DSDPSetMaxTrustRadius(dsdp,maxtrust); DSDPCHKERR(info);
00092 } else if (strncmp(runargs[kk],"-boundy",6)==0){
00093 yhigh=fabs(atof(runargs[kk+1]));ylow=-yhigh;
00094 info=DSDPSetYBounds(dsdp,ylow,yhigh);DSDPCHKERR(info);
00095 } else if (strncmp(runargs[kk],"-steptol",7)==0){
00096 steptol=fabs(atof(runargs[kk+1]));
00097 info=DSDPSetStepTolerance(dsdp,steptol); DSDPCHKERR(info);
00098 } else if (strncmp(runargs[kk],"-pnormtol",7)==0){
00099 pnormtol=fabs(atof(runargs[kk+1]));
00100 info=DSDPSetPNormTolerance(dsdp,pnormtol); DSDPCHKERR(info);
00101 } else if (strncmp(runargs[kk],"-reuse",6)==0){
00102 reuse=atoi(runargs[kk+1]);
00103 info=DSDPReuseMatrix(dsdp,reuse);DSDPCHKERR(info);
00104 } else if (strncmp(runargs[kk],"-dadd",6)==0){
00105 cc=atof(runargs[kk+1]);
00106 info=DSDPAddObjectiveConstant(dsdp,cc);DSDPCHKERR(info);
00107 } else if (strncmp(runargs[kk],"-dbound",6)==0){
00108 dbound=atof(runargs[kk+1]);
00109 info=DSDPSetDualBound(dsdp,dbound);DSDPCHKERR(info);
00110 } else if (strncmp(runargs[kk],"-fix",4)==0){
00111 info=DSDPSetFixedVariable(dsdp,1,atof(runargs[kk+1]));DSDPCHKERR(info);
00112 } else if (strncmp(runargs[kk],"-dobjmin",7)==0){
00113 dd=atof(runargs[kk+1]);
00114 info = DSDPSetDualLowerBound(dsdp,dd);DSDPCHKERR(info);
00115 } else if (strncmp(runargs[kk],"-dloginfo",8)==0){
00116 iloginfo=atoi(runargs[kk+1]);
00117 info=DSDPLogInfoAllow(iloginfo,0);
00118 }
00119 }
00120
00121 for (kk=0; kk<nargs; kk++){
00122 if (0){
00123 } else if (strncmp(runargs[kk],"-help",5)==0){
00124 info=DSDPPrintOptions();
00125 }
00126 }
00127 DSDPFunctionReturn(0);
00128 }
00129
00140 #define MAXOPTIONS 40
00141 #define STRLENGTH 40
00142 #define BUFFERSIZ 100
00143 #undef __FUNCT__
00144 #define __FUNCT__ "DSDPReadOptions"
00145 int DSDPReadOptions(DSDP dsdp, char filename[]){
00146
00147 int i,info,line=0;
00148 char thisline[BUFFERSIZ]="%",doption[STRLENGTH],dvalue[STRLENGTH];
00149 char fargs[2*MAXOPTIONS][STRLENGTH];
00150 char *fargs2[2*MAXOPTIONS];
00151 FILE *fp;
00152
00153 DSDPFunctionBegin;
00154
00155 for (i=0;i<2*MAXOPTIONS;i++){fargs2[i]=fargs[i];}
00156
00157 fp=fopen(filename,"r");
00158 if (fp){
00159 while(!feof(fp) ){
00160 if (line>=MAXOPTIONS) break;
00161 fgets(thisline,BUFFERSIZ,fp);
00162 if (sscanf(thisline,"%s %s",doption,dvalue)>=2){
00163 if (doption[0]!='%'){
00164 strncpy(fargs[2*line],doption,STRLENGTH-1);
00165 strncpy(fargs[2*line+1],dvalue,STRLENGTH-1);
00166 line++;
00167 }
00168 }
00169 thisline[0]='%';
00170 }
00171
00172 info=DSDPSetOptions(dsdp,fargs2,2*line);
00173 fclose(fp);
00174 }
00175 DSDPFunctionReturn(0);
00176 }
00177
00188 #undef __FUNCT__
00189 #define __FUNCT__ "DSDPView"
00190 int DSDPView(DSDP dsdp){
00191
00192 int info,reuse,m,maxit;
00193 double penalty,rho,mu0,gaptol,dnorm[3],derror[6],potential,ymax;
00194 double ylow,yhigh,maxtrust,steptol,inftol,infptol,pnormtol,dbound,tracex;
00195 DSDPSolutionType pdfeasible;
00196
00197 DSDPFunctionBegin;
00198 info=DSDPGetMaxIts(dsdp,&maxit); DSDPCHKERR(info);
00199 printf("Terminate DSDP after %d iterations.\n",maxit);
00200 info=DSDPGetDualBound(dsdp,&dbound); DSDPCHKERR(info);
00201 printf("Terminate DSDP if dual objective is greater than %8.4e\n",dbound);
00202 info=DSDPGetGapTolerance(dsdp,&gaptol);DSDPCHKERR(info);
00203 printf("Terminate DSDP if the relative duality gap is less than %8.4e\n",gaptol);
00204 info=DSDPGetStepTolerance(dsdp,&steptol); DSDPCHKERR(info);
00205 printf("Terminate DSDP if step length in D less than %8.4e\n",steptol);
00206 info=DSDPGetPNormTolerance(dsdp,&pnormtol); DSDPCHKERR(info);
00207 printf("Terminate DSDP only if Pnorm less than %8.4e\n",pnormtol);
00208 info=DSDPGetMaxTrustRadius(dsdp,&maxtrust); DSDPCHKERR(info);
00209 printf("Max Trust Radius is %8.4e\n",maxtrust);
00210 info=DSDPGetReuseMatrix(dsdp,&reuse);DSDPCHKERR(info);
00211 printf("Reapply Hessian of Barrier up to %d times per iteration.\n",reuse);
00212
00213 info=DSDPGetDataNorms(dsdp,dnorm);DSDPCHKERR(info);
00214 printf("The norms of C: %8.4e, A: %4.4e, and b: %8.4e\n",dnorm[0],dnorm[1],dnorm[2]);
00215 info=DSDPGetNumberOfVariables(dsdp,&m);DSDPCHKERR(info);
00216 printf("There are %d y variables: ",m);
00217 info=DSDPGetYMaxNorm(dsdp,&ymax); DSDPCHKERR(info);
00218 printf("largest is %8.4e, ",ymax);
00219 info=DSDPGetYBounds(dsdp,&ylow,&yhigh);DSDPCHKERR(info);
00220 printf("bounded below by %8.4e and above by %8.4e. \n",ylow,yhigh);
00221 info=DSDPGetTraceX(dsdp,&tracex);DSDPCHKERR(info);
00222 printf("The X variables have a trace of %8.4e ",tracex);
00223 info=DSDPGetPenaltyParameter(dsdp,&penalty); DSDPCHKERR(info);
00224 printf("bounded by penalty parameter: %8.4e\n",penalty);
00225 info=DSDPGetBarrierParameter(dsdp,&mu0);DSDPCHKERR(info);
00226 printf("Current Barrier Parameter: %8.4e\n",mu0);
00227 info=DSDPGetPotentialParameter(dsdp,&rho); DSDPCHKERR(info);
00228 printf("Potential Parameter: %8.4e ( times dimension) \n",rho);
00229 info=DSDPGetPotential(dsdp,&potential);DSDPCHKERR(info);
00230 printf("The value of the potential function is %8.4e\n",potential);
00231 info=DSDPGetRTolerance(dsdp,&inftol); DSDPCHKERR(info);
00232 printf("(D) Feasible only if R < %8.4e\n",inftol);
00233 info=DSDPGetPTolerance(dsdp,&infptol); DSDPCHKERR(info);
00234 printf("(P) Feasible only if Pinfeas < %8.4e\n",infptol);
00235 info=DSDPGetSolutionType(dsdp,&pdfeasible);DSDPCHKERR(info);
00236 if (pdfeasible==DSDP_PDFEASIBLE){
00237 printf(" DSDP Solutions are both feasible and bounded\n");
00238 } else if (pdfeasible==DSDP_UNBOUNDED){
00239 printf(" (D) is unbounded and (P) is infeasible\n");
00240 } else if (pdfeasible==DSDP_INFEASIBLE){
00241 printf(" (D) is infeasible and (D) is unbounded\n");
00242 } else if (pdfeasible==DSDP_PDUNKNOWN){
00243 printf(" Hmm. Not clear whether either solution is feasible.\n");
00244 }
00245 info=DSDPGetFinalErrors(dsdp,derror);DSDPCHKERR(info);
00246 printf("The errors: %8.4e, %4.4e, %8.4e, ",derror[0],derror[1],derror[2]);
00247 printf("%8.4e, %4.4e, %8.4e\n",derror[3],derror[4],derror[5]);
00248 DSDPFunctionReturn(0);
00249 }
00250
00251
00252 static char dsdpoptions[]="\
00253 -gaptol <1e-6> stop when relative duality gap less than \n\
00254 -r0 <-1> if nonnegative, initialize S by adding this multiple of the identity matrix \n\
00255 -penalty <1e10>< penalize dual infeasibility \n\
00256 -boundy <1e7> bound for variables y \n\
00257 -maxit <200> set maximum iterates \n\
00258 -zbar <1e10> Upper bound for dual solution \n\
00259 -mu0 <-1> if positive, set initial barrier parameter \n\
00260 -rho <3> Potential parameter as multiple of dimension \n\
00261 -drho <1> Use dynamic rho strategy \n\
00262 -pnormtol <1e30> stop only if pnorm less than \n\
00263 -reuse <4> Reuse the Schur Matrix this many times\n\
00264 -dobjmin <> apply a known lower bound for the objective at solution as a constraint. \n\
00265 -bigM <0> if positive, modify algorithm to make dual \n\
00266 infeasibility positive with a large associated cost \n\
00267 -dloginfo <0> - print more information for higher numbers \n\
00268 -params <filename> to read selected options from a file \n\
00269 -help for this help message\n";
00270
00279 int DSDPPrintOptions(){
00280 DSDPFunctionBegin;
00281 printf("%s",dsdpoptions);
00282 DSDPFunctionReturn(0);
00283 }