00001
00017 #ifndef BONMINSOLVER_H
00018 #define BONMINSOLVER_H
00019
00020 #include "OSConfig.h"
00021 #include "OSDefaultSolver.h"
00022 #include "OSrLWriter.h"
00023 #include "OSInstance.h"
00024 #include "OSParameters.h"
00025 #include "OSnLNode.h"
00026 #include "OSiLReader.h"
00027 #include "OSrLReader.h"
00028 #include "OSoLReader.h"
00029 #include "OSInstance.h"
00030 #include "OSExpressionTree.h"
00031 #include "OSnLNode.h"
00032 #include "OSDataStructures.h"
00033 #include "OSFileUtil.h"
00034 #include "OSErrorClass.h"
00035
00036 #include "OSResult.h"
00037 #include "OSInstance.h"
00038 #include "OSOption.h"
00039
00040 # include <cstddef>
00041 # include <cstdlib>
00042 # include <cctype>
00043 # include <cassert>
00044 # include <stack>
00045 #include <string>
00046 # include <cppad/cppad.hpp>
00047 #include<iostream>
00048
00049 #ifdef HAVE_CTIME
00050 # include <ctime>
00051 #else
00052 # ifdef HAVE_TIME_H
00053 # include <time.h>
00054 # else
00055 # error "don't have header file for time"
00056 # endif
00057 #endif
00058
00059
00060 #ifdef HAVE_CMATH
00061 # include <cmath>
00062 #else
00063 # ifdef HAVE_MATH_H
00064 # include <math.h>
00065 # else
00066 # error "don't have header file for math"
00067 # endif
00068 #endif
00069 #include<vector>
00070 #include <map>
00071
00072
00073
00074 #include "BonCbc.hpp"
00075 #include "BonTMINLP.hpp"
00076 #include "BonBonminSetup.hpp"
00077
00078
00079 using namespace Ipopt;
00080 using namespace Bonmin;
00081
00082
00083
00084
00085
00086 class BonminProblem : public TMINLP{
00087
00088
00089
00090 public:
00091
00093 BonminProblem(OSInstance *osinstance_ , OSOption *osoption_);
00094
00096 virtual ~BonminProblem();
00097
00098 OSInstance *osinstance;
00099
00100 OSOption *osoption;
00101
00102 TMINLP::SolverReturn status;
00103
00104
00114 virtual bool get_variables_types(Index n, VariableType* var_types);
00115
00117 virtual bool get_variables_linearity(Index n, Ipopt::TNLP::LinearityType* var_types);
00118
00123 virtual bool get_constraints_linearity(Index m, Ipopt::TNLP::LinearityType* const_types);
00125
00138 virtual bool get_nlp_info(Index& n, Index&m, Index& nnz_jac_g,
00139 Index& nnz_h_lag, TNLP::IndexStyleEnum& index_style);
00140
00141
00142
00144
00145
00146
00148 virtual bool get_bounds_info(Index n, Number* x_l, Number* x_u,
00149 Index m, Number* g_l, Number* g_u);
00150
00152 virtual bool get_starting_point(Index n, bool init_x, Number* x,
00153 bool init_z, Number* z_L, Number* z_U,
00154 Index m, bool init_lambda,
00155 Number* lambda);
00156
00158 virtual bool eval_f(Index n, const Number* x, bool new_x, Number& obj_value);
00159
00161 virtual bool eval_grad_f(Index n, const Number* x, bool new_x, Number* grad_f);
00162
00164 virtual bool eval_g(Index n, const Number* x, bool new_x, Index m, Number* g);
00165
00170 virtual bool eval_jac_g(Index n, const Number* x, bool new_x,
00171 Index m, Index nele_jac, Index* iRow, Index *jCol,
00172 Number* values);
00173
00178 virtual bool eval_h(Index n, const Number* x, bool new_x,
00179 Number obj_factor, Index m, const Number* lambda,
00180 bool new_lambda, Index nele_hess, Index* iRow,
00181 Index* jCol, Number* values);
00182
00184
00185
00186 virtual bool get_scaling_parameters(Number& obj_scaling,
00187 bool& use_x_scaling, Index n,
00188 Number* x_scaling,
00189 bool& use_g_scaling, Index m,
00190 Number* g_scaling);
00191
00194 virtual void finalize_solution(TMINLP::SolverReturn status_,
00195 Index n, const Number* x, Number obj_value);
00197
00198 virtual const SosInfo * sosConstraints() const{return NULL;}
00199 virtual const BranchingInfo* branchingInfo() const{return NULL;}
00200
00201 void printSolutionAtEndOfAlgorithm(){
00202 printSol_ = true;}
00203
00204
00205
00206
00207
00208 private:
00209 bool printSol_;
00210
00211 private:
00223
00224
00226
00227
00228
00229 std::string bonminErrorMsg;
00230
00231
00232 };
00233
00234
00249 class BonminSolver : public DefaultSolver{
00250 public:
00251
00252
00253
00255 BonminSolver();
00256
00258 ~BonminSolver();
00259
00260
00261
00262 SmartPtr<BonminProblem> tminlp;
00263
00264
00265 Bab bb;
00266
00267 TMINLP::SolverReturn status;
00268
00269
00270
00271
00274 virtual void solve() throw (ErrorClass) ;
00275
00280 virtual void buildSolverInstance() throw(ErrorClass);
00281
00286 virtual void setSolverOptions() throw(ErrorClass);
00287
00293 void dataEchoCheck();
00294
00299 OSiLReader *m_osilreader;
00300
00305 OSoLReader *m_osolreader;
00306
00307
00308
00313 void writeResult();
00314
00315
00316 private:
00317 OSrLWriter *osrlwriter;
00318
00319 BonminSetup bonminSetup;
00320
00321 std::string bonminErrorMsg;
00322 };
00323
00324
00325 #endif