CouenneProblem.hpp

Go to the documentation of this file.
00001 /* $Id: CouenneProblem.hpp 155 2009-06-16 20:19:39Z pbelotti $
00002  *
00003  * Name:    CouenneProblem.hpp
00004  * Author:  Pietro Belotti
00005  * Purpose: define the class CouenneProblem
00006  *
00007  * (C) Carnegie-Mellon University, 2006-09.
00008  * This file is licensed under the Common Public License (CPL)
00009  */
00010 
00011 #ifndef COUENNE_PROBLEM_HPP
00012 #define COUENNE_PROBLEM_HPP
00013 
00014 #include <vector>
00015 
00016 #include "OsiRowCut.hpp"
00017 #include "BonBabInfos.hpp"
00018 
00019 #include "CouenneTypes.hpp"
00020 #include "expression.hpp"
00021 #include "exprAux.hpp"
00022 #include "CouenneProblemElem.hpp"
00023 #include "CouenneObject.hpp"
00024 #include "CouenneJournalist.hpp"
00025 #include "domain.hpp"
00026 
00027 struct ASL;
00028 struct expr;
00029 
00030 class DepGraph;
00031 class CouenneCutGenerator;
00032 class CouenneSolverInterface;
00033 class quadElem;
00034 class LinMap;
00035 class QuadMap;
00036 
00037 // default tolerance for checking feasibility (and integrality) of NLP solutions
00038 const CouNumber feas_tolerance_default = 1e-5;
00039 
00040 
00049 class CouenneProblem {
00050 
00053   class GlobalCutOff {
00054   private:
00055     GlobalCutOff(const GlobalCutOff&);
00056     double cutoff_;
00057   public:
00058     GlobalCutOff ()         : cutoff_ (COIN_DBL_MAX) {}
00059     GlobalCutOff (double c) : cutoff_ (c) {}
00060     ~GlobalCutOff() {}
00061     inline void setCutOff (double cutoff) {cutoff_ = cutoff;}
00062     inline double getCutOff() const {return cutoff_;}
00063   };
00064 
00066   enum fixType {UNFIXED, FIXED, CONTINUOUS};
00067 
00068  protected:
00069 
00071   std::string problemName_;
00072 
00073   std::vector <exprVar           *> variables_;   
00074   std::vector <CouenneObjective  *> objectives_;  
00075   std::vector <CouenneConstraint *> constraints_; 
00076 
00078   std::vector <expression *> commonexprs_; 
00079 
00080   mutable Domain domain_; 
00081 
00084   std::set <exprAux *, compExpr> *auxSet_;
00085 
00087   mutable int curnvars_;
00088 
00090   int nIntVars_;
00091 
00093   mutable CouNumber *optimum_;
00094 
00096   CouNumber bestObj_;
00097 
00099   int *quadIndex_;
00100 
00102   bool *commuted_;
00103 
00106   int *numbering_;
00107 
00109   int ndefined_;
00110 
00115   DepGraph *graph_;
00116 
00118   int nOrigVars_;
00119 
00122   int nOrigCons_;
00123 
00125   int nOrigIntVars_;
00126 
00128   mutable GlobalCutOff* pcutoff_;
00129 
00131   mutable bool created_pcutoff_;
00132 
00133   bool doFBBT_;  
00134   bool doRCBT_;  
00135   bool doOBBT_;  
00136   bool doABT_;   
00137 
00138   int logObbtLev_;   
00139   int logAbtLev_;    
00140 
00142   JnlstPtr jnlst_;
00143 
00145   CouNumber opt_window_;
00146 
00148   bool useQuadratic_;
00149 
00151   CouNumber feas_tolerance_;
00152 
00156   std::vector <std::set <int> > dependence_;
00157 
00161   std::vector <CouenneObject> objects_;
00162 
00165   mutable int *integerRank_;
00166 
00168   mutable std::vector <int> numberInRank_;
00169 
00171   double maxCpuTime_;
00172 
00174   Bonmin::BabSetupBase *bonBase_;
00175 
00176 #ifdef COIN_HAS_ASL
00178   ASL *asl_;
00179 #endif
00180 
00184   int *unusedOriginalsIndices_;
00185 
00187   int nUnusedOriginals_;
00188 
00189  public:
00190 
00191   CouenneProblem  (ASL * = NULL,
00192                    Bonmin::BabSetupBase *base = NULL,
00193                    JnlstPtr jnlst = NULL);  
00194   CouenneProblem  (const CouenneProblem &); 
00195   ~CouenneProblem ();                       
00196 
00198   CouenneProblem *clone () const
00199   {return new CouenneProblem (*this);}
00200 
00201   int nObjs     () const {return (int) objectives_.   size ();} 
00202   int nCons     () const {return (int) constraints_.  size ();} 
00203   int nOrigCons () const {return nOrigCons_;}                   
00204 
00205   inline int nOrigVars    () const {return nOrigVars_;}                
00206   inline int nDefVars     () const {return ndefined_;}                 
00207   inline int nOrigIntVars () const {return nOrigIntVars_;}             
00208   inline int nIntVars     () const {return nIntVars_;}                 
00209   inline int nVars        () const {return (int) variables_. size ();} 
00210 
00212   inline int evalOrder (int i) const
00213   {return numbering_ [i];}
00214 
00216   inline int *evalVector ()
00217   {return numbering_;}
00218 
00219   // get elements from vectors
00220   inline CouenneConstraint *Con (int i) const {return constraints_ [i];} 
00221   inline CouenneObjective  *Obj (int i) const {return objectives_  [i];} 
00222 
00224   inline exprVar *Var   (int i) const 
00225   {return variables_ [i];}
00226 
00228   inline std::vector <exprVar *> &Variables () 
00229   {return variables_;}
00230 
00232   inline std::set <exprAux *, compExpr> *& AuxSet () 
00233   {return auxSet_;}
00234 
00236   inline DepGraph *getDepGraph () 
00237   {return graph_;}
00238 
00240   inline Domain *domain () const
00241   {return &domain_;}
00242 
00243   // Get and set current variable and bounds
00244   inline CouNumber   &X     (int i) const {return domain_.x   (i);} 
00245   inline CouNumber   &Lb    (int i) const {return domain_.lb  (i);} 
00246   inline CouNumber   &Ub    (int i) const {return domain_.ub  (i);} 
00247 
00248   // get and set current variable and bounds
00249   inline CouNumber  *X     () const {return domain_.x  ();} 
00250   inline CouNumber  *Lb    () const {return domain_.lb ();} 
00251   inline CouNumber  *Ub    () const {return domain_.ub ();} 
00252 
00253   // get optimal solution and objective value
00254   CouNumber  *&bestSol () const {return optimum_;} 
00255   CouNumber    bestObj () const {return bestObj_;} 
00256 
00258   bool *&Commuted () 
00259   {return commuted_;}
00260 
00262   void addObjective     (expression *, const std::string &);
00263 
00264   // Add (non linear) "=", ">=", "<=", and range constraints
00265   void addEQConstraint  (expression *, expression *); 
00266   void addGEConstraint  (expression *, expression *); 
00267   void addLEConstraint  (expression *, expression *); 
00268   void addRNGConstraint (expression *, expression *, 
00269                          expression *);               
00270 
00275   expression *addVariable (bool isint = false, Domain *d = NULL);
00276 
00279   exprAux *addAuxiliary (expression *);
00280 
00282   void reformulate ();
00283 
00287   bool standardize ();
00288 
00291   void print (std::ostream & = std::cout);
00292 
00293 #ifdef COIN_HAS_ASL
00295   int readnl (const struct ASL *);
00296 
00298   expression *nl2e (struct expr *, const ASL *asl);
00299 #endif
00300 
00301   // bound tightening parameters
00302   bool doFBBT () const {return doFBBT_;} 
00303   bool doRCBT () const {return doRCBT_;} 
00304   bool doOBBT () const {return doOBBT_;} 
00305   bool doABT  () const {return doABT_;}  
00306 
00307   int  logObbtLev () const {return logObbtLev_;} 
00308   int  logAbtLev  () const {return logAbtLev_;}  
00309 
00322   void writeAMPL (const std::string &fname, bool aux);
00323 
00327   void writeGAMS (const std::string &fname);
00328 
00331   //void initAuxs (const CouNumber *, const CouNumber *, const CouNumber *);
00332   void initAuxs () const;
00333 
00335   void getAuxs (CouNumber *) const;
00336 
00338   bool boundTightening (t_chg_bounds *, 
00339                         Bonmin::BabInfo * = NULL) const;
00340 
00342   bool btCore (t_chg_bounds *chg_bds) const;
00343 
00345   int obbt (const CouenneCutGenerator *cg,
00346             const OsiSolverInterface &csi,
00347             OsiCuts &cs,
00348             const CglTreeInfo &info,
00349             Bonmin::BabInfo * babInfo,
00350             t_chg_bounds *chg_bds);
00351 
00355   bool aggressiveBT (Bonmin::OsiTMINLPInterface *nlp,
00356                      t_chg_bounds *, 
00357                      Bonmin::BabInfo * = NULL) const;
00358 
00361   int redCostBT (const OsiSolverInterface *psi,
00362                  t_chg_bounds *chg_bds) const;
00363 
00366   int tightenBounds (t_chg_bounds *) const;
00367 
00369   int impliedBounds (t_chg_bounds *) const;
00370 
00372   void fillQuadIndices ();
00373 
00375   void fillObjCoeff (double *&);
00376 
00379   void auxiliarize (exprVar *, exprVar * = NULL);
00380 
00382   void setCutOff (CouNumber cutoff) const;
00383 
00385   CouNumber getCutOff () const
00386   {return pcutoff_ -> getCutOff ();}
00387 
00389   void installCutOff () const;
00390 
00392   ConstJnlstPtr Jnlst() const 
00393   {return ConstPtr(jnlst_);}
00394 
00396   bool checkNLP (const double *solution, double &obj, bool recompute = false) const;
00397 
00400   int getIntegerCandidate (const double *xFrac, double *xInt, double *lb, double *ub) const;
00401 
00403   bool readOptimum (std::string *fname = NULL);
00404 
00406   void readCutoff (const std::string &fname);
00407 
00409   static void registerOptions (Ipopt::SmartPtr <Bonmin::RegisteredOptions> roptions);
00410 
00412   exprAux *linStandardize (bool addAux, 
00413                            CouNumber c0, 
00414                            LinMap  &lmap,
00415                            QuadMap &qmap);
00416 
00419   int splitAux (CouNumber, expression *, expression *&, bool *);
00420 
00422   void indcoe2vector (int *indexL,
00423                       CouNumber *coeff,
00424                       std::vector <std::pair <exprVar *, CouNumber> > &lcoeff);
00425 
00427   void indcoe2vector (int *indexI,
00428                       int *indexJ,
00429                       CouNumber *coeff,
00430                       std::vector <quadElem> &qcoeff);
00431 
00442   void decomposeTerm (expression *term,
00443                       CouNumber initCoe,
00444                       CouNumber &c0,
00445                       LinMap  &lmap,
00446                       QuadMap &qmap);
00447 
00449   const std::string &problemName () const
00450   {return problemName_;}
00451 
00453   const std::vector <std::set <int> > &Dependence () const
00454   {return dependence_;}
00455 
00457   const std::vector <CouenneObject> &Objects () const
00458   {return objects_;}
00459 
00461   int findSOS (OsiSolverInterface *solver, OsiObject ** objects);
00462 
00464   inline void setMaxCpuTime (double time)
00465   {maxCpuTime_ = time;}
00466 
00468   inline double getMaxCpuTime () const
00469   {return maxCpuTime_;}
00470 
00472   inline void setBase (Bonmin::BabSetupBase *base) {
00473     bonBase_ = base;
00474     jnlst_   = base -> journalist ();
00475   }
00476 
00481   void createUnusedOriginals ();
00482 
00486   void restoreUnusedOriginals (CouNumber * = NULL) const;
00487 
00489   int *unusedOriginalsIndices () {return unusedOriginalsIndices_;}
00490 
00492   int nUnusedOriginals ()        {return nUnusedOriginals_;}
00493 
00494 protected:
00495 
00501   int fake_tighten (char direction,  
00502                     int index,       
00503                     const double *X, 
00504                     CouNumber *olb,  
00505                     CouNumber *oub,  
00506                     t_chg_bounds *chg_bds,
00507                     t_chg_bounds *f_chg) const;
00508 
00510   int obbtInner (CouenneSolverInterface *, 
00511                  OsiCuts &,
00512                  t_chg_bounds *, 
00513                  Bonmin::BabInfo *) const;
00514 
00515   int obbt_iter (CouenneSolverInterface *csi, 
00516                  t_chg_bounds *chg_bds, 
00517                  const CoinWarmStart *warmstart, 
00518                  Bonmin::BabInfo *babInfo,
00519                  double *objcoe,
00520                  int sense, 
00521                  int index) const;
00522 
00523   int call_iter (CouenneSolverInterface *csi, 
00524                  t_chg_bounds *chg_bds, 
00525                  const CoinWarmStart *warmstart, 
00526                  Bonmin::BabInfo *babInfo,
00527                  double *objcoe,
00528                  enum nodeType type,
00529                  int sense) const;
00530 
00534   void analyzeSparsity (CouNumber, 
00535                         LinMap &,
00536                         QuadMap &);
00537 
00540   void flattenMul (expression *mul, 
00541                    CouNumber &coe, 
00542                    std::map <int, CouNumber> &indices);
00543 
00545   void realign ();
00546 
00548   void fillDependence (Bonmin::BabSetupBase *base);
00549 
00551   void fillIntegerRank () const;
00552 
00554   int testIntFix (int index, 
00555                   CouNumber xFrac, 
00556                   enum fixType *fixed,
00557                   CouNumber *xInt,
00558                   CouNumber *dualL, CouNumber *dualR,
00559                   CouNumber *olb,   CouNumber *oub,
00560                   bool patient) const;
00561 };
00562 
00563 #endif

Generated on Wed Jul 8 03:05:41 2009 for Couenne by  doxygen 1.4.7