17 #include "CoinTime.hpp"
104 (*errflag) = !
tnlpSolved->eval_g(*n, x, 1, *m, c);
110 (*errflag) = !
tnlpSolved->eval_grad_f(*n, x, 1, a);
114 (*errflag) = !
tnlpSolved->eval_jac_g(*n, x, 1, *m, nnz, NULL, NULL, values) || (*errflag);
116 for (
int i = 0 ; i <
nnz ; i++) {
120 std::cout<<
"Error in gradient computation, i: "<<i
124 *a++ = values[indice];
134 Ipopt::Number obj_factor = (*phase == 1)? 0. : 1.;
137 for (
int i = 0 ; i <
end ; i++) {
141 *li_hess =
nnz_h + *n + 3;
144 mlam =
new Ipopt::Number[*
m];
146 for (
int i = 0; i<*
m; i++) {
147 mlam[i] = -lam[*n+i];
149 Ipopt::Number * values =
new Ipopt::Number [
nnz_h];
150 (*errflag) = !
tnlpSolved->eval_h(*n, x, 1, obj_factor, *m, mlam ,1,
hStruct[0] - 1, NULL, NULL, values);
174 const Ipopt::Index* iRow,
175 const Ipopt::Index* iCol,
int * permutation2,
176 fint * lws,
int nnz_offset,
int n_offset,
177 Ipopt::TNLP::IndexStyleEnum index_style)
179 for (
int i = 0 ; i <
nnz ; i++)
184 Ipopt::Index* tmpRow =
new Ipopt::Index[
nnz];
185 Ipopt::Index* tmpCol =
new Ipopt::Index[
nnz];
186 for (
int i=0; i<
nnz; i++) {
187 const Ipopt::Index&
irow = iRow[i];
188 const Ipopt::Index& jcol = iCol[i];
206 std::sort(permutation2, permutation2 + nnz, lt);
208 const int idx_offset = (index_style == Ipopt::TNLP::C_STYLE);
209 fint row = 1-idx_offset;
210 lws[0] = nnz + nnz_offset + 1;
211 fint * inds = lws + nnz_offset + 1;
212 fint * start = inds + nnz + n_offset;
213 *start++ = 1 + nnz_offset;
214 for (
fint i = 0 ; i <
nnz ; i++) {
215 inds[i] = lt.
colIndices[permutation2[i]] + idx_offset;
218 for (;row < lt.
rowIndices[permutation2[i]] ; row++)
219 *start++ = i + nnz_offset + 1;
222 for (;row <= m-idx_offset ; row++)
223 *start++ = nnz + nnz_offset +1;
226 for (
int i = 0; i<nnz_offset+1; i++)
227 printf(
"lws[%3d] = %3d\n", i, lws[i]);
228 for (
int i = nnz_offset+1; i<nnz_offset+nnz+1; i++)
229 printf(
"lws[%3d] = %3d [%3d,%3d]\n", i, lws[i], lt.
rowIndices[permutation2[i-nnz_offset-1]], lt.
colIndices[permutation2[i-nnz_offset-1]]);
230 for (
int i = nnz_offset+nnz+1; i<lws[0]+m+2; i++)
231 printf(
"lws[%3d] = %3d\n", i, lws[i]);
250 roptions->AddLowerBoundedNumberOption(
"eps",
"Tolerance for SQP solver",
252 roptions->AddLowerBoundedNumberOption(
"infty",
"A large number",0.,1, 1e20,
"");
253 roptions->AddBoundedIntegerOption(
"iprint",
"Print level (0=silent, 3=verbose)", 0,6,0);
254 roptions->AddLowerBoundedIntegerOption(
"kmax",
"Dimension of null-space",
256 roptions->AddLowerBoundedIntegerOption(
"maxf",
"Maximum filter length",0,100);
257 roptions->AddLowerBoundedIntegerOption(
"maxiter",
"Maximum number of iterations",0,1000);
258 roptions->AddLowerBoundedIntegerOption(
"mlp",
"Maximum level for degeneracy (bqpd)",0, 1000);
259 roptions->AddLowerBoundedIntegerOption(
"mxlws",
"FINTEGER workspace increment", 0, 500000);
260 roptions->AddLowerBoundedIntegerOption(
"mxws",
"REAL workspace increment",
262 roptions->AddLowerBoundedNumberOption(
"rho_init",
"Initial trust region size",0,1,10.);
264 roptions->AddLowerBoundedNumberOption(
"tt",
"Parameter for upper bound on filter",0,1, 125
e-2);
265 roptions->AddLowerBoundedNumberOption(
"ubd",
"Parameter for upper bound on filter", 0 , 1,1e2);
280 const std::string &
prefix):
281 TNLPSolver(roptions, options, journalist, prefix),
289 TNLPSolver(roptions, options, journalist,
"bonmin."),
300 warmF_ = (other.
warmF_.IsValid()) ? dynamic_cast<FilterWarmStart *>(other.
warmF_->clone()):NULL;
319 is.open(optFile.c_str());
321 catch (std::bad_alloc) {
322 journalist_->Printf(Ipopt::J_SUMMARY, Ipopt::J_MAIN,
"\nEXIT: Not enough memory.\n");
327 Ipopt::IpoptException E(
"Unknown Exception caught in ipopt",
"Unknown File", -1);
347 options_->GetIntegerValue(
"print_level", ivalue,
"");
348 Ipopt::EJournalLevel print_level = (Ipopt::EJournalLevel)ivalue;
352 stdout_jrnl->SetAllPrintLevels(print_level);
353 stdout_jrnl->SetPrintLevel(Ipopt::J_DBG, Ipopt::J_NONE);
377 assert(tnlp ==
cached_->tnlp_);
409 Ipopt::TNLP::IndexStyleEnum index_style;
410 Ipopt::Index nv, nc, nnz_j, nnz_hess;
411 tnlp->get_nlp_info( nv, nc,
412 nnz_j, (Ipopt::Index&) nnz_hess,
423 Ipopt::Index kmax_ipt;
424 options->GetIntegerValue(
"kmax", kmax_ipt,
"filter.");
425 if (kmax_ipt == -1) {
432 Ipopt::Index mlp_ipt;
433 options->GetIntegerValue(
"mlp", mlp_ipt,
"filter.");
436 Ipopt::Index maxf_ipt;
437 options->GetIntegerValue(
"maxf", maxf_ipt,
"filter.");
441 Ipopt::Index mxwk0_ipt;
442 options->GetIntegerValue(
"mxws", mxwk0_ipt,
"filter.");
446 Ipopt::Index mxiwk0_ipt;
447 options->GetIntegerValue(
"mxlws", mxiwk0_ipt,
"filter.");
457 lam =
new real [n+
m];
459 for (
int i = 0 ; i < n+
m ; i++) lam[i] = 0.;
469 for (
int i = 0 ; i < nplusm ; i++) {
474 for (
int i = 0 ; i < nplusm ; i++) {
475 if (ubounds[i] > infty) ubounds[i] =
infty;
478 maxa = n + nnz_jac_g;
479 fint maxia = n + nnz_jac_g + m + 3;
481 la =
new fint [maxia];
483 int * RowJac =
new int [nnz_jac_g];
484 int * ColJac =
new int [nnz_jac_g];
486 la[nnz_jac_g + n + 1] = 1;
488 for (
fint i = 1; i <=
n ; i++)
490 tnlp->eval_jac_g( nv, NULL, 0, nc , nnz_j, RowJac, ColJac, NULL);
494 la, n, 1, index_style);
502 int * cache =
new int[2*
nnz_h + 1];
504 tnlp->eval_h((Ipopt::Index&) n, NULL, 0, 1., (Ipopt::Index&) m, NULL, 0, (Ipopt::Index&)
nnz_h, cache + nnz_h, cache , NULL);
511 fint lh1 = nnz_h + 8 + 2 * n +
m;
517 #ifdef InitializeAll // ToDo: This shouldn't have to be initialized
518 for (
int i = 0 ; i <
maxWk ; i++) ws[i] = 0;
519 for (
int i = 0 ; i <
maxiWk ; i++) lws[i] = 0;
526 options->GetNumericValue(
"ubd",
F77_FUNC(ubdc,UBDC).
ubd,
"filter.");
527 options->GetNumericValue(
"tt",
F77_FUNC(ubdc,UBDC).
tt,
"filter.");
528 options->GetNumericValue(
"eps",
F77_FUNC_(nlp_eps_inf,NLP_EPS_INF).
eps,
"filter.");
529 options->GetNumericValue(
"infty",
F77_FUNC_(nlp_eps_inf,NLP_EPS_INF).infty,
"filter.");
532 options->GetIntegerValue(
"maxiter", (Ipopt::Index &)
maxiter,
"filter.");
533 options->GetNumericValue(
"rho_init",
rho,
"filter.");
537 F77_FUNC(scalec,SCALEC).scale_mode = 0;
543 for (
int i=0; i<14; i++) {
546 for (
int i=0; i<7; i++) {
553 options->GetIntegerValue(
"iprint",bufy,
"filter.");
557 Ipopt::TNLP::LinearityType * const_types =
558 new Ipopt::TNLP::LinearityType[
m];
559 tnlp->get_constraints_linearity(m, const_types);
560 for (
int i = 0 ; i <
m ; i++) {
567 delete [] const_types;
579 Ipopt::SolverReturn status = Ipopt::INTERNAL_ERROR;
584 status = Ipopt::SUCCESS;
588 status = Ipopt::DIVERGING_ITERATES;
593 status = Ipopt::LOCAL_INFEASIBILITY;
599 status = Ipopt::MAXITER_EXCEEDED;
603 status = Ipopt::INTERNAL_ERROR;
608 status = Ipopt::INTERNAL_ERROR;
612 Ipopt::Number* mlam = NULL;
614 mlam =
new Ipopt::Number[
cached_->m];
616 for (
int i = 0; i<
cached_->m; i++) {
619 Ipopt::Number* z_L =
new Ipopt::Number[
cached_->n];
620 Ipopt::Number* z_U =
new Ipopt::Number[
cached_->n];
622 for (
int i=0; i<
cached_->n; i++) {
624 z_L[i] = std::max(0.,
cached_->lam[i]);
630 z_U[i] = std::max(0.,-
cached_->lam[i]);
643 return optimizationStatus;
648 if(!warmF.IsValid())
return;
649 const fint xsize = warmF->primalSize();
650 const real* xarray = warmF->primal();
651 for (
int i = 0; i<xsize; i++) {
654 CoinCopyN(warmF->dual(), warmF->dualSize(),
lam);
655 CoinCopyN(warmF->lwsArray(), warmF->lwsSize(),
lws);
656 for (
int i = 0 ; i < 14 ; i ++) {
657 istat[i] = warmF->istat()[i];
659 use_warm_start_in_cache_ =
true;
665 if (use_warm_start_in_cache_) {
667 use_warm_start_in_cache_ =
false;
670 tnlp_->get_starting_point(n, 1, x, 0, NULL, NULL, m, 0, NULL);
673 cpuTime_ = - CoinCpuTime();
679 printf(
"========= 3333333333333333 =============\n");
680 for (
int i=0; i<
n; i++) {
681 printf(
"xL[%3d] = %15.8e xU[%3d] = %15.8e\n", i, bounds[i], i, bounds[m+n+i]);
683 for (
int i=0; i<
m; i++) {
684 printf(
"gL[%3d] = %15.8e gU[%3d] = %15.8e\n", i, bounds[n+i], i, bounds[m+2*n+i]);
688 for (
int i=0; i<
n; i++) {
689 printf(
"fxstart[%2d] = %23.16e\n", i, x[i]);
702 for (
int i=0; i<
n; i++) {
703 printf(
"fxsol[%2d] = %23.16e\n", i, x[i]);
707 printf(
"final f = %e\n", f);
708 printf(
"ifail = %d\n", ifail);
714 cpuTime_ += CoinCpuTime();
719 {
"Internal error in Filter SQP."};
728 return errorNames_[0];
741 if (warm == NULL ||
cached_.IsNull()) {
744 if(warm == NULL)
return 1;
777 if (fws && ! fws->
empty()) {
virtual const std::string & errorName() const
Get the string corresponding to error.
void fint fint fint real real fint real fint fint * l_hess
void fint fint fint real fint real real real real real real real real real fint real fint fint fint real fint * lws
Coin::SmartPtr< FilterWarmStart > warmF_
void fint fint fint * kmax
TNLPSolver::ReturnStatus callOptimizer()
Perform optimization using data structure in cache.
Ipopt::SmartPtr< Ipopt::Journalist > journalist_
Storage of Journalist for output.
void fint fint fint real fint * la
const Ipopt::Index * rowIndices
Bonmin::BqpdSolver F77_FUNC
void fint fint fint real * a
int default_log_level_
To record default log level.
static std::string solverName_
bool IsValid(const OSSmartPtr< U > &smart_ptr)
void fint fint fint real fint real real * bl
This is a generic class for calling an NLP solver to solve a TNLP.
Bonmin::BqpdSolver::fint fint
void optimize()
Optimize problem described by cache with filter.
void fint fint fint fint * maxf
void fint fint fint real fint real real real real real real real real real fint real fint fint * mlp
const Ipopt::Index * colIndices
void initialize(const Ipopt::SmartPtr< Ipopt::TNLP > &tnlp, Ipopt::SmartPtr< Ipopt::OptionsList > &options)
Fill data structures for filter with info from tnlp.
void fint fint fint real fint real real real real * f
void fint fint fint fint fint fint fint fint fint fint real real real real real real real real real fint real fint real char * cstype
virtual bool Initialize(std::string params_file)
Initialize the TNLPSolver (read options from params_file)
Option category for FilterSqp.
void fint fint fint fint fint fint fint fint fint fint real * rho
void fint fint fint real fint real real real real real real real real real * e
Bonmin::BqpdSolver::real real
struct @16 F77_FUNC_(nlp_eps_inf, NLP_EPS_INF)
virtual ReturnStatus OptimizeTNLP(const Ipopt::SmartPtr< Ipopt::TNLP > &tnlp)
Solves a problem expresses as a TNLP.
virtual void enableWarmStart()
Solves a problem expresses as a TNLP.
void fint fint fint * phase
FilterSolver(bool createEmpty=false)
Default constructor.
Warm start for filter interface.
void fint fint fint fint fint fint fint fint fint fint real real real real real real real real real fint real fint real char real fint fint fint real ftnlen cstype_len
FilterTypes::real real
Fortran type for double.used in filter.
void fint fint fint real fint real real real real real * fmin
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 fint fint fint fint fint fint fint fint fint fint real real real real real real real real * s
virtual CoinWarmStart * getWarmStart(Ipopt::SmartPtr< TMINLP2TNLP > tnlp) const
Get the warm start form the solver.
Cached information for reoptimizing.
virtual bool setWarmStart(const CoinWarmStart *warm, Ipopt::SmartPtr< TMINLP2TNLP > tnlp)
Set the warm start in the solver.
void load_ws(Coin::SmartPtr< FilterWarmStart >)
Load warm-start info into cache with filter.
virtual void disableWarmStart()
Solves a problem expresses as a TNLP.
Coin::SmartPtr< cachedInfo > cached_
Cached information on last problem optimized for reoptimization.
U * GetRawPtr(const OSSmartPtr< U > &smart_ptr)
void fint fint fint real fint real real real real real real real real real fint real fint fint fint real * ws
virtual Ipopt::SmartPtr< TNLPSolver > clone()
Virtual copy constructor.
void fint fint fint fint fint fint fint fint fint fint real real real real real real real real real fint real fint real char real fint * iuser
ReturnStatus
Standard return statuses for a solver.
void fint fint fint fint fint fint fint fint fint fint real real real real real real real real real fint real fint real char real fint fint fint * istat
bool use_warm_start_in_cache_
flag remembering if warm start information has been put into cache
bool empty() const
Is this an empty warm start?
void fint fint fint fint fint fint fint fint fint fint real real real real real real real real real fint real fint real char real fint fint fint real * rstat
static std::string errorNames_[1]
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
bool operator()(int i, int j)
void fint fint fint fint fint fint * mxwk
void fint fint fint fint fint fint fint fint fint fint real real real real real real real real real fint real fint real * lam
static int * permutationHess
virtual ReturnStatus ReOptimizeTNLP(const Ipopt::SmartPtr< Ipopt::TNLP > &tnlp)
Resolves a problem expresses as a TNLP.
void registerOptions()
Register this solver options into passed roptions.
virtual CoinWarmStart * clone() const
virtual copy
void fint fint fint fint fint fint fint fint fint fint real real real real real real real real real fint real fint real char real * user
void fint real real fint fint *errflag errflag
virtual CoinWarmStart * getEmptyWarmStart() const
Solves a problem expresses as a TNLP.
virtual const std::string & solverName() const
Return the name of 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 fint * nout
static int * permutationJac
void fint fint fint fint fint fint fint fint fint fint real real real real real real real real real fint real fint real char real fint fint * maxiter
int nnz
ATTENTION: Filter expect the jacobian to be ordered by row.
void fint fint fint real real fint real fint fint fint * li_hess
Ipopt::SmartPtr< Ipopt::OptionsList > options_
List of Options.
static Ipopt::TNLP * tnlpSolved
static std::string solverName_
void fint fint fint fint fint fint fint * mxiwk
void fint fint fint * maxa
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
void fint fint fint real fint real * x
virtual ~FilterSolver()
destructor
virtual bool warmStartIsValid(const CoinWarmStart *ws) const
Check that warm start object is valid.
void fint fint fint real fint real real real * bu
FilterTypes::fint fint
Fortran type for integer used in filter.