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");
326 Ipopt::IpoptException E(
"Unknown Exception caught in ipopt",
"Unknown File", -1);
345 options_->GetIntegerValue(
"print_level", ivalue,
"");
346 Ipopt::EJournalLevel print_level = (Ipopt::EJournalLevel)ivalue;
350 stdout_jrnl->SetAllPrintLevels(print_level);
351 stdout_jrnl->SetPrintLevel(Ipopt::J_DBG, Ipopt::J_NONE);
375 assert(tnlp ==
cached_->tnlp_);
407 Ipopt::TNLP::IndexStyleEnum index_style;
408 Ipopt::Index nv, nc, nnz_j, nnz_hess;
409 tnlp->get_nlp_info( nv, nc,
410 nnz_j, (Ipopt::Index&) nnz_hess,
421 Ipopt::Index kmax_ipt;
422 options->GetIntegerValue(
"kmax", kmax_ipt,
"filter.");
423 if (kmax_ipt == -1) {
430 Ipopt::Index mlp_ipt;
431 options->GetIntegerValue(
"mlp", mlp_ipt,
"filter.");
434 Ipopt::Index maxf_ipt;
435 options->GetIntegerValue(
"maxf", maxf_ipt,
"filter.");
439 Ipopt::Index mxwk0_ipt;
440 options->GetIntegerValue(
"mxws", mxwk0_ipt,
"filter.");
444 Ipopt::Index mxiwk0_ipt;
445 options->GetIntegerValue(
"mxlws", mxiwk0_ipt,
"filter.");
455 lam =
new real [n+
m];
457 for (
int i = 0 ; i < n+
m ; i++) lam[i] = 0.;
467 for (
int i = 0 ; i < nplusm ; i++) {
472 for (
int i = 0 ; i < nplusm ; i++) {
473 if (ubounds[i] > infty) ubounds[i] =
infty;
476 maxa = n + nnz_jac_g;
477 fint maxia = n + nnz_jac_g + m + 3;
479 la =
new fint [maxia];
481 int * RowJac =
new int [nnz_jac_g];
482 int * ColJac =
new int [nnz_jac_g];
484 la[nnz_jac_g + n + 1] = 1;
486 for (
fint i = 1; i <=
n ; i++)
488 tnlp->eval_jac_g( nv, NULL, 0, nc , nnz_j, RowJac, ColJac, NULL);
492 la, n, 1, index_style);
500 int * cache =
new int[2*
nnz_h + 1];
502 tnlp->eval_h((Ipopt::Index&) n, NULL, 0, 1., (Ipopt::Index&) m, NULL, 0, (Ipopt::Index&)
nnz_h, cache + nnz_h, cache , NULL);
509 fint lh1 = nnz_h + 8 + 2 * n +
m;
515 #ifdef InitializeAll // ToDo: This shouldn't have to be initialized
516 for (
int i = 0 ; i <
maxWk ; i++) ws[i] = 0;
517 for (
int i = 0 ; i <
maxiWk ; i++) lws[i] = 0;
524 options->GetNumericValue(
"ubd",
F77_FUNC(ubdc,UBDC).
ubd,
"filter.");
525 options->GetNumericValue(
"tt",
F77_FUNC(ubdc,UBDC).
tt,
"filter.");
526 options->GetNumericValue(
"eps",
F77_FUNC_(nlp_eps_inf,NLP_EPS_INF).
eps,
"filter.");
527 options->GetNumericValue(
"infty",
F77_FUNC_(nlp_eps_inf,NLP_EPS_INF).infty,
"filter.");
530 options->GetIntegerValue(
"maxiter", (Ipopt::Index &)
maxiter,
"filter.");
531 options->GetNumericValue(
"rho_init",
rho,
"filter.");
535 F77_FUNC(scalec,SCALEC).scale_mode = 0;
541 for (
int i=0; i<14; i++) {
544 for (
int i=0; i<7; i++) {
551 options->GetIntegerValue(
"iprint",bufy,
"filter.");
555 Ipopt::TNLP::LinearityType * const_types =
556 new Ipopt::TNLP::LinearityType[
m];
557 tnlp->get_constraints_linearity(m, const_types);
558 for (
int i = 0 ; i <
m ; i++) {
565 delete [] const_types;
577 Ipopt::SolverReturn status = Ipopt::INTERNAL_ERROR;
582 status = Ipopt::SUCCESS;
586 status = Ipopt::DIVERGING_ITERATES;
591 status = Ipopt::LOCAL_INFEASIBILITY;
597 status = Ipopt::MAXITER_EXCEEDED;
601 status = Ipopt::INTERNAL_ERROR;
606 status = Ipopt::INTERNAL_ERROR;
610 Ipopt::Number* mlam = NULL;
612 mlam =
new Ipopt::Number[
cached_->m];
614 for (
int i = 0; i<
cached_->m; i++) {
617 Ipopt::Number* z_L =
new Ipopt::Number[
cached_->n];
618 Ipopt::Number* z_U =
new Ipopt::Number[
cached_->n];
620 for (
int i=0; i<
cached_->n; i++) {
622 z_L[i] = std::max(0.,
cached_->lam[i]);
628 z_U[i] = std::max(0.,-
cached_->lam[i]);
641 return optimizationStatus;
646 if(!warmF.IsValid())
return;
647 const fint xsize = warmF->primalSize();
648 const real* xarray = warmF->primal();
649 for (
int i = 0; i<xsize; i++) {
652 CoinCopyN(warmF->dual(), warmF->dualSize(),
lam);
653 CoinCopyN(warmF->lwsArray(), warmF->lwsSize(),
lws);
654 for (
int i = 0 ; i < 14 ; i ++) {
655 istat[i] = warmF->istat()[i];
657 use_warm_start_in_cache_ =
true;
663 if (use_warm_start_in_cache_) {
665 use_warm_start_in_cache_ =
false;
668 tnlp_->get_starting_point(n, 1, x, 0, NULL, NULL, m, 0, NULL);
671 cpuTime_ = - CoinCpuTime();
677 printf(
"========= 3333333333333333 =============\n");
678 for (
int i=0; i<
n; i++) {
679 printf(
"xL[%3d] = %15.8e xU[%3d] = %15.8e\n", i, bounds[i], i, bounds[m+n+i]);
681 for (
int i=0; i<
m; i++) {
682 printf(
"gL[%3d] = %15.8e gU[%3d] = %15.8e\n", i, bounds[n+i], i, bounds[m+2*n+i]);
686 for (
int i=0; i<
n; i++) {
687 printf(
"fxstart[%2d] = %23.16e\n", i, x[i]);
700 for (
int i=0; i<
n; i++) {
701 printf(
"fxsol[%2d] = %23.16e\n", i, x[i]);
705 printf(
"final f = %e\n", f);
706 printf(
"ifail = %d\n", ifail);
712 cpuTime_ += CoinCpuTime();
717 {
"Internal error in Filter SQP."};
726 return errorNames_[0];
739 if (warm == NULL ||
cached_.IsNull()) {
742 if(warm == NULL)
return 1;
775 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.