16 #include "CoinTime.hpp"
72 fint irh1,
na,
na1,
nb,
nb1,
ka1,
kb1,
kc1,
irg1,
lu1,
lv,
lv1,
ll1;
82 fint ns,
ns1,
nt,
nt1,
nu,
nu1,
nx,
nx1,
np,
np1,
nprof,
lc;
83 fint lc1,
li,
li1,
lm,
lm1,
lp_,
lp1,
lq,
lq1,
lr,
lr1,
ls_,
ls1,
lt,
lt1;
112 roptions->AddLowerBoundedNumberOption(
"qp_fillin_factor",
"Factor for estimating fill-in for factorization method in Bqpd", 0.,
true, 4.);
113 roptions->AddBoundedIntegerOption(
"hot_start_m0de",
"Choice of the hot start option", 0, 6, 6);
114 roptions->AddLowerBoundedIntegerOption(
"reinit_freq",
"Number of pivots before recopy hot start", 0, 0);
122 if (createEmpty)
return;
128 const std::string &
prefix)
130 TNLPSolver(roptions, options, journalist, prefix),
133 options->GetNumericValue(
"qp_fillin_factor",
fillin_factor_,
"bqpd.");
134 options->GetIntegerValue(
"kmax",
kmax_ipt_,
"bqpd.");
135 options->GetIntegerValue(
"mlp",
mlp_ipt_,
"bqpd.");
136 options->GetIntegerValue(
"hot_start_m0de",
m0de_,
"bqpd.");
137 options->GetIntegerValue(
"reinit_freq",
reinit_freq_,
"bqpd.");
147 times().create -= CoinCpuTime();
159 retval->m0de_ =
m0de_;
161 times().create += CoinCpuTime();
175 is.open(optFile.c_str());
177 catch (std::bad_alloc) {
178 journalist_->Printf(Ipopt::J_SUMMARY, Ipopt::J_MAIN,
"\nEXIT: Not enough memory.\n");
182 Ipopt::IpoptException E(
"Unknown Exception caught in ipopt",
"Unknown File", -1);
211 Ipopt::IpoptException E(
"BqpdSolver called with object other than a BranchingTQP",
212 "BonBqpdSolver.cpp",-1);
220 times().solve -= CoinCpuTime();
224 times().solve += CoinCpuTime();
242 for (
int i=0; i<n+
m; i++) {
248 cached_->use_warm_start_in_cache_ =
true;
252 cached_->use_warm_start_in_cache_ =
true;
256 times().resolve -= CoinCpuTime();
260 times().resolve += CoinCpuTime();
270 double* fillin_factor)
284 F77_FUNC(refactorc,REFACTORC).nfreq = 500;
286 Ipopt::TNLP::IndexStyleEnum index_style;
287 Ipopt::Index nv, nc, nnz_jac_g, nnz_hess;
288 tqp->get_nlp_info(nv, nc, nnz_jac_g, nnz_hess, index_style);
292 if (kmax_ipt == -1) {
319 for (
int i=0; i<
n+
m; i++) {
320 bl[i] = std::max(
bl[i], -1e50);
321 bu[i] = std::min(
bu[i], 1e50);
326 const Ipopt::Number* obj_grad = tqp->ObjGrad();
328 for (
int i = 0; i<
n; i++) {
329 if (obj_grad[i]!=0.) {
333 int lamax =
amax_+m+2;
339 for (
int i = 0; i <
n ; i++) {
340 if (obj_grad[i]!=0.) {
341 a[nnz_grad] = obj_grad[i];
342 la[++nnz_grad] = i+1;
348 const Ipopt::Number* JacVals = tqp->ConstrJacVals();
349 const Ipopt::Index* RowJac = tqp->ConstrJacIRow();
350 const Ipopt::Index* ColJac = tqp->ConstrJacJCol();
354 la, nnz_grad, 1, Ipopt::TNLP::C_STYLE);
355 for (
int i=0; i<nnz_jac_g; i++) {
356 const int& indice = permutationJac[i];
357 a[nnz_grad+i] = JacVals[indice];
362 printf(
"nnz_grad = %d nnz_jac = %d\n", nnz_grad, nnz_jac_g);
363 for (
int i=0; i<1+lamax; i++) printf(
"la[%2d] = %d\n", i,
la[i]);
364 for (
int i=0; i<
amax_; i++) printf(
"a[%3d] = %e\n",i,
a[i]);
369 mxlws = (nnz_hess + n + 2) +
kmax + (9*n + m);
375 for (
int i=0; i<
mxws; i++) {
378 for (
int i=0; i<
mxlws; i++) {
384 const Ipopt::Number* HessVals = tqp->ObjHessVals();
385 const Ipopt::Index* RowHess = tqp->ObjHessIRow();
386 const Ipopt::Index* ColHess = tqp->ObjHessJCol();
389 ll = nnz_hess + n + 2;
393 permutationHess,
lws, 0, 0, Ipopt::TNLP::C_STYLE);
394 for (
int i=0; i<nnz_hess; i++) {
395 ws[i] = HessVals[permutationHess[i]];
400 printf(
"nnz_hess = %d\n", nnz_hess);
401 for (
int i=0; i<
ll; i++) printf(
"hess lws[%2d] = %d\n", i,
lws[i]);
402 for (
int i=0; i<
kk; i++) printf(
"hess ws[%3d] = %e\n",i,
ws[i]);
406 options->GetIntegerValue(
"iprint",bufy,
"bqpd.");
416 use_warm_start_in_cache_ =
false;
419 for (
int i=0; i<
mxws; i++) {
422 for (
int i=0; i<
mxlws; i++) {
435 Ipopt::SolverReturn status = Ipopt::INTERNAL_ERROR;
440 status = Ipopt::SUCCESS;
444 status = Ipopt::DIVERGING_ITERATES;
448 status = Ipopt::LOCAL_INFEASIBILITY;
453 Ipopt::Number* dummy =
new Ipopt::Number[dummy_len];
454 for (
int i=0; i<dummy_len; i++) {
463 return optimizationStatus;
491 #ifdef DISABLE_COPYING
495 times_.warm_start -= CoinCpuTime();
497 haveHotStart_ =
true;
567 xHot = CoinCopyOfArray(
x,
n);
569 gHot = CoinCopyOfArray(
g,
n);
570 rHot = CoinCopyOfArray(
r,
n+
m);
571 wHot = CoinCopyOfArray(
w,
n+
m);
572 eHot = CoinCopyOfArray(
e,
n+
m);
573 lsHot = CoinCopyOfArray(
ls,
n+
m);
574 alpHot = CoinCopyOfArray(
alp,
mlp);
575 lpHot = CoinCopyOfArray(
lp,
mlp);
577 wsHot = CoinCopyOfArray(
ws,
mxws);
578 lwsHot = CoinCopyOfArray(
lws,
mxlws);
579 infoHot[0] =
info[0];
581 times_.warm_start += CoinCpuTime();
590 #ifdef DISABLE_COPYING
594 times_.warm_start -= CoinCpuTime();
668 CoinCopyN(rHot,
n+
m,
r);
669 CoinCopyN(wHot,
n+
m,
w);
670 CoinCopyN(eHot,
n+
m,
e);
671 CoinCopyN(lsHot,
n+
m,
ls);
672 CoinCopyN(alpHot,
mlp,
alp);
673 CoinCopyN(lpHot,
mlp,
lp);
676 info[0] = infoHot[0];
679 times_.warm_start += CoinCpuTime();
697 haveHotStart_ =
false;
705 F77_FUNC(scalec,SCALEC).scale_mode = 0;
713 if (use_warm_start_in_cache_ && !bad_warm_start_info_) {
715 use_warm_start_in_cache_ =
false;
716 if (haveHotStart_ && pivots_ > next_reinit_) {
725 tqp_->get_starting_point(
n, 1,
x, 0, NULL, NULL,
m, 0, NULL);
727 bad_warm_start_info_ =
false;
731 printf(
"========= 222222222222 =============\n");
732 printf(
"kk = %d ll = %d mxws = %d mxlws = %d\n",
kk,
ll,
mxws,
mxlws);
733 for (
int i=0; i<
n; i++) {
734 printf(
"xL[%3d] = %15.8e xU[%3d] = %15.8e\n", i,
bl[i], i,
bu[i]);
736 for (
int i=0; i<
m; i++) {
737 printf(
"gL[%3d] = %15.8e gU[%3d] = %15.8e\n", i,
bl[n+i], i,
bu[n+i]);
740 cpuTime_ = - CoinCpuTime();
743 for (
int i=0; i<
n; i++) {
744 printf(
"qxstart[%2d] = %23.16e\n", i,
x[i]);
750 FILE* fp = fopen(
"QPinit.dat",
"w");
751 fprintf(fp,
"n = %d\n", n);
752 fprintf(fp,
"m = %d\n", m);
753 fprintf(fp,
"kmax = %d\n",
kmax);
754 fprintf(fp,
"amax = %d\n" ,amax_);
755 for (
int i=1; i<=amax_; i++) {
756 fprintf(fp,
"a = %23.16e\n",
a[i-1]);
758 int lamax = amax_ + m + 2;
759 fprintf(fp,
"lamax = %d\n" ,lamax);
760 for (
int i=1; i<=lamax+1; i++) {
761 fprintf(fp,
"la = %6d\n",
la[i-1]);
763 for (
int i=1; i<=
n; i++) {
764 fprintf(fp,
"x = %23.16e\n",
x[i-1]);
766 for (
int i=1; i<=n+
m; i++) {
767 fprintf(fp,
"bl = %23.16e\n",
bl[i-1]);
769 for (
int i=1; i<=n+
m; i++) {
770 fprintf(fp,
"bu = %23.16e\n",
bu[i-1]);
772 fprintf(fp,
"fmin = %23.16e\n", fmin);
773 fprintf(fp,
"mlp = %6d\n",
mlp);
774 fprintf(fp,
"mxws = %d\n",
mxws);
775 fprintf(fp,
"mxlws = %d\n",
mxlws);
779 FILE* fp = fopen(
"QPbounds.dat",
"w");
780 fprintf(fp,
"m0de = %d\n",
m0de);
781 for (
int i=1; i<=n+
m; i++) {
782 fprintf(fp,
"bl = %23.16e\n",
bl[i-1]);
784 for (
int i=1; i<=n+
m; i++) {
785 fprintf(fp,
"bu = %23.16e\n",
bu[i-1]);
790 F77_FUNC(bqpd,BQPD)(&
n, &
m, &
k, &
kmax,
a,
la,
x,
bl,
bu, &
f, &
fmin,
791 g,
r,
w,
e,
ls,
alp,
lp, &
mlp, &
peq,
ws,
lws,
794 times_.pivots += info[0];
798 fprintf(stdout,
"Reinitialize hot start...\n");
801 F77_FUNC(bqpd,BQPD)(&
n, &
m, &
k, &
kmax,
a,
la,
x,
bl,
bu, &
f, &
fmin,
802 g,
r,
w,
e,
ls,
alp,
lp, &
mlp, &
peq,
ws,
lws,
804 printf(
"new ifail = %d\n", ifail);
807 fprintf(stdout,
"Restarting Bqpd...");
809 tqp_->get_starting_point(n, 1, x, 0, NULL, NULL, m, 0, NULL);
811 F77_FUNC(bqpd,BQPD)(&
n, &
m, &
k, &
kmax,
a,
la,
x,
bl,
bu, &
f, &
fmin,
812 g,
r,
w,
e,
ls,
alp,
lp, &
mlp, &
peq,
ws,
lws,
814 printf(
"new ifail = %d\n", ifail);
818 if (haveHotStart_) unmarkHotStart();
826 for (
int i=0; i<mxws_new; i++) {
830 CoinCopyN(ws,
kk, ws_new);
837 tqp_->get_starting_point(n, 1, x, 0, NULL, NULL, m, 0, NULL);
839 F77_FUNC(bqpd,BQPD)(&
n, &
m, &
k, &
kmax,
a,
la,
x,
bl,
bu, &
f, &
fmin,
840 g,
r,
w,
e,
ls,
alp,
lp, &
mlp, &
peq,
ws,
lws,
843 if (ifail == 8) bad_warm_start_info_ =
true;
845 for (
int i=0; i<
n; i++) {
846 printf(
"qxsol[%2d] = %23.16e\n", i, x[i]);
850 printf(
"ifail = %d\n", ifail);
851 printf(
"final f = %e\n", f);
852 printf(
"final f + obj_val = %e\n", f+tqp_->ObjVal());
857 printf(
"========= 3333333333 =============\n");
858 printf(
"kk = %d ll = %d kkk = %d lll = %d mxws = %d mxlws = %d\n",
kk,
ll, kkk, lll,
mxws,
mxlws);
859 for (
int i=0; i<
kk+
kkk; i++) {
860 printf(
"ws[%3d] = %15.8e\n ", i, ws[i]);
862 printf(
"--------\n");
863 for (
int i=
kk+kkk; i<
mxws; i++) {
864 printf(
"ws[%3d] = %15.8e\n ", i, ws[i]);
866 for (
int i=0; i<
ll+
lll; i++) {
867 printf(
"lws[%5d] = %8d\n", i, lws[i]);
870 for (
int i=
ll+lll; i<
mxlws; i++) {
871 printf(
"lws[%5d] = %8d\n", i, lws[i]);
874 cpuTime_ += CoinCpuTime();
879 {
"Internal error in Filter SQP."};
888 return errorNames_[0];
908 const fint xsize = warmF->xSize();
910 const real* xarray = warmF->xArray();
911 for (
int i = 0; i<xsize; i++) {
914 CoinCopyN(warmF->lamArray(), warmF->lamSize(),
cached_->lam);
916 for (
int i = 0 ; i < 14 ; i ++) {
919 cached_->use_warm_start_in_cache_ =
true;
921 printf(
"BqpdSolver::setWarmStart called!\n");
933 printf(
"BqpdSolver::getWarmStart called!\n");
943 printf(
"BqpdSolver::getEmptyWarmStart called \n");
951 if (bws && ! bws->
empty()) {
Option category for Bqpd.
void fint fint fint real fint real real real real real real real real real fint real fint fint fint real fint * lws
TNLPSolver::ReturnStatus callOptimizer()
Perform optimization using data structure in cache.
virtual ReturnStatus ReOptimizeTNLP(const Ipopt::SmartPtr< Ipopt::TNLP > &tnlp)
Resolves a problem expresses as a TNLP.
void fint fint fint * kmax
virtual const std::string & errorName() const
Get the string corresponding to error.
void fint fint fint real fint real real real real real real real real real fint real fint fint fint real fint fint fint fint * info
Ipopt::SmartPtr< Ipopt::Journalist > journalist_
Storage of Journalist for output.
const fint * istat() const
void fint fint fint real fint * la
Bonmin::BqpdSolver F77_FUNC
Ipopt::SmartPtr< BranchingTQP > tqp_
int mlp_ipt_
Fill-in factor for QP factorization.
std::string prefix_
Prefix to use for reading bonmin's options.
void unmarkHotStart()
Forget about the hot start info.
fint lwsSize() const
Access to lws size.
void fint fint fint real * a
static int reinit_freq_
Hot start reinitialization fequency.
void fint fint fint real fint real real * bl
bool use_warm_start_in_cache_
flag remembering if warm start information has been put into cache
This is a generic class for calling an NLP solver to solve a TNLP.
Bonmin::BqpdSolver::fint fint
Warm start for filter interface.
void fint fint fint real fint real real real real real real real real real fint real fint fint * mlp
virtual bool Initialize(std::string params_file)
Initialize the TNLPSolver (read options from params_file)
static std::string errorNames_[1]
ipfint fint
Fortran type for integer used in filter.
void fint fint fint real fint real real real real * f
int default_log_level_
To record default log level.
void fint fint fint real fint real real real real real real real real real * e
Bonmin::BqpdSolver::real real
bool IsNull(const OSSmartPtr< U > &smart_ptr)
void fint fint fint real fint real real real real real real real real real fint real fint * lp
void fint fint fint real fint real real real real real real real real real fint real fint fint fint * peq
virtual CoinWarmStart * getEmptyWarmStart() const
Solves a problem expresses as a TNLP.
bool markHotStart()
Store most recent solution as hot start.
void fint fint fint real fint real real real real real real real real real fint real fint fint fint real fint fint * m0de
Warm start for filter interface.
static int m0de_
Hot start m0de.
double fillin_factor_
Fill-in factor for QP factorization.
void registerOptions()
Register this solver options into passed roptions.
void fint fint fint real fint real real real real real * fmin
const fint * lwsArray() const
Access to lws array.
void fint fint fint real fint real real real real real real real real real fint real * alp
static void TMat2RowPMat(bool symmetric, fint n, fint m, int nnz, const Ipopt::Index *iRow, const Ipopt::Index *iCol, int *permutation2, fint *lws, int nnz_offset, int n_offset, Ipopt::TNLP::IndexStyleEnum index_style)
Converting TMatrices into row-ordered matrices.
void copyFromHotStart()
Copy current values from hot start info.
void fint fint fint real fint real real real real real real real * r
virtual ReturnStatus OptimizeTNLP(const Ipopt::SmartPtr< Ipopt::TNLP > &tnlp)
Solves a problem expresses as a TNLP.
U * GetRawPtr(const OSSmartPtr< U > &smart_ptr)
Ipopt::SmartPtr< Bonmin::RegisteredOptions > roptions_
Registered Options.
void fint fint fint real fint real real real real real real real real real fint real fint fint fint real * ws
int kmax_ipt_
Fill-in factor for QP factorization.
virtual bool setWarmStart(const CoinWarmStart *warm, Ipopt::SmartPtr< TMINLP2TNLP > tnlp)
Set the warm start in the solver.
ReturnStatus
Standard return statuses for a solver.
virtual Ipopt::SmartPtr< TNLPSolver > clone()
Virtual copy constructor.
double * fillin_factor_
Fill-in factor for QP factorization.
void fint fint fint real fint real real real real real real real real real fint real fint fint fint real fint fint fint * ifail
Ipopt::SmartPtr< cachedInfo > cached_
Cached information on last problem optimized for reoptimization.
static int * permutationHess
void fint fint fint real fint real real real real real real real real real fint * ls
void initialize(const Ipopt::SmartPtr< BranchingTQP > &tqp, Ipopt::SmartPtr< Ipopt::OptionsList > &options, int kmax_ipt, int mlp_ipt, double *fillin_factor)
Fill data structures for filter with info from tnlp.
This is an adapter class that converts a TMINLP2TNLP object into a TNLP, which is now just a QP...
void fint fint fint real fint real real real real real real * g
BqpdSolver(bool createEmpty=false)
Default constructor.
void optimize()
Optimize problem described by cache with filter.
void fint fint fint real fint real real real real real real real real real fint real fint fint fint real fint fint fint fint fint fint * nout
static int * permutationJac
virtual const std::string & solverName() const
Return the name of the solver.
int amax_
Number of nonzeros in Jacobian and gradient.
static std::string solverName_
To record default log level.
virtual bool warmStartIsValid(const CoinWarmStart *ws) const
Check that warm start object is valid.
static std::string solverName_
void fint fint fint real fint real real real real real real real real * w
Cached information for reoptimizing.
Ipopt::SmartPtr< Ipopt::OptionsList > options_
List of Options.
double real
Fortran type for double.used in filter.
virtual CoinWarmStart * getWarmStart(Ipopt::SmartPtr< TMINLP2TNLP > tnlp) const
Get the warm start form the solver.
void fint fint fint real fint real real real real real real real real real fint real fint fint fint real fint fint fint fint fint * iprint
bool empty() const
Is this an empty warm start?
void fint fint fint real fint real * x
virtual ~BqpdSolver()
destructor
void fint fint fint real fint real real real * bu