DSDP
dsdprescone.c
Go to the documentation of this file.
1#include "dsdpcone_impl.h"
2#include "dsdpsys.h"
3#include "dsdpbasictypes.h"
9struct RDCone{
10 double primalr,dualr,x,logr;
11 DSDPPenalty UsePenalty;
12 DSDP dsdp; /* Really only need the Penalty flag, which is here. */
13};
14
15typedef struct RDCone RCone;
16
17#undef __FUNCT__
18#define __FUNCT__ "DSDPRHessian"
19static int DSDPRHessian( void *dspcone, double mu, DSDPSchurMat M, DSDPVec vrhs1, DSDPVec vrhs2){
20 RCone *K=(RCone*)dspcone;
21 int info,m;
22 double rr,sr,rssr;
23 DSDPFunctionBegin;
24 if (K->dualr ){
25 info=DSDPVecGetSize(vrhs2,&m);DSDPCHKERR(info);
26 info=DSDPSchurMatVariableCompute(M,m-1,&rr);DSDPCHKERR(info);
27 if (rr){
28 sr=-mu*rr/(K->dualr);
29 rssr=mu*rr/(K->dualr*K->dualr);
30 info=DSDPVecAddR(vrhs2,sr);DSDPCHKERR(info);
31 info=DSDPSchurMatAddDiagonalElement(M,m-1,rssr);DSDPCHKERR(info);
32 }
33 }
34 DSDPFunctionReturn(0);
35}
36
37
38#undef __FUNCT__
39#define __FUNCT__ "DSDPRHS"
40static int DSDPRHS( void *dspcone, double mu, DSDPVec vrow,DSDPVec vrhs1,DSDPVec vrhs2){
41 RCone *K=(RCone*)dspcone;
42 int info;
43 double rr,sr;
44 DSDPFunctionBegin;
45 if (K->dualr ){
46 sr=-mu/(K->dualr);
47 info=DSDPVecGetR(vrow,&rr);DSDPCHKERR(info);
48 info=DSDPVecAddR(vrhs2,rr*sr);DSDPCHKERR(info);
49 }
50 DSDPFunctionReturn(0);
51}
52
53
54#undef __FUNCT__
55#define __FUNCT__ "DSDPSetupRCone"
56static int DSDPSetupRCone(void* dspcone,DSDPVec y){
57 DSDPFunctionBegin;
58 DSDPFunctionReturn(0);
59}
60
61#undef __FUNCT__
62#define __FUNCT__ "DSDPSetupRCone2"
63static int DSDPSetupRCone2(void* dspcone, DSDPVec y, DSDPSchurMat M){
64 DSDPFunctionBegin;
65 DSDPFunctionReturn(0);
66}
67
68
69#undef __FUNCT__
70#define __FUNCT__ "DSDPDestroyRCone"
71static int DSDPDestroyRCone(void* dspcone){
72 int info;
73 DSDPFunctionBegin;
74 DSDPFREE(&dspcone,&info);DSDPCHKERR(info);
75 DSDPFunctionReturn(0);
76}
77
78
79#undef __FUNCT__
80#define __FUNCT__ "DSDPRSize"
81static int DSDPRSize(void*dspcone,double *n){
82 RCone *K=(RCone*)dspcone;
83 DSDPFunctionBegin;
84 if (K->dualr){*n=1;}
85 else {*n=0;}
86 DSDPFunctionReturn(0);
87}
88
89#undef __FUNCT__
90#define __FUNCT__ "DSDPRSparsity"
91static int DSDPRSparsity(void*dspcone,int row, int *tnnz, int rnnz[], int m){
92 DSDPFunctionBegin;
93 *tnnz=0;
94 DSDPFunctionReturn(0);
95}
96
97
98#undef __FUNCT__
99#define __FUNCT__ "DSDPComputeRS"
100static int DSDPComputeRS(void *dspcone, DSDPVec Y, DSDPDualFactorMatrix flag, DSDPTruth *ispsdefinite){
101 RCone *K=(RCone*)dspcone;
102 int info;
103 double rbeta;
104 DSDPFunctionBegin;
105 info=DSDPVecGetR(Y,&rbeta); DSDPCHKERR(info);
106 if (K->UsePenalty==DSDPAlways){
107 if (rbeta<0){ *ispsdefinite=DSDP_TRUE; } else { *ispsdefinite=DSDP_FALSE;}
108 } else {
109 if (rbeta>0) rbeta=0;
110 *ispsdefinite=DSDP_TRUE;
111 }
112 if (flag==DUAL_FACTOR){ K->dualr=rbeta; } else { K->primalr=rbeta;}
113 DSDPFunctionReturn(0);
114}
115#undef __FUNCT__
116#define __FUNCT__ "DSDPInvertRS"
117static int DSDPInvertRS(void *dspcone){
118 DSDPFunctionBegin;
119 DSDPFunctionReturn(0);
120}
121
122
123
124#undef __FUNCT__
125#define __FUNCT__ "DSDPComputeRStepLength"
126static int DSDPComputeRStepLength(void *dspcone, DSDPVec DY, DSDPDualFactorMatrix flag, double *maxsteplength){
127 RCone *K=(RCone*)dspcone;
128 double r,rbeta,msteplength=1.0e100,rt=1.0e30;
129 int info;
130 DSDPFunctionBegin;
131
132 info=DSDPVecGetR(DY,&rbeta); DSDPCHKERR(info);
133 if (flag==DUAL_FACTOR){ r=K->dualr; } else { r=K->primalr;}
134 if (r * rbeta<0) rt=-r/rbeta;
135
136 if (K->UsePenalty==DSDPAlways){msteplength=rt;}
137 else if (flag==PRIMAL_FACTOR){ msteplength=rt;}
138 else if (flag==DUAL_FACTOR){msteplength=rt/0.94;}
139
140 *maxsteplength=msteplength;
141 DSDPFunctionReturn(0);
142}
143
144#undef __FUNCT__
145#define __FUNCT__ "DSDPRX"
146static int DSDPRX( void *dspcone, double mu, DSDPVec y, DSDPVec dy, DSDPVec AX,double *tracexs){
147 RCone *K=(RCone*)dspcone;
148 int info;
149 double rr,dr,trxs,r=K->dualr;
150 DSDPFunctionBegin;
151
152 info=DSDPVecGetR(y,&rr); DSDPCHKERR(info);
153 info=DSDPVecGetR(dy,&dr); DSDPCHKERR(info);
154 if (K->dualr){
155 r=-1.0/rr;
156 K->x=mu*(r-r*dr*r);
157 trxs=K->x/r;
158 DSDPLogInfo(0,2,"RESIDUAL X (Minimum Penalty Parameter): %4.4e, Trace(XS): %4.4e\n",K->x,trxs);
159 /* *tracexs=trxs */
160 } else {
161 K->x=0.0;
162 }
163 DSDPFunctionReturn(0);
164}
165
166#undef __FUNCT__
167#define __FUNCT__ "DSDPSetX"
168static int DSDPSetX( void *dspcone, double mu, DSDPVec y, DSDPVec dy){
169 RCone *K=(RCone*)dspcone;
170 int info;
171 double rr,dr,trxs,r;
172 DSDPFunctionBegin;
173
174 info=DSDPVecGetR(y,&rr); DSDPCHKERR(info);
175 info=DSDPVecGetR(dy,&dr); DSDPCHKERR(info);
176 if (rr){
177 r=-1.0/rr;
178 K->x=mu*(r-r*dr*r);
179 trxs=K->x/r;
180 DSDPLogInfo(0,2,"RESIDUAL X (Minimum Penalty Parameter): %4.4e, Trace(XS): %4.4e\n",K->x,trxs);
181 /* *tracexs=trxs */
182 } else {
183 K->x=0.0;
184 }
185 DSDPFunctionReturn(0);
186}
187
188#undef __FUNCT__
189#define __FUNCT__ "DSDPComputeRLog"
190static int DSDPComputeRLog(void *dspcone, double *logobj, double *logdet){
191 RCone *K=(RCone*)dspcone;
192 DSDPFunctionBegin;
193 *logdet=K->logr;
194 *logobj=0;
195 if (K->dualr<0){
196 *logdet=log(-K->dualr);
197 K->logr=log(-K->dualr);
198 }
199 DSDPFunctionReturn(0);
200}
201
202#undef __FUNCT__
203#define __FUNCT__ "DSDPRANorm2"
204static int DSDPRANorm2(void *dspcone,DSDPVec Anorm2){
205 DSDPFunctionBegin;
206 DSDPFunctionReturn(0);
207}
208
209#undef __FUNCT__
210#define __FUNCT__ "DSDPRMultiplyAdd"
211static int DSDPRMultiplyAdd(void *dspcone,double mu,DSDPVec vrow,DSDPVec vin,DSDPVec vout){
212 RCone *K=(RCone*)dspcone;
213 int info;
214 double v1,v2,rssr;
215 DSDPFunctionBegin;
216 if (K->dualr){
217 info=DSDPVecGetR(vrow,&v1);DSDPCHKERR(info);
218 info=DSDPVecGetR(vin,&v2);DSDPCHKERR(info);
219 rssr=v1*v2*mu/(K->dualr*K->dualr);
220 info=DSDPVecAddR(vout,rssr);DSDPCHKERR(info);
221 }
222 DSDPFunctionReturn(0);
223}
224
225#undef __FUNCT__
226#define __FUNCT__ "DSDPRMonitor"
227static int DSDPRMonitor( void *dspcone, int tag){
228 DSDPFunctionBegin;
229 DSDPFunctionReturn(0);
230}
231
232static struct DSDPCone_Ops kops;
233static const char* matname="R Cone";
234
235#undef __FUNCT__
236#define __FUNCT__ "RConeOperationsInitialize"
237static int RConeOperationsInitialize(struct DSDPCone_Ops* coneops){
238 int info;
239 if (coneops==NULL) return 0;
240 info=DSDPConeOpsInitialize(coneops); DSDPCHKERR(info);
241 coneops->conehessian=DSDPRHessian;
242 coneops->conesetup=DSDPSetupRCone;
243 coneops->conesetup2=DSDPSetupRCone2;
244 coneops->conedestroy=DSDPDestroyRCone;
245 coneops->conecomputes=DSDPComputeRS;
246 coneops->coneinverts=DSDPInvertRS;
247 coneops->conesetxmaker=DSDPSetX;
248 coneops->conecomputex=DSDPRX;
249 coneops->conerhs=DSDPRHS;
250 coneops->conemaxsteplength=DSDPComputeRStepLength;
251 coneops->conelogpotential=DSDPComputeRLog;
252 coneops->conesize=DSDPRSize;
253 coneops->conesparsity=DSDPRSparsity;
254 coneops->coneanorm2=DSDPRANorm2;
255 coneops->conemonitor=DSDPRMonitor;
256 coneops->conehmultiplyadd=DSDPRMultiplyAdd;
257 coneops->id=19;
258 coneops->name=matname;
259 return 0;
260}
261
262/*
263\fn int RConeSetType(RCone *rcone, DSDPPenalty UsePenalty);
264\brief Set penalty type.
265
266\param dsdp the solver
267\param UsePenalty true or false
268*/
269#undef __FUNCT__
270#define __FUNCT__ "RConeSetType"
271int RConeSetType(RCone *rcone, DSDPPenalty UsePenalty){
272 DSDPFunctionBegin;
273 rcone->UsePenalty=UsePenalty;
274 DSDPFunctionReturn(0);
275}
276/*
277\fn int RConeGetRX(RCone *rcone, double *rx);
278\brief Get slack of trace of matrix
279
280\param rcone cone
281\param rx dual of r.
282Accurate only when r > 0.
283
284*/
285#undef __FUNCT__
286#define __FUNCT__ "RConeGetRX"
287int RConeGetRX(RCone *rcone, double *xtrace){
288 DSDPFunctionBegin;
289 *xtrace=rcone->x;
290 DSDPFunctionReturn(0);
291}
292
300#undef __FUNCT__
301#define __FUNCT__ "DSDPAddRCone"
302int DSDPAddRCone(DSDP dsdp, RCone **rrcone){
303 RCone *rcone;
304 DSDPPenalty UsePenalty=DSDPInfeasible;
305 int info;
306 DSDPFunctionBegin;
307 info=RConeOperationsInitialize(&kops); DSDPCHKERR(info);
308 DSDPCALLOC1(&rcone,RCone,&info); DSDPCHKERR(info);
309 info=RConeSetType(rcone,UsePenalty); DSDPCHKERR(info);
310 rcone->dsdp=dsdp;
311 rcone->logr=0;
312 *rrcone=rcone;
313 info=DSDPAddCone(dsdp,&kops,(void*)rcone); DSDPCHKERR(info);
314 DSDPFunctionReturn(0);
315}
316
Solver, solution types, termination codes,.
DSDPDualFactorMatrix
DSDP requires two instances of the data structures S.
@ PRIMAL_FACTOR
@ DUAL_FACTOR
DSDPTruth
Boolean variables.
@ DSDP_FALSE
@ DSDP_TRUE
int DSDPConeOpsInitialize(struct DSDPCone_Ops *dops)
Initialize the function pointers to 0.
Definition dsdpcone.c:443
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.
Definition dsdpcops.c:569
int DSDPAddRCone(DSDP dsdp, RCone **rrcone)
A separate cone specifies that r must be nonnegative.
int DSDPSchurMatVariableCompute(DSDPSchurMat, int, double *)
Determine with the cone should compute this diagonal element of M and RHS.
int DSDPSchurMatAddDiagonalElement(DSDPSchurMat, int, double)
Determine with the cone should compute this diagonal element of M and RHS.
Error handling, printing, and profiling.
struct DSDPVec_C DSDPVec
This object hold m+2 variables: a scaling of C, the y variables, and r.
Definition dsdpvec.h:25
Schur complement matrix whose solution is the Newton direction.
Internal structures for the DSDP solver.
Definition dsdp.h:65