sdpconesetup.c
Go to the documentation of this file.
#include "dsdpsdp.h"
#include "dsdpsys.h"
#undef __FUNCT__
#define __FUNCT__ "DSDPDataTransposeInitialize"
int DSDPDataTransposeInitialize(DSDPDataTranspose *ATranspose){
DSDPFunctionBegin;
ATranspose->nnzblocks=0;
ATranspose->nzblocks=0;
ATranspose->idA=0;
ATranspose->idAP=0;
ATranspose->ttnzmat=0;
ATranspose->nnzblocks=0;
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "DSDPDataTransposeSetup"
int DSDPDataTransposeSetup(DSDPDataTranspose *ATranspose, SDPblk *blk, int nblocks, int m){
int i,ii,kk,vvar,info;
int nnzmats,tnzmats=0;
DSDPFunctionBegin;
info=DSDPDataTransposeTakeDown(ATranspose);DSDPCHKERR(info);
/* Determine sparsity pattern of SDP Data Matrices */
DSDPCALLOC2(&ATranspose->nnzblocks,int,(m),&info);DSDPCHKERR(info);
DSDPCALLOC2(&ATranspose->nzblocks,int*,(m),&info);DSDPCHKERR(info);
DSDPCALLOC2(&ATranspose->idA,int*,(m),&info);DSDPCHKERR(info);
ATranspose->m=m;
for (i=0;i<m;i++){ ATranspose->nnzblocks[i]=0; }
for (kk=0; kk<nblocks; kk++){
info=DSDPBlockDataMarkNonzeroMatrices(&blk[kk].ADATA,ATranspose->nnzblocks);DSDPCHKERR(info);
}
for (tnzmats=0,i=0;i<m;i++){ tnzmats += ATranspose->nnzblocks[i];}
DSDPCALLOC2(&ATranspose->ttnzmat,int,tnzmats,&info);DSDPCHKERR(info);
ATranspose->nzblocks[0]=ATranspose->ttnzmat;
for (i=1;i<m;i++){
ATranspose->nzblocks[i]=ATranspose->nzblocks[i-1]+ATranspose->nnzblocks[i-1];
}
DSDPCALLOC2(&ATranspose->idAP,int,tnzmats,&info);DSDPCHKERR(info);
ATranspose->idA[0]=ATranspose->idAP;
for (i=1;i<m;i++){
ATranspose->idA[i]=ATranspose->idA[i-1]+ATranspose->nnzblocks[i-1];
}
for (i=0;i<m;i++){ATranspose->nnzblocks[i]=0;}
for (kk=0; kk<nblocks; kk++){
info=DSDPBlockCountNonzeroMatrices(&blk[kk].ADATA,&nnzmats);DSDPCHKERR(info);
for (i=0;i<nnzmats;i++){
info=DSDPBlockGetMatrix(&blk[kk].ADATA,i,&ii,0,0);DSDPCHKERR(info);
vvar=ATranspose->nnzblocks[ii];
ATranspose->nzblocks[ii][vvar]=kk;
ATranspose->idA[ii][vvar]=i;
ATranspose->nnzblocks[ii]++;
}
}
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "DSDPDataTransposeTakeDown"
int DSDPDataTransposeTakeDown(DSDPDataTranspose *ATranspose){
int info;
DSDPFunctionBegin;
DSDPFREE(&ATranspose->ttnzmat,&info);DSDPCHKERR(info);
DSDPFREE(&ATranspose->idAP,&info);DSDPCHKERR(info);
DSDPFREE(&ATranspose->nzblocks,&info);DSDPCHKERR(info);
DSDPFREE(&ATranspose->nnzblocks,&info);DSDPCHKERR(info);
DSDPFREE(&ATranspose->idA,&info);DSDPCHKERR(info);
info=DSDPDataTransposeInitialize(ATranspose);DSDPCHKERR(info);
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "DSDPCreateSDPCone"
int DSDPCreateSDPCone(DSDP dsdp, int blocks, SDPCone* dspcone){
int i,info;
SDPCone sdpcone;
DSDPFunctionBegin;
DSDPCALLOC1(&sdpcone,struct SDPCone_C,&info);DSDPCHKERR(info);
*dspcone=sdpcone;
sdpcone->keyid=SDPCONEKEY;
info=DSDPAddSDP(dsdp,sdpcone);DSDPCHKERR(info);
info=DSDPGetNumberOfVariables(dsdp,&sdpcone->m);DSDPCHKERR(info);
DSDPCALLOC2(&sdpcone->blk,SDPblk,blocks,&info); DSDPCHKERR(info);
for (i=0;i<blocks; i++){
info=DSDPBlockInitialize(&sdpcone->blk[i]); DSDPCHKBLOCKERR(i,info);
}
sdpcone->nblocks=blocks;
sdpcone->optype=3;
info=DSDPUseDefaultDualMatrix(sdpcone); DSDPCHKERR(info);
sdpcone->nn=0;
sdpcone->dsdp=dsdp;
info=DSDPDataTransposeInitialize(&sdpcone->ATR); DSDPCHKERR(info);
info=DSDPBlockEventZero();DSDPCHKERR(info);
info=DSDPDualMatEventZero();DSDPCHKERR(info);
info=DSDPVMatEventZero();DSDPCHKERR(info);
DSDPFunctionReturn(0);
}
int DSDPCreateS(DSDPBlockData*,char,int,DSDPVec,DSDPVMat,SDPConeVec,SDPConeVec,DSDPDualMat*, DSDPDualMat*, DSDPDSMat*, void*);
#undef __FUNCT__
#define __FUNCT__ "DSDPBlockSetup"
int DSDPBlockSetup(SDPblk *blk, int blockj, DSDPVec WY){
int n,info,trank,flag;
DSDPFunctionBegin;
/*
info=DSDPBlockTakeDown(blk);DSDPCHKERR(info);
*/
n=blk->n;
info=DSDPVMatExist(blk->T,&flag);DSDPCHKERR(info);
if (flag==0){
info=DSDPMakeVMat(blk->format,n,&blk->T);DSDPCHKERR(info);
}
info = DSDPIndexCreate(blk->n,&blk->IS);DSDPCHKERR(info);
info = SDPConeVecCreate(blk->n,&blk->W);DSDPCHKERR(info);
info = SDPConeVecDuplicate(blk->W,&blk->W2);DSDPCHKERR(info);
/* Build Lanczos structures */
info=DSDPSetMaximumLanczosIterations(&blk->Lanczos,20); DSDPCHKERR(info);
if (n>30){info=DSDPSetMaximumLanczosIterations(&blk->Lanczos,20); DSDPCHKERR(info);}
if (n>300){info=DSDPSetMaximumLanczosIterations(&blk->Lanczos,40); DSDPCHKERR(info);}
if (n>1000){info=DSDPSetMaximumLanczosIterations(&blk->Lanczos,50); DSDPCHKERR(info);}
if (1){
info=DSDPFastLanczosSetup(&blk->Lanczos,blk->W);DSDPCHKERR(info);
DSDPLogInfo(0,19,"SDP Block %d using Fast Lanczos\n",blockj);
} else {
info=DSDPRobustLanczosSetup(&blk->Lanczos,blk->W);DSDPCHKERR(info);
DSDPLogInfo(0,19,"SDP Block %d using Full Lanczos\n",blockj);
}
/* Eigenvalues and Eigenvectors */
info=DSDPBlockFactorData(&blk->ADATA,blk->T,blk->W);DSDPCHKERR(info);
info=DSDPBlockDataRank(&blk->ADATA,&trank,n);DSDPCHKERR(info);
info=DSDPCreateS(&blk->ADATA,blk->format,trank,WY,blk->T,blk->W,blk->W2,&blk->S,&blk->SS,&blk->DS,0);DSDPCHKERR(info);
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "SDPConeBlockNNZ"
int SDPConeBlockNNZ(SDPblk *blk,int m){
int i,ii,n,info,nnz,nnzmats,tnnzmats,tnnz=0;
double scl;
DSDPDataMat AA;
DSDPFunctionBegin;
nnzmats=blk->ADATA.nnzmats;tnnzmats=nnzmats;
n=blk->n;
for (i=0;i<nnzmats;i++){
info=DSDPBlockGetMatrix(&blk->ADATA,i,&ii,&scl,&AA);DSDPCHKERR(info);
if (ii==0){tnnzmats--; continue;}
if (ii==m-1){continue;}
info = DSDPDataMatCountNonzeros(AA,&nnz,n); DSDPCHKERR(info);
tnnz+= (nnz*(tnnzmats-i));
}
if (tnnzmats>1){ tnnz=tnnz/((tnnzmats)*(tnnzmats+1)/2); }
if (tnnz<1) tnnz = 1;
blk->nnz=tnnz;
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "SDPConeSetup2"
int SDPConeSetup2(SDPCone sdpcone, DSDPVec yy0, DSDPSchurMat M){
int kk,n,m,info;
double nn=0;
SDPblk *blk;
DSDPFunctionBegin;
info=DSDPVecGetSize(yy0,&m);DSDPCHKERR(info);
for (kk=0; kk<sdpcone->nblocks; kk++){
blk=&sdpcone->blk[kk];
n=blk->n;
info=SDPConeBlockNNZ(blk,m);DSDPCHKERR(info);
info=DSDPBlockSetup(blk,kk,sdpcone->Work);DSDPCHKERR(info);
nn+=n*blk->gammamu;
}
sdpcone->nn=(int)nn;
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "SDPConeSetup"
int SDPConeSetup(SDPCone sdpcone, DSDPVec yy0){
int kk,n,m,info;
DSDPFunctionBegin;
info = DSDPVecGetSize(yy0,&m);DSDPCHKERR(info);
if (m!=sdpcone->m+2){DSDPSETERR(8,"CHECK DIMENSION\n");}
info = DSDPVecDuplicate(yy0,&sdpcone->Work);DSDPCHKERR(info);
info = DSDPVecDuplicate(yy0,&sdpcone->Work2);DSDPCHKERR(info);
info = DSDPVecDuplicate(yy0,&sdpcone->YY);DSDPCHKERR(info);
info = DSDPVecDuplicate(yy0,&sdpcone->YX);DSDPCHKERR(info);
info = DSDPVecDuplicate(yy0,&sdpcone->DYX);DSDPCHKERR(info);
for (kk=0; kk<sdpcone->nblocks; kk++){
n=sdpcone->blk[kk].n;
info=SDPConeSetRIdentity(sdpcone,kk,n,1.0);DSDPCHKERR(info);
}
info=DSDPDataTransposeSetup(&sdpcone->ATR,sdpcone->blk,sdpcone->nblocks,m); DSDPCHKERR(info);
info=DSDPBlockEventInitialize();DSDPCHKERR(info);
info=DSDPDualMatEventInitialize();DSDPCHKERR(info);
info=DSDPVMatEventInitialize();DSDPCHKERR(info);
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "DSDPBlockInitialize"
int DSDPBlockInitialize(SDPblk *blk){
int info;
DSDPFunctionBegin;
blk->n=0;
blk->format='N';
blk->gammamu=1.0;
blk->bmu=0.0;
blk->nnz=10000000;
info = DSDPDualMatInitialize(&blk->S); DSDPCHKERR(info);
info = DSDPDualMatInitialize(&blk->SS); DSDPCHKERR(info);
info = DSDPDSMatInitialize(&blk->DS); DSDPCHKERR(info);
info = DSDPVMatInitialize(&blk->T); DSDPCHKERR(info);
info = DSDPLanczosInitialize(&blk->Lanczos); DSDPCHKERR(info);
info = DSDPBlockDataInitialize(&blk->ADATA); DSDPCHKERR(info);
info = DSDPIndexInitialize(&blk->IS); DSDPCHKERR(info);
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "DSDPBlockTakeDown"
int DSDPBlockTakeDown(SDPblk *blk){
int info;
DSDPFunctionBegin;
if (!blk){DSDPFunctionReturn(0);}
info=DSDPBlockTakeDownData(&blk->ADATA);DSDPCHKERR(info);
info=SDPConeVecDestroy(&blk->W);DSDPCHKERR(info);
info=SDPConeVecDestroy(&blk->W2);DSDPCHKERR(info);
info=DSDPIndexDestroy(&blk->IS);DSDPCHKERR(info);
info=DSDPLanczosDestroy(&blk->Lanczos);DSDPCHKERR(info);
info=DSDPDualMatDestroy(&blk->SS);DSDPCHKERR(info);
info=DSDPDualMatDestroy(&blk->S);DSDPCHKERR(info);
info=DSDPDSMatDestroy(&blk->DS);DSDPCHKERR(info);
info=DSDPVMatDestroy(&blk->T);DSDPCHKERR(info);
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "DSDPConeTakeDown"
int DSDPConeTakeDown(SDPCone sdpcone){
int blockj,info;
DSDPFunctionBegin;
for (blockj=0; blockj<sdpcone->nblocks; blockj++){
info=DSDPBlockTakeDown(&sdpcone->blk[blockj]);DSDPCHKERR(info);
}
info=DSDPVecDestroy(&sdpcone->Work);DSDPCHKERR(info);
info=DSDPVecDestroy(&sdpcone->Work2);DSDPCHKERR(info);
info=DSDPVecDestroy(&sdpcone->YY);DSDPCHKERR(info);
info=DSDPVecDestroy(&sdpcone->YX);DSDPCHKERR(info);
info=DSDPVecDestroy(&sdpcone->DYX);DSDPCHKERR(info);
info=DSDPDataTransposeTakeDown(&sdpcone->ATR);DSDPCHKERR(info);
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "SDPConeDestroy"
int SDPConeDestroy(SDPCone sdpcone){
int blockj,info;
DSDPFunctionBegin;
info=DSDPConeTakeDown(sdpcone);DSDPCHKERR(info);
for (blockj=0; blockj<sdpcone->nblocks; blockj++){
info=DSDPBlockDataDestroy(&sdpcone->blk[blockj].ADATA);DSDPCHKERR(info);
}
DSDPFREE(&sdpcone->blk,&info);DSDPCHKERR(info);
DSDPFREE(&sdpcone,&info);DSDPCHKERR(info);
info=DSDPBlockEventZero();DSDPCHKERR(info);
info=DSDPDualMatEventZero();DSDPCHKERR(info);
info=DSDPVMatEventZero();DSDPCHKERR(info);
DSDPFunctionReturn(0);
}
SDPConeSetRIdentity
int SDPConeSetRIdentity(SDPCone sdpcone, int blockj, int n, double rr)
Add identify matrix to dual matrix.
Definition dsdpadddatamat.c:438
DSDPBlockDataDestroy
int DSDPBlockDataDestroy(DSDPBlockData *ADATA)
Free the data matrices.
Definition dsdpblock.c:195
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
DSDPBlockDataInitialize
int DSDPBlockDataInitialize(DSDPBlockData *ADATA)
Set pointers to null.
Definition dsdpblock.c:163
DSDPBlockDataMarkNonzeroMatrices
int DSDPBlockDataMarkNonzeroMatrices(DSDPBlockData *ADATA, int *annz)
Mark which variable in block have a data matrix.
Definition dsdpblock.c:254
DSDPBlockCountNonzeroMatrices
int DSDPBlockCountNonzeroMatrices(DSDPBlockData *ADATA, int *nzmats)
Count how many data matrices are in a block of data.
Definition dsdpblock.c:272
DSDPBlockFactorData
int DSDPBlockFactorData(DSDPBlockData *ADATA, DSDPVMat X, SDPConeVec W)
Factor the data matrices.
Definition dsdpblock.c:113
DSDPBlockTakeDownData
int DSDPBlockTakeDownData(DSDPBlockData *ADATA)
Free structures in block of data.
Definition dsdpblock.c:182
DSDPDataMatCountNonzeros
int DSDPDataMatCountNonzeros(DSDPDataMat A, int *nnz, int n)
Compute the square of the Frobenius norm.
Definition dsdpdatamat.c:152
DSDPDSMatDestroy
int DSDPDSMatDestroy(DSDPDSMat *A)
Free the data structure.
Definition dsdpdsmat.c:70
DSDPDSMatInitialize
int DSDPDSMatInitialize(DSDPDSMat *B)
Set pointers to null.
Definition dsdpdsmat.c:254
DSDPDualMatInitialize
int DSDPDualMatInitialize(DSDPDualMat *S)
Set pointers to null.
Definition dsdpdualmat.c:471
DSDPDualMatDestroy
int DSDPDualMatDestroy(DSDPDualMat *S)
Free the matrix structure.
Definition dsdpdualmat.c:65
DSDPFastLanczosSetup
int DSDPFastLanczosSetup(DSDPLanczosStepLength *, SDPConeVec)
Use Lanczos procedure. Assume off tridiagonal entries are zero.
Definition dsdpstep.c:133
DSDPLanczosDestroy
int DSDPLanczosDestroy(DSDPLanczosStepLength *)
Free data structure.
Definition dsdpstep.c:191
DSDPLanczosInitialize
int DSDPLanczosInitialize(DSDPLanczosStepLength *)
Initialize Lanczos structure.
Definition dsdpstep.c:92
DSDPSetMaximumLanczosIterations
int DSDPSetMaximumLanczosIterations(DSDPLanczosStepLength *LZ, int)
Set parameter.
Definition dsdpstep.c:119
DSDPRobustLanczosSetup
int DSDPRobustLanczosSetup(DSDPLanczosStepLength *, SDPConeVec)
Use slowerer but more robust method.
Definition dsdpstep.c:163
dsdpsdp.h
Internal SDPCone data structures and routines.
DSDPAddSDP
int DSDPAddSDP(DSDP, SDPCone)
Pass a semidefinite cone to the solver.
Definition sdpkcone.c:331
DSDPMakeVMat
int DSDPMakeVMat(char, int, DSDPVMat *)
Allocate V matrix.
Definition sdpsss.c:351
dsdpsys.h
Error handling, printing, and profiling.
DSDPVec
struct DSDPVec_C DSDPVec
This object hold m+2 variables: a scaling of C, the y variables, and r.
Definition dsdpvec.h:25
DSDPVMatInitialize
int DSDPVMatInitialize(DSDPVMat *B)
Set pointers to null.
Definition dsdpxmat.c:424
DSDPVMatExist
int DSDPVMatExist(DSDPVMat X, int *flag)
Answer whether the array has been allocated or not.
Definition dsdpxmat.c:440
DSDPVMatDestroy
int DSDPVMatDestroy(DSDPVMat *X)
Deallocate matrix.
Definition dsdpxmat.c:86
DSDPConeTakeDown
int DSDPConeTakeDown(SDPCone sdpcone)
Free data structure of the cone.
Definition sdpconesetup.c:328
DSDPBlockTakeDown
int DSDPBlockTakeDown(SDPblk *blk)
Free data structures in one block of the cone.
Definition sdpconesetup.c:305
DSDPBlockSetup
int DSDPBlockSetup(SDPblk *blk, int blockj, DSDPVec WY)
Allocate data structures of one block the cone.
Definition sdpconesetup.c:154
DSDPCreateS
int DSDPCreateS(DSDPBlockData *, char, int, DSDPVec, DSDPVMat, SDPConeVec, SDPConeVec, DSDPDualMat *, DSDPDualMat *, DSDPDSMat *, void *)
Create S1, S2, and DS.
Definition sdpsss.c:314
DSDPBlockInitialize
int DSDPBlockInitialize(SDPblk *blk)
Initialize data structures in one block of the cone.
Definition sdpconesetup.c:279
SDPConeSetup
int SDPConeSetup(SDPCone sdpcone, DSDPVec yy0)
Allocate data structure of the cone.
Definition sdpconesetup.c:249
SDPConeDestroy
int SDPConeDestroy(SDPCone sdpcone)
Free data structure of the cone.
Definition sdpconesetup.c:350
SDPConeSetup2
int SDPConeSetup2(SDPCone sdpcone, DSDPVec yy0, DSDPSchurMat M)
Allocate data structure of the cone.
Definition sdpconesetup.c:224
DSDPDataTransposeSetup
int DSDPDataTransposeSetup(DSDPDataTranspose *ATranspose, SDPblk *blk, int nblocks, int m)
Set up transpose structure for data.
Definition sdpconesetup.c:36
DSDPDataTransposeTakeDown
int DSDPDataTransposeTakeDown(DSDPDataTranspose *ATranspose)
Free transpose structure for data.
Definition sdpconesetup.c:89
DSDPDataTransposeInitialize
int DSDPDataTransposeInitialize(DSDPDataTranspose *ATranspose)
Initialize transpose structure for data.
Definition sdpconesetup.c:15
SDPConeVecDuplicate
int SDPConeVecDuplicate(SDPConeVec V1, SDPConeVec *V2)
Allocate another vector with the same structure as the first.
Definition sdpconevec.c:195
DSDPIndexDestroy
int DSDPIndexDestroy(DSDPIndex *IS)
Deallocate memory.
Definition sdpconevec.c:264
DSDPIndexCreate
int DSDPIndexCreate(int n, DSDPIndex *IS)
Allocate array for indices.
Definition sdpconevec.c:248
DSDPIndexInitialize
int DSDPIndexInitialize(DSDPIndex *IS)
Set structure pointers to 0.
Definition sdpconevec.c:234
DSDPBlockData
Internal structure for data in one block of semidefintie.
Definition dsdpsdp.h:39
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
DSDPDataTranspose
Internal structure for transpose of data.
Definition dsdpsdp.h:25
DSDPDualMat_C
Represents an S matrix for one block in the semidefinite cone.
Definition dsdpdualmat.h:18
DSDPSchurMat_C
Schur complement matrix whose solution is the Newton direction.
Definition dsdpschurmat.h:35
DSDPVMat_C
Dense symmetric matrix for one block in the semidefinite cone.
Definition dsdpxmat.h:17
DSDP_C
Internal structures for the DSDP solver.
Definition dsdp.h:65
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
SDPblk
Internal structure for block of semidefinite cone.
Definition dsdpsdp.h:52