00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef FilterSolver_H
00011 #define FilterSolver_H
00012
00013 #include "BonTNLPSolver.hpp"
00014 #include "BonFilterTypes.hpp"
00015 #include "BonBqpdSolver.hpp"
00016 #include "BonFilterWarmStart.hpp"
00017
00018 namespace Bonmin
00019 {
00020 class FilterSolver : public TNLPSolver
00021 {
00022 public:
00023
00024 friend struct BqpdSolver::cachedInfo;
00025
00026 class UnsolvedFilterError: public TNLPSolver::UnsolvedError
00027 {
00028 public:
00029 UnsolvedFilterError(int errorNum,
00030 Ipopt::SmartPtr<TMINLP2TNLP> model,
00031 const std::string &name):
00032 TNLPSolver::UnsolvedError(errorNum, model, name)
00033 {}
00034 virtual const std::string& errorName() const;
00035
00036 virtual const std::string& solverName() const;
00037 virtual ~UnsolvedFilterError()
00038 {}
00039
00040 private:
00041 static std::string errorNames_[1];
00042 static std::string solverName_;
00043 };
00044
00046 typedef FilterTypes::fint fint;
00048 typedef FilterTypes::real real;
00049
00050
00051 virtual UnsolvedError * newUnsolvedError(int num,
00052 Ipopt::SmartPtr<TMINLP2TNLP> problem,
00053 std::string name)
00054 {
00055 return new UnsolvedFilterError(num, problem, name);
00056 }
00057
00058
00060 FilterSolver(bool createEmpty = false);
00061
00062
00064 FilterSolver(Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions,
00065 Ipopt::SmartPtr<Ipopt::OptionsList> options,
00066 Ipopt::SmartPtr<Ipopt::Journalist> journalist
00067 );
00068
00070 virtual ~FilterSolver();
00071
00074 virtual bool Initialize(std::string params_file);
00075
00078 virtual bool Initialize(std::istream& is);
00079
00082
00083 virtual ReturnStatus OptimizeTNLP(const Ipopt::SmartPtr<Ipopt::TNLP> & tnlp);
00084
00086 virtual ReturnStatus ReOptimizeTNLP(const Ipopt::SmartPtr<Ipopt::TNLP> & tnlp);
00087
00089 virtual bool setWarmStart(const CoinWarmStart * warm,
00090 Ipopt::SmartPtr<TMINLP2TNLP> tnlp);
00091
00093 virtual CoinWarmStart * getUsedWarmStart(Ipopt::SmartPtr<TMINLP2TNLP> tnlp) const{
00094 if(warmF_.IsValid())
00095 return new FilterWarmStart(*warmF_);
00096 else return NULL;
00097 }
00098
00099
00101 virtual CoinWarmStart * getWarmStart(Ipopt::SmartPtr<TMINLP2TNLP> tnlp) const;
00102
00103 virtual CoinWarmStart * getEmptyWarmStart() const;
00104
00106 virtual bool warmStartIsValid(const CoinWarmStart * ws) const;
00107
00108
00109 virtual void enableWarmStart()
00110 {
00111 }
00112 virtual void disableWarmStart()
00113 {
00114 warmF_ = NULL;
00115
00116 }
00118
00120 virtual SmartPtr<TNLPSolver> clone();
00121
00123 virtual double CPUTime()
00124 {
00125 return (cached_.IsValid()) ? cached_->cpuTime_: 0.;
00126 }
00127
00129 virtual int IterationCount()
00130 {
00131 return (cached_.IsValid()) ? cached_->istat[1]:0;
00132 }
00133
00135 virtual void turnOffOutput()
00136 {
00137 if (cached_.IsValid()) cached_->iprint = 0;
00138 }
00140 virtual void turnOnOutput()
00141 {
00142 if (cached_.IsValid()) cached_->iprint = 3;
00143 }
00144
00146 virtual std::string & solverName()
00147 {
00148 return solverName_;
00149 }
00150
00152 void registerOptions()
00153 {
00154 registerOptions(roptions_);
00155 }
00156
00158 virtual int errorCode() const
00159 {
00160 return -1;
00161 }
00163 static void registerOptions(Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions);
00164 private:
00168 TNLPSolver::ReturnStatus callOptimizer();
00170 Coin::SmartPtr<FilterWarmStart> warmF_;
00171
00173 struct cachedInfo : public Coin::ReferencedObject
00174 {
00175 fint n;
00176 fint m;
00177 fint nnz_h_;
00178 fint kmax;
00179 fint maxa;
00180 fint maxf;
00181 fint mlp;
00182 fint maxWk;
00183 fint maxiWk;
00184 fint iprint;
00185 fint nout;
00186 fint ifail;
00187 real rho;
00188 real * x;
00189 real * c;
00190 real f;
00191 real fmin;
00192 real * bounds;
00193 real * s;
00194 real * a;
00195 fint * la;
00196 real * ws;
00197 fint * lws;
00198 real * lam;
00199 char * cstype;
00200 fint maxiter;
00201 fint * istat;
00202 real * rstat;
00203 Ipopt::TNLP * tnlp_;
00204 fint * hStruct_;
00205 int * permutationJac_;
00206 int * permutationHess_;
00208 double cpuTime_;
00211 bool use_warm_start_in_cache_;
00212
00213
00215 cachedInfo():
00216 n(-1),
00217 m(-1),
00218 nnz_h_(-1),
00219 kmax(-1),
00220 maxa(-1),
00221 maxf(-1),
00222 mlp(-1),
00223 maxWk(-1),
00224 maxiWk(-1),
00225 iprint(-1),
00226 nout(6),
00227 ifail(-100),
00228 rho(0),
00229 x(NULL),
00230 c(NULL),
00231 f(1e100),
00232 fmin(-1e100),
00233 bounds(NULL),
00234 s(NULL),
00235 a(NULL),
00236 la(NULL),
00237 ws(NULL),
00238 lws(NULL),
00239 lam(NULL),
00240 cstype(NULL),
00241 maxiter(1000),
00242 istat(NULL),
00243 rstat(NULL),
00244 tnlp_(NULL),
00245 hStruct_(NULL),
00246 permutationJac_(NULL),
00247 permutationHess_(NULL),
00248 cpuTime_(0),
00249 use_warm_start_in_cache_(false)
00250 {}
00251
00252 cachedInfo(const Ipopt::SmartPtr<Ipopt::TNLP> &tnlp,
00253 Ipopt::SmartPtr<Ipopt::OptionsList>& options):
00254 n(-1),
00255 m(-1),
00256 nnz_h_(-1),
00257 kmax(-1),
00258 maxa(-1),
00259 maxf(-1),
00260 mlp(-1),
00261 maxWk(-1),
00262 maxiWk(-1),
00263 iprint(-1),
00264 nout(6),
00265 ifail(0),
00266 rho(0),
00267 x(NULL),
00268 c(NULL),
00269 f(1e100),
00270 fmin(-1e100),
00271 bounds(NULL),
00272 s(NULL),
00273 a(NULL),
00274 la(NULL),
00275 ws(NULL),
00276 lws(NULL),
00277 lam(NULL),
00278 cstype(NULL),
00279 maxiter(1000),
00280 istat(NULL),
00281 rstat(NULL),
00282 tnlp_(NULL),
00283 hStruct_(NULL),
00284 permutationJac_(NULL),
00285 permutationHess_(NULL),
00286 cpuTime_(0),
00287 use_warm_start_in_cache_(false)
00288 {
00289 initialize(tnlp, options);
00290 }
00291
00293 void initialize(const Ipopt::SmartPtr<Ipopt::TNLP> &tnlp,
00294 Ipopt::SmartPtr<Ipopt::OptionsList>& options);
00295
00297 void optimize();
00298
00300 ~cachedInfo()
00301 {
00302 delete [] x;
00303 delete [] c;
00304 delete [] bounds;
00305 delete [] s;
00306 delete [] a;
00307 delete [] la;
00308 delete [] ws;
00309 delete [] lws;
00310 delete [] lam;
00311 delete [] cstype;
00312 delete [] istat;
00313 delete [] rstat;
00314 delete [] permutationJac_;
00315 delete [] permutationHess_;
00316 delete [] hStruct_;
00317 tnlp_ = NULL;
00318 }
00319
00320 void load_ws(Coin::SmartPtr<FilterWarmStart>);
00321 };
00322
00324 Coin::SmartPtr<cachedInfo> cached_;
00325
00326
00327 static std::string solverName_;
00328
00330 static void TMat2RowPMat(bool symmetric, fint n, fint m, int nnz, const Index* iRow,
00331 const Index* iCol, int * permutation2,
00332 fint * lws, int nnz_offset, int n_offset,
00333 Ipopt::TNLP::IndexStyleEnum index_style);
00334 };
00335
00336 }
00337 #endif