TMINLP.hpp

Go to the documentation of this file.
00001 // (C) Copyright International Business Machines Corporation and Carnegie Mellon University 2004
00002 // All Rights Reserved.
00003 // This code is published under the Common Public License.
00004 //
00005 // Authors :
00006 // Pierre Bonami, Carnegie Mellon University,
00007 // Carl D. Laird, Carnegie Mellon University,
00008 // Andreas Waechter, International Business Machines Corporation
00009 //
00010 // Date : 12/01/2004
00011 
00012 #ifndef __TMINLP_HPP__
00013 #define __TMINLP_HPP__
00014 
00015 #include "IpUtils.hpp"
00016 #include "IpReferenced.hpp"
00017 #include "IpException.hpp"
00018 #include "IpAlgTypes.hpp"
00019 #include "CoinPackedMatrix.hpp"
00020 #include "OsiCuts.hpp"
00021 #include "IpTNLP.hpp"
00022 
00023 #include "CoinHelperFunctions.hpp"
00024 namespace Ipopt
00025 {
00026 
00054   class TMINLP : public ReferencedObject
00055   {
00056   public:
00057     enum SolverReturn{
00058       SUCCESS,
00059       INFEASIBLE,
00060       LIMIT_EXCEEDED,
00061       MINLP_ERROR};
00064     TMINLP()
00065     {}
00066     ;
00067 
00069     virtual ~TMINLP()
00070     {}
00071     ;
00073 
00075     struct SosInfo
00076     {
00078       int num;
00080       char * types;
00082       int * priorities;
00083       
00087       int numNz;
00089       int * starts;
00091       int * indices;
00093       double * weights;
00096       SosInfo():num(0), types(NULL), priorities(NULL), numNz(0), starts(NULL),
00097              indices(NULL), weights(NULL)
00098       {}
00100       SosInfo(const SosInfo & source):num(source.num), types(NULL), priorities(NULL), 
00101           numNz(source.numNz), starts(NULL),indices(NULL),
00102            weights(NULL)
00103       {
00104 
00105         if(num > 0) {
00106           assert(source.types!=NULL);
00107           assert(source.priorities!=NULL);
00108           assert(source.starts!=NULL);
00109           assert(source.indices!=NULL);
00110           assert(source.weights!=NULL);
00111           types = new char[num];
00112           priorities = new int[num];
00113           starts = new int[num + 1];
00114           indices = new int[numNz];
00115           weights = new double[numNz];
00116           for(int i = 0 ; i < num ; i++) {
00117             source.types[i] = types[i];
00118             source.priorities[i] = priorities[i];
00119             source.starts[i] = starts[i];
00120           }
00121           for(int i = 0 ; i < numNz ; i++) {
00122             source.indices[i] = indices[i];
00123             source.weights[i] = weights[i];
00124           }
00125         }
00126         else {
00127           assert(source.types==NULL);
00128           assert(source.priorities==NULL);
00129           assert(source.starts==NULL);
00130           assert(source.indices==NULL);
00131           assert(source.weights==NULL);
00132         }
00133 
00134       }
00135 
00137       ~SosInfo()
00138       {
00139         gutsOfDestructor();
00140       }
00141 
00142 
00144       void gutsOfDestructor()
00145       {
00146         num = 0;
00147         numNz = 0;
00148         if(types) delete [] types;
00149         types = NULL;
00150         if(starts) delete [] starts;
00151         starts = NULL;
00152         if(indices) delete [] indices;
00153         indices = NULL;
00154         if(priorities) delete [] priorities;
00155         priorities = NULL;
00156         if(weights) delete [] weights;
00157         weights = NULL;
00158       }
00159     };
00160 
00162     struct BranchingInfo
00163     {
00165       int size;
00167       int * priorities;
00169       int * branchingDirections;
00171       double * upPsCosts;
00173       double * downPsCosts;
00174       BranchingInfo():
00175       size(0),
00176       priorities(NULL),
00177       branchingDirections(NULL),
00178       upPsCosts(NULL),
00179       downPsCosts(NULL)
00180       {}
00181       BranchingInfo(const BranchingInfo &other)
00182       {
00183         gutsOfDestructor();
00184         size = other.size;
00185         priorities = CoinCopyOfArray(other.priorities, size);
00186         branchingDirections = CoinCopyOfArray(other.branchingDirections, size);
00187         upPsCosts = CoinCopyOfArray(other.upPsCosts, size);
00188         downPsCosts = CoinCopyOfArray(other.downPsCosts, size);
00189       }
00190       void gutsOfDestructor()
00191       {
00192       if (priorities != NULL) delete [] priorities;
00193       priorities = NULL;
00194       if (branchingDirections != NULL) delete [] branchingDirections;  
00195       branchingDirections = NULL;
00196       if (upPsCosts != NULL) delete [] upPsCosts;
00197       upPsCosts = NULL;
00198       if (downPsCosts != NULL) delete [] downPsCosts;
00199       downPsCosts = NULL;
00200       } 
00201     };
00203     enum VariableType
00204     {
00205       CONTINUOUS,
00206       BINARY,
00207       INTEGER
00208     };
00209 
00211     enum ConstraintType
00212     {
00213       LINEAR,
00214       NON_LINEAR
00215     };
00216 
00222     virtual bool get_nlp_info(Index& n, Index& m, Index& nnz_jac_g,
00223         Index& nnz_h_lag, TNLP::IndexStyleEnum& index_style)=0;
00224 
00227     virtual bool get_var_types(Index n, VariableType* var_types)=0;
00228 
00230     virtual bool get_constraints_types(Index m, ConstraintType* const_types)=0;
00231 
00240     virtual bool get_bounds_info(Index n, Number* x_l, Number* x_u,
00241         Index m, Number* g_l, Number* g_u)=0;
00242 
00250     virtual bool get_starting_point(Index n, bool init_x, Number* x,
00251                                     bool init_z, Number* z_L, Number* z_U,
00252         Index m, bool init_lambda,
00253         Number* lambda)=0;
00254 
00256     virtual bool eval_f(Index n, const Number* x, bool new_x,
00257         Number& obj_value)=0;
00258 
00261     virtual bool eval_grad_f(Index n, const Number* x, bool new_x,
00262         Number* grad_f)=0;
00263 
00265     virtual bool eval_g(Index n, const Number* x, bool new_x,
00266         Index m, Number* g)=0;
00267 
00273     virtual bool eval_jac_g(Index n, const Number* x, bool new_x,
00274         Index m, Index nele_jac, Index* iRow,
00275         Index *jCol, Number* values)=0;
00276 
00284     virtual bool eval_h(Index n, const Number* x, bool new_x,
00285         Number obj_factor, Index m, const Number* lambda,
00286         bool new_lambda, Index nele_hess,
00287         Index* iRow, Index* jCol, Number* values)=0;
00289 
00293     virtual void finalize_solution(SolverReturn status,
00294         Index n, const Number* x, Number obj_value)const =0;
00296     
00297     virtual const BranchingInfo * branchingInfo() const = 0;
00298 
00299     virtual const SosInfo * sosConstraints() const = 0;
00300   private:
00310     //TMINLP();
00311 
00313     TMINLP(const TMINLP&);
00314 
00316     void operator=(const TMINLP&);
00318 
00319 
00320   };
00321 
00322 } // namespace Ipopt
00323 
00324 #endif

Generated on Fri May 16 21:06:02 2008 for Bonmin by  doxygen 1.4.7