9 :x_is_new(true), glob_grd(0x0), glob_prnt(0x0)
15 assert(glob_grd != 0x0 && glob_prnt != 0x0 &&
"this default implementation is made so far to be called within fsqp routine only");
20 for (i=0; i<=nparam-1; i++) {
22 delta=std::max(glob_grd->
udelta,
23 glob_grd->
rteps*std::max(1.e0,fabs(xi)));
24 if (xi<0.e0) delta=-delta;
25 if (!(glob_prnt->
ipd==1 || j != 1 || glob_prnt->
iprint<3)) {
27 if (i==0) fprintf(glob_prnt->
io,
"\tdelta(i)\t %22.14f\n",delta);
28 if (i!=0) fprintf(glob_prnt->
io,
"\t\t\t %22.14f\n",delta);
32 obj(nparam,j,x,&gradf[i],cd);
33 gradf[i]=(gradf[i]-glob_grd->
valnom)/delta;
43 assert(glob_grd != 0x0 && glob_prnt != 0x0 &&
"this default implementation is made so far to be called within fsqp routine only");
48 for (i=0; i<=nparam-1; i++) {
50 delta=std::max(glob_grd->
udelta,
51 glob_grd->
rteps*std::max(1.e0,fabs(xi)));
52 if (xi<0.e0) delta=-delta;
53 if (!(j != 1 || glob_prnt->
iprint<3)) {
55 if (i==0) fprintf(glob_prnt->
io,
"\tdelta(i)\t %22.14f\n",delta);
56 if (i!=0) fprintf(glob_prnt->
io,
"\t\t\t %22.14f\n",delta);
61 constr(nparam,j,x,&gradg[i],cd);
62 gradg[i]=(gradg[i]-glob_grd->
valnom)/delta;
98 : cfsqp_version(
"CFSQP 2.5d")
115 int neq,
int ncsrl,
int ncsrn,
int *mesh_pts,
116 int mode,
int iprint,
int miter,
int *inform,
double bigbnd,
117 double eps,
double epseqn,
double udelta,
double *bl,
double *bu,
118 double *x,
double *f,
double *g,
double *lambda,
OFSQPProblem& problem,
void *cd)
333 int i,ipp,j,ncnstr,nclin,nctotl,nob,nobL,modem,nn,
334 nppram,nrowa,ncsipl1,ncsipn1,nfsip1;
335 bool feasbl,feasb,prnt,Linfty;
336 int *indxob,*indxcn,*mesh_pts1;
338 double xi,gi,gmax,dummy,epskt;
339 struct _constraint *cs;
340 struct _objective *ob;
341 struct _parameter *param;
342 struct _parameter _param;
347 glob_info.
nfsip=nfsr;
353 for (i=1; i<=nfsip1; i++)
354 nfsr=nfsr+mesh_pts[i];
357 nineq=nineq-ncsrl-ncsrn;
363 for (i=1; i<=ncsipn1; i++)
364 ncsrn=ncsrn+mesh_pts[nfsip1+i];
366 for (i=1; i<=ncsipl1; i++)
367 ncsrl=ncsrl+mesh_pts[nfsip1+ncsipn1+i];
369 nineq=nineq+ncsrn+ncsrl;
371 cs=(
struct _constraint *)calloc(nineq+neq+1,
372 sizeof(
struct _constraint));
373 for (i=1; i<=nineq+neq; i++) {
374 cs[i].grad=make_dv(nparam);
379 _param.x=make_dv(nparam+1);
380 _param.bl=make_dv(nparam);
381 _param.bu=make_dv(nparam);
382 _param.mult=make_dv(nparam+1);
386 bl=bl-1; bu=bu-1; x=x-1;
387 for (i=1; i<=nparam; i++) {
394 f=f-1; g=g-1; lambda=lambda-1;
399 tolfea=glob_grd.
epsmac*1.e2;
405 signeq=make_dv(neqn);
410 glob_prnt.
iprint=iprint%10;
412 glob_prnt.
iter_mod=std::max(iprint-iprint%10,1);
417 fprintf(glob_prnt.
io,
418 "\n\n CFSQP Version 2.5d (Released February 1998) \n");
419 fprintf(glob_prnt.
io,
420 " Copyright (c) 1993 --- 1998 \n");
421 fprintf(glob_prnt.
io,
422 " C.T. Lawrence, J.L. Zhou \n");
423 fprintf(glob_prnt.
io,
424 " and A.L. Tits \n");
425 fprintf(glob_prnt.
io,
426 " All Rights Reserved \n\n");
431 check(nparam,nf,nfsr,&Linfty,nineq,nineqn,neq,neqn,
432 ncsrl,ncsrn,mode,&modem,eps,bgbnd,param);
433 if (glob_prnt.
info==7) {
434 *inform=glob_prnt.
info;
439 maxit=std::max(std::max(miter,10*std::max(nparam,ncnstr)),1000);
448 for (i=1; i<=nparam; i++) {
450 if (param->bl[i]<=xi && param->bu[i]>=xi)
continue;
459 for (i=1; i<=nclin; i++) {
462 pb->
constr(nparam,j,(param->x)+1,&gi,param->cd);
463 if (gi>glob_grd.
epsmac) feasbl=
false;
465 pb->
constr(nparam,j+neqn,(param->x)+1,&gi,param->cd);
466 if (fabs(gi)>glob_grd.
epsmac) feasbl=
false;
476 fprintf(glob_prnt.
io,
477 " The given initial point is infeasible for inequality\n");
478 fprintf(glob_prnt.
io,
479 " constraints and linear equality constraints:\n");
480 sbout1(glob_prnt.
io,nparam,
" ",dummy,
485 lenw=2*nparam*nparam+10*nparam+2*nctotl+1;
486 leniw=std::max(2*nparam+2*nctotl+3,2*nclin+2*nparam+6);
491 nrowa=std::max(nclin,1);
494 initpt(nparam,nineqn,neq,neqn,nclin,nctotl,nrowa,param,
498 if (glob_prnt.
info!=0) {
499 *inform=glob_prnt.
info;
504 indxob=make_iv(std::max(nineq+neq,nf));
505 indxcn=make_iv(nineq+neq);
507 if (glob_prnt.
info!=-1) {
508 for (i=1; i<=nineqn; i++) {
509 pb->
constr(nparam,i,(param->x)+1,&(cs[i].val),param->cd);
510 if (cs[i].val>0.e0) feasb=
false;
515 ob=(
struct _objective *)calloc(nineqn+1,
516 sizeof(
struct _objective));
517 for (i=1; i<=nineqn; i++) {
518 ob[i].grad=make_dv(nparam);
521 for (i=1; i<=nineqn; i++) {
524 ob[nob].val=cs[i].val;
525 gmax=std::max(gmax,ob[nob].val);
527 for (i=1; i<=nineq-nineqn; i++)
529 for (i=1; i<=neq-neqn; i++)
530 indxcn[i+nineq-nineqn]=nineq+neqn+i;
537 ob=(
struct _objective *)calloc(nf+1,
sizeof(
struct _objective));
538 for (i=1; i<=nf; i++) {
539 ob[i].grad=make_dv(nparam);
542 for (i=1; i<=nineqn; i++) {
545 for (i=1; i<=neq-neqn; i++)
546 cs[i+nineq+neqn].val=cs[i+nineq].val;
547 for (i=1; i<=neqn; i++) {
549 pb->
constr(nparam,j,(param->x)+1,&(cs[j].val),param->cd);
552 for (i=1; i<=nineq-nineqn; i++)
553 indxcn[i+nn]=nineqn+i;
554 for (i=1; i<=neq-neqn; i++)
555 indxcn[i+nineq+neqn]=nineq+neqn+i;
559 if (glob_prnt.
iprint>0 && feasb && !prnt) {
560 fprintf(glob_prnt.
io,
561 "The given initial point is feasible for inequality\n");
562 fprintf(glob_prnt.
io,
563 " constraints and linear equality constraints:\n");
564 sbout1(glob_prnt.
io,nparam,
" ",dummy,
570 if (glob_prnt.
info!=0) {
571 fprintf(glob_prnt.
io,
572 "To generate a feasible point for nonlinear inequality\n");
573 fprintf(glob_prnt.
io,
574 "constraints and linear equality constraints, ");
575 fprintf(glob_prnt.
io,
"ncallg = %10d\n",glob_info.
ncallg);
577 fprintf(glob_prnt.
io,
" iteration %26d\n",
580 fprintf(glob_prnt.
io,
" iteration %26d\n",
582 if (ipp==0) glob_prnt.
iter++;
584 if (feasb && !feasbl) {
585 fprintf(glob_prnt.
io,
586 "Starting from the generated point feasible for\n");
587 fprintf(glob_prnt.
io,
588 "inequality constraints and linear equality constraints:\n");
589 sbout1(glob_prnt.
io,nparam,
" ",
593 if (glob_prnt.
info!=0 || !prnt || !feasb) {
594 fprintf(glob_prnt.
io,
595 "Starting from the generated point feasible for\n");
596 fprintf(glob_prnt.
io,
597 "inequality constraints and linear equality constraints:\n");
598 sbout1(glob_prnt.
io,nparam,
" ",
605 if (ipp>0 && !feasb && !prnt) {
606 fprintf(glob_prnt.
io,
607 " The given initial point is infeasible for inequality\n");
608 fprintf(glob_prnt.
io,
609 " constraints and linear equality constraints:\n");
610 sbout1(glob_prnt.
io,nparam,
" ",dummy,
618 glob_prnt.
iprint=iprint%10;
620 glob_prnt.
iter_mod=std::max(iprint-iprint%10,1);
621 glob_info.
mode=modem;
623 if (Linfty) nobL=2*nob;
625 if (nob!=0 || neqn!=0)
goto L910;
626 fprintf(glob_prnt.
io,
627 "current feasible iterate with no objective specified\n");
628 *inform=glob_prnt.
info;
629 for (i=1; i<=nineq+neq; i++)
631 dealloc(nineq,neq,signeq,indxcn,indxob,cs,param);
642 nctotl=nppram+ncnstr+std::max(nobL,1);
643 leniw=2*(ncnstr+std::max(nobL,1))+2*nppram+6;
644 lenw=2*nppram*nppram+10*nppram+6*(ncnstr+std::max(nobL,1)+1);
646 if (modem==1 && nn==0) glob_info.
M=3;
648 param->x[nparam+1]=gmax;
650 for (i=1; i<=neqn; i++) {
651 if (cs[i+nineq].val>0.e0) signeq[i]=-1.e0;
659 mesh_pts1=&mesh_pts[glob_info.
nfsip];
670 nrowa=std::max(ncnstr+std::max(nobL,1),1);
674 cfsqp1(miter,nparam,nob,nobL,nfsip1,nineqn,neq,neqn,ncsipl1,ncsipn1,
675 mesh_pts1,ncnstr,nctotl,nrowa,feasb,epskt,epseqn,indxob,
676 indxcn,param,cs,ob,signeq);
680 if (glob_prnt.
info==-1) {
681 for (i=1; i<=nob; i++)
684 for (i=1; i<=nineqn; i++)
689 if (glob_prnt.
info!=0) {
691 for (i=1; i<=nparam; i++)
693 for (i=1; i<=nineq+neq; i++)
695 *inform=glob_prnt.
info;
696 dealloc(nineq,neq,signeq,indxcn,indxob,cs,param);
697 for (i=1; i<=nf; i++) {
706 fprintf(glob_prnt.
io,
707 "Error: No feasible point is found for nonlinear inequality\n");
708 fprintf(glob_prnt.
io,
709 "constraints and linear equality constraints\n");
710 *inform=glob_prnt.
info;
711 dealloc(nineq,neq,signeq,indxcn,indxob,cs,param);
712 for (i=1; i<=nineqn; i++)
719 *inform=glob_prnt.
info;
720 for (i=1; i<=nparam; i++) {
722 lambda[i]=param->mult[i];
724 for (i=1; i<=nineq+neq; i++) {
726 lambda[i+nparam]=cs[i].mult;
728 for (i=1; i<=nf; i++) {
730 lambda[i+nparam+nineq+neq]=ob[i].mult;
734 if (nf==1) lambda[1+nparam+nineq+neq]=1.e0;
736 dealloc(nineq,neq,signeq,indxcn,indxob,cs,param);
748 OFSQP::dealloc(
int nineq,
int neq,
double *signeq,
int *indxob,
749 int *indxcn,
struct _constraint *cs,
struct _parameter *param)
756 free_dv(param->mult);
760 for (i=1; i<=nineq+neq; i++)
767 OFSQP::cfsqp1(
int miter,
int nparam,
int nob,
int nobL,
int nfsip,
int nineqn,
768 int neq,
int neqn,
int ncsipl,
int ncsipn,
int *mesh_pts,
int ncnstr,
769 int nctotl,
int nrowa,
int feasb,
double epskt,
double epseqn,
770 int *indxob,
int *indxcn,
struct _parameter *param,
771 struct _constraint *cs,
struct _objective *ob,
double *signeq)
773 int i,iskp,nfs,ncf,ncg,nn,nstart,nrst,ncnst1;
774 int *iact,*iskip,*istore;
775 double Cbar,Ck,dbar,fmax,fM,fMp,steps,d0nm,dummy,
776 sktnom,scvneq,grdftd,psf;
777 double *di,*d,*gm,*grdpsf,*penp,*bl,*bu,*clamda,
778 *cvec,*psmu,*span,*backup;
779 double **hess,**hess1,**a;
781 struct _violation *viol;
782 struct _violation _viol;
786 hess=make_dm(nparam,nparam);
787 hess1=make_dm(nparam+1,nparam+1);
788 a=make_dm(nrowa,nparam+2);
789 di=make_dv(nparam+1);
792 grdpsf=make_dv(nparam);
796 clamda=make_dv(nctotl+nparam+1);
797 cvec=make_dv(nparam+1);
800 backup=make_dv(nob+ncnstr);
801 iact=make_iv(nob+nineqn+neqn);
802 iskip=make_iv(glob_info.
nnineq+1);
803 istore=make_iv(nineqn+nob);
811 nrst=glob_prnt.
ipd=0;
817 if (glob_prnt.
iter==0) diagnl(nparam,1.e0,hess);
820 if (glob_prnt.
iter>0) glob_prnt.
iter--;
821 if (glob_prnt.
iter!=0) diagnl(nparam,1.e0,hess);
829 if (glob_info.
mode!=0)
836 ncnst1=ncnstr-nineqn-neqn;
839 for (i=1; i<=ncnst1; i++) {
840 glob_grd.
valnom=cs[indxcn[i]].val;
841 backup[i]=glob_grd.
valnom;
842 if (feasb && i>nineqn && i<=nn) {
843 gm[i-nineqn]=glob_grd.
valnom*signeq[i-nineqn];
844 scvneq=scvneq+fabs(glob_grd.
valnom);
846 if (feasb && i<=nn) {
848 if (i<=nineqn) istore[i]=0;
849 if (i>nineqn) penp[i-nineqn]=2.e0;
851 pb->
gradcn(nparam,indxcn[i],(param->x)+1,(cs[indxcn[i]].grad)+1,param->cd);
853 nullvc(nparam,grdpsf);
855 if (feasb && neqn!=0)
856 resign(nparam,neqn,&psf,grdpsf,penp,cs,signeq,12,12);
858 for (i=1; i<=nob; i++) {
860 glob_grd.
valnom=ob[i].val;
863 pb->
gradcn(nparam,indxob[i],(param->x)+1,(ob[i].grad)+1,param->cd);
867 pb->
obj(nparam,i,(param->x)+1,&(ob[i].val),param->cd);
868 glob_grd.
valnom=ob[i].val;
869 backup[i+ncnst1]=glob_grd.
valnom;
870 pb->
gradob(nparam,i,(param->x)+1,(ob[i].grad)+1,param->cd);
872 if (nobL!=nob) fmax=std::max(fmax,-ob[i].val);
874 fmax=std::max(fmax,ob[i].val);
876 if (feasb && nob==0) fmax=0.e0;
882 for (i=1; i<=nob; i++) {
886 sbout2(glob_prnt.
io,nparam,i,
"gradf(j,",
")",tempv);
890 sbout1(glob_prnt.
io,nparam,
"gradf(j) ",
896 sbout2(glob_prnt.
io,nparam,indxob[i],
"gradg(j,",
")",tempv);
899 for (i=1; i<=ncnst1; i++) {
900 tempv=cs[indxcn[i]].grad;
901 sbout2(glob_prnt.
io,nparam,indxcn[i],
"gradg(j,",
")",tempv);
904 sbout1(glob_prnt.
io,nparam,
"grdpsf(j) ",dummy,
906 sbout1(glob_prnt.
io,neqn,
"P ",dummy,
910 for (i=1; i<=nparam; i++) {
911 tempv=colvec(hess,i,nparam);
912 sbout2(glob_prnt.
io,nparam,i,
"hess (j,",
")",tempv);
923 out(miter,nparam,nob,nobL,nfsip,nineqn,nn,nineqn,ncnst1,
924 ncsipl,ncsipn,mesh_pts,param->x,cs,ob,fM,fmax,steps,
928 dealloc1(nparam,nrowa,a,hess,hess1,di,d,gm,
929 grdpsf,penp,bl,bu,clamda,cvec,psmu,span,backup,
933 for (i=1; i<=ncnst1; i++) cs[i].val=backup[i];
934 for (i=1; i<=nob; i++) ob[i].val=backup[i+ncnst1];
935 for (i=1; i<=neqn; i++)
936 cs[glob_info.
nnineq+i].mult = signeq[i]*psmu[i];
937 dealloc1(nparam,nrowa,a,hess,hess1,di,d,gm,
938 grdpsf,penp,bl,bu,clamda,cvec,psmu,span,backup,
942 if (!feasb && glob_prnt.
iprint==0) glob_prnt.
iter++;
944 if ((ncsipl+ncsipn)!=0 || nfsip)
945 update_omega(nparam,ncsipl,ncsipn,mesh_pts,nineqn,nob,nobL,
946 nfsip,steps,fmax,cs,ob,param->x,viol,param->cd,feasb);
948 dir(nparam,nob,nobL,nfsip,nineqn,neq,neqn,nn,ncsipl,ncsipn,
949 ncnst1,feasb,&steps,epskt,epseqn,&sktnom,&scvneq,Ck,&d0nm,
950 &grdftd,indxob,indxcn,iact,&iskp,iskip,istore,param,di,d,
951 cs,ob,&fM,&fMp,&fmax,&psf,grdpsf,penp,a,bl,bu,clamda,cvec,
952 hess,hess1,backup,signeq,viol);
954 glob_log.
first=
false;
957 step1(nparam,nob,nobL,nfsip,nineqn,neq,neqn,nn,ncsipl,ncsipn,
958 ncnst1,&ncg,&ncf,indxob,indxcn,iact,&iskp,iskip,istore,
959 feasb,grdftd,ob,&fM,&fMp,&fmax,&psf,penp,&steps,&scvneq,
960 bu,param->x,di,d,cs,backup,signeq,viol,param->cd);
961 if (nstop==0)
continue;
964 hessian(nparam,nob,nfsip,nobL,nineqn,neq,neqn,nn,ncsipn,ncnst1,
965 nfs,&nstart,feasb,bu,param,ob,fmax,&fM,&fMp,&psf,grdpsf,
966 penp,cs,gm,indxob,indxcn,bl,clamda,di,hess,d,steps,&nrst,
967 signeq,span,hess1,cvec,psmu,viol);
968 if (nstop==0 || glob_info.
mode==0)
continue;
969 if (d0nm>dbar) Ck=std::max(0.5e0*Ck,Cbar);
970 if (d0nm<=dbar && glob_log.
dlfeas) Ck=Ck;
971 if (d0nm<=dbar && !glob_log.
dlfeas &&
981 OFSQP::dealloc1(
int nparam,
int nrowa,
double **a,
double **hess,
double **hess1,
982 double *di,
double *d,
double *gm,
double *grdpsf,
double *penp,
983 double *bl,
double *bu,
double *clamda,
double *cvec,
double *psmu,
984 double *span,
double *backup,
int *iact,
int *iskip,
int *istore)
987 free_dm(hess,nparam);
988 free_dm(hess1,nparam+1);
1012 OFSQP::check(
int nparam,
int nf,
int nfsip,
bool *Linfty,
int nineq,
1013 int nnl,
int neq,
int neqn,
int ncsipl,
int ncsipn,
int mode,
1014 int *modem,
double eps,
double bigbnd,
struct _parameter *param)
1020 error(
"nparam should be positive! ",
1023 error(
"nf should not be negative! ",
1026 error(
"nineq should not be negative! ",
1028 if (nineq>=0 && nnl>=0 && nineq<nnl)
1029 error(
"nineq should be no smaller than nnl! ",
1032 error(
"neqn should not be negative! ",
1035 error(
"neq should not be smaller than neqn ",
1038 error(
"nf should not be smaller than nfsip ",
1040 if (nineq<ncsipn+ncsipl)
1041 error(
"ncsrl+ncsrn should not be larger than nineq",
1043 if (nparam<=neq-neqn)
1044 error(
"Must have nparam > number of linear equalities",
1047 error(
"iprint mod 10 should be 0,1,2 or 3! ",
1049 if (eps<=glob_grd.
epsmac) {
1050 error(
"eps should be bigger than epsmac! ",
1052 fprintf(glob_prnt.
io,
1053 "epsmac = %22.14e which is machine dependent.\n",
1056 if (!(mode==100 || mode==101 || mode==110 || mode==111
1057 || mode==200 || mode==201 || mode==210 || mode==211))
1058 error(
"mode is not properly specified! ",
1060 if (glob_prnt.
info!=0) {
1061 fprintf(glob_prnt.
io,
1062 "Error: Input parameters are not consistent.\n");
1065 for (i=1; i<=nparam; i++) {
1069 fprintf(glob_prnt.
io,
1070 "lower bounds should be smaller than upper bounds\n");
1073 if (glob_prnt.
info!=0)
return;
1074 if (bli<(-bigbnd)) param->bl[i]=-bigbnd;
1075 if (bui>bigbnd) param->bu[i]=bigbnd;
1089 if (!i) *Linfty=
false;
1099 OFSQP::initpt(
int nparam,
int nnl,
int neq,
int neqn,
int nclin,
int nctotl,
1100 int nrowa,
struct _parameter *param,
struct _constraint *cs)
1102 int i,j,infoql,mnn,temp1,iout,zero;
1103 double x0i,*atemp,*htemp;
1104 double *x,*bl,*bu,*cvec,*clamda,*bj;
1107 hess=make_dm(nparam,nparam);
1108 a=make_dm(nrowa,nparam);
1112 cvec=make_dv(nparam);
1113 clamda=make_dv(nctotl+nparam+1);
1117 for (i=1; i<=nclin; i++) {
1118 glob_grd.
valnom=cs[i].val;
1121 pb->
gradcn(nparam,j,(param->x)+1,cs[i].grad+1,param->cd);
1122 else pb->
gradcn(nparam,j+neqn,(param->x)+1,cs[i].grad+1,param->cd);
1124 for (i=1; i<=nparam; i++) {
1126 bl[i]=param->bl[i]-x0i;
1127 bu[i]=param->bu[i]-x0i;
1130 for (i=nclin; i>=1; i--)
1131 bj[nclin-i+1]=-cs[i].val;
1132 for (i=nclin; i>=1; i--)
1133 for (j=1; j<=nparam; j++)
1134 a[nclin-i+1][j]=-cs[i].grad[j];
1135 diagnl(nparam,1.e0,hess);
1143 htemp=
convert(hess,nparam,nparam);
1144 atemp=
convert(a,nrowa,nparam);
1146 ObjQLD::ql0001_(&nclin,&temp1,&nrowa,&nparam,&nparam,&mnn,(htemp+1),
1147 (cvec+1),(atemp+1),(bj+1),(bl+1),(bu+1),(x+1),(clamda+1),
1148 &iout,&infoql,&zero,(w+1),&lenw,(iw+1),&leniw,
1154 for (i=1; i<=nparam; i++)
1155 param->x[i]=param->x[i]+x[i];
1157 for (i=1; i<=nclin; i++) {
1159 if (j<=glob_info.
nnineq) pb->
constr(nparam,j,(param->x)+1,
1160 &(cs[i].val),param->cd);
1161 else pb->
constr(nparam,j+neqn,(param->x)+1,&(cs[i].val),param->cd);
1165 if (glob_prnt.
info==1 && glob_prnt.
iprint!=0) {
1166 fprintf(glob_prnt.
io,
1167 "\n Error: No feasible point is found for the");
1168 fprintf(glob_prnt.
io,
" linear constraints.\n");
1171 free_dm(hess,nparam);
1187 OFSQP::update_omega(
int nparam,
int ncsipl,
int ncsipn,
int *mesh_pts,
1188 int nineqn,
int nob,
int nobL,
int nfsip,
double steps,
1189 double fmax,
struct _constraint *cs,
struct _objective *ob,
1190 double *x,
struct _violation *viol,
void *cd,
int feasb)
1192 int i,j,i_max,index,offset,nineq;
1194 double epsilon,g_max,fprev,fnow,fnext,fmult;
1202 for (i=1; i<=ncsipl; i++)
1203 cs[nineq-ncsipl+i].act_sip=
false;
1204 for (i=1; i<=ncsipn; i++)
1205 cs[nineqn-ncsipn+i].act_sip=
false;
1207 for (i=nob-nfsip+1; i<=nob; i++)
1208 ob[i].act_sip=
false;
1215 offset=nineqn-ncsipn;
1216 for (i=1; i<=glob_info.
ncsipn; i++) {
1217 for (j=1; j<=mesh_pts[glob_info.
nfsip+i]; j++) {
1220 if (cs[offset].val >= -epsilon &&
1221 cs[offset].val>=cs[offset+1].val) {
1222 cs[offset].act_sip=
true;
1224 if (cs[offset].mult==0.e0 && !glob_log.
first) {
1225 glob_grd.
valnom=cs[offset].val;
1226 pb->
gradcn(nparam,offset,x+1,cs[offset].grad+1,cd);
1230 }
else if (j==mesh_pts[glob_info.
nfsip+i]) {
1231 if (cs[offset].val >= -epsilon &&
1232 cs[offset].val>cs[offset-1].val) {
1233 cs[offset].act_sip=
true;
1235 if (cs[offset].mult==0.e0 && !glob_log.
first) {
1236 glob_grd.
valnom=cs[offset].val;
1237 pb->
gradcn(nparam,offset,x+1,cs[offset].grad+1,cd);
1242 if (cs[offset].val >= -epsilon && cs[offset].val >
1243 cs[offset-1].val && cs[offset].val >=
1245 cs[offset].act_sip=
true;
1247 if (cs[offset].mult==0.e0 && !glob_log.
first) {
1248 glob_grd.
valnom=cs[offset].val;
1249 pb->
gradcn(nparam,offset,x+1,cs[offset].grad+1,cd);
1254 if (cs[offset].val >= -glob_grd.
epsmac) {
1255 cs[offset].act_sip=
true;
1257 if (cs[offset].mult==0.e0 && !glob_log.
first) {
1258 glob_grd.
valnom=cs[offset].val;
1259 pb->
gradcn(nparam,offset,x+1,cs[offset].grad+1,cd);
1263 if (cs[offset].mult>0.e0) {
1264 cs[offset].act_sip=
true;
1268 if (cs[offset].d1bind) {
1269 cs[offset].act_sip=
true;
1271 if (cs[offset].mult==0.e0 && !glob_log.
first) {
1272 glob_grd.
valnom=cs[offset].val;
1273 pb->
gradcn(nparam,offset,x+1,cs[offset].grad+1,cd);
1282 offset=nineq-ncsipl;
1283 for (i=1; i<=glob_info.
ncsipl; i++) {
1284 if (feasb) index=glob_info.
nfsip+glob_info.
ncsipn+i;
1285 else index=glob_info.
ncsipn+i;
1286 for (j=1; j<=mesh_pts[index]; j++) {
1289 if (cs[offset].val >= -epsilon &&
1290 cs[offset].val>=cs[offset+1].val) {
1291 cs[offset].act_sip=
true;
1296 if (j==mesh_pts[index]) {
1297 if (cs[offset].val >= -epsilon &&
1298 cs[offset].val>cs[offset-1].val) {
1299 cs[offset].act_sip=
true;
1304 if (cs[offset].val >= -epsilon && cs[offset].val >
1305 cs[offset-1].val && cs[offset].val >=
1307 cs[offset].act_sip=
true;
1312 if (cs[offset].val >= -glob_grd.
epsmac ||
1313 cs[offset].mult>0.e0 || cs[offset].d1bind) {
1314 cs[offset].act_sip=
true;
1323 if (glob_log.
first) {
1325 offset=nineqn-ncsipn;
1326 for (i=1; i<=glob_info.
ncsipn; i++) {
1328 g_max=cs[i_max].val;
1329 if (!cs[i_max].act_sip) {
1330 cs[i_max].act_sip=
true;
1333 for (j=2;j<=mesh_pts[glob_info.
nfsip+i];j++) {
1335 if (cs[offset].val>g_max) {
1337 g_max=cs[i_max].val;
1340 if (!cs[i_max].act_sip) {
1341 cs[i_max].act_sip=
true;
1344 if (!cs[offset].act_sip) {
1345 cs[offset].act_sip=
true;
1350 offset=nineq-ncsipl;
1351 for (i=1; i<=glob_info.
ncsipl; i++) {
1353 g_max=cs[i_max].val;
1354 if (!cs[i_max].act_sip) {
1355 cs[i_max].act_sip=
true;
1358 if (feasb) index=glob_info.
nfsip+glob_info.
ncsipn+i;
1359 else index=glob_info.
ncsipn+i;
1360 for (j=2;j<=mesh_pts[index]; j++) {
1362 if (cs[offset].val>g_max) {
1364 g_max=cs[i_max].val;
1367 if (!cs[i_max].act_sip) {
1368 cs[i_max].act_sip=
true;
1371 if (!cs[offset].act_sip) {
1372 cs[offset].act_sip=
true;
1379 if (steps<1.e0 && viol->type==CONSTR) {
1381 if (!cs[i].act_sip) {
1386 if (glob_prnt.
iprint>=2 && display)
1387 fprintf(glob_prnt.
io,
" |Xi_k| for g %26d\n",
1390 for (i=1; i<=ncsipl; i++)
1391 cs[nineq-ncsipl+i].d1bind=
false;
1392 for (i=1; i<=ncsipn; i++)
1393 cs[nineqn-ncsipn+i].d1bind=
false;
1401 if (feasb) index=glob_info.
nfsip;
1402 else index=glob_info.
ncsipn;
1403 for (i=1; i<=index; i++) {
1404 for (j=1; j<=mesh_pts[i]; j++) {
1407 fnow=fabs(ob[offset].val);
1408 fmult=std::max(fabs(ob[offset].mult),
1409 fabs(ob[offset].mult_L));
1411 fnow=ob[offset].val;
1412 fmult=ob[offset].mult;
1415 if (nobL>nob) fnext=fabs(ob[offset+1].val);
1416 else fnext=ob[offset+1].val;
1417 if ((fnow>=fmax-epsilon)&& fnow>=fnext) {
1418 ob[offset].act_sip=
true;
1420 if (fmult==0.e0 && !glob_log.
first) {
1421 glob_grd.
valnom=ob[offset].val;
1422 if (feasb) pb->
gradob(nparam,offset,x+1,ob[offset].grad+1,cd);
1423 else pb->
gradcn(nparam,offset,x+1,ob[offset].grad+1,cd);
1427 }
else if (j==mesh_pts[i]) {
1428 if (nobL>nob) fprev=fabs(ob[offset-1].val);
1429 else fprev=ob[offset-1].val;
1430 if ((fnow>=fmax-epsilon)&& fnow>fprev) {
1431 ob[offset].act_sip=
true;
1433 if (fmult==0.e0 && !glob_log.
first) {
1434 glob_grd.
valnom=ob[offset].val;
1435 if (feasb) pb->
gradob(nparam,offset,x+1,ob[offset].grad+1,cd);
1436 else pb->
gradcn(nparam,offset,x+1,ob[offset].grad+1,cd);
1442 fprev=fabs(ob[offset-1].val);
1443 fnext=fabs(ob[offset+1].val);
1445 fprev=ob[offset-1].val;
1446 fnext=ob[offset+1].val;
1448 if ((fnow>=fmax-epsilon)&& fnow>fprev &&
1450 ob[offset].act_sip=
true;
1452 if (fmult==0.e0 && !glob_log.
first) {
1453 glob_grd.
valnom=ob[offset].val;
1454 if (feasb) pb->
gradob(nparam,offset,x+1,
1455 ob[offset].grad+1,cd);
1456 else pb->
gradcn(nparam,offset,x+1,ob[offset].grad+1,cd);
1461 if (fnow>= fmax-glob_grd.
epsmac && !ob[offset].act_sip) {
1462 ob[offset].act_sip=
true;
1464 if (fmult==0.e0 && !glob_log.
first) {
1465 glob_grd.
valnom=ob[offset].val;
1466 if (feasb) pb->
gradob(nparam,offset,x+1,
1467 ob[offset].grad+1,cd);
1468 else pb->
gradcn(nparam,offset,x+1,ob[offset].grad+1,cd);
1472 if (fmult!=0.e0 && !ob[offset].act_sip) {
1473 ob[offset].act_sip=
true;
1481 if (glob_log.
first) {
1483 if (feasb) index=glob_info.
nfsip;
1484 else index=glob_info.
ncsipn;
1485 for (i=1; i<=index; i++) {
1487 if (nobL==nob) g_max=ob[i_max].val;
1488 else g_max=fabs(ob[i_max].val);
1489 if (!ob[i_max].act_sip) {
1490 ob[i_max].act_sip=
true;
1493 for (j=2;j<=mesh_pts[i];j++) {
1495 if (nobL==nob) fnow=ob[offset].val;
1496 else fnow=fabs(ob[offset].val);
1502 if (!ob[i_max].act_sip) {
1503 ob[i_max].act_sip=
true;
1506 if (!ob[offset].act_sip) {
1507 ob[offset].act_sip=
true;
1514 if (steps<1.e0 && viol->type==OBJECT) {
1516 if (!ob[i].act_sip) {
1521 if (glob_prnt.
iprint>=2 && display)
1522 fprintf(glob_prnt.
io,
" |Omega_k| for f %26d\n",
1537 OFSQP::dir(
int nparam,
int nob,
int nobL,
int nfsip,
int nineqn,
int neq,
int neqn,
1538 int nn,
int ncsipl,
int ncsipn,
int ncnstr,
1539 int feasb,
double *steps,
double epskt,
double epseqn,
1540 double *sktnom,
double *scvneq,
double Ck,
double *d0nm,
1541 double *grdftd,
int *indxob,
int *indxcn,
int *iact,
int *iskp,
1542 int *iskip,
int *istore,
struct _parameter *param,
double *di,
1543 double *d,
struct _constraint *cs,
struct _objective *ob,
1544 double *fM,
double *fMp,
double *fmax,
double *psf,
double *grdpsf,
1545 double *penp,
double **a,
double *bl,
double *bu,
double *clamda,
1546 double *cvec,
double **hess,
double **hess1,
1547 double *backup,
double *signeq,
struct _violation *viol)
1549 int i,j,k,kk,ncg,ncf,nqprm0,nclin0,nctot0,infoqp,nqprm1,ncl,
1550 nclin1,ncc,nff,nrowa0,nrowa1,ninq,nobb,nobbL,
1552 bool display,need_d1;
1553 double fmxl,vv,dx,dmx,dnm1,dnm,v0,v1,vk,temp1,temp2,theta,
1554 rhol,rhog,rho,grdfd0,grdfd1,dummy,grdgd0,grdgd1,thrshd,
1555 sign,*adummy,dnmtil,*tempv;
1560 ncl=glob_info.
nnineq-nineqn;
1579 nctot0=nqprm0+nclin0;
1581 nrowa0=std::max(nclin0,1);
1582 for (i=1; i<=ncnstr; i++) {
1584 if (i>nineqn && i<=glob_info.
nnineq)
1585 iskip[glob_info.
nnineq+2-i]=i;
1588 if (i<=ncl) iskip[ncl+2-i]=nineqn+i;
1589 if (i<=ncl) iw[i]=nineqn+i;
1590 if (i>ncl) iw[i]=nineqn+neqn+i;
1593 for (i=1; i<=nob; i++)
1595 nullvc(nparam, cvec);
1597 dqp(nparam,nqprm0,nob,nobL,nfsip,nineqn,neq,neqn,nn,ncsipl,ncsipn,
1598 ncnstr,nctot0,nrowa0,nineqn,&infoqp,param,di,feasb,ob,
1599 *fmax,grdpsf,cs,a,cvec,bl,bu,clamda,hess,hess1,di,vv,0);
1602 if (!feasb) glob_prnt.
info=2;
1613 for (i=nn; i>=1; i--) {
1614 if (fuscmp(cs[indxcn[i]].mult,thrshd)) {
1626 for (i=nob; i>=1; i--) {
1628 ltem1=fuscmp(ob[i].mult,thrshd);
1629 ltem2=(nobL!=nob) && (fuscmp(ob[i].mult_L,thrshd));
1630 if (ltem1 || ltem2) {
1639 if (nob>0) vv=ob[iact[nn+1]].val;
1640 *d0nm=sqrt(scaprd(nparam,di,di));
1641 if (glob_log.
first && nclin0==0) {
1642 dx=sqrt(scaprd(nparam,param->x,param->x));
1643 dmx=std::max(dx,1.e0);
1645 for (i=1; i<=nparam; i++)
1646 di[i]=di[i]*dmx/(*d0nm);
1650 matrvc(nparam,nparam,hess,di,w);
1651 if (nn==0) *grdftd = -scaprd(nparam,w,di);
1652 *sktnom=sqrt(scaprd(nparam,w,w));
1653 if (((*d0nm<=epskt)||((gLgeps>0.e0)&&(*sktnom<=gLgeps)))&&
1654 (neqn==0 || *scvneq<=epseqn)) {
1657 if (feasb && glob_log.
first && neqn!=0) {
1663 if (!feasb) glob_prnt.
info=2;
1665 if (glob_prnt.
iprint<3 || !display)
return;
1668 sbout1(glob_prnt.
io,nparam,
"multipliers for x ",dummy,
1671 fprintf(glob_prnt.
io,
"\t\t\t %s\t %22.14e\n",
1672 " for g ",cs[1].mult);
1673 for (j=2; j<=ncnstr; j++)
1674 fprintf(glob_prnt.
io,
" \t\t\t\t\t\t %22.14e\n",cs[j].mult);
1677 fprintf(glob_prnt.
io,
"\t\t\t %s\t %22.14e\n",
1678 " for f ",ob[1].mult);
1679 for (j=2; j<=nob; j++)
1680 fprintf(glob_prnt.
io,
" \t\t\t\t\t\t %22.14e\n",ob[j].mult);
1684 if (glob_prnt.
iprint>=3 && display) {
1685 sbout1(glob_prnt.
io,nparam,
"d0 ",dummy,di,2,2);
1686 sbout1(glob_prnt.
io,0,
"d0norm ",*d0nm,adummy,1,2);
1687 sbout1(glob_prnt.
io,0,
"ktnorm ",*sktnom,adummy,1,2);
1689 if (neqn!=0 && *d0nm<=std::min(0.5e0*epskt,(0.1e-1)*glob_grd.
rteps)
1690 && *scvneq>epseqn) {
1700 if (nn!=0) *grdftd=slope(nob,nobL,neqn,nparam,feasb,ob,grdpsf,
1701 di,d,*fmax,dummy,0,adummy,0);
1703 if (nn==0 && nobL<=1) {
1704 for (i=1; i<=nparam; i++) d[i]=0.e0;
1720 if (glob_info.
mode==1) {
1721 vk=std::min(Ck*(*d0nm)*(*d0nm),*d0nm);
1723 for (i=1; i<=nn; i++) {
1724 tempv=cs[indxcn[i]].grad;
1725 grdgd0=scaprd(nparam,tempv,di);
1726 temp1=vk+cs[indxcn[i]].val+grdgd0;
1735 if (glob_info.
mode==0) nclin1=ncnstr+std::max(nobL,1);
1736 if (glob_info.
mode==1) nclin1=ncnstr;
1737 nrowa1=std::max(nclin1,1);
1739 di1(nparam,nqprm1,nob,nobL,nfsip,nineqn,neq,neqn,ncnstr,
1740 ncsipl,ncsipn,nrowa1,&infoqp,glob_info.
mode,
1741 param,di,ob,*fmax,grdpsf,cs,cvec,bl,bu,clamda,
1745 if (!feasb) glob_prnt.
info=2;
1750 dnm1=sqrt(scaprd(nparam,d,d));
1751 if (glob_prnt.
iprint>=3 && display) {
1752 sbout1(glob_prnt.
io,nparam,
"d1 ",dummy,d,2,2);
1753 sbout1(glob_prnt.
io,0,
"d1norm ",dnm1,adummy,1,2);
1757 for (i=1; i<=nparam; i++) d[i]=0.e0;
1759 if (glob_info.
mode!=1) {
1761 v1=std::max(0.5e0,pow(dnm1,2.5));
1767 for (i=1; i<=nn; i++) {
1768 tempv=cs[indxcn[i]].grad;
1769 grdgd0=scaprd(nparam,tempv,di);
1770 grdgd1=scaprd(nparam,tempv,d);
1771 temp1=vk+cs[indxcn[i]].val+grdgd0;
1772 temp2=grdgd1-grdgd0;
1773 if (temp1<=0.e0)
continue;
1774 if (fabs(temp2)<glob_grd.
epsmac) {
1779 rhol=std::max(rhol,-temp1/temp2);
1780 if (temp2<0.e0 && rhol<1.e0)
continue;
1793 rhog=slope(nob,nobL,neqn,nparam,feasb,ob,grdpsf,
1794 di,d,*fmax,theta,glob_info.
mode,adummy,0);
1795 rhog=std::min(rhol,rhog);
1798 if (nob==1) grdfd1=scaprd(nparam,ob[1].grad,d);
1800 grdfd1=grdfd1-scaprd(nparam,grdpsf,d);
1801 temp1=grdfd1-grdfd0;
1802 temp2=(theta-1.e0)*grdfd0/temp1;
1803 if(temp1<=0.e0) rhog=rhol;
1804 else rhog=std::min(rhol,temp2);
1807 if (*steps==1.e0 && rhol<0.5e0) rho=rhol;
1809 for (i=1; i<=nparam; i++) {
1810 if (rho!=rhog) cvec[i]=di[i];
1811 di[i]=(1.e0-rho)*di[i]+rho*d[i];
1813 dnm=sqrt(scaprd(nparam,di,di));
1814 if (!(glob_prnt.
iprint<3 || glob_info.
mode==1 || nn==0)&&display) {
1815 sbout1(glob_prnt.
io,0,
"rho ",rho,adummy,1,2);
1816 sbout1(glob_prnt.
io,nparam,
"d ",dummy,di,2,2);
1817 sbout1(glob_prnt.
io,0,
"dnorm ",dnm,adummy,1,2);
1820 for (i=1; i<=nob; i++) bl[i]=ob[i].val;
1822 if (!(glob_prnt.
iprint!=3 || glob_info.
mode==0 || nn==0)
1824 sbout1(glob_prnt.
io,0,
"Ck ",Ck,adummy,1,2);
1825 sbout1(glob_prnt.
io,0,
"rhol ",rho,adummy,1,2);
1826 sbout1(glob_prnt.
io,nparam,
"dl ",dummy,di,2,2);
1827 sbout1(glob_prnt.
io,0,
"dlnorm ",dnm,adummy,1,2);
1829 if (glob_info.
mode!=0) {
1830 glob_log.
local=
true;
1831 step1(nparam,nob,nobL,nfsip,nineqn,neq,neqn,nn,ncsipl,ncsipn,
1832 ncnstr,&ncg,&ncf,indxob,indxcn,iact,iskp,iskip,istore,
1833 feasb,*grdftd,ob,fM,fMp,fmax,psf,penp,steps,scvneq,bu,
1834 param->x,di,d,cs,backup,signeq,viol,param->cd);
1835 if (!glob_log.
update) nstop=1;
1840 glob_log.
local=
false;
1841 if (rho!=rhog && nn!=0)
1842 for (i=1; i<=nparam; i++)
1843 di[i]=(1-rhog)*cvec[i]+rhog*d[i];
1844 dnm=sqrt(scaprd(nparam,di,di));
1847 if (!(glob_prnt.
iprint<3 || glob_info.
mode==0 || nn==0) &&
1849 sbout1(glob_prnt.
io,0,
"rhog ",rhog,adummy,1,2);
1850 sbout1(glob_prnt.
io,nparam,
"dg ",dummy,di,2,2);
1851 sbout1(glob_prnt.
io,0,
"dgnorm ",dnm,adummy,1,2);
1853 if (rho !=0.e0) *grdftd=slope(nob,nobL,neqn,nparam,feasb,ob,
1854 grdpsf,di,d,*fmax,theta,0,bl,1);
1855 if (glob_info.
mode!=1 || rho!=rhog)
1856 for (i=1; i<=nparam; i++)
1857 bu[i]=param->x[i]+di[i];
1859 if (rho!=rhog) ncg=0;
1870 for (i=ncc; i<=ncnstr; i++) {
1871 if (i<=nn) kk=iact[i];
1873 if (kk>nineqn && kk<=glob_info.
nnineq) {
1877 if (kk<=glob_info.
nnineq) {
1879 temp1=dnm*sqrt(scaprd(nparam,tempv,tempv));
1882 if (temp2!=0.e0 || cs[kk].val >= (-0.2e0*temp1) ||
1886 if (feasb && kk<=nineqn) istore[kk]=1;
1887 pb->
constr(nparam,kk,bu+1,&(cs[kk].val),param->cd);
1888 if (!feasb || (feasb && (kk>glob_info.
nnineq+neqn)))
continue;
1889 if (kk<=nineqn) nncn=ninq;
1890 fmxl=std::max(fmxl,cs[kk].val);
1891 if (feasb &&(kk<=nineqn || (kk>glob_info.
nnineq 1893 if (fabs(fmxl)>bgbnd) {
1894 for (i=1; i<=nparam; i++) d[i]=0.e0;
1902 if (kk<=nineqn)
continue;
1907 if ((neqn!=0)&&(feasb))
1908 resign(nparam,neqn,psf,grdpsf,penp,cs,signeq,10,20);
1911 if (ncg!=0)
for (i=1; i<=ncg; i++) {
1913 if (iact[i]<=nineqn) istore[iact[i]]=1;
1914 fmxl=std::max(fmxl,cs[iact[i]].val);
1915 if (fabs(fmxl)>bgbnd) {
1916 for (i=1; i<=nparam; i++) d[i]=0.e0;
1928 if (rho!=rhog) ncf=0;
1933 if (ob[iact[nn+1]].mult<0.e0) sign=-1.e0;
1934 for (i=nff; i<=nob; i++) {
1936 if (!feasb) kk=iact[i];
1939 for (j=1; j<=nparam; j++)
1940 w[nparam+j]=sign*ob[iact[k]].grad[j]-ob[kk].grad[j];
1941 temp1=fabs(ob[kk].val-sign*vv);
1942 temp2=dnm*sqrt(scaprd(nparam,&w[nparam],&w[nparam]));
1943 if (temp1!=0.e0 && temp2!=0.e0) {
1946 if (temp2==0.e0 && temp1>0.2e0)
continue;
1949 iw[nobb+ninq+neq]=kk;
1950 if (feasb) istore[nineqn+kk]=1;
1953 pb->
constr(nparam,indxob[kk],bu+1,&(ob[kk].val),param->cd);
1956 pb->
obj(nparam,kk,bu+1,&(ob[kk].val),param->cd);
1958 if (nobL!=nob) fmxl=std::max(fmxl, -ob[kk].val);
1960 fmxl=std::max(fmxl,ob[kk].val);
1961 if (fabs(fmxl)>bgbnd) {
1962 for (i=1; i<=nparam; i++) d[i]=0.e0;
1970 for (i=1; i<=ncf; i++) {
1971 iw[ninq+neq+i]=iact[i+nn];
1972 istore[nineqn+iact[i+nn]]=1;
1973 fmxl=std::max(fmxl,ob[iact[i+nn]].val);
1974 if (nobL != nob) fmxl=std::max(fmxl,-ob[iact[i+nn]].val);
1975 if (fabs(fmxl)>bgbnd) {
1976 for (i=1; i<=nparam; i++) d[i]=0.e0;
1985 matrvc(nparam,nparam,hess,di,cvec);
1986 vv=-std::min(0.01e0*dnm,pow(dnm,2.5));
1990 if (nobL!=nob) nobbL=2*nobb;
1991 if (nobL==nob) nobbL=nobb;
1997 nclin0=ninq+neq+nobbL;
1999 nctot0=nqprm0+nclin0;
2000 nrowa0=std::max(nclin0,1);
2003 dqp(nparam,nqprm0,nobb,nobbL,nfsip,nncn,neq,neqn,nn,ncsipl,ncsipn,i,
2004 nctot0,nrowa0,nineqn,&infoqp,param,di,feasb,ob,fmxl,
2005 grdpsf,cs,a,cvec,bl,bu,clamda,hess,hess1,d,vv,1);
2006 dnmtil=sqrt(scaprd(nparam,d,d));
2007 if (infoqp!=0 || dnmtil>dnm) {
2008 for (i=1; i<=nparam; i++) d[i]=0.e0;
2015 for (i=1; i<=nineqn+nob; i++)
2017 if (glob_prnt.
iprint<3 || !display) {
2021 sbout1(glob_prnt.
io,nparam,
"dtilde ",dummy,d,2,2);
2022 sbout1(glob_prnt.
io,0,
"dtnorm ",dnmtil,adummy,1,2);
2034 OFSQP::dqp(
int nparam,
int nqpram,
int nob,
int nobL,
int nfsip,
int nineqn,
2035 int neq,
int neqn,
int nn,
int ncsipl,
int ncsipn,
int ncnstr,
2036 int nctotl,
int nrowa,
int nineqn_tot,
int *infoqp,
2037 struct _parameter *param,
double *di,
int feasb,
struct _objective *ob,
2038 double fmax,
double *grdpsf,
struct _constraint *cs,
2039 double **a,
double *cvec,
double *bl,
double *bu,
double *clamda,
2040 double **hess,
double **hess1,
double *x,
2043 int i,ii,j,jj,ij,k,iout,mnn,nqnp,zero,temp1,temp2,ncnstr_used,
2046 double x0i,xdi,*bj,*htemp,*atemp;
2050 iw_hold=make_iv(nrowa);
2051 for (i=1; i<=nparam; i++) {
2053 if (job==1) xdi=di[i];
2054 if (job==0) xdi=0.e0;
2055 bl[i]=param->bl[i]-x0i-xdi;
2056 bu[i]=param->bu[i]-x0i-xdi;
2057 cvec[i]=cvec[i]-grdpsf[i];
2068 for (i=1; i<=ncnstr; i++) {
2070 if ((jj>glob_info.
nnineq)||(jj<=nineqn_tot-ncsipn)||
2071 ((jj>nineqn_tot)&&(jj<=glob_info.
nnineq-ncsipl))||
2075 if (i<=(neq-neqn) || (i>neq && i<=(ncnstr-nineqn)))
2077 if (!feasb) x0i=0.e0;
2078 bj[k]=x0i-cs[jj].val;
2079 for (j=1; j<=nparam; j++)
2080 a[k][j]=-cs[jj].grad[j];
2081 if (nobL>1) a[k][nqpram]=0.e0;
2090 for (i=1; i<=nparam; i++)
2091 cvec[i]=cvec[i]+ob[1].grad[i];
2092 }
else if (nobL>1) {
2096 for (i=1; i<=nob; i++)
2097 if (ob[iw[ncnstr+i]].act_sip) numf_used++;
2099 for (i=1; i<=nob; i++) {
2101 if ((i<=nob-nfsip) || ob[iw[ij]].act_sip) {
2104 bj[k]=fmax-ob[iw[ij]].val;
2105 if (nobL>nob) bj[k+numf_used]=fmax+ob[iw[ij]].val;
2106 for (j=1; j<=nparam; j++) {
2107 a[k][j]=-ob[iw[ij]].grad[j];
2108 if (nobL>nob) a[k+numf_used][j]=ob[iw[ij]].grad[j];
2111 if (nobL>nob) a[k+numf_used][nqpram]=1.e0;
2115 if (nobL>nob) k=k+numf_used;
2117 matrcp(nparam,hess,nparam+1,hess1);
2125 htemp=
convert(hess1,nparam+1,nparam+1);
2126 atemp=
convert(a,nrowa,nqpram);
2128 ObjQLD::ql0001_(&k,&temp1,&nrowa,&nqpram,&temp2,&mnn,(htemp+1),
2129 (cvec+1),(atemp+1),(bj+1),(bl+1),(bu+1),(x+1),
2130 (clamda+1),&iout,infoqp,&zero,(w+1),&lenw,(iw+1),&leniw,
2135 if (*infoqp!=0 || job==1) {
2144 nullvc(nqpram,param->mult);
2146 for (i=1; i<=ncnstr; i++)
2149 for (i=1; i<=nob; i++) {
2153 for (i=1; i<=nqpram; i++) {
2155 if (clamda[ii]==0.e0 && clamda[ii+nqpram]==0.e0)
continue;
2156 else if (clamda[ii]!=0.e0) clamda[ii]=-clamda[ii];
2157 else clamda[ii]=clamda[ii+nqpram];
2160 for (i=1; i<=nqpram; i++)
2161 param->mult[i]=clamda[k+i];
2163 for (i=1; i<=numf_used; i++) {
2167 ob[iw_hold[ij]].mult=clamda[ii]-clamda[ii+numf_used];
2168 ob[iw_hold[ij]].mult_L=clamda[ii+numf_used];
2171 ob[iw_hold[ij]].mult=clamda[ii];
2175 for (i=1; i<=ncnstr_used; i++)
2176 cs[iw_hold[i]].mult=clamda[i];
2188 OFSQP::di1(
int nparam,
int nqpram,
int nob,
int nobL,
int nfsip,
int nineqn,
2189 int neq,
int neqn,
int ncnstr,
int ncsipl,
int ncsipn,
2190 int nrowa,
int *infoqp,
int mode,
struct _parameter *param,
2191 double *d0,
struct _objective *ob,
double fmax,
double 2192 *grdpsf,
struct _constraint *cs,
double *cvec,
double *bl,
double *bu,
2193 double *clamda,
double **hess1,
double *x,
double steps)
2195 int i,k,ii,jj,iout,j,mnn,zero,temp1,temp3,ncnstr_used,numf_used;
2197 double x0i,eta,*atemp,*htemp,**a,*bj;
2199 if ((ncsipl+ncsipn)!=0)
2202 if (nobL>nob) nrowa=nrowa-2*nfsip+2*glob_info.
tot_actf_sip;
2205 nrowa=std::max(nrowa,1);
2206 a=make_dm(nrowa,nqpram);
2208 iw_hold=make_iv(nrowa);
2210 if (mode==0) eta=0.1e0;
2211 if (mode==1) eta=3.e0;
2212 for (i=1; i<=nparam; i++) {
2214 bl[i]=param->bl[i]-x0i;
2215 bu[i]=param->bu[i]-x0i;
2216 if (mode==0) cvec[i]=-eta*d0[i];
2217 if (mode==1) cvec[i]=0.e0;
2224 for (i=1; i<=ncnstr; i++) {
2226 if ((jj>glob_info.
nnineq)||(jj<=nineqn-ncsipn)||
2227 ((jj>nineqn)&&(jj<=glob_info.
nnineq-ncsipl))||
2231 for (j=1; j<=nparam; j++)
2232 a[k][j]=-cs[jj].grad[j];
2234 if ((i>(neq-neqn) && i<=neq) || i>ii) a[k][nqpram]=1.e0;
2242 for (i=1; i<=nob; i++) {
2243 if ((i<=nob-nfsip) || ob[i].act_sip) {
2245 bj[k]=fmax-ob[i].val;
2246 for (j=1; j<=nparam; j++) {
2247 a[k][j]=-ob[i].grad[j]+grdpsf[j];
2248 if (nobL>nob) a[k+numf_used][j]=ob[i].grad[j]+grdpsf[j];
2251 if (nobL>nob) a[k+numf_used][nqpram]=1.e0;
2257 for (j=1; j<=nparam; j++)
2262 diagnl(nqpram,eta,hess1);
2264 hess1[nqpram][nqpram]=0.e0;
2269 if (nobL>nob) temp3=k+numf_used;
2272 htemp=
convert(hess1,nparam+1,nparam+1);
2273 atemp=
convert(a,nrowa,nqpram);
2275 ObjQLD::ql0001_(&temp3,&temp1,&nrowa,&nqpram,&nqpram,&mnn,(htemp+1),
2276 (cvec+1),(atemp+1),(bj+1),(bl+1),(bu+1),(x+1),
2277 (clamda+1),&iout,infoqp,&zero,(w+1),&lenw,(iw+1),&leniw,
2285 if (ncsipl+ncsipn) {
2286 for (i=1; i<=ncnstr_used; i++)
2287 if (clamda[i]>0.e0) cs[iw_hold[i]].d1bind=
true;
2302 OFSQP::step1(
int nparam,
int nob,
int nobL,
int nfsip,
int nineqn,
int neq,
int neqn,
2303 int nn,
int ncsipl,
int ncsipn,
int ncnstr,
int *ncg,
int *ncf,
2304 int *indxob,
int *indxcn,
int *iact,
int *iskp,
int *iskip,
2305 int *istore,
int feasb,
double grdftd,
struct _objective *ob,
2306 double *fM,
double *fMp,
double *fmax,
double *psf,
double *penp,
2307 double *steps,
double *scvneq,
double *xnew,
double *x,
double *di,
2308 double *d,
struct _constraint *cs,
double *backup,
double *signeq,
2309 struct _violation *sip_viol,
void *cd)
2311 int i,ii,ij,jj,itry,ikeep,j,job,nlin,mnm,ltem1,ltem2;
2312 bool display,fbind,cdone,fdone,eqdone,reform,sipldone;
2313 double prod1,prod,dummy,fmax1,tolfe,ostep,temp,**adummy,fii;
2315 nlin=glob_info.
nnineq-nineqn;
2318 fbind=cdone=fdone=eqdone=
false;
2320 sipldone=(ncsipl==0);
2323 prod1=(0.1e0)*grdftd;
2325 adummy=make_dm(1,1);
2329 if (glob_prnt.
iprint >= 3 && display)
2330 sbout1(glob_prnt.
io,0,
"directional deriv ",grdftd,*(adummy+1),
2335 if (glob_prnt.
iprint >= 3 && display)
2336 fprintf(glob_prnt.
io,
"\t\t\t trial number %22d\n",
2338 prod=prod1*(*steps);
2339 if (!feasb || (nobL > 1)) prod=prod+tolfe;
2340 for (i=1; i<=nparam; i++) {
2341 if (glob_log.
local) xnew[i]=x[i]+(*steps)*di[i];
2342 else xnew[i]=x[i]+(*steps)*di[i]+d[i]*(*steps)*(*steps);
2345 if (glob_prnt.
iprint >= 3 && display) {
2346 sbout1(glob_prnt.
io,0,
"trial step ",*steps,
2348 sbout1(glob_prnt.
io,nparam,
"trial point ",
2356 for (i=ii; i<=*iskp; i++) {
2358 pb->
constr(nparam,ij,xnew+1,&(cs[ij].val),cd);
2359 if (glob_prnt.
iprint >= 3 && display) {
2360 if (i==1) fprintf(glob_prnt.
io,
2361 "\t\t\t trial constraints %d \t %22.14e\n",ij,
2363 if (i!=1) fprintf(glob_prnt.
io,
2364 "\t\t\t\t\t %d \t %22.14e\n",ij,cs[ij].val);
2366 if (cs[ij].val<=tolfe)
continue;
2368 if (ncsipl && ii>glob_info.
nnineq-ncsipl) {
2369 sip_viol->type = CONSTR;
2370 sip_viol->index = ij;
2372 sip_viol->type =
NONE;
2373 sip_viol->index = 0;
2383 for (i=jj; i<=ncsipl; i++) {
2384 ij=glob_info.
nnineq-ncsipl+i;
2385 if (cs[ij].act_sip||element(iskip,nlin-ikeep,ij))
2387 pb->
constr(nparam,ij,xnew+1,&(cs[ij].val),cd);
2388 if (glob_prnt.
iprint >= 3 && display) {
2389 if (i==1) fprintf(glob_prnt.
io,
2390 "\t\t\t trial constraints %d \t %22.14e\n",ij,
2392 if (i!=1) fprintf(glob_prnt.
io,
2393 "\t\t\t\t\t %d \t %22.14e\n",ij,cs[ij].val);
2395 if (cs[ij].val<=tolfe)
continue;
2397 sip_viol->type=CONSTR;
2403 if (nn==0)
goto L310;
2406 if (!glob_log.
local && fbind)
goto L315;
2408 for (i=1; i<=nn; i++) {
2411 ij=glob_info.
nnineq+neqn;
2412 if (!((ii<=nineqn && istore[ii]==1)||
2413 (ii>glob_info.
nnineq && ii<=ij && eqdone))) {
2415 if(ii>glob_info.
nnineq && ii<=ij)
2416 temp=signeq[ii-glob_info.
nnineq];
2417 pb->
constr(nparam,ii,xnew+1,&(cs[ii].val),cd);
2421 if (glob_prnt.
iprint>=3 && display) {
2422 if (i==1 && ikeep==nlin) fprintf(glob_prnt.
io,
2423 "\t\t\t trial constraints %d \t %22.14e\n",ii,
2425 if (i!=1 || ikeep!=nlin) fprintf(glob_prnt.
io,
2426 "\t\t\t\t\t %d \t %22.14e\n",ii,cs[ii].val);
2428 if (!(glob_log.
local || cs[ii].val<=tolfe)) {
2430 if (ncsipn && ii>nineqn-ncsipn) {
2431 sip_viol->type=CONSTR;
2434 sip_viol->type=
NONE;
2439 if (glob_log.
local && cs[ii].val>tolfe) {
2440 if (ncsipn && ii>nineqn-ncsipn) {
2441 sip_viol->type=CONSTR;
2444 sip_viol->type=
NONE;
2450 L310: cdone=eqdone=
true;
2452 L315:
if (fdone)
break;
2453 if (nob>0) fmax1=-bgbnd;
2455 for (i=1; i<=nob; i++) {
2456 if (nob!=0 && i==0)
continue;
2460 if (!(eqdone || neqn==0)) {
2461 for (j=1; j<=neqn; j++)
2463 &(cs[glob_info.
nnineq+j].val),cd);
2468 if (!eqdone) job=10;
2469 resign(nparam,neqn,psf,*(adummy+1),penp,cs,signeq,
2472 if (istore[nineqn+ii]!=1 && i!=0) {
2473 pb->
obj(nparam,ii,xnew+1,&(ob[ii].val),cd);
2477 else fii=ob[ii].val;
2478 if (i==0 && glob_prnt.
iprint>=3 && display)
2479 fprintf(glob_prnt.
io,
2480 "\t\t\t trial penalty term \t %22.14e\n",-*psf);
2481 if (i==1 && glob_prnt.
iprint>=3 && display)
2482 fprintf(glob_prnt.
io,
2483 "\t\t\t trial objectives %d \t %22.14e\n",
2485 if (i>1 && glob_prnt.
iprint>=3 && display)
2486 fprintf(glob_prnt.
io,
2487 "\t\t\t\t\t %d \t %22.14e\n",ii,fii-*psf);
2489 if (istore[ii]!=1) {
2490 pb->
constr(nparam,indxob[ii],xnew+1,&(ob[ii].val),cd);
2493 if (ob[ii].val>tolfe) reform=
false;
2494 if (i==1 && glob_prnt.
iprint>2 && display)
2495 fprintf(glob_prnt.
io,
2496 "\t\t\t trial objectives %d \t %22.14e\n",
2497 indxob[ii],ob[ii].val);
2498 if (i!=1 && glob_prnt.
iprint>2 && display)
2499 fprintf(glob_prnt.
io,
2500 "\t\t\t\t\t %d \t %22.14e\n",indxob[ii],
2504 fmax1=std::max(fmax1,fii);
2505 if (nobL!=nob) fmax1=std::max(fmax1,-fii);
2506 if (!feasb && reform)
continue;
2507 if (!glob_log.
local) {
2508 if ((fii-*psf)>(*fMp+prod)) {
2510 shift(nob,ii,&iact[nn]);
2511 if (nfsip && ii>nob-nfsip) {
2512 sip_viol->type=OBJECT;
2515 sip_viol->type=
NONE;
2520 if (nobL==nob || (-fii-*psf)<=(*fMp+prod))
2523 shift(nob,ii,&iact[nn]);
2524 if (nfsip && ii>nob-nfsip) {
2525 sip_viol->type=OBJECT;
2528 sip_viol->type=
NONE;
2533 ltem1=(fii-*psf)>(*fMp+prod);
2534 ltem2=(nobL!=nob)&&((-fii-*psf)>(*fMp+prod));
2535 if (ltem1 || ltem2)
goto L1500;
2540 if (ostep==*steps) mnm=ikeep+neq-neqn;
2541 if (ostep!=*steps) mnm=ncnstr-nn;
2542 for (i=1; i<=mnm; i++) {
2544 if (ikeep!=nlin && ostep==*steps) {
2545 if (i<= ikeep) ii=iskip[nlin+2-i];
2546 else ii=indxcn[nn+i-ikeep+nlin];
2548 pb->
constr(nparam,ii,xnew+1,&(cs[ii].val),cd);
2551 for (i=1; i<=ncnstr; i++) {
2553 *scvneq=*scvneq-cs[i].val;
2554 backup[i]=cs[i].val;
2556 for (i=1; i<=nob; i++)
2557 backup[i+ncnstr]=ob[i].val;
2558 if (!feasb && reform) {
2559 for (i=1; i<=nparam; i++)
2564 if (glob_log.
local) *ncg=ncnstr;
2569 for (i=1; i<=nn; i++)
2571 for (i=1; i<=nob; i++)
2575 cdone=fdone=eqdone=reform=
false;
2578 if (glob_info.
modec==2) fbind=
false;
2580 for (i=1; i<=nob+nineqn; i++)
2582 *steps=*steps*0.5e0;
2583 if (*steps<glob_grd.
epsmac)
break;
2589 if (*steps<1.e0)
return;
2590 for (i=1; i<=nob+nineqn; i++)
2603 OFSQP::hessian(
int nparam,
int nob,
int nfsip,
int nobL,
int nineqn,
int neq,
2604 int neqn,
int nn,
int ncsipn,
int ncnstr,
int nfs,
int *nstart,
2605 int feasb,
double *xnew,
struct _parameter *param,
2606 struct _objective *ob,
double fmax,
double *fM,
double *fMp,
2607 double *psf,
double *grdpsf,
double *penp,
struct _constraint *cs,
2608 double *gm,
int *indxob,
int *indxcn,
double *delta,
double *eta,
2609 double *gamma,
double **hess,
double *hd,
double steps,
int *nrst,
2610 double *signeq,
double *span,
2611 double **phess,
double *psb,
double *psmu,
2612 struct _violation *sip_viol)
2614 int i,j,k,ifail,np,mnm;
2616 double dhd,gammd,etad,dummy,theta,signgj,psfnew,delta_s;
2624 if (feasb && nstop && !neqn)
2625 if ((fabs(w[1]-fmax) <= objeps) ||
2626 (fabs(w[1]-fmax) <= objrep*fabs(w[1]))) nstop=0;
2628 for (i=1; i<= nparam; i++)
2629 param->x[i]=xnew[i];
2635 delta_s=glob_grd.
rteps;
2642 nullvc(nparam,delta);
2644 for (j=1; j<=2; j++) {
2645 nullvc(nparam, gamma);
2647 for (i=1; i<=nparam; i++) {
2649 for (k=1; k<=nob; k++)
2650 hd[i]=hd[i]+ob[k].grad[i]*ob[k].mult;
2655 for (i=1; i<=nparam; i++) {
2657 for (k=1; k<=nineqn; k++)
2658 gamma[i]=gamma[i]+cs[k].grad[i]*cs[k].mult;
2662 for (i=1; i<=nparam; i++) {
2664 for (k=1; k<=neqn; k++)
2665 eta[i]=eta[i]+cs[glob_info.
nnineq+k].grad[i]*
2666 cs[glob_info.
nnineq+k].mult;
2670 for (i=1; i<=nparam; i++) {
2672 if (done) psb[i]=hd[i]+param->mult[i]+gamma[i];
2673 gamma[i]=gamma[i]+hd[i]-grdpsf[i]+eta[i];
2674 }
else if (nobL==1) {
2675 if (done) psb[i]=ob[1].grad[i]+param->mult[i]+gamma[i];
2676 gamma[i]=gamma[i]+ob[1].grad[i]-grdpsf[i]+eta[i];
2677 }
else if (nobL==0) {
2678 if (done) psb[i]=param->mult[i]+gamma[i];
2679 gamma[i]=gamma[i]-grdpsf[i]+eta[i];
2681 if (!done) delta[i]=gamma[i];
2683 if (!done && !glob_log.
d0_is0) {
2685 for (i=1; i<=nn; i++) {
2686 if ((feasb) && (i>nineqn)) signgj=signeq[i-nineqn];
2687 if ((!feasb) || (i<=nineqn)) signgj=1.e0;
2688 if ((feasb) && (ncsipn) && (i>nineqn-ncsipn) &&
2689 (cs[indxcn[i]].mult==0.e0))
continue;
2690 glob_grd.
valnom=cs[indxcn[i]].val*signgj;
2691 pb->
gradcn(nparam,indxcn[i],xnew+1,cs[indxcn[i]].grad+1,param->cd);
2693 resign(nparam,neqn,psf,grdpsf,penp,cs,signeq,11,11);
2695 for (i=1; i<=nob; i++) {
2696 glob_grd.
valnom=ob[i].val;
2697 if ((i<=nob-nfsip)||(i>nob-nfsip &&
2698 ((ob[i].mult !=0.e0)||(ob[i].mult_L !=0.e0)))) {
2700 pb->
gradob(nparam,i,xnew+1,ob[i].grad+1,param->cd);
2701 else pb->
gradcn(nparam,indxob[i],xnew+1,ob[i].grad+1,param->cd);
2706 if (glob_log.
d0_is0) done=
true;
2709 if (!(feasb && steps<delta_s && ((sip_viol->type==OBJECT &&
2710 !ob[sip_viol->index].act_sip)||(sip_viol->type==CONSTR &&
2711 !cs[sip_viol->index].act_sip)))) {
2712 if (*nrst<(5*nparam) || steps>0.1e0) {
2714 for (i=1; i<=nparam; i++) {
2715 gamma[i]=gamma[i]-delta[i];
2716 delta[i]=xnew[i]-param->x[i];
2718 matrvc(nparam,nparam,hess,delta,hd);
2719 dhd=scaprd(nparam,delta,hd);
2720 if (sqrt(scaprd(nparam,delta,delta)) <= glob_grd.
epsmac) {
2726 gammd=scaprd(nparam,delta,gamma);
2727 if (gammd >= (0.2e0*dhd)) theta=1.e0;
2728 else theta=0.8e0*dhd/(dhd-gammd);
2729 for (i=1; i<=nparam; i++)
2730 eta[i]=hd[i]*(1.e0-theta)+theta*gamma[i];
2731 etad=theta*gammd+(1.e0-theta)*dhd;
2732 for (i=1; i<=nparam; i++) {
2733 for (j=i; j<=nparam; j++) {
2734 hess[i][j]=hess[i][j] - hd[i]*hd[j]/dhd +
2736 hess[j][i]=hess[i][j];
2741 diagnl(nparam,1.e0,hess);
2744 for (i=1; i<=nparam; i++)
2745 param->x[i]=xnew[i];
2748 if (neqn!=0 && (feasb)) {
2749 i=glob_info.
nnineq-nineqn;
2751 for (j=1; j<=nparam; j++) {
2753 for (k=1; k<=i; k++)
2754 gamma[j]=gamma[j]+cs[k+nineqn].grad[j]*
2757 for (i=1; i<=nparam; i++)
2758 psb[i]=psb[i]+gamma[i];
2762 for (j=1; j<=nparam; j++) {
2764 for (k=1; k<=i; k++)
2765 gamma[j]=gamma[j]+cs[k+neqn+glob_info.
nnineq].grad[j]*
2766 cs[glob_info.
nnineq+neqn+k].mult;
2768 for (i=1; i<=nparam; i++)
2769 psb[i]=psb[i]+gamma[i];
2772 estlam(nparam,neqn,&ifail,bgbnd,phess,delta,eta,
2773 gamma,cs,psb,hd,xnew,psmu);
2775 for (i=1; i<=neqn; i++) {
2776 if (ifail != 0 || glob_log.
d0_is0) penp[i]=2.e0*penp[i];
2778 etad=psmu[i]+penp[i];
2780 penp[i]=std::max((1.e0-psmu[i]),(2.e0*penp[i]));
2782 if (penp[i] > bgbnd) {
2788 resign(nparam,neqn,psf,grdpsf,penp,cs,signeq,20,12);
2793 np=indexs(*nstart,nfs);
2795 for (i=1; i<=neqn; i++)
2796 gm[(np-1)*neqn+i]=cs[glob_info.
nnineq+i].val;
2799 for (i=1; i<=neqn; i++)
2800 psfnew=psfnew+gm[i]*penp[i];
2803 *fMp=span[1]-psfnew;
2804 mnm=std::min(*nstart,nfs);
2805 for (i=2; i<=mnm; i++) {
2808 for (j=1; j<=neqn; j++)
2809 psfnew=psfnew+gm[(i-1)*neqn +j]*penp[j];
2811 *fM=std::max(*fM, span[i]);
2812 *fMp=std::max(*fMp,span[i]-psfnew);
2815 if (glob_prnt.
iprint < 3 || !display)
return;
2816 for (i=1; i<=nob; i++) {
2818 sbout2(glob_prnt.
io,nparam,indxob[i],
"gradg(j,",
2822 if (nob>1) sbout2(glob_prnt.
io,nparam,i,
"gradf(j,",
")",
2824 if (nob==1) sbout1(glob_prnt.
io,nparam,
"gradf(j) ",
2825 dummy,ob[1].grad,2,2);
2828 for (i=1; i<=ncnstr; i++) {
2829 tempv=cs[indxcn[i]].grad;
2830 sbout2(glob_prnt.
io,nparam,indxcn[i],
"gradg(j,",
")",tempv);
2833 sbout1(glob_prnt.
io,nparam,
"grdpsf(j) ",
2835 sbout1(glob_prnt.
io,neqn,
"P ",dummy,
2837 sbout1(glob_prnt.
io,neqn,
"psmu ",dummy,
2841 sbout1(glob_prnt.
io,nparam,
"multipliers for x ",dummy,
2844 fprintf(glob_prnt.
io,
"\t\t\t %s\t %22.14e\n",
2845 " for g ",cs[1].mult);
2846 for (j=2; j<=ncnstr; j++)
2847 fprintf(glob_prnt.
io,
" \t\t\t\t\t\t %22.14e\n",cs[j].mult);
2850 fprintf(glob_prnt.
io,
"\t\t\t %s\t %22.14e\n",
2851 " for f ",ob[1].mult);
2852 for (j=2; j<=nob; j++)
2853 fprintf(glob_prnt.
io,
" \t\t\t\t\t\t %22.14e\n",ob[j].mult);
2855 for (i=1; i<=nparam; i++) {
2856 tempv=colvec(hess,i,nparam);
2857 sbout2(glob_prnt.
io,nparam,i,
"hess (j,",
")",tempv);
2870 OFSQP::out(
int miter,
int nparam,
int nob,
int nobL,
int nfsip,
int ncn,
2871 int nn,
int nineqn,
int ncnstr,
int ncsipl,
int ncsipn,
2872 int *mesh_pts,
double *x,
struct _constraint *cs,
2873 struct _objective *ob,
double fM,
double fmax,
2874 double steps,
double sktnom,
double d0norm,
int feasb)
2876 int i,j,index,offset;
2878 double SNECV,dummy,*adummy,gmax;
2883 if (glob_prnt.
iter>=miter && nstop != 0) {
2886 if (glob_prnt.
iprint==0)
goto L9000;
2888 if (glob_prnt.
iprint==0 && glob_prnt.
iter<miter) {
2892 if ((glob_prnt.
info>0 && glob_prnt.
info<3) || glob_prnt.
info==7)
2894 if (glob_prnt.
iprint==1 && nstop!=0) {
2896 if (glob_prnt.
initvl==0)
goto L9000;
2897 if (feasb && nob>0) {
2898 fprintf(glob_prnt.
io,
" objectives\n");
2899 for (i=1; i<=nob-nfsip; i++) {
2901 fprintf(glob_prnt.
io,
" \t\t\t %22.14e\n",ob[i].val);
2903 fprintf(glob_prnt.
io,
" \t\t\t %22.14e\n",fabs(ob[i].val));
2907 for (i=1; i<=glob_info.
nfsip; i++) {
2908 if (nob==nobL) gmax=ob[++offset].val;
2909 else gmax=fabs(ob[++offset].val);
2910 for (j=2; j<=mesh_pts[i]; j++) {
2912 if (nob==nobL && ob[offset].val>gmax)
2913 gmax=ob[offset].val;
2914 else if (nob!=nobL && fabs(ob[offset].val)>gmax)
2915 gmax=fabs(ob[offset].val);
2917 fprintf(glob_prnt.
io,
" \t\t\t %22.14e\n",gmax);
2921 if (glob_info.
mode==1 && glob_prnt.
iter>1 && feasb)
2922 sbout1(glob_prnt.
io,0,
"objective max4 ",fM,adummy,1,1);
2924 sbout1(glob_prnt.
io,0,
"objmax ",fmax,adummy,1,1);
2925 if (ncnstr==0) fprintf(glob_prnt.
io,
"\n");
2927 fprintf(glob_prnt.
io,
" constraints\n");
2928 for (i=1; i<=nineqn-ncsipn; i++)
2929 fprintf(glob_prnt.
io,
" \t\t\t %22.14e\n",cs[i].val);
2931 offset=nineqn-ncsipn;
2932 for (i=1; i<=glob_info.
ncsipn; i++) {
2933 gmax=cs[++offset].val;
2934 for (j=2; j<=mesh_pts[glob_info.
nfsip+i]; j++) {
2936 if (cs[offset].val>gmax) gmax=cs[offset].val;
2938 fprintf(glob_prnt.
io,
" \t\t\t %22.14e\n",gmax);
2941 for (i=nineqn+1; i<=glob_info.
nnineq-ncsipl; i++)
2942 fprintf(glob_prnt.
io,
" \t\t\t %22.14e\n",cs[i].val);
2944 offset=glob_info.
nnineq-ncsipl;
2945 for (i=1; i<=glob_info.
ncsipl; i++) {
2946 gmax=cs[++offset].val;
2947 if (feasb) index=glob_info.
nfsip+glob_info.
ncsipn+i;
2948 else index=glob_info.
ncsipn+i;
2949 for (j=2; j<=mesh_pts[index]; j++) {
2951 if (cs[offset].val>gmax) gmax=cs[offset].val;
2953 fprintf(glob_prnt.
io,
" \t\t\t %22.14e\n",gmax);
2956 for (i=glob_info.
nnineq+1; i<=ncnstr; i++)
2957 fprintf(glob_prnt.
io,
" \t\t\t %22.14e\n",cs[i].val);
2959 if (ncnstr!=0) fprintf(glob_prnt.
io,
"\n");
2962 if (glob_prnt.
iprint==1 && nstop==0)
2963 fprintf(glob_prnt.
io,
" iteration %26d\n",
2965 if (glob_prnt.
iprint<=2 && nstop==0)
2966 fprintf(glob_prnt.
io,
" inform %26d\n",
2968 if (glob_prnt.
iprint==1 && nstop==0 && (ncsipl+ncsipn)!=0)
2969 fprintf(glob_prnt.
io,
" |Xi_k| %26d\n",
2971 if (glob_prnt.
iprint==1 && nstop==0 && nfsip!=0)
2972 fprintf(glob_prnt.
io,
" |Omega_k| %26d\n",
2975 if (!((glob_prnt.
iter)%glob_prnt.
iter_mod)) display=
true;
2976 else display=(nstop==0);
2977 if (glob_prnt.
iter_mod!=1 && display)
2978 fprintf(glob_prnt.
io,
"\n iteration %26d\n",
2980 if (glob_prnt.
initvl==0 && display)
2981 sbout1(glob_prnt.
io,nparam,
"x ",dummy,x,2,1);
2984 fprintf(glob_prnt.
io,
" objectives\n");
2985 for (i=1; i<=nob-nfsip; i++) {
2987 fprintf(glob_prnt.
io,
" \t\t\t %22.14e\n",ob[i].val);
2989 fprintf(glob_prnt.
io,
" \t\t\t %22.14e\n",
2995 if (feasb) index=glob_info.
nfsip;
2996 else index=glob_info.
ncsipn;
2997 for (i=1; i<=index; i++) {
2998 if (nob==nobL) gmax=ob[++offset].val;
2999 else gmax=fabs(ob[++offset].val);
3000 for (j=2; j<=mesh_pts[i]; j++) {
3002 if (nob==nobL && ob[offset].val>gmax)
3003 gmax=ob[offset].val;
3004 else if (nob!=nobL && fabs(ob[offset].val)>gmax)
3005 gmax=fabs(ob[offset].val);
3007 fprintf(glob_prnt.
io,
" \t\t\t %22.14e\n",gmax);
3011 if (glob_info.
mode==1 && glob_prnt.
iter>1 && display)
3012 sbout1(glob_prnt.
io,0,
"objective max4 ",fM,adummy,1,1);
3013 if (nob>1 && display)
3014 sbout1(glob_prnt.
io,0,
"objmax ",fmax,adummy,1,1);
3015 if (ncnstr != 0 && display ) {
3016 fprintf(glob_prnt.
io,
" constraints\n");
3017 for (i=1; i<=nineqn-ncsipn; i++)
3018 fprintf(glob_prnt.
io,
" \t\t\t %22.14e\n",cs[i].val);
3020 offset=nineqn-ncsipn;
3021 for (i=1; i<=glob_info.
ncsipn; i++) {
3022 gmax=cs[++offset].val;
3023 for (j=2; j<=mesh_pts[glob_info.
nfsip+i]; j++) {
3025 if (cs[offset].val>gmax) gmax=cs[offset].val;
3027 fprintf(glob_prnt.
io,
" \t\t\t %22.14e\n",gmax);
3030 for (i=nineqn+1; i<=glob_info.
nnineq-ncsipl; i++)
3031 fprintf(glob_prnt.
io,
" \t\t\t %22.14e\n",cs[i].val);
3033 offset=glob_info.
nnineq-ncsipl;
3034 for (i=1; i<=glob_info.
ncsipl; i++) {
3035 gmax=cs[++offset].val;
3036 if (feasb) index=glob_info.
nfsip+glob_info.
ncsipn+i;
3037 else index=glob_info.
ncsipn+i;
3038 for (j=2; j<=mesh_pts[index];
3041 if (cs[offset].val>gmax) gmax=cs[offset].val;
3043 fprintf(glob_prnt.
io,
" \t\t\t %22.14e\n",gmax);
3046 for (i=glob_info.
nnineq+1; i<=ncnstr; i++)
3047 fprintf(glob_prnt.
io,
" \t\t\t %22.14e\n",cs[i].val);
3050 for (i=glob_info.
nnineq+1; i<=glob_info.
nnineq+nn-nineqn; i++)
3051 SNECV=SNECV+fabs(cs[i].val);
3052 if (glob_prnt.
initvl==0 && (nn-nineqn)!=0)
3053 sbout1(glob_prnt.
io,0,
"SNECV ",
3057 if (glob_prnt.
iter<=1 && display) {
3058 fprintf(glob_prnt.
io,
" \n");
3059 fprintf(glob_prnt.
io,
" iteration %26d\n",
3063 if (glob_prnt.
iprint>=2 && glob_prnt.
initvl==0 && display)
3064 sbout1(glob_prnt.
io,0,
"step ",steps,adummy,1,1);
3065 if (glob_prnt.
initvl==0 && display &&
3066 (nstop==0 || glob_prnt.
info!=0 || glob_prnt.
iprint==2)) {
3067 sbout1(glob_prnt.
io,0,
"d0norm ",d0norm,adummy,1,1);
3068 sbout1(glob_prnt.
io,0,
"ktnorm ",sktnom,adummy,1,1);
3070 if (glob_prnt.
initvl==0 && feasb && display)
3071 fprintf(glob_prnt.
io,
" ncallf %26d\n",
3073 if (glob_prnt.
initvl==0 && (nn!=0 || !feasb) && display)
3074 fprintf(glob_prnt.
io,
" ncallg %26d\n",
3078 fprintf(glob_prnt.
io,
3079 "\n The following was calculated during iteration %5d:\n",
3081 if (nstop != 0 && (glob_prnt.
iter_mod==1))
3082 fprintf(glob_prnt.
io,
"\n iteration %26d\n",
3085 if (nstop!=0 || glob_prnt.
iprint==0)
goto L9000;
3086 fprintf(glob_prnt.
io,
"\n");
3088 fprintf(glob_prnt.
io,
" inform %26d\n",
3090 if (glob_prnt.
info==0) fprintf(glob_prnt.
io,
3091 "\nNormal termination: You have obtained a solution !!\n");
3092 if (glob_prnt.
info==0 && sktnom>0.1e0) fprintf(glob_prnt.
io,
3093 "Warning: Norm of Kuhn-Tucker vector is large !!\n");
3094 if (glob_prnt.
info==3) {
3095 fprintf(glob_prnt.
io,
3096 "\nWarning: Maximum iterations have been reached before\n");
3097 fprintf(glob_prnt.
io,
"obtaining a solution !!\n\n");
3099 if (glob_prnt.
info==4) {
3100 fprintf(glob_prnt.
io,
3101 "\nError : Step size has been smaller than the computed\n");
3102 fprintf(glob_prnt.
io,
"machine precision !!\n\n");
3104 if (glob_prnt.
info==5) fprintf(glob_prnt.
io,
3105 "\nError: Failure in constructing d0 !!\n\n");
3106 if (glob_prnt.
info==6) fprintf(glob_prnt.
io,
3107 "\nError: Failure in constructing d1 !!\n\n");
3108 if (glob_prnt.
info==8) {
3109 fprintf(glob_prnt.
io,
3110 "\nError: The new iterate is numerically equivalent to the\n");
3111 fprintf(glob_prnt.
io,
3112 "previous iterate, though the stopping criterion is not \n");
3113 fprintf(glob_prnt.
io,
"satisfied\n");
3115 if (glob_prnt.
info==9) {
3116 fprintf(glob_prnt.
io,
3117 "\nError: Could not satisfy nonlinear equality constraints -\n");
3118 fprintf(glob_prnt.
io,
" Penalty parameter too large\n");
3120 fprintf(glob_prnt.
io,
"\n");
3144 void OFSQP::diagnl(
int nrowa,
double diag,
double **a)
3148 for (i=1; i<=nrowa; i++) {
3149 for (j=i; j<=nrowa; j++) {
3163 void OFSQP::error(
const char string[],
int *inform)
3166 fprintf(stderr,
"%s\n",
string);
3179 OFSQP::estlam(
int nparam,
int neqn,
int *ifail,
double bigbnd,
double **hess,
3180 double *cvec,
double *a,
double *b,
struct _constraint *cs,
3181 double *psb,
double *bl,
double *bu,
double *x)
3183 int i,j,zero,one,lwar2,mnn,iout;
3186 for (i=1; i<=neqn; i++) {
3189 cvec[i]=scaprd(nparam,cs[i+glob_info.
nnineq].grad,psb);
3191 for (j=i; j<=neqn; j++) {
3192 hess[i][j]=scaprd(nparam,cs[i+glob_info.
nnineq].grad,
3193 cs[j+glob_info.
nnineq].grad);
3194 hess[j][i]=hess[i][j];
3201 ctemp=
convert(hess,neqn,neqn);
3205 ObjQLD::ql0001_(&zero,&zero,&one,&neqn,&neqn,&mnn,(ctemp+1),(cvec+1),
3206 (a+1),(b+1),(bl+1),(bu+1),(x+1),(w+1),&iout,ifail,
3207 &zero,(w+3),&lwar2,(iw+1),&leniw,&glob_grd.
epsmac);
3219 double *OFSQP::colvec(
double **a,
int col,
int nrows)
3224 temp=make_dv(nrows);
3225 for (i=1;i<=nrows;i++)
3236 double OFSQP::scaprd(
int n,
double *x,
double *y)
3253 void OFSQP::fool(
double x,
double y,
double *z)
3265 double OFSQP::small()
3267 double one,two,z,tsmall;
3274 fool(tsmall,one,&z);
3276 return tsmall*two*two;
3285 bool OFSQP::fuscmp(
double val,
double thrshd)
3289 if (fabs(val)<=thrshd) temp=
false;
3300 int OFSQP::indexs(
int i,
int nfs)
3304 while (mm>nfs) mm -= nfs;
3314 void OFSQP::matrcp(
int ndima,
double **a,
int ndimb,
double **b)
3318 for (i=1; i<=ndima; i++)
3319 for (j=1; j<=ndima; j++)
3321 if (ndimb<=ndima)
return;
3322 for (i=1; i<=ndimb; i++) {
3334 void OFSQP::matrvc(
int la,
int na,
double **a,
double *x,
double *y)
3339 for (i=1; i<=la; i++) {
3341 for (j=1; j<=na; j++)
3342 yi=yi + a[i][j]*x[j];
3353 void OFSQP::nullvc(
int nparam,
double *x)
3357 for (i=1; i<=nparam; i++)
3373 OFSQP::resign(
int n,
int neqn,
double *psf,
double *grdpsf,
double *penp,
3374 struct _constraint *cs,
double *signeq,
int job1,
int job2)
3379 if (job2==10 || job2==12) *psf=0.e0;
3380 for (i=1; i<=neqn; i++) {
3381 if (job1==10 || job1==12) cs[i+nineq].val=
3382 signeq[i]*cs[i+nineq].val;
3383 if (job2==10 || job2==12) *psf=*psf+cs[i+nineq].val*penp[i];
3384 if (job1==10 || job1==20)
continue;
3385 for (j=1; j<=n; j++)
3386 cs[i+nineq].grad[j]=cs[i+nineq].grad[j]*signeq[i];
3388 if (job2==10 || job2==20)
return;
3390 for (i=1; i<=n; i++)
3391 for (j=1; j<=neqn; j++)
3392 grdpsf[i]=grdpsf[i]+cs[j+nineq].grad[i]*penp[j];
3402 OFSQP::sbout1(FILE *io,
int n,
const char *s1,
double z,
double *z1,
int job,
int level)
3407 if (level == 1) fprintf(io,
" %s\t %22.14e\n",s1,z);
3408 if (level == 2) fprintf(io,
"\t\t\t %s\t %22.14e\n",s1,z);
3412 if (level == 1) fprintf(io,
" %s\t %22.14e\n",s1,z1[1]);
3413 if (level == 2) fprintf(io,
"\t\t\t %s\t %22.14e\n",s1,z1[1]);
3414 for (j=2; j<=n; j++) {
3415 if (level == 1) fprintf(io,
" \t\t\t %22.14e\n",z1[j]);
3416 if (level == 2) fprintf(io,
" \t\t\t\t\t\t %22.14e\n",z1[j]);
3427 OFSQP::sbout2(FILE *io,
int n,
int i,
const char *s1,
const char *s2,
double *z)
3431 fprintf(io,
"\t\t\t %8s %5d %1s\t %22.14e\n",s1,i,s2,z[1]);
3432 for (j=2; j<=n; j++)
3433 fprintf(io,
"\t\t\t\t\t\t %22.14e\n",z[j]);
3443 void OFSQP::shift(
int n,
int ii,
int *iact)
3447 if (ii == iact[1])
return;
3448 for (j=1; j<=n; j++) {
3449 if (ii != iact[j])
continue;
3450 for (k=j; k>=2; k--)
3454 if (n!=0) iact[1]=ii;
3465 OFSQP::slope(
int nob,
int nobL,
int neqn,
int nparam,
int feasb,
3466 struct _objective *ob,
double *grdpsf,
double *x,
double *y,
3467 double fmax,
double theta,
int job,
double *prev,
int old)
3470 double slope1,rhs,rhog,grdftx,grdfty,diff,grpstx,grpsty;
3474 if (feasb && nob==0) tslope=0.e0;
3475 if (neqn==0 || !feasb) {
3479 grpstx=scaprd(nparam,grdpsf,x);
3480 grpsty=scaprd(nparam,grdpsf,y);
3482 for (i=1; i<=nob; i++) {
3483 if (old) slope1=prev[i]+scaprd(nparam,ob[i].grad,x);
3484 else slope1=ob[i].val+scaprd(nparam,ob[i].grad,x);
3485 tslope=std::max(tslope,slope1);
3486 if (nobL != nob) tslope=std::max(tslope,-slope1);
3488 tslope=tslope-fmax-grpstx;
3489 if (job == 0)
return tslope;
3490 rhs=theta*tslope+fmax;
3492 for (i=1; i<=nob; i++) {
3493 grdftx=scaprd(nparam,ob[i].grad,x)-grpstx;
3494 grdfty=scaprd(nparam,ob[i].grad,y)-grpsty;
3496 if (diff <= 0.e0)
continue;
3497 rhog=std::min(rhog,(rhs-ob[i].val-grdftx)/diff);
3498 if (nobL != nob) rhog=std::min(rhog,-(rhs+ob[i].val+grdftx)/diff);
3509 bool OFSQP::element(
int *
set,
int length,
int index)
3515 for (i=1; i<=length; i++) {
3516 if (
set[i]==0)
break;
3517 if (
set[i]==index) {
3542 OFSQP::make_dv(
int len)
3547 v=(
double *)calloc(len,
sizeof(
double));
3549 fprintf(stderr,
"Run-time error in make_dv");
3561 OFSQP::make_iv(
int len)
3566 v=(
int *)calloc(len,
sizeof(
int));
3568 fprintf(stderr,
"Run-time error in make_iv");
3580 OFSQP::make_dm(
int rows,
int cols)
3585 if (rows == 0) rows=1;
3586 if (cols == 0) cols=1;
3587 temp=(
double **)calloc(rows,
sizeof(
double *));
3589 fprintf(stderr,
"Run-time error in make_dm");
3593 for (i=1; i<=rows; i++) {
3594 temp[i]=(
double *)calloc(cols,
sizeof(
double));
3596 fprintf(stderr,
"Run-time error in make_dm");
3610 OFSQP::free_dv(
double *v)
3612 free((
char *) (v+1));
3621 OFSQP::free_iv(
int *v)
3623 free((
char *) (v+1));
3632 OFSQP::free_dm(
double **m,
int rows)
3637 for (i=1; i<=rows; i++) free((
char *) (m[i]+1));
3638 free ((
char *) (m+1));
3653 temp = make_dv(m*n);
3655 for (i=1; i<=n; i++)
3656 for (j=1; j<=m; j++)
3657 temp[(m*(i-1)+j)] = a[j][i];
3675 void obj(
int nparam,
int j,
double* x,
double* fj,
void* cd)
3677 *fj=pow((x[0]+3.e0*x[1]+x[2]),2.e0)+4.e0*pow((x[0]-x[1]),2.e0);
3681 void gradob(
int nparam,
int j,
double* x,
double* gradfj,
void* cd)
3685 fa=2.e0*(x[0]+3.e0*x[1]+x[2]);
3686 fb=8.e0*(x[0]-x[1]);
3688 gradfj[1]=fa*3.e0-fb;
3693 void constr(
int nparam,
int j,
double* x,
double* gj,
void* cd)
3697 *gj=pow(x[0],3.e0)-6.e0*x[1]-4.e0*x[2]+3.e0;
3700 *gj=1.e0-x[0]-x[1]-x[2];
3706 void gradcn(
int nparam,
int j,
double* x,
double* gradgj,
void* cd)
3710 gradgj[0]=3.e0*x[0]*x[0];
3715 gradgj[0]=gradgj[1]=gradgj[2]=-1.e0;
3727 int nparam, nf, nineq, neq, mode, iprint, miter, neqn, nineqn, ncsrl, ncsrn, nfsr, mesh_pts[1], inform;
3728 double bigbnd, eps, epsneq, udelta;
3729 double *x, *bl, *bu, *f, *g, *lambda;
3744 ncsrl = ncsrn = nfsr = mesh_pts[0] = 0;
3745 bl =
new double[nparam];
3746 bu =
new double[nparam];
3747 x =
new double[nparam];
3748 f =
new double[nf+1];
3749 g =
new double[nineq+neq+1];
3750 lambda =
new double[nineq+neq+nf+nparam];
3752 bl[0] = bl[1] = bl[2] = 0.e0;
3753 bu[0] = bu[1] = bu[2] = bigbnd;
3759 solver.
cfsqp(nparam, nf, nfsr, nineqn, nineq, neqn, neq, ncsrl, ncsrn, mesh_pts, mode, iprint, miter, &inform, bigbnd, eps,
3760 epsneq, udelta, bl, bu, x, f, g, lambda, pb, 0x0);
3777 void obj(
int nparam,
int j,
double* x,
double* fj,
void* cd)
3781 pi=3.14159265358979e0;
3782 theta=pi*(8.5e0+j*0.5e0)/180.e0;
3784 for (i=0; i<=5; i++)
3785 *fj=*fj+cos(2.e0*pi*x[i]*sin(theta));
3786 *fj=2.e0*(*fj+cos(2.e0*pi*3.5e0*sin(theta)))/15.e0+1.e0/15.e0;
3790 void constr(
int nparam,
int j,
double* x,
double* gj,
void* cd)
3795 case 1: *gj=ss-x[0];
break;
3796 case 2: *gj=ss+x[0]-x[1];
break;
3797 case 3: *gj=ss+x[1]-x[2];
break;
3798 case 4: *gj=ss+x[2]-x[3];
break;
3799 case 5: *gj=ss+x[3]-x[4];
break;
3800 case 6: *gj=ss+x[4]-x[5];
break;
3801 case 7: *gj=ss+x[5]-3.5e0;
break;
3812 int nparam, nf, nineq, neq, mode, iprint, miter, neqn, nineqn, ncsrl, ncsrn, nfsr, mesh_pts[1], inform;
3813 double bigbnd, eps, epsneq, udelta;
3814 double *x, *bl, *bu, *f, *g, *lambda;
3829 ncsrl = ncsrn = nfsr = mesh_pts[0] = 0;
3830 bl =
new double[nparam];
3831 bu =
new double[nparam];
3832 x =
new double[nparam];
3833 f =
new double[nf+1];
3834 g =
new double[nineq+neq+1];
3835 lambda =
new double[nineq+neq+nf+nparam];
3837 bl[0] = bl[1] = bl[2] = bl[3] = bl[4] = bl[5] = -bigbnd;
3838 bu[0] = bu[1] = bu[2] = bu[3] = bu[4] = bu[5] = bigbnd;
3847 solver.
cfsqp(nparam, nf, nfsr, nineqn, nineq, neqn, neq, ncsrl, ncsrn, mesh_pts, mode, iprint, miter, &inform, bigbnd, eps,
3848 epsneq, udelta, bl, bu, x, f, g, lambda, pb, 0x0);
3864 int nparam, nf, nineq, neq, mode, iprint, miter, neqn, nineqn, ncsrl, ncsrn, nfsr, mesh_pts[1], inform;
3865 double bigbnd, eps, epsneq, udelta;
3866 double *x, *bl, *bu, *f, *g, *lambda;
3884 bl =
new double[nparam];
3885 bu =
new double[nparam];
3886 x =
new double[nparam];
3887 f =
new double[mesh_pts[0]+1];
3888 g =
new double[nineq+neq+1];
3889 lambda =
new double[nineq+neq+mesh_pts[0]+nparam+1];
3891 bl[0] = bl[1] = bl[2] = bl[3] = bl[4] = bl[5] = -bigbnd;
3892 bu[0] = bu[1] = bu[2] = bu[3] = bu[4] = bu[5] = bigbnd;
3901 solver.
cfsqp(nparam, nf, nfsr, nineqn, nineq, neqn, neq, ncsrl, ncsrn, mesh_pts, mode, iprint, miter, &inform, bigbnd, eps,
3902 epsneq, udelta, bl, bu, x, f, g, lambda, pb, 0x0);
3918 void obj(
int nparam,
int j,
double* x,
double* fj,
void* cd)
3920 *fj=x[0]*x[3]*(x[0]+x[1]+x[2])+x[2];
3924 void gradob(
int nparam,
int j,
double* x,
double* gradfj,
void* cd)
3926 gradfj[0]=x[3]*(x[0]+x[1]+x[2])+x[0]*x[3];
3927 gradfj[1]=x[0]*x[3];
3928 gradfj[2]=x[0]*x[3]+1.e0;
3929 gradfj[3]=x[0]*(x[0]+x[1]+x[2]);
3933 void constr(
int nparam,
int j,
double* x,
double* gj,
void* cd)
3937 *gj=25.e0-x[0]*x[1]*x[2]*x[3];
3940 *gj=x[0]*x[0]+x[1]*x[1]+x[2]*x[2]+x[3]*x[3]-40.e0;
3946 void gradcn(
int nparam,
int j,
double* x,
double* gradgj,
void* cd)
3950 gradgj[0]=-x[1]*x[2]*x[3];
3951 gradgj[1]=-x[0]*x[2]*x[3];
3952 gradgj[2]=-x[0]*x[1]*x[3];
3953 gradgj[3]=-x[0]*x[1]*x[2];
3956 gradgj[0]=2.e0*x[0];
3957 gradgj[1]=2.e0*x[1];
3958 gradgj[2]=2.e0*x[2];
3959 gradgj[3]=2.e0*x[3];
3971 int nparam, nf, nineq, neq, mode, iprint, miter, neqn, nineqn, ncsrl, ncsrn, nfsr, mesh_pts[1], inform;
3972 double bigbnd, eps, epsneq, udelta;
3973 double *x, *bl, *bu, *f, *g, *lambda;
3988 ncsrl = ncsrn = nfsr = mesh_pts[0] = 0;
3989 bl =
new double[nparam];
3990 bu =
new double[nparam];
3991 x =
new double[nparam];
3992 f =
new double[nf+1];
3993 g =
new double[nineq+neq+1];
3994 lambda =
new double[nineq+neq+nf+nparam+1];
3996 bl[0] = bl[1] = bl[2] = bl[3] = 1.e0;
3997 bu[0] = bu[1] = bu[2] = bu[3] = 5.e0;
4004 solver.
cfsqp(nparam, nf, nfsr, nineqn, nineq, neqn, neq, ncsrl, ncsrn, mesh_pts, mode, iprint, miter, &inform, bigbnd, eps,
4005 epsneq, udelta, bl, bu, x, f, g, lambda, pb, 0x0);
4021 void obj(
int nparam,
int j,
double* x,
double* fj,
void* cd)
4027 void gradob(
int nparam,
int j,
double* x,
double* gradfj,
void* cd)
4042 void constr(
int nparam,
int j,
double* x,
double* gj,
void* cd)
4050 t=3.14159265358979312e0*(j-1)*0.025e0;
4054 t=3.14159265358979312e0*(j-1-r)*0.025e0;
4056 t=3.14159265358979312e0*(1.2e0+(j-1-2*r)*0.2e0)*0.25e0;
4058 for (k=1; k<=9; k++)
4060 s1=s1+x[k-1]*cos(k*t);
4061 s2=s2+x[k-1]*sin(k*t);
4065 *gj=(1.e0-x[9])*(1.e0-x[9])-z;
4069 *gj=z-(1.e0+x[9])*(1.e0+x[9]);
4082 int nparam, nf, nineq, neq, mode, iprint, miter, neqn, nineqn, ncsrl, ncsrn, nfsr, mesh_pts[3], numc, inform;
4083 double bigbnd, eps, epsneq, udelta;
4084 double *x, *bl, *bu, *f, *g, *lambda;
4098 nineqn = nineq = ncsrn = 3;
4100 mesh_pts[0] = mesh_pts[1] = r;
4101 mesh_pts[2] = 3*r/2;
4104 bl =
new double[2*nparam];
4105 bu =
new double[2*nparam];
4106 x =
new double[2*nparam];
4107 f =
new double[2*(nf+1)];
4108 g =
new double[2*(numc+1)];
4109 lambda =
new double[2*(numc+nf+nparam+1)];
4111 bl[0] = bl[1] = bl[2] = bl[3] = bl[4] = bl[5] = bl[6] = bl[7] = bl[8] = bl[9] = -bigbnd;
4112 bu[0] = bu[1] = bu[2] = bu[3] = bu[4] = bu[5] = bu[6] = bu[7] = bu[8] = bu[9] = bigbnd;
4114 x[0] = x[1] = x[2] = x[3] = x[4] = x[5] = x[6] = x[7] = x[8] = 0.1e0;
4117 solver.
cfsqp(nparam, nf, nfsr, nineqn, nineq, neqn, neq, ncsrl, ncsrn, mesh_pts, mode, iprint, miter, &inform, bigbnd, eps,
4118 epsneq, udelta, bl, bu, x, f, g, lambda, pb, 0x0);
4133 void obj(
int nparam,
int j,
double* x,
double* fj,
void* cd)
4135 *fj=(1.e0/3.e0)*pow(x[0],2.e0)+pow(x[1],2.e0)+0.5e0*x[0];
4139 void gradob(
int nparam,
int j,
double* x,
double* gradfj,
void* cd)
4141 gradfj[0]=(2.e0/3.e0)*x[0]+0.5e0;
4142 gradfj[1]=2.e0*x[1];
4146 void constr(
int nparam,
int j,
double *x,
double* gj,
void* cd)
4151 *gj=pow((1.e0-pow(y*x[0],2.e0)),2.e0)-x[0]*y*y-pow(x[1],2.e0)
4156 void gradcn(
int nparam,
int j,
double* x,
double* gradgj,
void* cd)
4161 gradgj[0]=-4.e0*(1.e0-pow(y*x[0],2.e0))*y*y*x[0]-y*y;
4162 gradgj[1]=-2.e0*x[1]+1.e0;
4172 int nparam, nf, nineq, neq, mode, iprint, miter, neqn, nineqn, ncsrl, ncsrn, nfsr, mesh_pts[1], inform;
4173 double bigbnd, eps, epsneq, udelta;
4174 double *x, *bl, *bu, *f, *g, *lambda;
4191 bl =
new double[nparam];
4192 bu =
new double[nparam];
4193 x =
new double[nparam];
4194 f =
new double[nf+1];
4195 g =
new double[nineq + (mesh_pts[0]-1)*(ncsrl+ncsrn) + neq+1];
4196 lambda =
new double[nineq + (mesh_pts[0]-1)*(ncsrl+ncsrn) + neq + nf + nparam];
4198 bl[0] = bl[1] = -bigbnd;
4199 bu[0] = bu[1] = bigbnd;
4204 solver.
cfsqp(nparam, nf, nfsr, nineqn, nineq, neqn, neq, ncsrl, ncsrn, mesh_pts, mode, iprint, miter, &inform, bigbnd, eps,
4205 epsneq, udelta, bl, bu, x, f, g, lambda, pb, 0x0);
virtual void gradob(int nparam, int j, double *x, double *gradfj, void *cd)
void cfsqp(int nparam, int nf, int nfsr, int nineqn, int nineq, int neqn, int neq, int ncsrl, int ncsrn, int *mesh_pts, int mode, int iprint, int miter, int *inform, double bigbnd, double eps, double epseqn, double udelta, double *bl, double *bu, double *x, double *f, double *g, double *lambda, OFSQPProblem &problem, void *cd)
void setFSQPstruct(fsqpDetails::Grd &grd, fsqpDetails::Prnt &prnt)
Optimization-based Robot Controller namespace. a library of classes to write and solve optimization p...
void convert(const LinearConstraint &cstr, const std::vector< int > &mapping, eConstraintOutput type, MatrixBase< Derived > &A, VectorBase1 &b, VectorBase2 &l, double infinity=0.)
virtual void gradcn(int nparam, int j, double *x, double *gradgj, void *cd)
Declaration file of the ObjQLD class. This class should be merged with ocra::ObjQLD. It has been created to have a cml-free solver.
virtual void constr(int nparam, int j, double *x, double *gj, void *cd)=0
virtual void obj(int nparam, int j, double *x, double *fj, void *cd)=0