dsdpadddata.c
Go to the documentation of this file.
#include "dsdpsdp.h"
#include "dsdpsys.h"
#undef __FUNCT__
#define __FUNCT__ "SDPConeCheckI"
int SDPConeCheckI(SDPCone sdpcone,int vari){
DSDPFunctionBegin;
SDPConeValid(sdpcone);
if (vari<0 || vari>sdpcone->m) {
DSDPSETERR2(1,"Bad Data Matrix: variable: %d (Max: %d)\n",vari,sdpcone->m+1);}
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "SDPConeCheckJ"
int SDPConeCheckJ(SDPCone sdpcone,int blockj){
DSDPFunctionBegin;
SDPConeValid(sdpcone);
if (blockj<0 || blockj>= sdpcone->nblocks) {
DSDPSETERR2(2,"Bad Data Matrix: Block: %d (Max: %d)\n",blockj,sdpcone->nblocks-1);}
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "SDPConeCheckN"
int SDPConeCheckN(SDPCone sdpcone,int blockj, int n){
int info;
DSDPFunctionBegin;
info=SDPConeCheckJ(sdpcone,blockj);DSDPCHKERR(info);
if (sdpcone->blk[blockj].n==0 && n>0){info=SDPConeSetBlockSize(sdpcone,blockj,n);DSDPCHKERR(info);}
if (sdpcone->blk[blockj].n != n){
DSDPSETERR3(3,"Check Dimension of Data Matrix: Block: %d, %d -- expecting %d\n",
blockj,n,sdpcone->blk[blockj].n);
}
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "SDPConeCheckM"
int SDPConeCheckM(SDPCone sdpcone,int m){
DSDPFunctionBegin;
SDPConeValid(sdpcone);
if (m!=sdpcone->m){
DSDPSETERR1(4,"Check dimension of array. This problem has %d variables\n",sdpcone->m);}
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "SDPConeValidStorageFormat"
int SDPConeValidStorageFormat(SDPCone sdpcone, char format){
DSDPFunctionBegin;
if (format!='P' && format != 'U'){
DSDPSETERR1(4,"Check format of Block: %c is not supported! Use P or U. \n",format);
}
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "SDPConeCheckStorageFormat"
int SDPConeCheckStorageFormat(SDPCone sdpcone,int blockj, char format){
int info;
DSDPFunctionBegin;
info=SDPConeCheckJ(sdpcone,blockj);DSDPCHKERR(info);
info=SDPConeValidStorageFormat(sdpcone,format);DSDPCHKERR(info);
if (sdpcone->blk[blockj].format=='N'){
sdpcone->blk[blockj].format = format;
}
if (sdpcone->blk[blockj].format != format){
DSDPSETERR3(4,"Check format of Data Matrix: Block: %d, %c -- expecting %c\n",
blockj,format,sdpcone->blk[blockj].format);
}
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "SDPConeRemoveDataMatrix"
int SDPConeRemoveDataMatrix(SDPCone sdpcone,int blockj, int vari){
int info;
DSDPFunctionBegin;
info=SDPConeCheckI(sdpcone,vari);DSDPCHKERR(info);
info=SDPConeCheckJ(sdpcone,blockj);DSDPCHKERR(info);
info=DSDPBlockRemoveDataMatrix(&sdpcone->blk[blockj].ADATA,vari);DSDPCHKERR(info);
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "SDPConeAddDataMatrix"
int SDPConeAddDataMatrix(SDPCone sdpcone,int blockj, int vari, int n, char format, struct DSDPDataMat_Ops* dsdpdataops, void* data){
int info;
DSDPFunctionBegin;
info=SDPConeCheckI(sdpcone,vari);DSDPCHKERR(info);
info=SDPConeCheckJ(sdpcone,blockj);DSDPCHKERR(info);
info=SDPConeCheckN(sdpcone,blockj,n);DSDPCHKERR(info);
info=SDPConeCheckStorageFormat(sdpcone,blockj,format);DSDPCHKERR(info);
info=DSDPBlockAddDataMatrix(&sdpcone->blk[blockj].ADATA,vari,dsdpdataops,data);DSDPCHKERR(info);
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "SDPConeSetRMatrix"
int SDPConeSetRMatrix(SDPCone sdpcone,int blockj, int n, char format, struct DSDPDataMat_Ops* dsdpdataops, void* data){
int info;
int vari=sdpcone->m+1;
DSDPFunctionBegin;
info=SDPConeCheckJ(sdpcone,blockj);DSDPCHKERR(info);
info=SDPConeCheckN(sdpcone,blockj,n);DSDPCHKERR(info);
info=SDPConeCheckStorageFormat(sdpcone,blockj,format);DSDPCHKERR(info);
info=DSDPBlockRemoveDataMatrix(&sdpcone->blk[blockj].ADATA,vari);DSDPCHKERR(info);
info=DSDPBlockSetDataMatrix(&sdpcone->blk[blockj].ADATA,vari,dsdpdataops,data);DSDPCHKERR(info);
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "SDPConeViewDataMatrix"
int SDPConeViewDataMatrix(SDPCone sdpcone,int blockj, int vari){
int info,ii,vari2,nnzmats;
DSDPDataMat AA;
DSDPFunctionBegin;
info=SDPConeCheckI(sdpcone,vari);DSDPCHKERR(info);
info=SDPConeCheckJ(sdpcone,blockj);DSDPCHKERR(info);
info=DSDPBlockCountNonzeroMatrices(&sdpcone->blk[blockj].ADATA,&nnzmats);DSDPCHKERR(info);
for (ii=0;ii<nnzmats; ii++){ /* Matrix Entries */
info=DSDPBlockGetMatrix(&sdpcone->blk[blockj].ADATA,ii,&vari2,0,&AA);DSDPCHKVARERR(vari,info);
if (vari2==vari){ info = DSDPDataMatView(AA);DSDPCHKERR(info);}
}
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "SDPConeClearVMatrix"
int SDPConeClearVMatrix(SDPCone sdpcone,int blockj, int n){
int info;
DSDPFunctionBegin;
SDPConeValid(sdpcone);
info=DSDPVMatDestroy(&sdpcone->blk[blockj].T);DSDPCHKERR(info);
info=DSDPVMatInitialize(&sdpcone->blk[blockj].T);DSDPCHKERR(info);
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "SDPConeSetXMat"
int SDPConeSetXMat(SDPCone sdpcone,int blockj, int n){
int info;
char UPLQ;
DSDPVMat T;
DSDPFunctionBegin;
SDPConeValid(sdpcone);
info=SDPConeClearVMatrix(sdpcone,blockj,n);DSDPCHKERR(info);
DSDPLogInfo(0,10,"Create block X Mat: Block: %d, size: %d.\n",blockj,n);
info=SDPConeGetStorageFormat(sdpcone,blockj,&UPLQ); DSDPCHKERR(info);
info=DSDPMakeVMat(UPLQ,n,&T);DSDPCHKERR(info);
sdpcone->blk[blockj].T=T;
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "SDPConeSetXArray"
int SDPConeSetXArray(SDPCone sdpcone,int blockj, int n, double xx[], int nn){
int info;
char UPLQ;
DSDPVMat T;
DSDPFunctionBegin;
info=SDPConeCheckJ(sdpcone,blockj);DSDPCHKERR(info);
info=SDPConeCheckN(sdpcone,blockj,n);DSDPCHKERR(info);
info=SDPConeClearVMatrix(sdpcone,blockj,n);DSDPCHKERR(info);
DSDPLogInfo(0,10,"Set block X array: Block: %d, size: %d.\n",blockj,n);
info=SDPConeGetStorageFormat(sdpcone,blockj,&UPLQ); DSDPCHKERR(info);
info=DSDPMakeVMatWithArray(UPLQ,xx,nn,n,&T);DSDPCHKERR(info);
sdpcone->blk[blockj].T=T;
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "SDPConeGetXArray"
int SDPConeGetXArray(SDPCone sdpcone,int blockj, double* xx[], int *nn){
int info,flag;
DSDPFunctionBegin;
info=SDPConeCheckJ(sdpcone,blockj);DSDPCHKERR(info);
info=DSDPVMatExist(sdpcone->blk[blockj].T,&flag);DSDPCHKERR(info);
if (flag==0){
DSDPSETERR(6,"No X Array available, Call DSDPSetup() or SDPConeSetXArray.\n");}
info=DSDPVMatGetArray(sdpcone->blk[blockj].T,xx,nn);DSDPCHKERR(info);
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "SDPConeRestoreXArray"
int SDPConeRestoreXArray(SDPCone sdpcone,int blockj, double* xx[], int *nn){
int info,flag;
DSDPFunctionBegin;
info=SDPConeCheckJ(sdpcone,blockj);DSDPCHKERR(info);
info=DSDPVMatExist(sdpcone->blk[blockj].T,&flag);DSDPCHKERR(info);
if (flag==0){
DSDPSETERR(6,"No X Array available, Call DSDPSetup() or SDPConeSetXArray.\n");}
info=DSDPVMatRestoreArray(sdpcone->blk[blockj].T,xx,nn);DSDPCHKERR(info);
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "SDPConeMatrixView"
int SDPConeMatrixView(SDPCone sdpcone, int blockj){
int info;
DSDPFunctionBegin;
info=SDPConeCheckJ(sdpcone,blockj);DSDPCHKERR(info);
info=DSDPVMatView(sdpcone->blk[blockj].T);DSDPCHKERR(info);
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "SDPConeUseFullSymmetricFormat"
int SDPConeUseFullSymmetricFormat(SDPCone sdpcone, int blockj){
int info;
DSDPFunctionBegin;
info=SDPConeSetStorageFormat(sdpcone,blockj,'U');DSDPCHKERR(info);
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "SDPConeUsePackedFormat"
int SDPConeUsePackedFormat(SDPCone sdpcone, int blockj){
int info;
DSDPFunctionBegin;
info=SDPConeSetStorageFormat(sdpcone,blockj,'P');DSDPCHKERR(info);
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "SDPConeSetStorageFormat"
int SDPConeSetStorageFormat(SDPCone sdpcone, int blockj, char format){
int info;
DSDPFunctionBegin;
info=SDPConeValidStorageFormat(sdpcone,format);DSDPCHKERR(info);
info=SDPConeCheckJ(sdpcone,blockj);DSDPCHKERR(info);
sdpcone->blk[blockj].format=format;
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "SDPConeGetStorageFormat"
int SDPConeGetStorageFormat(SDPCone sdpcone, int blockj, char *format){
int info;
DSDPFunctionBegin;
info=SDPConeCheckJ(sdpcone,blockj);DSDPCHKERR(info);
*format=sdpcone->blk[blockj].format;
if (*format=='N') *format='P';
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "SDPConeScaleBarrier"
int SDPConeScaleBarrier(SDPCone sdpcone,int blockj, double ggamma){
int info;
DSDPFunctionBegin;
info=SDPConeCheckJ(sdpcone,blockj);DSDPCHKERR(info);
sdpcone->blk[blockj].gammamu=ggamma;
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "SDPConeSetBlockSize"
int SDPConeSetBlockSize(SDPCone sdpcone, int blockj, int n){
int info,n0;
DSDPFunctionBegin;
DSDPLogInfo(0,10,"Set block size: Block: %d, size: %d.\n",blockj,n);
info=SDPConeCheckJ(sdpcone,blockj);DSDPCHKERR(info);
n0=sdpcone->blk[blockj].n;
if (n0==n){DSDPFunctionReturn(0);}
if (n0!=0 &&n0!=n){
DSDPSETERR2(5,"Block %d Size previously set to %d \n",blockj,n0); }
sdpcone->blk[blockj].n=n;
sdpcone->nn+=n-n0;
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "SDPConeGetBlockSize"
int SDPConeGetBlockSize(SDPCone sdpcone, int blockj, int *n){
int info;
DSDPFunctionBegin;
info=SDPConeCheckJ(sdpcone,blockj);DSDPCHKERR(info);
*n=sdpcone->blk[blockj].n;
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "SDPConeGetNumberOfBlocks"
int SDPConeGetNumberOfBlocks(SDPCone sdpcone, int *nblocks){
DSDPFunctionBegin;
SDPConeValid(sdpcone);
*nblocks=sdpcone->nblocks;
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "SDPConeSetSparsity"
int SDPConeSetSparsity(SDPCone sdpcone, int blockj, int nnz){
int info;
DSDPFunctionBegin;
DSDPLogInfo(0,10,"Set block nonzeros: Block: %d, Nonzero Matrices: %d.\n",blockj,nnz);
info=SDPConeCheckJ(sdpcone,blockj);DSDPCHKERR(info);
if (nnz>sdpcone->m) nnz=sdpcone->m;
info=DSDPBlockDataAllocate(&sdpcone->blk[blockj].ADATA,nnz+2); DSDPCHKERR(info);
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "SDPConeView"
int SDPConeView(SDPCone sdpcone){
int blockj,info;
DSDPFunctionBegin;
for (blockj=0; blockj<sdpcone->nblocks; blockj++){
printf("Block: %d, Dimension: %d\n",blockj,sdpcone->blk[blockj].n);
info=DSDPBlockView(&sdpcone->blk[blockj].ADATA);DSDPCHKERR(info);
}
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "SDPConeView2"
int SDPConeView2(SDPCone sdpcone){
int blockj,info;
DSDPFunctionBegin;
for (blockj=0; blockj<sdpcone->nblocks; blockj++){
printf("Block: %d, Dimension: %d\n",blockj,sdpcone->blk[blockj].n);
info=DSDPBlockView2(&sdpcone->blk[blockj].ADATA);DSDPCHKERR(info);
}
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "SDPConeView3"
int SDPConeView3(SDPCone sdpcone){
int blockj,id,n,info,nnzmats;
DSDPFunctionBegin;
for (blockj=0; blockj<sdpcone->nblocks; blockj++){
n=sdpcone->blk[blockj].n;
printf("Block: %d \n",blockj);
printf(" Dimension: %d\n",n);
info=DSDPDSMatGetType(sdpcone->blk[blockj].DS,&id);
if (id==1){
printf(" DS Matrix Type: Dense, Using LAPACK\n");
} else {
printf(" DS Matrix Type: %d\n",id);
}
info=DSDPDualMatGetType(sdpcone->blk[blockj].S,&id);
if (id==1){
printf(" Dual Matrix Type: Dense, Using LAPACK\n");
} else {
printf(" Dual Matrix Type: %d\n",id);
}
info=DSDPBlockCountNonzeroMatrices(&sdpcone->blk[blockj].ADATA,&nnzmats);DSDPCHKERR(info);
printf(" Number of Data Matrices: %d of %d\n",nnzmats-1,sdpcone->m+1);
printf(" Number of Data Nonzeros: %d\n",sdpcone->blk[blockj].nnz);
}
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "SDPConeCheckData"
int SDPConeCheckData(SDPCone sdpcone){
int i,ii,blockj,nnzmats,info;
double scl=0;
DSDPDataMat AA;
DSDPIndex IS;
DSDPVMat T;
DSDPDSMat DS;
DSDPDualMat S1,S2;
SDPConeVec W,W2;
DSDPFunctionBegin;
for (blockj=0; blockj<sdpcone->nblocks; blockj++){
T=sdpcone->blk[blockj].T;DS=sdpcone->blk[blockj].DS;
W=sdpcone->blk[blockj].W;W2=sdpcone->blk[blockj].W2;
S1=sdpcone->blk[blockj].S;S2=sdpcone->blk[blockj].SS;
IS=sdpcone->blk[blockj].IS;
printf("Block: %d\n",blockj);
info=DSDPVMatCheck(T,W,W2);DSDPCHKERR(info);
info=DSDPDSMatCheck(DS,W,W2,T);DSDPCHKERR(info);
info=DSDPDualMatCheck(S1,W,W2,IS,T);DSDPCHKERR(info);
info=DSDPDualMatCheck(S2,W,W2,IS,T);DSDPCHKERR(info);
info=DSDPBlockCountNonzeroMatrices(&sdpcone->blk[blockj].ADATA,&nnzmats);DSDPCHKERR(info);
for (ii=0;ii<nnzmats;ii++){
info=DSDPBlockGetMatrix(&sdpcone->blk[blockj].ADATA,ii,&i,&scl,&AA);DSDPCHKERR(info);
if (i==0) continue;
printf(" Variable: %d, \n",i);
info=DSDPDataMatCheck(AA,W,IS,T);DSDPCHKERR(info);
}
}
DSDPFunctionReturn(0);
}
SDPConeClearVMatrix
int SDPConeClearVMatrix(SDPCone sdpcone, int blockj, int n)
Free V matrix.
Definition dsdpadddata.c:228
SDPConeSetRMatrix
int SDPConeSetRMatrix(SDPCone sdpcone, int blockj, int n, char format, struct DSDPDataMat_Ops *dsdpdataops, void *data)
Add identity to dual matrix.
Definition dsdpadddata.c:181
SDPConeSetXMat
int SDPConeSetXMat(SDPCone sdpcone, int blockj, int n)
Create X matrix.
Definition dsdpadddata.c:247
SDPConeCheckJ
int SDPConeCheckJ(SDPCone sdpcone, int blockj)
Check validity of parameter.
Definition dsdpadddata.c:31
SDPConeCheckI
int SDPConeCheckI(SDPCone sdpcone, int vari)
Check validity of parameter.
Definition dsdpadddata.c:15
SDPConeCheckN
int SDPConeCheckN(SDPCone sdpcone, int blockj, int n)
Check validity of parameter.
Definition dsdpadddata.c:48
SDPConeCheckM
int SDPConeCheckM(SDPCone sdpcone, int m)
Check validity of parameter.
Definition dsdpadddata.c:68
SDPConeValidStorageFormat
int SDPConeValidStorageFormat(SDPCone sdpcone, char format)
Check validity of parameter.
Definition dsdpadddata.c:84
SDPConeCheckStorageFormat
int SDPConeCheckStorageFormat(SDPCone sdpcone, int blockj, char format)
Check validity of parameters.
Definition dsdpadddata.c:101
DSDPDataMatCheck
int DSDPDataMatCheck(DSDPDataMat AA, SDPConeVec W, DSDPIndex IS, DSDPVMat XX)
Check correctness of operations on the data.
Definition dsdpblock.c:498
DSDPBlockView2
int DSDPBlockView2(DSDPBlockData *ADATA)
Print the data.
Definition dsdpblock.c:474
DSDPBlockDataAllocate
int DSDPBlockDataAllocate(DSDPBlockData *ADATA, int nnz)
Allocate some structures.
Definition dsdpblock.c:221
DSDPBlockGetMatrix
int DSDPBlockGetMatrix(DSDPBlockData *ADATA, int id, int *vari, double *scl, DSDPDataMat *A)
Get a data matrix from a block of data.
Definition dsdpblock.c:307
DSDPBlockAddDataMatrix
int DSDPBlockAddDataMatrix(DSDPBlockData *ADATA, int vari, struct DSDPDataMat_Ops *dsdpdataops, void *data)
Add data matrix into SDP block.
Definition dsdpblock.c:381
DSDPBlockSetDataMatrix
int DSDPBlockSetDataMatrix(DSDPBlockData *ADATA, int vari, struct DSDPDataMat_Ops *dsdpdataops, void *data)
Set data matrix into SDP block.
Definition dsdpblock.c:406
DSDPBlockRemoveDataMatrix
int DSDPBlockRemoveDataMatrix(DSDPBlockData *ADATA, int vari)
Remove a data matrix.
Definition dsdpblock.c:351
DSDPBlockCountNonzeroMatrices
int DSDPBlockCountNonzeroMatrices(DSDPBlockData *ADATA, int *nzmats)
Count how many data matrices are in a block of data.
Definition dsdpblock.c:272
DSDPBlockView
int DSDPBlockView(DSDPBlockData *ADATA)
Print the structure of the block.
Definition dsdpblock.c:454
DSDPDataMatView
int DSDPDataMatView(DSDPDataMat A)
Print matrix.
Definition dsdpdatamat.c:423
dsdpsdp.h
Internal SDPCone data structures and routines.
DSDPMakeVMatWithArray
int DSDPMakeVMatWithArray(char, double[], int, int, DSDPVMat *)
Allocate V matrix using the given array.
Definition sdpsss.c:381
DSDPMakeVMat
int DSDPMakeVMat(char, int, DSDPVMat *)
Allocate V matrix.
Definition sdpsss.c:351
dsdpsys.h
Error handling, printing, and profiling.
DSDPVMatInitialize
int DSDPVMatInitialize(DSDPVMat *B)
Set pointers to null.
Definition dsdpxmat.c:424
DSDPVMatGetArray
int DSDPVMatGetArray(DSDPVMat X, double **v, int *nn)
Get the array that stores the matrix.
Definition dsdpxmat.c:211
DSDPVMatRestoreArray
int DSDPVMatRestoreArray(DSDPVMat X, double **v, int *nn)
Restore the array that stores the matrix.
Definition dsdpxmat.c:233
DSDPVMatExist
int DSDPVMatExist(DSDPVMat X, int *flag)
Answer whether the array has been allocated or not.
Definition dsdpxmat.c:440
DSDPVMatCheck
int DSDPVMatCheck(DSDPVMat X, SDPConeVec W1, SDPConeVec W2)
Test correctness of operations.
Definition dsdpxmat.c:327
DSDPVMatDestroy
int DSDPVMatDestroy(DSDPVMat *X)
Deallocate matrix.
Definition dsdpxmat.c:86
DSDPVMatView
int DSDPVMatView(DSDPVMat X)
Print matrix.
Definition dsdpxmat.c:107
DSDPDSMat_C
Symmetric Delta S matrix for one block in the semidefinite cone.
Definition dsdpdsmat.h:23
DSDPDataMat_C
Symmetric data matrix for one block in the semidefinite cone.
Definition dsdpdatamat.h:15
DSDPDataMat_Ops
Table of function pointers that operate on the data matrix.
Definition dsdpdatamat_impl.h:15
DSDPDualMat_C
Represents an S matrix for one block in the semidefinite cone.
Definition dsdpdualmat.h:18
DSDPVMat_C
Dense symmetric matrix for one block in the semidefinite cone.
Definition dsdpxmat.h:17
SDPConeVec_C
Vector whose length corresponds to dimension of a block in a cone.
Definition sdpconevec.h:13
SDPCone_C
Internal structure for semidefinite cone.
Definition dsdpsdp.h:80