# CouenneMINLPInterface.hpp

Go to the documentation of this file.

    00001 /* $Id: CouenneMINLPInterface.hpp 490 2011-01-14 16:07:12Z pbelotti $
    00002  *
    00003  * Name:    CouenneMINLPInterface
    00004  * Author:  Pietro Belotti
    00005  * Purpose: MINLP interface with computation of gradient and Jacobian
    00006  *          through CouenneExpressions
    00007  *
    00008  * (C) Pietro Belotti 2010
    00009  * This file is licensed under the Eclipse Public License (EPL)
    00010  */
    00011
    00012 #ifndef CouenneMINLPInterface_hpp
    00013 #define CouenneMINLPInterface_hpp
    00014
    00015 //#define INT_BIAS 0e-8
    00016
    00017 //#include <string>
    00018 //#include <iostream>
    00019
    00020 #include "OsiSolverInterface.hpp"
    00021
    00022 // #include "CoinWarmStartBasis.hpp"
    00023
    00024 // #include "BonTMINLP.hpp"
    00025 // #include "BonTMINLP2TNLP.hpp"
    00026 // #include "BonTNLP2FPNLP.hpp"
    00027 //#include "BonTNLPSolver.hpp"
    00028 //#include "BonCutStrengthener.hpp"
    00029 //#include "BonRegisteredOptions.hpp"
    00030
    00031 #include "CouenneTypes.hpp"
    00032
    00033 namespace Ipopt {
    00034   class OptionsList;
    00035 }
    00036
    00037 namespace Couenne {
    00038
    00039   class expression;
    00040   class CouenneProblem;
    00041
    00042   //class RegisteredOptions;
    00043   //class StrongBranchingSolver;
    00044
    00046
    00047   enum Solver {
    00048     EIpopt=0,
    00049     EFilterSQP,
    00050     EAll
    00051   };
    00052
    00054
    00058
    00059   class CouenneMINLPInterface: public OsiSolverInterface {
    00060
    00061   public:
    00062
    00065     void setObj (int index, expression *newObj) {}
    00066
    00068     void setInitSol (const CouNumber *sol);
    00069
    00072     CouNumber solve (CouNumber *solution);
    00073
    00075     CouenneProblem *problem () const
    00076     {return problem_;}
    00077
    00079     Ipopt::OptionsList *options () const
    00080     {return options_;}
    00081
    00082   private:
    00083
    00085     CouenneProblem *problem_;
    00086
    00088     Ipopt::OptionsList *options_;
    00089
    00091     virtual std::string appName ()
    00092     {return "couenne";}
    00093
    00094
    00095 #if 0
    00096     //friend class BonminParam;
    00097
    00098   public:
    00099
    00100     //     /// Error class to throw exceptions from CouenneMINLPInterface.
    00101     //      *  Inherited from CoinError, we just want to have a different class to be able to catch
    00102     //      *  errors thrown by CouenneMINLPInterface.
    00103     //
    00104
    00105     //     class SimpleError: public CoinError {
    00106
    00107     //     private:
    00108     //       SimpleError();
    00109
    00110     //     public:
    00111     //       ///Alternate constructor using strings
    00112     //       SimpleError(std::string message,
    00113     //            std::string methodName,
    00114     //            std::string f = std::string(),
    00115     //            int l = -1):
    00116     //         CoinError(message,methodName,std::string("CouenneMINLPInterface"), f, l)  {}
    00117     //     };
    00118
    00119     // #ifdef __LINE__
    00120     // #define SimpleError(x, y) SimpleError((x), (y), __FILE__, __LINE__)
    00121     // #endif
    00122
    00123     //   // Error when problem is not solved
    00124     //   TNLPSolver::UnsolvedError * newUnsolvedError(int num, Ipopt::SmartPtr<TMINLP2TNLP> problem, std::string name){
    00125     //     return app_ -> newUnsolvedError (num, problem, name);
    00126     //   }
    00127     //   //#############################################################################
    00128
    00129
    00130     //   /// Type of the messages specifically outputed by CouenneMINLPInterface.
    00131     //   enum MessagesTypes{
    00132     //     SOLUTION_FOUND///found a feasible solution,
    00133     //     INFEASIBLE_SOLUTION_FOUND///found an infeasible problem,
    00134     //     UNSOLVED_PROBLEM_FOUND///found an unsolved problem,
    00135     //     WARNING_RESOLVING /// Warn that a problem is resolved,
    00136     //     WARN_SUCCESS_WS/// Problem not solved with warm start but solved without,
    00137     //     WARN_SUCCESS_RANDOM/// Subproblem not solve with warm start but solved with random point,
    00138     //     WARN_CONTINUING_ON_FAILURE/// a failure occured but is continuing,
    00139     //     SUSPECT_PROBLEM/// Output the number of the problem.,
    00140     //     SUSPECT_PROBLEM2/// Output the number of the problem.,
    00141     //     IPOPT_SUMMARY /// Output summary statistics on Ipopt solution.,
    00142     //     BETTER_SOL /// Found a better solution with random values.,
    00143     //     LOG_HEAD/// Head of "civilized" log.,
    00144     //     LOG_FIRST_LINE/// First line (first solve) of log.,
    00145     //     LOG_LINE///standard line (retry solving) of log.,
    00146     //     ALTERNATE_OBJECTIVE/// Recomputed integer feasible with alternate objective function,
    00147     //     WARN_RESOLVE_BEFORE_INITIAL_SOLVE /// resolve() has been called but there
    00148     //                                               was no previous call to initialSolve().
    00149     //                                          ,
    00150     //     ERROR_NO_TNLPSOLVER /// Trying to access non-existent TNLPSolver,
    00151     //     WARNING_NON_CONVEX_OA /// Warn that there are equality or ranged constraints and OA may works bad.,
    00152     //     SOLVER_DISAGREE_STATUS /// Different solver gives different status for problem.,
    00153     //     SOLVER_DISAGREE_VALUE /// Different solver gives different optimal value for problem.,
    00154     //     OSITMINLPINTERFACE_DUMMY_END
    00155     //   };
    00156
    00157     //#############################################################################
    00158
    00159
    00160     //   /// Messages outputed by an CouenneMINLPInterface.
    00161     // class Messages : public CoinMessages
    00162     //   {
    00163     //   public:
    00164     //     /// Constructor
    00165     //     Messages();
    00166     //   };
    00167
    00168
    00169     //#############################################################################
    00170
    00171
    00173
    00174
    00175     CouenneMINLPInterface ();
    00176
    00178     void initialize(Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions,
    00179                     Ipopt::SmartPtr<Ipopt::OptionsList> options,
    00180                     Ipopt::SmartPtr<Ipopt::Journalist> journalist_,
    00181                     Ipopt::SmartPtr<TMINLP> tminlp);
    00182
    00184     void setModel(Ipopt::SmartPtr<TMINLP> tminlp);
    00185
    00187     void setSolver(Ipopt::SmartPtr<TNLPSolver> app);
    00188
    00190     void use(Ipopt::SmartPtr<TMINLP2TNLP> tminlp2tnlp){
    00191       problem_ = tminlp2tnlp;}
    00192
    00194     CouenneMINLPInterface (const CouenneMINLPInterface &);
    00195
    00197     OsiSolverInterface * clone (bool copyData = true) const;
    00198
    00200     CouenneMINLPInterface & operator=(const CouenneMINLPInterface& rhs);
    00201
    00203     virtual ~CouenneMINLPInterface ();
    00204
    00206     void readOptionFile(const std::string & fileName);
    00207
    00209     const Ipopt::SmartPtr<Ipopt::OptionsList> options() const;
    00210
    00212     Ipopt::SmartPtr<Ipopt::OptionsList> options();
    00213
    00214     //---------------------------------------------------------------------------
    00216
    00217
    00218     virtual void initialSolve();
    00219
    00225
    00226     virtual void resolve();
    00227
    00231
    00232     virtual void resolveForCost(int numretry, bool keepWs);
    00233
    00236
    00237     virtual void resolveForRobustness(int numretry);
    00238
    00240     virtual void branchAndBound()
    00241     {
    00242       //throw SimpleError ("Function not implemented for CouenneMINLPInterface","branchAndBound()");
    00243     }
    00245
    00246
    00247     //---------------------------------------------------------------------------
    00249
    00250
    00251     virtual bool isAbandoned ()                   const;
    00252     virtual bool isProvenOptimal ()               const;
    00253     virtual bool isProvenPrimalInfeasible ()      const;
    00254     virtual bool isProvenDualInfeasible ()        const;
    00255     virtual bool isPrimalObjectiveLimitReached () const;
    00256     virtual bool isDualObjectiveLimitReached ()   const;
    00257     virtual bool isIterationLimitReached ()       const;
    00258
    00260     void continuingOnAFailure()
    00261     {
    00262       hasContinuedAfterNlpFailure_ = true;
    00263     }
    00264
    00266     bool hasContinuedOnAFailure()
    00267     {
    00268       return hasContinuedAfterNlpFailure_;
    00269     }
    00270
    00272     void ignoreFailures()
    00273     {
    00274       pretendFailIsInfeasible_ = 2;
    00275     }
    00276
    00278     void forceInfeasible()
    00279     {
    00280       problem_->set_obj_value(1e200);
    00281     }
    00282
    00284     void forceBranchable()
    00285     {
    00286       problem_->set_obj_value(-1e200);
    00287       problem_->force_fractionnal_sol();
    00288     }
    00290
    00291
    00292     //---------------------------------------------------------------------------
    00294
    00302
    00306
    00308     // Set an integer parameter
    00309     bool setIntParam(OsiIntParam key, int value);
    00310     // Set an double parameter
    00311     bool setDblParam(OsiDblParam key, double value);
    00312     // Set a string parameter
    00313     bool setStrParam(OsiStrParam key, const std::string & value);
    00314     // Get an integer parameter
    00315     bool getIntParam(OsiIntParam key, int& value) const;
    00316     // Get an double parameter
    00317     bool getDblParam(OsiDblParam key, double& value) const;
    00318     // Get a string parameter
    00319     bool getStrParam(OsiStrParam key, std::string& value) const;
    00320
    00321     // Get the push values for starting point
    00322     inline double getPushFact() const
    00323     {
    00324       return pushValue_;
    00325     }
    00326
    00328
    00329
    00330     //---------------------------------------------------------------------------
    00332
    00333     //        These methods call the solver's query routines to return
    00334     //        information about the problem referred to by the current object.
    00335     //        Querying a problem that has no data associated with it result in
    00336     //        zeros for the number of rows and columns, and NULL pointers from
    00337     //        the methods that return vectors.
    00338
    00339     //        Const pointers returned from any data-query method are valid as
    00340     //        long as the data is unchanged and the solver is not called.
    00341
    00343
    00344
    00345
    00346     virtual int getNumCols() const;
    00347
    00349     virtual int getNumRows() const;
    00350
    00352     const OsiSolverInterface::OsiNameVec& getVarNames() ;
    00354     virtual const double * getColLower() const;
    00355
    00357     virtual const double * getColUpper() const;
    00358
    00360     //  <ul>
    00361     //  <li>'L': <= constraint
    00362     //  <li>'E': =  constraint
    00363     //  <li>'G': >= constraint
    00364     //  <li>'R': ranged constraint
    00365     //  <li>'N': free constraint
    00366     //  </ul>
    00367
    00368     virtual const char * getRowSense() const;
    00369
    00371     //  <ul>
    00372     //  <li> if rowsense()[i] == 'L' then rhs()[i] == rowupper()[i]
    00373     //  <li> if rowsense()[i] == 'G' then rhs()[i] == rowlower()[i]
    00374     //  <li> if rowsense()[i] == 'R' then rhs()[i] == rowupper()[i]
    00375     //  <li> if rowsense()[i] == 'N' then rhs()[i] == 0.0
    00376     //  </ul>
    00377
    00378     virtual const double * getRightHandSide() const;
    00379
    00381     //          <ul>
    00382     //  <li> if rowsense()[i] == 'R' then
    00383     //  rowrange()[i] == rowupper()[i] - rowlower()[i]
    00384     //  <li> if rowsense()[i] != 'R' then
    00385     //  rowrange()[i] is 0.0
    00386     //  </ul>
    00387
    00388     virtual const double * getRowRange() const;
    00389
    00391     virtual const double * getRowLower() const;
    00392
    00394     virtual const double * getRowUpper() const;
    00395
    00398     virtual double getObjSense() const
    00399     {
    00400       return 1;
    00401     }
    00402
    00404     virtual bool isContinuous(int colNumber) const;
    00405
    00407     virtual bool isBinary(int columnNumber) const;
    00408
    00412     virtual bool isInteger (int columnNumber) const;
    00413
    00415     virtual bool isIntegerNonBinary(int columnNumber) const;
    00416
    00418     virtual bool isFreeBinary(int columnNumber) const;
    00419
    00421     virtual double getInfinity() const;
    00422
    00424     const int * getPriorities() const
    00425     {
    00426       const TMINLP::BranchingInfo * branch = tminlp_->branchingInfo();
    00427       if(branch)
    00428         return branch->priorities;
    00429       else return NULL;
    00430     }
    00431
    00433     const int * getBranchingDirections() const
    00434     {
    00435       const TMINLP::BranchingInfo * branch = tminlp_->branchingInfo();
    00436       if(branch)
    00437         return branch->branchingDirections;
    00438       else return NULL;
    00439     }
    00440
    00441     const double * getUpPsCosts() const
    00442     {
    00443       const TMINLP::BranchingInfo * branch = tminlp_->branchingInfo();
    00444       if(branch)
    00445         return branch->upPsCosts;
    00446       else return NULL;
    00447     }
    00448
    00449     const double * getDownPsCosts() const
    00450     {
    00451       const TMINLP::BranchingInfo * branch = tminlp_->branchingInfo();
    00452       if(branch)
    00453         return branch->downPsCosts;
    00454       else return NULL;
    00455     }
    00456
    00458
    00460
    00461
    00463     virtual const double * getColSolution() const;
    00464
    00466     virtual const double * getRowPrice() const;
    00467
    00469     virtual const double * getReducedCost() const;
    00470
    00473     virtual const double * getRowActivity() const;
    00474
    00475
    00480
    00481     virtual int getIterationCount () const;
    00482
    00484     int nCallOptimizeTNLP()
    00485     {
    00486       return nCallOptimizeTNLP_;
    00487     }
    00488
    00490     double totalNlpSolveTime()
    00491     {
    00492       return totalNlpSolveTime_;
    00493     }
    00494
    00496     int totalIterations()
    00497     {
    00498       return totalIterations_;
    00499     }
    00500
    00501
    00503
    00504     //-------------------------------------------------------------------------
    00506
    00508
    00511     virtual void setColLower( int elementIndex, double elementValue );
    00512
    00515     virtual void setColUpper( int elementIndex, double elementValue );
    00516
    00519
    00520     virtual void setColLower(const double * array);
    00521
    00524
    00525     virtual void setColUpper(const double * array);
    00526
    00527
    00530     virtual void setRowLower( int elementIndex, double elementValue );
    00531
    00533     virtual void setRowUpper( int elementIndex, double elementValue );
    00534
    00536     virtual void setRowType(int index, char sense, double rightHandSide,
    00537                             double range);
    00538
    00539
    00544     virtual void setObjSense(double s);
    00545
    00549
    00550     virtual void setColSolution(const double *colsol);
    00551
    00555
    00556     virtual void setRowPrice(const double * rowprice);
    00557
    00559
    00560
    00561     //---------------------------------------------------------------------------
    00563
    00564
    00566
    00571
    00572     virtual CoinWarmStart *getEmptyWarmStart () const;
    00573
    00575     virtual CoinWarmStart* getWarmStart() const;
    00576
    00579     virtual bool setWarmStart(const CoinWarmStart* warmstart);
    00580
    00581     void setExposeWarmStart(bool value) {
    00582       exposeWarmStart_ = value;
    00583     }
    00584
    00585     bool getExposeWarmStart() {
    00586       return exposeWarmStart_;
    00587     }
    00588
    00589     void randomStartingPoint();
    00590
    00591     //Returns true if a basis is available
    00592     virtual bool basisIsAvailable() const
    00593     {
    00594       // Throw an exception
    00595       throw SimpleError("Needs coding for this interface", "basisIsAvailable");
    00596     }
    00597
    00598
    00600
    00601     //-------------------------------------------------------------------------
    00603
    00604
    00605     virtual void setContinuous(int index);
    00607     virtual void setInteger(int index);
    00609
    00610     //Set numIterationSuspect_
    00611     void setNumIterationSuspect(int value)
    00612     {
    00613       numIterationSuspect_ = value;
    00614     }
    00615
    00622
    00623
    00625
    00626     virtual int getNumElements() const
    00627     {
    00628       return -1;
    00629     }
    00630
    00631
    00635
    00636     virtual const double * getObjCoefficients() const;
    00637
    00639
    00640     virtual const CoinPackedMatrix * getMatrixByRow() const
    00641     {
    00642       return NULL;
    00643     }
    00644
    00645
    00647
    00648     virtual const CoinPackedMatrix * getMatrixByCol() const
    00649     {
    00650       return NULL;
    00651     }
    00652
    00654
    00655     virtual void setObjCoeff( int elementIndex, double elementValue )
    00656     {
    00657       throw SimpleError("CouenneMINLPInterface does not implement this function.",
    00658                         "setObjCoeff");
    00659     }
    00660
    00662
    00663     virtual void addCol(const CoinPackedVectorBase& vec,
    00664                         const double collb, const double colub,
    00665                         const double obj)
    00666     {
    00667       throw SimpleError("CouenneMINLPInterface does not implement this function.",
    00668                         "addCol");
    00669     }
    00670
    00672
    00673     virtual void deleteCols(const int num, const int * colIndices)
    00674     {
    00675       throw SimpleError("CouenneMINLPInterface does not implement this function.",
    00676                         "deleteCols");
    00677     }
    00678
    00680
    00681     virtual void addRow(const CoinPackedVectorBase& vec,
    00682                         const double rowlb, const double rowub)
    00683     {
    00684       throw SimpleError("CouenneMINLPInterface does not implement this function.",
    00685                         "addRow");
    00686     }
    00687
    00689
    00690     virtual void addRow(const CoinPackedVectorBase& vec,
    00691                         const char rowsen, const double rowrhs,
    00692                         const double rowrng)
    00693     {
    00694       throw SimpleError("CouenneMINLPInterface model does not implement this function.",
    00695                         "addRow");
    00696     }
    00698
    00699     virtual void deleteRows(const int num, const int * rowIndices)
    00700     {
    00701       if(num)
    00702         freeCachedRowRim();
    00703       problem_->removeCuts(num, rowIndices);
    00704     }
    00705
    00706
    00708
    00709     virtual void loadProblem(const CoinPackedMatrix& matrix,
    00710                              const double* collb, const double* colub,
    00711                              const double* obj,
    00712                              const double* rowlb, const double* rowub)
    00713     {
    00714       throw SimpleError("CouenneMINLPInterface does not implement this function.",
    00715                         "loadProblem");
    00716     }
    00717
    00718
    00720
    00721     virtual void assignProblem(CoinPackedMatrix*& matrix,
    00722                                double*& collb, double*& colub, double*& obj,
    00723                                double*& rowlb, double*& rowub)
    00724     {
    00725       throw SimpleError("CouenneMINLPInterface does not implement this function.",
    00726                         "assignProblem");
    00727     }
    00728
    00730
    00731     virtual void loadProblem(const CoinPackedMatrix& matrix,
    00732                              const double* collb, const double* colub,
    00733                              const double* obj,
    00734                              const char* rowsen, const double* rowrhs,
    00735                              const double* rowrng)
    00736     {
    00737       throw SimpleError("CouenneMINLPInterface does not implement this function.",
    00738                         "loadProblem");
    00739     }
    00740
    00742
    00743     virtual void assignProblem(CoinPackedMatrix*& matrix,
    00744                                double*& collb, double*& colub, double*& obj,
    00745                                char*& rowsen, double*& rowrhs,
    00746                                double*& rowrng)
    00747     {
    00748       throw SimpleError("CouenneMINLPInterface does not implement this function.",
    00749                         "assignProblem");
    00750     }
    00751
    00752
    00754
    00755     virtual void loadProblem(const int numcols, const int numrows,
    00756                              const int* start, const int* index,
    00757                              const double* value,
    00758                              const double* collb, const double* colub,
    00759                              const double* obj,
    00760                              const double* rowlb, const double* rowub)
    00761     {
    00762       throw SimpleError("CouenneMINLPInterface does not implement this function.",
    00763                         "loadProblem");
    00764     }
    00765
    00767
    00768     virtual void loadProblem(const int numcols, const int numrows,
    00769                              const int* start, const int* index,
    00770                              const double* value,
    00771                              const double* collb, const double* colub,
    00772                              const double* obj,
    00773                              const char* rowsen, const double* rowrhs,
    00774                              const double* rowrng)
    00775     {
    00776       throw SimpleError("CouenneMINLPInterface model does not implement this function.",
    00777                         "loadProblem");
    00778     }
    00779
    00781
    00782     virtual int readMps(const char *filename,
    00783                         const char *extension = "mps")
    00784     {
    00785       throw SimpleError("CouenneMINLPInterface does not implement this function.",
    00786                         "readMps");
    00787     }
    00788
    00789
    00791
    00792     virtual void writeMps(const char *filename,
    00793                           const char *extension = "mps",
    00794                           double objSense=0.0) const
    00795     {
    00796       throw SimpleError("CouenneMINLPInterface does not implement this function.",
    00797                         "writeMps");
    00798     }
    00799
    00801     virtual std::vector<double*> getDualRays(int maxNumRays) const
    00802     {
    00803       throw SimpleError("CouenneMINLPInterface does not implement this function.",
    00804                         "getDualRays");
    00805     }
    00806
    00808     virtual std::vector<double*> getPrimalRays(int maxNumRays) const
    00809     {
    00810       throw SimpleError("CouenneMINLPInterface does not implement this function.",
    00811                         "getPrimalRays");
    00812     }
    00813
    00815
    00816
    00817
    00818     //---------------------------------------------------------------------------
    00819
    00820
    00821
    00823
    00825     void turnOffSolverOutput(){
    00826       app_->turnOffOutput();}
    00827     void turnOnSolverOutput(){
    00828       app_->turnOnOutput();}
    00830
    00832
    00833
    00834     virtual double getObjValue() const;
    00835
    00837
    00839     const TMINLP2TNLP * problem() const
    00840     {
    00841       return GetRawPtr(problem_);
    00842     }
    00843
    00844     TMINLP2TNLP * problem()
    00845     {
    00846       return GetRawPtr(problem_);
    00847     }
    00848
    00849     const TMINLP * model() const
    00850     {
    00851       return GetRawPtr(tminlp_);
    00852     }
    00853
    00854     Bonmin::TMINLP * model()
    00855     {
    00856       return GetRawPtr(tminlp_);
    00857     }
    00858
    00859     const Bonmin::TNLPSolver * solver() const
    00860     {
    00861       return GetRawPtr(app_);
    00862     }
    00863
    00864     TNLPSolver * solver()
    00865     {
    00866       return GetRawPtr(app_);
    00867     }
    00869
    00870
    00871
    00872
    00873
    00874
    00875
    00876     virtual void extractLinearRelaxation(OsiSolverInterface &si, const double *x,
    00877                                          bool getObj = 1);
    00878
    00882
    00883     virtual void extractLinearRelaxation(OsiSolverInterface &si, bool getObj = 1,
    00884                                          bool solveNlp = 1){
    00885       if(solveNlp)
    00886         initialSolve();
    00887       extractLinearRelaxation(si, getColSolution(), getObj);
    00888       if(solveNlp){
    00889         app_->enableWarmStart();
    00890         setColSolution(problem()->x_sol());
    00891         setRowPrice(problem()->duals_sol());
    00892       }
    00893     }
    00894
    00898     void getOuterApproximation(OsiCuts &cs, bool getObj, const double * x2, bool global)
    00899     {
    00900       getOuterApproximation(cs, getColSolution(), getObj, x2, global);
    00901     }
    00902
    00906     void getOuterApproximation(OsiCuts &cs, const double * x, bool getObj, const double * x2, bool global){
    00907       getOuterApproximation(cs, x, getObj, x2, 0., global);}
    00908
    00912     virtual void getOuterApproximation(OsiCuts &cs, const double * x, bool getObj, const double * x2,
    00913                                        double theta, bool global);
    00914
    00916     virtual void getConstraintOuterApproximation(OsiCuts & cs, int constraintNumber,
    00917                                                  const double * x,
    00918                                                  const double * x2, bool global);
    00919
    00921     void getConstraintOuterApproximation(OsiCuts & cs, int constraintNumber,
    00922                                          const double * x2, bool global){
    00923       getConstraintOuterApproximation(cs, constraintNumber, getColSolution(),x2,global);
    00924     }
    00925
    00927     void getBendersCut(OsiCuts &cs, const double * x, const double *lambda, bool getObj = 1);
    00928
    00936     double getFeasibilityOuterApproximation(int n, const double * x_bar,const int *ind, OsiCuts &cs, bool addOnlyViolated, bool global);
    00937
    00946
    00947     double solveFeasibilityProblem(int n, const double * x_bar, const int* ind, double a, double s, int L);
    00948
    00956
    00957     double solveFeasibilityProblem(int n, const double * x_bar, const int* ind, int L, double cutoff);
    00958
    00961     void switchToFeasibilityProblem(int n, const double * x_bar, const int* ind, double a, double s, int L);
    00962
    00965     void switchToFeasibilityProblem(int n, const double * x_bar, const int* ind,
    00966                                     double rhs_local_branching_constraint);
    00967
    00969     void switchToOriginalProblem();
    00971
    00974
    00975
    00976     enum OaMessagesTypes {
    00977       CUT_NOT_VIOLATED_ENOUGH = 0,
    00978       VIOLATED_OA_CUT_GENERATED,
    00979       OA_CUT_GENERATED,
    00980       OA_MESSAGES_DUMMY_END
    00981     };
    00982
    00984     class OaMessages :public CoinMessages{
    00985     public:
    00987       OaMessages();
    00988     };
    00989
    00991     class OaMessageHandler : public CoinMessageHandler{
    00992     public:
    00994       OaMessageHandler():CoinMessageHandler(){
    00995       }
    00997       OaMessageHandler(FILE * fp):CoinMessageHandler(fp){
    00998       }
    01000       virtual ~OaMessageHandler(){
    01001       }
    01003       OaMessageHandler(const OaMessageHandler &other):
    01004         CoinMessageHandler(other){}
    01006       OaMessageHandler(const CoinMessageHandler &other):
    01007         CoinMessageHandler(other){}
    01009       OaMessageHandler & operator=(const OaMessageHandler &rhs){
    01010         CoinMessageHandler::operator=(rhs);
    01011         return *this;}
    01013       virtual CoinMessageHandler* clone() const{
    01014         return new OaMessageHandler(*this);}
    01016       void print(OsiRowCut &row);
    01017     };
    01018
    01019     void setOaMessageHandler(const CoinMessageHandler &handler){
    01020       delete oaHandler_;
    01021       oaHandler_ = new OaMessageHandler(handler);
    01022     }
    01024
    01025     //-----------------------------------------------------------------------
    01027
    01028     virtual ApplyCutsReturnCode applyCuts(const OsiCuts & cs,
    01029                                           double effectivenessLb = 0.0){
    01030       freeCachedRowRim();
    01031       problem_->addCuts(cs);
    01032       ApplyCutsReturnCode rc;
    01033       return rc;}
    01034
    01036     virtual void applyRowCuts(int numberCuts, const OsiRowCut * cuts);
    01037
    01038
    01040     virtual void applyRowCuts(int numberCuts, const OsiRowCut ** cuts)
    01041     {
    01042       if(numberCuts)
    01043         freeCachedRowRim();
    01044       problem_->addCuts(numberCuts, cuts);
    01045     }
    01046
    01048         obj the objective value of x.
    01049     double getConstraintsViolation(const double * x, double & obj);
    01050
    01052         value where obj is the estimated objective value of x.
    01053     double getNonLinearitiesViolation(const double *x, const double obj);
    01054
    01055     //---------------------------------------------------------------------------
    01056
    01057     void extractInterfaceParams();
    01058
    01059
    01061     virtual void setAppDefaultOptions(Ipopt::SmartPtr<Ipopt::OptionsList> Options);
    01062
    01064     static void registerOptions (Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions);
    01065
    01066     Ipopt::SmartPtr<Bonmin::RegisteredOptions> regOptions(){
    01067       if(IsValid(app_))
    01068         return app_->roptions();
    01069       else
    01070         return NULL;
    01071     }
    01072
    01074
    01075
    01076     void SetStrongBrachingSolver(Ipopt::SmartPtr<StrongBranchingSolver> strong_branching_solver);
    01079     virtual void markHotStart();
    01083     virtual void solveFromHotStart();
    01086     virtual void unmarkHotStart();
    01088
    01089   protected:
    01090
    01092
    01093     enum RandomGenerationType{
    01094       uniform =0, perturb=1, perturb_suffix=2};
    01096     int initializeJacobianArrays();
    01097
    01099
    01100
    01101
    01103     void solveAndCheckErrors(bool doResolve, bool throwOnFailure,
    01104                              const char * whereFrom);
    01105
    01106
    01108
    01109     virtual void applyRowCut( const OsiRowCut & rc )
    01110     {
    01111       const OsiRowCut * cut = &rc;
    01112       problem_->addCuts(1, &cut);
    01113     }
    01115
    01116     virtual void applyColCut( const OsiColCut & cc )
    01117     {
    01118       throw SimpleError("Ipopt model does not implement this function.",
    01119                         "applyColCut");
    01120     }
    01121
    01122     //  /// Read the name of the variables in an ampl .col file.
    01123     //  void readVarNames() const;
    01124
    01126
    01128
    01129
    01130     Ipopt::SmartPtr<TMINLP> tminlp_;
    01132     Ipopt::SmartPtr<TMINLP2TNLP> problem_;
    01134     Ipopt::SmartPtr<Ipopt::TNLP> problem_to_optimize_;
    01136     bool feasibility_mode_;
    01138     Ipopt::SmartPtr<TNLPSolver> app_;
    01139
    01141     std::list<Ipopt::SmartPtr<TNLPSolver> > debug_apps_;
    01143     bool testOthers_;
    01145
    01147     CoinWarmStart* warmstart_;
    01148
    01150
    01151
    01152     void freeCachedColRim();
    01154     void freeCachedRowRim();
    01156     void freeCachedData();
    01159     void extractSenseRhsAndRange() const;
    01161     mutable char    *rowsense_;
    01162
    01164     mutable double  *rhs_;
    01165
    01167     mutable double  *rowrange_;
    01170     mutable double  *reducedCosts_;
    01172     double OsiDualObjectiveLimit_;
    01174     mutable bool hasVarNamesFile_;
    01176
    01177     int nCallOptimizeTNLP_;
    01179     double totalNlpSolveTime_;
    01181     int totalIterations_;
    01183     double maxRandomRadius_;
    01185     int randomGenerationType_;
    01187     double max_perturbation_;
    01189     double pushValue_;
    01191     int numRetryInitial_;
    01193     int numRetryResolve_;
    01195     int numRetryInfeasibles_;
    01197     int numRetryUnsolved_;
    01199     Messages messages_;
    01203     int pretendFailIsInfeasible_;
    01205     bool hasContinuedAfterNlpFailure_;
    01208     int numIterationSuspect_ ;
    01212     bool hasBeenOptimized_;
    01216     mutable double * obj_;
    01218     static bool hasPrintedOptions;
    01219
    01221     Ipopt::SmartPtr<TNLP2FPNLP> feasibilityProblem_;
    01222
    01223
    01225
    01226
    01227     int * jRow_;
    01229     int * jCol_;
    01231     double * jValues_;
    01233     int nnz_jac;
    01235
    01237     Ipopt::TNLP::LinearityType * constTypes_;
    01239
    01240     int nNonLinear_;
    01242     double tiny_;
    01244     double veryTiny_;
    01246     double infty_;
    01248     TNLPSolver::ReturnStatus optimizationStatus_;
    01250     bool exposeWarmStart_;
    01252     bool firstSolve_;
    01254     SmartPtr<CutStrengthener> cutStrengthener_;
    01255
    01258
    01259
    01260     OaMessages oaMessages_;
    01262     OaMessageHandler * oaHandler_;
    01264   protected:
    01266     void createApplication(Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions,
    01267                            Ipopt::SmartPtr<Ipopt::OptionsList> options,
    01268                            Ipopt::SmartPtr<Ipopt::Journalist> journalist);
    01270     CouenneMINLPInterface(Ipopt::SmartPtr<TNLPSolver> app);
    01271
    01273     bool internal_setWarmStart(const CoinWarmStart* ws);
    01274
    01276     CoinWarmStart* internal_getWarmStart() const;
    01277   private:
    01279     SmartPtr<StrongBranchingSolver> strong_branching_solver_;
    01281     TNLPSolver::ReturnStatus optimizationStatusBeforeHotStart_;
    01282     static const char * OPT_SYMB;
    01283     static const char * FAILED_SYMB;
    01284     static const char * INFEAS_SYMB;
    01285     static const char * UNBOUND_SYMB;
    01287     const char * statusAsString(TNLPSolver::ReturnStatus r){
    01288       if(r == TNLPSolver::solvedOptimal || r == TNLPSolver::solvedOptimalTol){
    01289         return OPT_SYMB;}
    01290       else if(r == TNLPSolver::provenInfeasible){
    01291         return INFEAS_SYMB;}
    01292       else if(r == TNLPSolver::unbounded){
    01293         return UNBOUND_SYMB;}
    01294       else return FAILED_SYMB;
    01295     }
    01296     const char * statusAsString(){
    01297       return statusAsString(optimizationStatus_);}
    01298 #endif
    01299   };
    01300 }
    01301
    01302 #endif
    01303

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines