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");
183 Ipopt::IpoptException E(
"Unknown Exception caught in ipopt",
"Unknown File", -1);
213 Ipopt::IpoptException E(
"BqpdSolver called with object other than a BranchingTQP",
214 "BonBqpdSolver.cpp",-1);
222 times().solve -= CoinCpuTime();
226 times().solve += CoinCpuTime();
244 for (
int i=0; i<n+
m; i++) {
250 cached_->use_warm_start_in_cache_ =
true;
254 cached_->use_warm_start_in_cache_ =
true;
258 times().resolve -= CoinCpuTime();
262 times().resolve += CoinCpuTime();
272 double* fillin_factor)
286 F77_FUNC(refactorc,REFACTORC).nfreq = 500;
288 Ipopt::TNLP::IndexStyleEnum index_style;
289 Ipopt::Index nv, nc, nnz_jac_g, nnz_hess;
290 tqp->get_nlp_info(nv, nc, nnz_jac_g, nnz_hess, index_style);
294 if (kmax_ipt == -1) {
321 for (
int i=0; i<
n+
m; i++) {
322 bl[i] = std::max(
bl[i], -1e50);
323 bu[i] = std::min(
bu[i], 1e50);
328 const Ipopt::Number* obj_grad = tqp->ObjGrad();
330 for (
int i = 0; i<
n; i++) {
331 if (obj_grad[i]!=0.) {
335 int lamax =
amax_+m+2;
341 for (
int i = 0; i <
n ; i++) {
342 if (obj_grad[i]!=0.) {
343 a[nnz_grad] = obj_grad[i];
344 la[++nnz_grad] = i+1;
350 const Ipopt::Number* JacVals = tqp->ConstrJacVals();
351 const Ipopt::Index* RowJac = tqp->ConstrJacIRow();
352 const Ipopt::Index* ColJac = tqp->ConstrJacJCol();
356 la, nnz_grad, 1, Ipopt::TNLP::C_STYLE);
357 for (
int i=0; i<nnz_jac_g; i++) {
358 const int& indice = permutationJac[i];
359 a[nnz_grad+i] = JacVals[indice];
364 printf(
"nnz_grad = %d nnz_jac = %d\n", nnz_grad, nnz_jac_g);
365 for (
int i=0; i<1+lamax; i++) printf(
"la[%2d] = %d\n", i,
la[i]);
366 for (
int i=0; i<
amax_; i++) printf(
"a[%3d] = %e\n",i,
a[i]);
371 mxlws = (nnz_hess + n + 2) +
kmax + (9*n + m);
377 for (
int i=0; i<
mxws; i++) {
380 for (
int i=0; i<
mxlws; i++) {
386 const Ipopt::Number* HessVals = tqp->ObjHessVals();
387 const Ipopt::Index* RowHess = tqp->ObjHessIRow();
388 const Ipopt::Index* ColHess = tqp->ObjHessJCol();
391 ll = nnz_hess + n + 2;
395 permutationHess,
lws, 0, 0, Ipopt::TNLP::C_STYLE);
396 for (
int i=0; i<nnz_hess; i++) {
397 ws[i] = HessVals[permutationHess[i]];
402 printf(
"nnz_hess = %d\n", nnz_hess);
403 for (
int i=0; i<
ll; i++) printf(
"hess lws[%2d] = %d\n", i,
lws[i]);
404 for (
int i=0; i<
kk; i++) printf(
"hess ws[%3d] = %e\n",i,
ws[i]);
408 options->GetIntegerValue(
"iprint",bufy,
"bqpd.");
418 use_warm_start_in_cache_ =
false;
421 for (
int i=0; i<
mxws; i++) {
424 for (
int i=0; i<
mxlws; i++) {
437 Ipopt::SolverReturn status = Ipopt::INTERNAL_ERROR;
442 status = Ipopt::SUCCESS;
446 status = Ipopt::DIVERGING_ITERATES;
450 status = Ipopt::LOCAL_INFEASIBILITY;
455 Ipopt::Number* dummy =
new Ipopt::Number[dummy_len];
456 for (
int i=0; i<dummy_len; i++) {
465 return optimizationStatus;
493 #ifdef DISABLE_COPYING
497 times_.warm_start -= CoinCpuTime();
499 haveHotStart_ =
true;
569 xHot = CoinCopyOfArray(
x,
n);
571 gHot = CoinCopyOfArray(
g,
n);
572 rHot = CoinCopyOfArray(
r,
n+
m);
573 wHot = CoinCopyOfArray(
w,
n+
m);
574 eHot = CoinCopyOfArray(
e,
n+
m);
575 lsHot = CoinCopyOfArray(
ls,
n+
m);
576 alpHot = CoinCopyOfArray(
alp,
mlp);
577 lpHot = CoinCopyOfArray(
lp,
mlp);
579 wsHot = CoinCopyOfArray(
ws,
mxws);
580 lwsHot = CoinCopyOfArray(
lws,
mxlws);
581 infoHot[0] =
info[0];
583 times_.warm_start += CoinCpuTime();
592 #ifdef DISABLE_COPYING
596 times_.warm_start -= CoinCpuTime();
670 CoinCopyN(rHot,
n+
m,
r);
671 CoinCopyN(wHot,
n+
m,
w);
672 CoinCopyN(eHot,
n+
m,
e);
673 CoinCopyN(lsHot,
n+
m,
ls);
674 CoinCopyN(alpHot,
mlp,
alp);
675 CoinCopyN(lpHot,
mlp,
lp);
678 info[0] = infoHot[0];
681 times_.warm_start += CoinCpuTime();
699 haveHotStart_ =
false;
707 F77_FUNC(scalec,SCALEC).scale_mode = 0;
715 if (use_warm_start_in_cache_ && !bad_warm_start_info_) {
717 use_warm_start_in_cache_ =
false;
718 if (haveHotStart_ && pivots_ > next_reinit_) {
727 tqp_->get_starting_point(
n, 1,
x, 0, NULL, NULL,
m, 0, NULL);
729 bad_warm_start_info_ =
false;
733 printf(
"========= 222222222222 =============\n");
734 printf(
"kk = %d ll = %d mxws = %d mxlws = %d\n",
kk,
ll,
mxws,
mxlws);
735 for (
int i=0; i<
n; i++) {
736 printf(
"xL[%3d] = %15.8e xU[%3d] = %15.8e\n", i,
bl[i], i,
bu[i]);
738 for (
int i=0; i<
m; i++) {
739 printf(
"gL[%3d] = %15.8e gU[%3d] = %15.8e\n", i,
bl[n+i], i,
bu[n+i]);
742 cpuTime_ = - CoinCpuTime();
745 for (
int i=0; i<
n; i++) {
746 printf(
"qxstart[%2d] = %23.16e\n", i,
x[i]);
752 FILE* fp = fopen(
"QPinit.dat",
"w");
753 fprintf(fp,
"n = %d\n", n);
754 fprintf(fp,
"m = %d\n", m);
755 fprintf(fp,
"kmax = %d\n",
kmax);
756 fprintf(fp,
"amax = %d\n" ,amax_);
757 for (
int i=1; i<=amax_; i++) {
758 fprintf(fp,
"a = %23.16e\n",
a[i-1]);
760 int lamax = amax_ + m + 2;
761 fprintf(fp,
"lamax = %d\n" ,lamax);
762 for (
int i=1; i<=lamax+1; i++) {
763 fprintf(fp,
"la = %6d\n",
la[i-1]);
765 for (
int i=1; i<=
n; i++) {
766 fprintf(fp,
"x = %23.16e\n",
x[i-1]);
768 for (
int i=1; i<=n+
m; i++) {
769 fprintf(fp,
"bl = %23.16e\n",
bl[i-1]);
771 for (
int i=1; i<=n+
m; i++) {
772 fprintf(fp,
"bu = %23.16e\n",
bu[i-1]);
774 fprintf(fp,
"fmin = %23.16e\n", fmin);
775 fprintf(fp,
"mlp = %6d\n",
mlp);
776 fprintf(fp,
"mxws = %d\n",
mxws);
777 fprintf(fp,
"mxlws = %d\n",
mxlws);
781 FILE* fp = fopen(
"QPbounds.dat",
"w");
782 fprintf(fp,
"m0de = %d\n",
m0de);
783 for (
int i=1; i<=n+
m; i++) {
784 fprintf(fp,
"bl = %23.16e\n",
bl[i-1]);
786 for (
int i=1; i<=n+
m; i++) {
787 fprintf(fp,
"bu = %23.16e\n",
bu[i-1]);
792 F77_FUNC(bqpd,BQPD)(&
n, &
m, &
k, &
kmax,
a,
la,
x,
bl,
bu, &
f, &
fmin,
793 g,
r,
w,
e,
ls,
alp,
lp, &
mlp, &
peq,
ws,
lws,
796 times_.pivots += info[0];
800 fprintf(stdout,
"Reinitialize hot start...\n");
803 F77_FUNC(bqpd,BQPD)(&
n, &
m, &
k, &
kmax,
a,
la,
x,
bl,
bu, &
f, &
fmin,
804 g,
r,
w,
e,
ls,
alp,
lp, &
mlp, &
peq,
ws,
lws,
806 printf(
"new ifail = %d\n", ifail);
809 fprintf(stdout,
"Restarting Bqpd...");
811 tqp_->get_starting_point(n, 1, x, 0, NULL, NULL, m, 0, NULL);
813 F77_FUNC(bqpd,BQPD)(&
n, &
m, &
k, &
kmax,
a,
la,
x,
bl,
bu, &
f, &
fmin,
814 g,
r,
w,
e,
ls,
alp,
lp, &
mlp, &
peq,
ws,
lws,
816 printf(
"new ifail = %d\n", ifail);
820 if (haveHotStart_) unmarkHotStart();
828 for (
int i=0; i<mxws_new; i++) {
832 CoinCopyN(ws,
kk, ws_new);
839 tqp_->get_starting_point(n, 1, x, 0, NULL, NULL, m, 0, NULL);
841 F77_FUNC(bqpd,BQPD)(&
n, &
m, &
k, &
kmax,
a,
la,
x,
bl,
bu, &
f, &
fmin,
842 g,
r,
w,
e,
ls,
alp,
lp, &
mlp, &
peq,
ws,
lws,
845 if (ifail == 8) bad_warm_start_info_ =
true;
847 for (
int i=0; i<
n; i++) {
848 printf(
"qxsol[%2d] = %23.16e\n", i, x[i]);
852 printf(
"ifail = %d\n", ifail);
853 printf(
"final f = %e\n", f);
854 printf(
"final f + obj_val = %e\n", f+tqp_->ObjVal());
859 printf(
"========= 3333333333 =============\n");
860 printf(
"kk = %d ll = %d kkk = %d lll = %d mxws = %d mxlws = %d\n",
kk,
ll, kkk, lll,
mxws,
mxlws);
861 for (
int i=0; i<
kk+
kkk; i++) {
862 printf(
"ws[%3d] = %15.8e\n ", i, ws[i]);
864 printf(
"--------\n");
865 for (
int i=
kk+kkk; i<
mxws; i++) {
866 printf(
"ws[%3d] = %15.8e\n ", i, ws[i]);
868 for (
int i=0; i<
ll+
lll; i++) {
869 printf(
"lws[%5d] = %8d\n", i, lws[i]);
872 for (
int i=
ll+lll; i<
mxlws; i++) {
873 printf(
"lws[%5d] = %8d\n", i, lws[i]);
876 cpuTime_ += CoinCpuTime();
881 {
"Internal error in Filter SQP."};
890 return errorNames_[0];
910 const fint xsize = warmF->xSize();
912 const real* xarray = warmF->xArray();
913 for (
int i = 0; i<xsize; i++) {
916 CoinCopyN(warmF->lamArray(), warmF->lamSize(),
cached_->lam);
918 for (
int i = 0 ; i < 14 ; i ++) {
921 cached_->use_warm_start_in_cache_ =
true;
923 printf(
"BqpdSolver::setWarmStart called!\n");
935 printf(
"BqpdSolver::getWarmStart called!\n");
945 printf(
"BqpdSolver::getEmptyWarmStart called \n");
953 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