5#define COMPUTEUBS(a,b,c) (-(a)-(b)-(c))
19 double *u,*au,*us,*uss,*ux,*uds;
27#define BConeValid(a) {if (!(a)||((a)->keyid!=BKEY)){ DSDPSETERR(101,"DSDPERROR: Invalid Bcone object\n");}}
30#define __FUNCT__ "BConeSetUp"
31static int BConeSetup(
void *dcone,
DSDPVec y){
37 if (bcone->nn<1)
return 0;
38 DSDPCALLOC2(&bcone->us,
double,nn,&info);DSDPCHKERR(info);
39 DSDPCALLOC2(&bcone->uss,
double,nn,&info);DSDPCHKERR(info);
40 DSDPCALLOC2(&bcone->ux,
double,nn,&info);DSDPCHKERR(info);
41 DSDPCALLOC2(&bcone->uds,
double,nn,&info);DSDPCHKERR(info);
42 DSDPFunctionReturn(0);
46#define __FUNCT__ "BConeSetUp2"
51 info=DSDPVecDuplicate(Y,&bcone->WY);DSDPCHKERR(info);
52 info=DSDPVecDuplicate(Y,&bcone->WY2);DSDPCHKERR(info);
53 DSDPFunctionReturn(0);
57#define __FUNCT__ "BConeDestroy"
58static int BConeDestroy(
void *dcone){
62 DSDPFREE(&bcone->ib,&info);DSDPCHKERR(info);
63 DSDPFREE(&bcone->u,&info);DSDPCHKERR(info);
64 DSDPFREE(&bcone->au,&info);DSDPCHKERR(info);
65 DSDPFREE(&bcone->us,&info);DSDPCHKERR(info);
66 DSDPFREE(&bcone->uss,&info);DSDPCHKERR(info);
67 DSDPFREE(&bcone->uds,&info);DSDPCHKERR(info);
68 DSDPFREE(&bcone->ux,&info);DSDPCHKERR(info);
70 info=DSDPVecDestroy(&bcone->WY);DSDPCHKERR(info);
71 info=DSDPVecDestroy(&bcone->WY2);DSDPCHKERR(info);
73 DSDPFREE(&dcone,&info);DSDPCHKERR(info);
74 DSDPFunctionReturn(0);
78#define __FUNCT__ "BConeSize"
79static int BConeSize(
void *dcone,
double *n){
82 *n=(double)(bcone->nn);
83 DSDPFunctionReturn(0);
88#define __FUNCT__ "BConeComputeS"
89static int BConeComputeS(
BCone bcone,
DSDPVec Y,
double ss[],
int n){
91 int *ib=bcone->ib, nn=bcone->nn;
92 double cr,rr,r,yy,*au=bcone->au,*u=bcone->u;
95 info=DSDPVecGetC(Y,&cr);
96 info=DSDPVecGetR(Y,&rr);
100 info=DSDPVecGetElement(Y,ii,&yy);
101 ss[i]=-cr*u[i]-au[i]*yy-r;
103 DSDPFunctionReturn(0);
107#define __FUNCT__ "BConeHessian"
108static int BConeHessian(
void* dcone,
double mu,
DSDPSchurMat M,
112 int *ib=bcone->ib, nn=bcone->nn;
113 double *us=bcone->us;
114 double *au=bcone->au,*u=bcone->u;
115 double dd,cc,rr,cs,as,rs;
117 DSDPVec DD=bcone->WY,MScale=bcone->WY2;
120 if (bcone->nn<1)
return 0;
122 info=DSDPVecZero(DD);DSDPCHKERR(info);
125 info=DSDPVecGetC(MScale,&cc);DSDPCHKERR(info);
126 info=DSDPVecGetR(MScale,&rr);DSDPCHKERR(info);
129 info=DSDPVecGetElement(MScale,ii,&dd);DSDPCHKERR(info);
136 info=DSDPVecAddC(vrhs2,mu*cs);DSDPCHKERR(info);
137 info=DSDPVecAddC(DD,mu*cs*cs);DSDPCHKERR(info);
138 info=DSDPSchurMatAddC(M,ii,mu*as*cs);DSDPCHKERR(info);
142 info=DSDPVecAddElement(vrhs2,ii,mu*as);DSDPCHKERR(info);
143 info=DSDPVecAddElement(DD,ii,mu*as*as);DSDPCHKERR(info);
146 info=DSDPVecAddR(vrhs2,mu*rs);DSDPCHKERR(info);
147 info=DSDPVecAddR(DD,mu*rs*rs);DSDPCHKERR(info);
154 DSDPFunctionReturn(0);
158#define __FUNCT__ "BConeHessian"
159static int BConeRHS(
void* dcone,
double mu,
DSDPVec vrow,
163 int *ib=bcone->ib, nn=bcone->nn;
164 double *us=bcone->us, *au=bcone->au,*u=bcone->u;
165 double dd,cc,rr,cs,as,rs;
170 info=DSDPVecGetC(vrow,&cc);DSDPCHKERR(info);
171 info=DSDPVecGetR(vrow,&rr);DSDPCHKERR(info);
174 info=DSDPVecGetElement(vrow,ii,&dd);DSDPCHKERR(info);
181 info=DSDPVecAddC(vrhs2,mu*cs);DSDPCHKERR(info);
184 info=DSDPVecAddElement(vrhs2,ii,mu*as);DSDPCHKERR(info);
187 info=DSDPVecAddR(vrhs2,mu*rs);DSDPCHKERR(info);
191 DSDPFunctionReturn(0);
196#define __FUNCT__ "BConeMultiply"
200 int *ib=bcone->ib, nn=bcone->nn;
201 double *au=bcone->au,*us=bcone->us;
208 info=DSDPVecGetElement(vin,ii,&dd);DSDPCHKERR(info);
209 info=DSDPVecGetElement(vrow,ii,&vv);DSDPCHKERR(info);
210 if (dd==0 || vv==0)
continue;
212 assa=mu*vv*assa*assa;
213 info=DSDPVecAddElement(vout,ii,assa);DSDPCHKERR(info);
215 DSDPFunctionReturn(0);
219#define __FUNCT__ "BConeS"
232 info=BConeComputeS(bcone,Y,us,nn);DSDPCHKERR(info);
238 DSDPFunctionReturn(0);
242#define __FUNCT__ "BConeSInvert"
243static int BConeSInvert(
void* dcone){
245 DSDPFunctionReturn(0);
250#define __FUNCT__ "BConeSetX"
253 DSDPFunctionReturn(0);
257#define __FUNCT__ "BConeX"
261 int *ib=bcone->ib, nn=bcone->nn;
262 double *au=bcone->au, *us=bcone->uss, *ux=bcone->ux, *uds=bcone->uds, *u=bcone->u;
263 double *xuout=bcone->xuout;
264 double ds,dus,dau,xx,cr,rr;
265 double pobj1=0,xdots1=0;
270 info=BConeS(dcone,Y,
PRIMAL_FACTOR,&psdefinite); DSDPCHKERR(info);
271 info=BConeComputeS(bcone,DY,uds,nn);DSDPCHKERR(info);
272 info=DSDPVecGetC(Y,&cr);DSDPCHKERR(info);
273 info=DSDPVecGetR(Y,&rr);DSDPCHKERR(info);
278 ds=uds[i]; dus=us[i]; dau=au[i];
279 xx=(mu/dus)-(mu/dus)*(ds/dus);
281 info=DSDPVecAddElement(AX,ii,dau*xx);DSDPCHKERR(info);
284 if (xuout) xuout[i]=xx;
287 info=DSDPVecAddC(AX,pobj1);DSDPCHKERR(info);
289 DSDPFunctionReturn(0);
294#define __FUNCT__ "BConeComputeMaxStepLength"
297 double mstep=1.0e200;
300 double *us,*uds=bcone->uds;
303 if (bcone->nn<1)
return 0;
310 info=BConeComputeS(bcone,DY,uds,nn);DSDPCHKERR(info);
313 if (uds[i]<0){mstep=DSDPMin(mstep,-us[i]/uds[i]);}
316 *maxsteplength=mstep;
318 DSDPFunctionReturn(0);
323#define __FUNCT__ "BConePotential"
324static int BConePotential(
void* dcone,
double *logobj,
double *logdet){
328 double mu=bcone->muscale;
330 double *us=bcone->us;
333 if (bcone->nn<1)
return 0;
335 sumlog+= mu*log(us[i]);
339 DSDPFunctionReturn(0);
343#define __FUNCT__ "BConeSparsity"
344static int BConeSparsity(
void *dcone,
int row,
int *tnnz,
int rnnz[],
int m){
347 DSDPFunctionReturn(0);
352#define __FUNCT__ "BConeMonitor"
353static int BConeMonitor(
void *dcone,
int di){
355 DSDPFunctionReturn(0);
360#define __FUNCT__ "LPANorm2"
361static int LPANorm2(
void *dcone,
DSDPVec ANorm){
363 int *ib=bcone->ib, nn=bcone->nn;
365 double yy=1.0,cnorm2=0;
370 info=DSDPVecAddElement(ANorm,ii,yy);
371 yy=u[i]; cnorm2+=yy*yy;
373 info=DSDPVecAddC(ANorm,cnorm2);
374 info=DSDPVecAddR(ANorm,bcone->r*bcone->nn);
375 DSDPFunctionReturn(0);
380#define __FUNCT__ "BConeView"
381int BConeView(
BCone bcone){
383 int *ib=bcone->ib, nn=bcone->nn;
384 double *au=bcone->au,*u=bcone->u;
387 ib=bcone->ib; nn=bcone->nn;
388 au=bcone->au; u=bcone->u;
392 printf(
"Upper Bound. Var %d: %4.8e\n",ii,u[i]);
394 printf(
"Lower Bound. Var %d: %4.8e\n",ii,u[i]);
397 DSDPFunctionReturn(0);
401static struct DSDPCone_Ops kops;
402static const char *bconename=
"VariableBounds Cone";
405#define __FUNCT__ "BConeOperationsInitialize"
406static int BConeOperationsInitialize(
struct DSDPCone_Ops* coneops){
408 if (coneops==NULL)
return 0;
410 coneops->conehessian=BConeHessian;
411 coneops->conerhs=BConeRHS;
412 coneops->conesetup=BConeSetup;
413 coneops->conesetup2=BConeSetup2;
414 coneops->conedestroy=BConeDestroy;
415 coneops->conecomputes=BConeS;
416 coneops->coneinverts=BConeSInvert;
417 coneops->conecomputex=BConeX;
418 coneops->conesetxmaker=BConeSetX;
419 coneops->conemaxsteplength=BConeComputeMaxStepLength;
420 coneops->conelogpotential=BConePotential;
421 coneops->conesize=BConeSize;
422 coneops->conemonitor=BConeMonitor;
423 coneops->conesparsity=BConeSparsity;
424 coneops->conehmultiplyadd=BConeMultiply;
425 coneops->coneanorm2=LPANorm2;
427 coneops->name=bconename;
432#define __FUNCT__ "DSDPAddBounds"
437 info=BConeOperationsInitialize(&kops); DSDPCHKERR(info);
438 info=
DSDPAddCone(dsdp,&kops,(
void*)bcone); DSDPCHKERR(info);
439 DSDPFunctionReturn(0);
443#define __FUNCT__ "DSDPCreateBCone"
467int DSDPCreateBCone(
DSDP dsdp,
BCone *dspcone){
469 struct BCone_C *bcone;
471 if (!dsdp){DSDPFunctionReturn(1);}
472 DSDPCALLOC1(&bcone,
struct BCone_C,&info);DSDPCHKERR(info);
476 info=BConeOperationsInitialize(&kops); DSDPCHKERR(info);
477 info=
DSDPAddCone(dsdp,&kops,(
void*)bcone); DSDPCHKERR(info);
478 info=DSDPGetNumberOfVariables(dsdp,&m);DSDPCHKERR(info);
485 DSDPFunctionReturn(0);
490#define __FUNCT__ "BConeScaleBarrier"
491int BConeScaleBarrier(
BCone bcone,
double muscale){
495 bcone->muscale=muscale;
497 DSDPFunctionReturn(0);
501#define __FUNCT__ "BConeCopyX"
517int BConeCopyX(
BCone bcone,
double xl[],
double xu[],
int m){
522 if (m!=bcone->m){ DSDPSETERR1(6,
"Invalid Array Length.\n",bcone->m);}
523 xx=bcone->ux; au=bcone->au; nn=bcone->nn; ib=bcone->ib;
535 DSDPFunctionReturn(0);
538#define __FUNCT__ "BConeSetBound"
539int BConeSetBound(
BCone bcone,
int vari,
double ai,
double bound){
543 if (vari<1 || vari>bcone->m){ DSDPSETERR2(6,
"Invalid Variable number 1 <= %d <= %d.\n",vari,bcone->m);}
544 if (bcone->nn>=bcone->nnmax){
545 DSDPLogInfo(0,19,
"REALLOCATING SPACE FOR BOUNDS! %d \n",bcone->nnmax);
546 info=BConeAllocateBounds(bcone,2*bcone->nn+4);DSDPCHKERR(info);
549 bcone->u[spot]=bound;
551 bcone->ib[spot]=vari;
553 DSDPFunctionReturn(0);
557#define __FUNCT__ "BConeSetLowerBound"
566int BConeSetLowerBound(
BCone bcone,
int vari,
double lbound){
569 info=BConeSetBound(bcone,vari,-1.0,-lbound);DSDPCHKERR(info);
570 DSDPFunctionReturn(0);
574#define __FUNCT__ "BConeSetUpperBound"
583int BConeSetUpperBound(
BCone bcone,
int vari,
double ubound){
586 info=BConeSetBound(bcone,vari,1.0,ubound);DSDPCHKERR(info);
587 DSDPFunctionReturn(0);
591#define __FUNCT__ "BConeSetPSlackVariable"
607int BConeSetPSlackVariable(
BCone bcone,
int vari){
610 info=BConeSetUpperBound(bcone,vari,0);DSDPCHKERR(info);
611 DSDPFunctionReturn(0);
615#define __FUNCT__ "BConeSetPSurplusVariable"
624int BConeSetPSurplusVariable(
BCone bcone,
int vari){
627 info=BConeSetLowerBound(bcone,vari,0);DSDPCHKERR(info);
628 DSDPFunctionReturn(0);
632#define __FUNCT__ "BConeAllocateBounds"
645int BConeAllocateBounds(
BCone bcone,
int nnz){
651 if (nnz<=bcone->nnmax){DSDPFunctionReturn(0);}
652 DSDPCALLOC2(&uu,
double,(nnz),&info); DSDPCHKERR(info);
653 DSDPCALLOC2(&au,
double,(nnz),&info); DSDPCHKERR(info);
654 DSDPCALLOC2(&uindex,
int,(nnz),&info); DSDPCHKERR(info);
655 for (j=0;j<nnz;j++){uu[j]=0; uindex[j]=0; au[j]=0;}
657 for (j=0;j<bcone->nn;j++){uu[j]=bcone->u[j];}
658 for (j=0;j<bcone->nn;j++){uindex[j]=bcone->ib[j];}
659 for (j=0;j<bcone->nn;j++){au[j]=bcone->au[j];}
660 DSDPFREE(&bcone->u,&info);DSDPCHKERR(info);
661 DSDPFREE(&bcone->au,&info);DSDPCHKERR(info);
662 DSDPFREE(&bcone->ib,&info);DSDPCHKERR(info);
670 DSDPFunctionReturn(0);
674#define __FUNCT__ "BConeSetXArray"
675int BConeSetXArray(
BCone bcone,
double *xuout,
int n){
678 if (n==bcone->nn) bcone->xuout=xuout;
679 DSDPFunctionReturn(0);
The API to DSDP for those applications using DSDP as a subroutine library.
struct BCone_C * BCone
The BCone object points to lower and upper bounds on the variable y in (D).
DSDPDualFactorMatrix
DSDP requires two instances of the data structures S.
DSDPTruth
Boolean variables.
int DSDPConeOpsInitialize(struct DSDPCone_Ops *dops)
Initialize the function pointers to 0.
Implementations of a cone (SDP,LP,...) must provide a structure of function pointers.
int DSDPAddCone(DSDP, struct DSDPCone_Ops *, void *)
Apply DSDP to a conic structure.
int DSDPSchurMatAddDiagonal(DSDPSchurMat, DSDPVec)
Add elements to a row of the Schur matrix.
int DSDPSchurMatAddR(DSDPSchurMat, int, double)
Add an element to the Schur matrix correponding the variable r.
int DSDPSchurMatDiagonalScaling(DSDPSchurMat, DSDPVec)
Get the scaling and nonzero pattern of each diagonal element of the matrix.
Error handling, printing, and profiling.
struct DSDPVec_C DSDPVec
This object hold m+2 variables: a scaling of C, the y variables, and r.
Schur complement matrix whose solution is the Newton direction.
Internal structures for the DSDP solver.