6 static void DprintfD(FILE*fp,
double d1){
7 int i1=(int)d1,i2=(
int)(d1*100),i3=(
int)(d1*10000),i4=(
int)(d1*10000000);
8 if ( d1==(
double)i1){ fprintf(fp,
"%2.0f ",d1);
9 }
else if (d1==(
double)i2/100.0){ fprintf(fp,
"%4.2f ",d1);
10 }
else if (d1==(
double)i3/10000.0){ fprintf(fp,
"%6.4f ",d1);
11 }
else if (d1==(
double)i4/1000000.0){ fprintf(fp,
"%8.6f ",d1);
12 }
else { fprintf(fp,
"%22.22e ",d1);
17 static void Dprintf(FILE*fp,
int i1,
int i2,
int i3,
int i4,
double d1){
18 if (fabs(d1)<1e-30){
return;}
19 fprintf(fp,
"%d %d %d %d ",i1,i2,i3+1,i4+1);
30 #define __FUNCT__ "DPrintUpperRightMatrix" 31 static void DPrintUpperRightMatrix(
int constraint,
int block,
double amat[],
int n, FILE*fp){
33 for (row=0;row<n;row++){
34 for (col=0;col<=row;col++){
35 if (fabs(amat[col])>1.0e-20){
36 Dprintf(fp,constraint,block,col,row,amat[col]);
45 #define __FUNCT__ "DPrintUpperFullMatrix" 46 static void DPrintUpperFullMatrix(
int constraint,
int block,
double amat[],
int n, FILE*fp){
48 for (row=0;row<n;row++){
49 for (col=0;col<=row;col++){
50 if (fabs(amat[col])>1.0e-20){
51 Dprintf(fp,constraint,block,col,row,amat[col]);
60 #define __FUNCT__ "DPrintMatrix" 61 static void DPrintMatrix(
char UPLQ,
int constraint,
int block,
double amat[],
int n, FILE*fp){
63 DPrintUpperRightMatrix(constraint,block,amat,n,fp);
64 }
else if (UPLQ==
'U'){
65 DPrintUpperFullMatrix(constraint,block,amat,n,fp);
71 #define __FUNCT__ "DPrintLPArray" 72 static int DPrintLPArray(
int cc,
int block,
double *vv,
int n, FILE *fp ){
75 if ( fabs(vv[i]) > 0){
76 Dprintf(fp,cc,block,i,i,vv[i]);
84 #define __FUNCT__ "DSDPPrintSolution" 95 int i,kk,info,n,nn,lpn=0,nblocks,nvars;
96 double *ss,*xx,*y,*lparray;
100 DSDPCALLOC2(&y,
double,(nvars+2),&info);DSDPCHKERR(info);
103 if (lpcone){info=
LPConeGetXArray(lpcone,&xx,&lpn);DSDPCHKERR(info);nblocks--;}
104 DSDPCALLOC2(&lparray,
double,(lpn+1),&info);DSDPCHKERR(info);
115 info=
DSDPGetY(dsdp,y+1,nvars);DSDPCHKERR(info);
116 y[0]=1.0;y[nvars+1]=0;
117 info=
DSDPGetR(dsdp,y+nvars+1);DSDPCHKERR(info);
118 for (i=0; i<nvars; i++){ DprintfD(fp,-y[i+1]);}
122 for (kk=0;kk<nblocks;kk++){
125 info=
SDPConeComputeS(sdpcone,kk,y[0],y+1,nvars,y[nvars+1],n,ss,nn);DSDPCHKERR(info);
127 DPrintMatrix(UPLQ,1,kk+1,ss,n,fp);
131 info=
LPConeCopyS(lpcone,lparray,lpn);DSDPCHKERR(info);
132 info=DPrintLPArray(1,nblocks+1,lparray,lpn,fp);DSDPCHKERR(info);
137 for (kk=0; kk<nblocks; kk++){
141 DPrintMatrix(UPLQ,2,kk+1,xx,n,fp);
146 info=DPrintLPArray(2,nblocks+1,xx,nn,fp);DSDPCHKERR(info);
155 #define __FUNCT__ "DSDPPrintData" 166 int info,nblocks,i,nvars,n,nn,kk,lpblock=0,lpn=0;
167 double *ss,*y=0,*vv=0;
168 char filename[100]=
"";
173 DSDPCALLOC2(&y,
double,(nvars+3),&info);DSDPCHKERR(info);
175 strncat(filename,
"output.sdpa",50);
177 fp=fopen(
"input.sdpa",
"w");
180 DSDPCALLOC2(&vv,
double,lpn,&info);DSDPCHKERR(info);
183 if (n==0){nblocks--;}
185 fprintf(fp,
"%d \n%d\n",nvars,nblocks+lpblock);
186 for (kk=0;kk<nblocks;kk++){
191 fprintf(fp,
"%d ",-lpn);
195 for (i=0;i<nvars;i++){
200 for (i=0;i<=nvars;i++){
201 for (kk=0;kk<nvars+2;kk++) y[kk]=0.0;
202 if (i==0){y[i]=1.0;}
else {y[i]=-1.0; }
203 for (kk=0;kk<nblocks;kk++){
206 info=
SDPConeComputeS(sdpcone,kk,y[0],y+1,nvars,y[nvars+1],n,ss,nn);DSDPCHKERR(info);
208 DPrintMatrix(UPLQ,i,kk+1,ss,n,fp);
211 if (lpcone && lpn>0){
213 for (i=0;i<=nvars;i++){
215 info=DPrintLPArray(i,nblocks+1,vv,lpn,fp);DSDPCHKERR(info);
int LPConeGetDimension(LPCone lpcone, int *n)
Get the dimension is the number of variables x, which equals the number of slack variables s...
int SDPConeGetBlockSize(SDPCone sdpcone, int blockj, int *n)
Get the dimension of one block in the semidefinite cone.
int DSDPPrintSolution(FILE *fp, DSDP dsdp, SDPCone sdpcone, LPCone lpcone)
Print solution in SDPA format.
Internal structures for the DSDP solver.
int LPConeCopyS(LPCone lpcone, double s[], int n)
Copy the variables s into the spedified array.
int SDPConeRestoreXArray(SDPCone sdpcone, int blockj, double *xx[], int *nn)
Restore the dense array and set these pointers to null.
int DSDPPrintData(DSDP dsdp, SDPCone sdpcone, LPCone lpcone)
Print data in SDPA format to a file named "output.sdpa".
int SDPConeGetXArray(SDPCone sdpcone, int blockj, double *xx[], int *nn)
After applying the solver, set a pointer to the array in the object with the solution X...
int LPConeGetXArray(LPCone lpcone, double *x[], int *n)
Get the array used to store the x variables.
The API to DSDP for those applications using DSDP as a subroutine library.
int SDPConeGetNumberOfBlocks(SDPCone sdpcone, int *nblocks)
Get the number of blocks in the semidefinite cone.
int LPConeGetData(LPCone lpcone, int vari, double vv[], int n)
Get one column (or row) of the LP data.
Internal structure for semidefinite cone.
int DSDPGetY(DSDP dsdp, double y[], int m)
Copies the variables y into an array.
int DSDPGetNumberOfVariables(DSDP dsdp, int *m)
Copy the number of variables y.
int SDPConeGetStorageFormat(SDPCone sdpcone, int blockj, char *format)
Get the storage format for the block.
int DSDPGetR(DSDP dsdp, double *res)
Copy the infeasibility in (D), or the variable r in (DD).
int DSDPComputeX(DSDP dsdp)
Compute the X variables.
int SDPConeComputeS(SDPCone sdpcone, int blockj, double cc, double y[], int nvars, double r, int n, double s[], int nn)
Compute the dual matrix S.
int DSDPCopyB(DSDP dsdp, double bb[], int m)
Copies the variables b from solver into an array.
struct LPCone_C * LPCone
The LPCone object points to blocks of data that specify linear scalar inequality constraints.