DSDP
dsdpsetdata.c
Go to the documentation of this file.
1
6#include "dsdp.h"
7#include "dsdp5.h"
8#include "dsdpsys.h"
9
23#undef __FUNCT__
24#define __FUNCT__ "DSDPSetDualObjective"
25int DSDPSetDualObjective(DSDP dsdp,int i, double bi){
26 int info;
27 DSDPFunctionBegin;
28 DSDPValid(dsdp);
29 if (i>dsdp->m || i<=0){
30 DSDPSETERR2(1,"Invalid variable number: Is 1 <= %d <= %d?\n",i,dsdp->m);}
31 info=DSDPVecSetElement(dsdp->b,i,bi);DSDPCHKERR(info);
32 DSDPFunctionReturn(0);
33}
34
44#undef __FUNCT__
45#define __FUNCT__ "DSDPCopyB"
46int DSDPCopyB(DSDP dsdp,double bb[], int m){
47 int i,info;
48 double *b;
49 DSDPFunctionBegin;
50 DSDPValid(dsdp);
51 if (dsdp->m < m) DSDPFunctionReturn(1);
52 info=DSDPVecGetArray(dsdp->b,&b);DSDPCHKERR(info);
53 for (i=0;i<m;i++) bb[i]=b[i+1];
54 info=DSDPVecRestoreArray(dsdp->b,&b);DSDPCHKERR(info);
55 DSDPFunctionReturn(0);
56}
57
58
75#undef __FUNCT__
76#define __FUNCT__ "DSDPSetY0"
77int DSDPSetY0(DSDP dsdp,int i, double yi0){
78 int info;double scale;
79 DSDPFunctionBegin;
80 DSDPValid(dsdp);
81 if (i>dsdp->m || i<=0){
82 DSDPSETERR2(1,"Invalid variable number: Is 1<= %d <= %d\n",i,dsdp->m);}
83 info=DSDPGetScale(dsdp,&scale);DSDPCHKERR(info);
84 info=DSDPVecSetElement(dsdp->y,i,scale*yi0);DSDPCHKERR(info);
85 DSDPFunctionReturn(0);
86}
87
98#undef __FUNCT__
99#define __FUNCT__ "DSDPGetY"
100int DSDPGetY(DSDP dsdp,double y[], int m){
101 int i,info;
102 double scale,*yy;
103 DSDPFunctionBegin;
104 DSDPValid(dsdp);
105 if (dsdp->m < m-1) DSDPFunctionReturn(1);
106 if (dsdp->m > m) DSDPFunctionReturn(1);
107 info=DSDPVecCopy(dsdp->xmaker[0].y,dsdp->ytemp); DSDPCHKERR(info);
108 info=DSDPGetScale(dsdp,&scale);DSDPCHKERR(info);
109 info=DSDPVecGetArray(dsdp->ytemp,&yy);DSDPCHKERR(info);
110 for (i=0;i<m;i++) y[i]=yy[i+1]/scale;
111 info=DSDPVecRestoreArray(dsdp->ytemp,&yy);DSDPCHKERR(info);
112 DSDPFunctionReturn(0);
113}
114
115
116
126#undef __FUNCT__
127#define __FUNCT__ "DSDPGetScale"
128int DSDPGetScale(DSDP dsdp,double *scale){
129 int info;double sscale;
130 DSDPFunctionBegin;
131 DSDPValid(dsdp);
132 info=DSDPVecGetC(dsdp->y,&sscale);DSDPCHKERR(info);
133 *scale=fabs(sscale);
134 if (sscale==0) *scale=1.0;
135 DSDPFunctionReturn(0);
136}
137
151#undef __FUNCT__
152#define __FUNCT__ "DSDPSetScale"
153int DSDPSetScale(DSDP dsdp,double scale){
154 int info;double sscale;
155 DSDPFunctionBegin;
156 DSDPValid(dsdp);
157 scale=fabs(scale);
158 if (scale==0) scale=1.0;
159 info=DSDPGetScale(dsdp,&sscale);DSDPCHKERR(info);
160 sscale=scale/sscale;
161 info=DSDPVecScale(sscale,dsdp->y);
162 dsdp->mutarget*=sscale;
163 dsdp->pobj*=sscale;
164 dsdp->dobj*=sscale;
165 dsdp->ppobj*=sscale;
166 dsdp->ddobj*=sscale;
167 dsdp->mu*=sscale;
168 DSDPLogInfo(0,2,"Set DSDP C Scaling: %4.4e\n",scale);
169 DSDPFunctionReturn(0);
170}
171
183#undef __FUNCT__
184#define __FUNCT__ "DSDPAddObjectiveConstant"
185int DSDPAddObjectiveConstant(DSDP dsdp,double c){
186 int info;
187 DSDPFunctionBegin;
188 DSDPValid(dsdp);
189 info=DSDPVecSetC(dsdp->b,-c);DSDPCHKERR(info);
190 DSDPLogInfo(0,2,"Add Objective Constant: %4.4e\n",c);
191 DSDPFunctionReturn(0);
192}
193
204#undef __FUNCT__
205#define __FUNCT__ "DSDPSetMaxIts"
206int DSDPSetMaxIts(DSDP dsdp,int its){
207 DSDPFunctionBegin;
208 DSDPValid(dsdp);
209 if (its >= 0) dsdp->maxiter = its;
210 DSDPLogInfo(0,2,"Set Maximum Iterates: %4d\n",its);
211 DSDPFunctionReturn(0);
212}
213
223#undef __FUNCT__
224#define __FUNCT__ "DSDPGetMaxIts"
225int DSDPGetMaxIts(DSDP dsdp,int *its){
226 DSDPFunctionBegin;
227 DSDPValid(dsdp);
228 *its=dsdp->maxiter;
229 DSDPFunctionReturn(0);
230}
231
232
244#undef __FUNCT__
245#define __FUNCT__ "DSDPSetMaxTrustRadius"
246int DSDPSetMaxTrustRadius(DSDP dsdp,double rad){
247 DSDPFunctionBegin;
248 DSDPValid(dsdp);
249 if (rad > 0) dsdp->maxtrustradius = rad;
250 DSDPLogInfo(0,2,"Set Maximum Trust Radius: %4.4e\n",rad);
251 DSDPFunctionReturn(0);
252}
253
263#undef __FUNCT__
264#define __FUNCT__ "DSDPGetMaxTrustRadius"
265int DSDPGetMaxTrustRadius(DSDP dsdp,double *rad){
266 DSDPFunctionBegin;
267 DSDPValid(dsdp);
268 *rad=dsdp->maxtrustradius;
269 DSDPFunctionReturn(0);
270}
271
281#undef __FUNCT__
282#define __FUNCT__ "DSDPSetZBar"
283int DSDPSetZBar(DSDP dsdp,double ppobj){
284 int info;
285 double scale;
286 DSDPFunctionBegin;
287 DSDPValid(dsdp);
288 info=DSDPGetScale(dsdp,&scale);DSDPCHKERR(info);
289 dsdp->ppobj=ppobj*scale;
290 DSDPLogInfo(0,2,"Set Primal Objective and Upper bound on solution: %4.4e. \n",ppobj);
291 DSDPFunctionReturn(0);
292}
293
309#undef __FUNCT__
310#define __FUNCT__ "DSDPSetR0"
311int DSDPSetR0(DSDP dsdp,double res){
312 int info;
313 double scale;
314 DSDPFunctionBegin;
315 DSDPValid(dsdp);
316 info=DSDPGetScale(dsdp,&scale);DSDPCHKERR(info);
317 info=DSDPSetRR(dsdp,scale*res); DSDPCHKERR(info);
318 if (res>=0)dsdp->goty0=DSDP_TRUE;
319 DSDPLogInfo(0,2,"Set Dual Initial Infeasibility to %4.4e times Identity Matrix. \n",res);
320 DSDPFunctionReturn(0);
321}
322
338#undef __FUNCT__
339#define __FUNCT__ "DSDPSetBarrierParameter"
340int DSDPSetBarrierParameter(DSDP dsdp,double mu){
341 int info;double scale;
342 DSDPFunctionBegin;
343 DSDPValid(dsdp);
344 info=DSDPGetScale(dsdp,&scale);DSDPCHKERR(info);
345 dsdp->mutarget = mu*scale;
346 DSDPLogInfo(0,2,"Set InitialBarrierParameter: %4.4e \n",mu);
347 DSDPFunctionReturn(0);
348}
349
362#undef __FUNCT__
363#define __FUNCT__ "DSDPGetBarrierParameter"
364int DSDPGetBarrierParameter(DSDP dsdp, double *mu){
365 int info;double scale;
366 DSDPFunctionBegin;
367 info=DSDPGetScale(dsdp,&scale);DSDPCHKERR(info);
368 *mu=dsdp->mutarget/scale;
369 DSDPFunctionReturn(0);
370}
371
372
381#undef __FUNCT__
382#define __FUNCT__ "DSDPUsePenalty"
383int DSDPUsePenalty(DSDP dsdp,int yesorno){
384 DSDPPenalty UsePenalty;
385 int info;
386 DSDPFunctionBegin;
387 DSDPValid(dsdp);
388 if (yesorno>0){
389 UsePenalty=DSDPAlways;
390 } else if (yesorno<0){
391 UsePenalty=DSDPNever;
392 } else {
393 UsePenalty=DSDPInfeasible;
394 }
395 dsdp->UsePenalty=UsePenalty;
396 info=RConeSetType(dsdp->rcone,UsePenalty);DSDPCHKERR(info);
397 DSDPLogInfo(0,2,"Set UsePenalty: %d \n",yesorno);
398 DSDPFunctionReturn(0);
399}
400
416#undef __FUNCT__
417#define __FUNCT__ "DSDPSetPenaltyParameter"
418int DSDPSetPenaltyParameter(DSDP dsdp,double Gamma){
419 int info;
420 double scale,ppenalty;
421 DSDPFunctionBegin;
422 DSDPValid(dsdp);
423 info=DSDPGetScale(dsdp,&scale);DSDPCHKERR(info);
424 ppenalty=fabs(Gamma*scale);
425 info=DSDPVecSetR(dsdp->b,ppenalty);DSDPCHKERR(info);
426 DSDPLogInfo(0,2,"Set Penalty Parameter: %4.4e\n",Gamma);
427 DSDPFunctionReturn(0);
428}
429
441#undef __FUNCT__
442#define __FUNCT__ "DSDPGetPenaltyParameter"
443int DSDPGetPenaltyParameter(DSDP dsdp,double *Gamma){
444 int info;
445 double ppenalty;
446 DSDPFunctionBegin;
447 DSDPValid(dsdp);
448 info=DSDPVecGetR(dsdp->b,&ppenalty);DSDPCHKERR(info);
449 *Gamma=fabs(ppenalty);
450 DSDPFunctionReturn(0);
451}
452
453/* Not current; not documented
454*/
455#undef __FUNCT__
456#define __FUNCT__ "DSDPGetPenalty"
457int DSDPGetPenalty(DSDP dsdp,double *penalty){
458 int info;double ppenalty;
459 DSDPFunctionBegin;
460 DSDPValid(dsdp);
461 info=DSDPVecGetR(dsdp->b,&ppenalty);DSDPCHKERR(info);
462 *penalty=fabs(ppenalty);
463 DSDPFunctionReturn(0);
464}
465
466
467
477#undef __FUNCT__
478#define __FUNCT__ "DSDPGetPPObjective"
479int DSDPGetPPObjective(DSDP dsdp,double *ppobj){
480 int info;
481 double scale;
482 DSDPFunctionBegin;
483 DSDPValid(dsdp);
484 info=DSDPGetScale(dsdp,&scale);DSDPCHKERR(info);
485 *ppobj=(dsdp->ppobj)/scale;
486 if (dsdp->cnorm==0) *ppobj=0;
487 DSDPFunctionReturn(0);
488}
489
500#undef __FUNCT__
501#define __FUNCT__ "DSDPGetDObjective"
502int DSDPGetDObjective(DSDP dsdp,double *dobj){
503 int info; double scale;
504 DSDPFunctionBegin;
505 DSDPValid(dsdp);
506 info=DSDPGetScale(dsdp,&scale);DSDPCHKERR(info);
507 *dobj = (dsdp->dobj)/scale;
508 if (dsdp->cnorm==0) *dobj=-fabs(*dobj);
509 DSDPFunctionReturn(0);
510}
521#undef __FUNCT__
522#define __FUNCT__ "DSDPGetDDObjective"
523int DSDPGetDDObjective(DSDP dsdp,double *ddobj){
524 int info; double scale;
525 DSDPFunctionBegin;
526 DSDPValid(dsdp);
527 info=DSDPGetScale(dsdp,&scale);DSDPCHKERR(info);
528 *ddobj = (dsdp->ddobj)/scale;
529 if (dsdp->cnorm==0) *ddobj=-fabs(*ddobj);
530 DSDPFunctionReturn(0);
531}
532
543#undef __FUNCT__
544#define __FUNCT__ "DSDPGetDualityGap"
545int DSDPGetDualityGap(DSDP dsdp,double *dgap){
546 int info; double scale;
547 DSDPFunctionBegin;
548 DSDPValid(dsdp);
549 info=DSDPGetScale(dsdp,&scale);DSDPCHKERR(info);
550 *dgap = (dsdp->dualitygap)/scale;
551 DSDPFunctionReturn(0);
552}
553
562#undef __FUNCT__
563#define __FUNCT__ "DSDPGetIts"
564int DSDPGetIts(DSDP dsdp,int *its){
565 DSDPFunctionBegin;
566 DSDPValid(dsdp);
567 *its=dsdp->itnow;
568 DSDPFunctionReturn(0);
569}
570
580#undef __FUNCT__
581#define __FUNCT__ "DSDPStopReason"
582int DSDPStopReason(DSDP dsdp,DSDPTerminationReason *reason){
583 DSDPFunctionBegin;
584 DSDPValid(dsdp);
585 *reason=dsdp->reason;
586 DSDPFunctionReturn(0);
587}
588
589
599#undef __FUNCT__
600#define __FUNCT__ "DSDPGetR"
601int DSDPGetR(DSDP dsdp, double *res){
602 int info;double rr,scale;
603 DSDPFunctionBegin;
604 DSDPValid(dsdp);
605 info=DSDPGetRR(dsdp,&rr);DSDPCHKERR(info);
606 info=DSDPGetScale(dsdp,&scale);DSDPCHKERR(info);
607 *res=rr/scale;
608 DSDPFunctionReturn(0);
609}
610
619#undef __FUNCT__
620#define __FUNCT__ "DSDPGetDataNorms"
621int DSDPGetDataNorms(DSDP dsdp, double dnorm[3]){
622 int info;
623 DSDPFunctionBegin;
624 DSDPValid(dsdp);
625 if (dsdp->setupcalled==DSDP_FALSE){
626 info=DSDPComputeDataNorms(dsdp);DSDPCHKERR(info);
627 }
628 dnorm[0]=dsdp->cnorm;
629 dnorm[1]=dsdp->anorm;
630 dnorm[2]=dsdp->bnorm;
631 DSDPFunctionReturn(0);
632}
633
634
643#undef __FUNCT__
644#define __FUNCT__ "DSDPGetMaxYElement"
645int DSDPGetMaxYElement(DSDP dsdp,double* ymax){
646 int info;
647 DSDPFunctionBegin;
648 info=DSDPGetYMaxNorm(dsdp,ymax);DSDPCHKERR(info);
649 DSDPFunctionReturn(0);
650}
651
652#undef __FUNCT__
653#define __FUNCT__ "DSDPGetDimension"
661int DSDPGetDimension(DSDP dsdp, double *n){
662 int info;
663 DSDPFunctionBegin;
664 info=DSDPGetConicDimension(dsdp,n);DSDPCHKERR(info);
665 DSDPFunctionReturn(0);
666}
667
676#undef __FUNCT__
677#define __FUNCT__ "DSDPGetYMaxNorm"
678int DSDPGetYMaxNorm(DSDP dsdp, double *ynorm){
679 int info;
680 double cc,rr,yy;
681 DSDPFunctionBegin;
682 DSDPValid(dsdp);
683 info=DSDPVecGetC(dsdp->y,&cc);DSDPCHKERR(info);
684 info=DSDPVecGetR(dsdp->y,&rr);DSDPCHKERR(info);
685 info=DSDPVecSetC(dsdp->y,0);DSDPCHKERR(info);
686 info=DSDPVecSetR(dsdp->y,0);DSDPCHKERR(info);
687 info=DSDPVecNormInfinity(dsdp->y,&yy);DSDPCHKERR(info);
688 info=DSDPVecSetC(dsdp->y,cc);DSDPCHKERR(info);
689 info=DSDPVecSetR(dsdp->y,rr);DSDPCHKERR(info);
690 if (cc) yy/=fabs(cc);
691 if (ynorm) *ynorm=yy;
692 DSDPFunctionReturn(0);
693}
694
705#undef __FUNCT__
706#define __FUNCT__ "DSDPGetNumberOfVariables"
707int DSDPGetNumberOfVariables(DSDP dsdp, int *m){
708 DSDPFunctionBegin;
709 DSDPValid(dsdp);
710 *m=dsdp->m;
711 DSDPFunctionReturn(0);
712}
713
722#undef __FUNCT__
723#define __FUNCT__ "DSDPGetPnorm"
724int DSDPGetPnorm(DSDP dsdp, double *pnorm){
725 DSDPFunctionBegin;
726 DSDPValid(dsdp);
727 *pnorm=dsdp->pnorm;
728 DSDPFunctionReturn(0);
729}
730
740#undef __FUNCT__
741#define __FUNCT__ "DSDPGetStepLengths"
742int DSDPGetStepLengths(DSDP dsdp, double *pstep, double *dstep){
743 DSDPFunctionBegin;
744 DSDPValid(dsdp);
745 *dstep=dsdp->dstep;
746 *pstep=dsdp->pstep;
747 DSDPFunctionReturn(0);
748}
749
763#undef __FUNCT__
764#define __FUNCT__ "DSDPSetPotentialParameter"
765int DSDPSetPotentialParameter(DSDP dsdp, double rho){
766 DSDPFunctionBegin;
767 DSDPValid(dsdp);
768 if (rho>1) dsdp->rhon=rho;
769 DSDPLogInfo(0,2,"Set Potential Parameter %4.4f\n",rho);
770 DSDPFunctionReturn(0);
771}
772
782#undef __FUNCT__
783#define __FUNCT__ "DSDPGetPotentialParameter"
784int DSDPGetPotentialParameter(DSDP dsdp, double *rho){
785 DSDPFunctionBegin;
786 DSDPValid(dsdp);
787 *rho=dsdp->rhon;
788 DSDPFunctionReturn(0);
789}
790
801#undef __FUNCT__
802#define __FUNCT__ "DSDPGetPotential"
803int DSDPGetPotential(DSDP dsdp, double *potential){
804 DSDPFunctionBegin;
805 DSDPValid(dsdp);
806 *potential=dsdp->potential;
807 DSDPFunctionReturn(0);
808}
809
819#undef __FUNCT__
820#define __FUNCT__ "DSDPUseDynamicRho"
821int DSDPUseDynamicRho(DSDP dsdp, int yesorno){
822 DSDPFunctionBegin;
823 DSDPValid(dsdp);
824 if (yesorno) dsdp->usefixedrho=DSDP_FALSE;
825 else dsdp->usefixedrho=DSDP_TRUE;
826 DSDPLogInfo(0,2,"Set UseDynamicRho: %d \n",yesorno);
827 DSDPFunctionReturn(0);
828}
829
830/* Not Current or documented
831*/
832#undef __FUNCT__
833#define __FUNCT__ "DSDPBoundDualVariables"
834/* !
835\fn int DSDPBoundDualVariables(DSDP dsdp, double lbound, double ubound)
836\brief Bounds on the variables y.
837
838\param dsdp is the solver
839\param lbound will be the lower bound of the variables y
840\param ubound will be the upper bound of the variables y
841\sa DSDPSetYBounds()
842\ingroup DSDPSolver
843*/
844int DSDPBoundDualVariables(DSDP dsdp,double lbound, double ubound){
845 int info;
846 double bbound;
847 DSDPFunctionBegin;
848 bbound=DSDPMax(fabs(lbound),fabs(ubound));
849 DSDPLogInfo(0,2,"Bound Variables between %4.4e and %4.4e \n",-bbound,bbound);
850 info = BoundYConeSetBounds(dsdp->ybcone,-bbound,bbound);DSDPCHKERR(info);
851 DSDPFunctionReturn(0);
852}
853
864#undef __FUNCT__
865#define __FUNCT__ "DSDPGetYBounds"
866int DSDPGetYBounds(DSDP dsdp,double *lbound, double *ubound){
867 int info;
868 DSDPFunctionBegin;
869 info=BoundYConeGetBounds(dsdp->ybcone,lbound,ubound);DSDPCHKERR(info);
870 DSDPFunctionReturn(0);
871}
872
883#undef __FUNCT__
884#define __FUNCT__ "DSDPSetYBounds"
885int DSDPSetYBounds(DSDP dsdp,double lbound, double ubound){
886 int info;
887 DSDPFunctionBegin;
888 info=BoundYConeSetBounds(dsdp->ybcone,lbound,ubound);DSDPCHKERR(info);
889 DSDPFunctionReturn(0);
890}
891
892
893
903#undef __FUNCT__
904#define __FUNCT__ "DSDPReuseMatrix"
905int DSDPReuseMatrix(DSDP dsdp, int rm){
906 DSDPFunctionBegin;
907 DSDPValid(dsdp);
908 dsdp->reuseM=rm;
909 DSDPLogInfo(0,2,"Reuse the Schur Matrix: %d times\n",rm);
910 DSDPFunctionReturn(0);
911}
912
913
923#undef __FUNCT__
924#define __FUNCT__ "DSDPGetReuseMatrix"
925int DSDPGetReuseMatrix(DSDP dsdp, int *rm){
926 DSDPFunctionBegin;
927 DSDPValid(dsdp);
928 *rm=dsdp->reuseM;
929 DSDPFunctionReturn(0);
930}
931
932
943#undef __FUNCT__
944#define __FUNCT__ "DSDPSetMonitor"
945int DSDPSetMonitor(DSDP dsdp, int (*monitor)(DSDP,void*), void* monitorctx){
946 DSDPFunctionBegin;
947 DSDPValid(dsdp);
948 if (dsdp->nmonitors<MAX_DSDP_MONITORS){
949 DSDPLogInfo(0,2,"Set Monitor\n");
950 dsdp->dmonitor[dsdp->nmonitors].monitor=monitor;
951 dsdp->dmonitor[dsdp->nmonitors].monitorctx=monitorctx;
952 dsdp->nmonitors++;
953 }
954 DSDPFunctionReturn(0);
955}
956
966#undef __FUNCT__
967#define __FUNCT__ "DSDPSetConvergenceFlag"
968int DSDPSetConvergenceFlag(DSDP dsdp, DSDPTerminationReason reason ){
969 DSDPFunctionBegin;
970 DSDPValid(dsdp);
971 dsdp->reason=reason;
972 if (reason==DSDP_INFEASIBLE_START){
973 DSDPLogInfo(0,2,"Initial Point Infeasible, Check variable bounds? \n",0);
974 }
975 DSDPFunctionReturn(0);
976}
977
int BoundYConeGetBounds(LUBounds lucone, double *lb, double *ub)
Get bounds on the variables.
Definition allbounds.c:532
int BoundYConeSetBounds(LUBounds lucone, double lb, double ub)
Set bounds on the variables.
Definition allbounds.c:512
The API to DSDP for those applications using DSDP as a subroutine library.
Internal data structure for the DSDP solver.
int DSDPSetRR(DSDP, double)
Set variable r.
Definition dualimpl.c:345
int DSDPComputeDataNorms(DSDP)
Compute norms of A,C, and b.
Definition dsdpsetup.c:283
int DSDPGetConicDimension(DSDP, double *)
Get the total dimension of the cones.
Definition dsdpcops.c:401
int DSDPGetRR(DSDP, double *)
Get variable r.
Definition dualimpl.c:361
DSDPTerminationReason
There are many reasons to terminate the solver.
@ DSDP_INFEASIBLE_START
@ DSDP_FALSE
@ DSDP_TRUE
Error handling, printing, and profiling.
Internal structures for the DSDP solver.
Definition dsdp.h:65