OsiNullSolverInterface2.hpp

Go to the documentation of this file.
00001 // Copyright (C) 2000, International Business Machines
00002 // Corporation and others.  All Rights Reserved.
00003 #ifndef OsiNullSolverInterface_H
00004 #define OsiNullSolverInterface_H
00005 
00006 #include <string>
00007 #include <vector>
00008 
00009 #include "CoinMessageHandler.hpp"
00010 #include "CoinPackedVectorBase.hpp"
00011 
00012 #include "OsiData.hpp"
00013 #include "OsiCollections.hpp"
00014 #include "OsiSolverParameters.hpp"
00015 
00016 class CoinPackedMatrix;
00017 class CoinWarmStart;
00018 
00019 class OsiCuts;
00020 class OsiAuxInfo;
00021 class OsiRowCut;
00022 class OsiRowCutDebugger;
00023 class CoinSet;
00024 class CoinBuild;
00025 class CoinModel;
00026 class OsiSolverBranch;
00027 class OsiSolverResult;
00028 #include "CoinFinite.hpp"
00029 
00030 #ifndef COIN_DBL_MAX
00031 static const double OsiNullInfinity = DBL_MAX;
00032 #else
00033 static const double OsiNullInfinity = COIN_DBL_MAX;
00034 #endif
00035 
00036 //#############################################################################
00037 
00038 class OsiNullSolverInterface : public OsiSolverInterface  {
00039 
00040 public:
00042 
00043 
00044    virtual void initialSolve(){
00045       CoinAssertHint(0, "OsiNull does not have a solver");
00046    }; 
00047    
00049    virtual void resolve(){
00050       CoinAssertHint(0, "OsiNull does not have a solver");
00051    }
00052    
00054    virtual void branchAndBound(){
00055       CoinAssertHint(0, "OsiNull does not have a solver");
00056    }
00058    // Set an integer parameter
00059    // copy all parameters in this section from one solver to another
00060    void copyParameters(OsiNullSolverInterface & rhs);
00062 
00063    //------------------------------------------------------------------------
00065 
00066 
00067    virtual bool isAbandoned() const{
00068       CoinAssertHint(0, "OsiNull does not have a solver");
00069       return false;
00070    }
00072    virtual bool isProvenOptimal() const{
00073       CoinAssertHint(0, "OsiNull does not have a solver");
00074       return false;
00075    }
00077    virtual bool isProvenPrimalInfeasible() const{
00078       CoinAssertHint(0, "OsiNull does not have a solver");
00079       return false;
00080    }
00082    virtual bool isProvenDualInfeasible() const{
00083       CoinAssertHint(0, "OsiNull does not have a solver");
00084       return false;
00085    }
00087    virtual bool isPrimalObjectiveLimitReached() const{
00088       CoinAssertHint(0, "OsiNull does not have a solver");
00089       return false;
00090    }
00092    virtual bool isDualObjectiveLimitReached() const{
00093       CoinAssertHint(0, "OsiNull does not have a solver");
00094       return false;
00095    }
00097    virtual bool isIterationLimitReached() const{
00098       CoinAssertHint(0, "OsiNull does not have a solver");
00099       return false;
00100    }
00102 
00103    //------------------------------------------------------------------------
00121    virtual CoinWarmStart *getEmptyWarmStart () const {
00122       CoinAssertHint(0, "OsiNull does not have a solver");
00123       return NULL;
00124    }
00125 
00132    virtual CoinWarmStart* getWarmStart() const {
00133       CoinAssertHint(0, "OsiNull does not have a solver");
00134       return NULL;
00135    }
00136 
00144    virtual bool setWarmStart(const CoinWarmStart* warmstart){
00145       CoinAssertHint(0, "OsiNull does not have a solver");
00146       return false;
00147    }
00149 
00150    //------------------------------------------------------------------------
00161 
00162    virtual int getNumCols() const {
00163       return data_->getNcol();
00164    };
00165   
00167    virtual int getNumRows() const {
00168       return data_->getNrow();
00169    };
00170   
00172    virtual int getNumElements() const {
00173       const CoinPackedMatrix * Mrow = data_->getMatrixByRow();
00174       const CoinPackedMatrix * Mcol = data_->getMatrixByCol();
00175       if(Mrow){
00176          return Mrow->getNumElements();
00177       } else if(Mcol){
00178          return Mcol->getNumElements();
00179       }
00180       return 0;
00181    };
00182 
00184    virtual int getNumIntegers() const {
00185       int i, nInt = 0;
00186       const char * colType = data_->getColType();
00187       for(i = 0; i < getNumCols(); i++){
00188          if(colType[i] == 'B' || colType[i] == 'I')
00189             nInt++;
00190       }
00191       return nInt;
00192    }
00193   
00195    virtual const double * getColLower() const {
00196       return data_->getColLower();
00197    }
00198    
00200    virtual const double * getColUpper() const {
00201       return data_->getColUpper();
00202    }
00203    
00213    virtual const char * getRowSense() const {
00214   
00227       return data_->getRowSense();
00228    }
00229 
00230    virtual const double * getRightHandSide() const {
00231   
00240       return data_->getRowRhs();
00241    }
00242 
00243    virtual const double * getRowRange() const {
00244       return data_->getRowRange();
00245    }
00246 
00248    virtual const double * getRowLower() const {
00249       return data_->getRowLower();
00250    }
00251   
00253    virtual const double * getRowUpper() const {
00254       return data_->getRowUpper();
00255    }
00256   
00258    virtual const double * getObjCoefficients() const {
00259       return data_->getObj();
00260    }
00261   
00263    virtual double getObjSense() const {
00264       CoinAssertHint(0, "Sorry, not implemented yet.");
00265       return 1;
00266    }
00267 
00269    virtual bool isContinuous(int colIndex) const {
00270       return data_->getColType()[colIndex] == 'C';
00271    }
00272   
00274    virtual bool isBinary(int colIndex) const {
00275       return data_->getColType()[colIndex] == 'B';
00276    }
00277   
00282    virtual bool isInteger(int colIndex) const {
00283       return (data_->getColType()[colIndex] == 'B' || 
00284               data_->getColType()[colIndex] == 'I' ); 
00285    }
00286     
00288    virtual const CoinPackedMatrix * getMatrixByRow() const {
00289       return data_->getMatrixByRow();
00290    }
00291   
00293    virtual const CoinPackedMatrix * getMatrixByCol() const {
00294       return data_->getMatrixByCol();
00295    }
00297    virtual double getInfinity() const {
00298       return data_->getInfinity();
00299    }
00301     
00304 
00305    virtual const double * getColSolution() const {
00306       return data_->getPrimalSol();
00307    }
00308   
00310    //TODO: let user enter dual sol also
00311    virtual const double * getRowPrice() const {
00312       CoinAssertHint(0, "Sorry, not implemented yet.");
00313       return NULL;
00314    }
00315   
00317    virtual const double * getReducedCost() const {
00318       CoinAssertHint(0, "Sorry, not implemented yet.");
00319       return NULL;
00320    }
00321   
00324    virtual const double * getRowActivity() const {
00325       return data_->getRowActivity();
00326    }
00327   
00329    virtual double getObjValue() const {
00330       CoinAssertHint(0, "Sorry, not implemented yet.");
00331       return 0.0;
00332    }
00333    
00336    virtual int getIterationCount() const {
00337       CoinAssertHint(0, "OsiNull does not have a solver");
00338    }
00339   
00353    virtual std::vector<double*> getDualRays(int maxNumRays) const {
00365       CoinAssertHint(0, "OsiNull does not have a solver");
00366    }
00367 
00368    virtual std::vector<double*> getPrimalRays(int maxNumRays) const {
00369       CoinAssertHint(0, "OsiNull does not have a solver");
00370    }
00371   
00372    //-------------------------------------------------------------------------
00383 
00385    virtual void setObjCoeff( int elementIndex, double elementValue ) {
00386       CoinAssertHint(0, "Sorry, not implemented yet.");
00387    }
00388 
00391    virtual void setColLower( int elementIndex, double elementValue ) {
00392       CoinAssertHint(0, "Sorry, not implemented yet.");
00393    }
00394 
00397    virtual void setColUpper( int elementIndex, double elementValue ) {
00398       CoinAssertHint(0, "Sorry, not implemented yet.");
00399    }
00400   
00403    virtual void setRowLower( int elementIndex, double elementValue ) {
00404       CoinAssertHint(0, "Sorry, not implemented yet.");
00405    }
00406       
00409    virtual void setRowUpper( int elementIndex, double elementValue ) {
00410       CoinAssertHint(0, "Sorry, not implemented yet.");
00411    }
00412     
00414    virtual void setRowType(int index, char sense, double rightHandSide,
00415                            double range) {
00416       CoinAssertHint(0, "Sorry, not implemented yet.");
00417    }
00418 
00421    virtual void setObjSense(double s) {
00422       CoinAssertHint(0, "Sorry, not implemented yet.");
00423    }
00424 
00433    virtual void setColType(const char * colType){
00434       data_->setColType(colType);
00435    }
00436   
00437    /*
00438      Set the primal solution variable values
00439     
00440      colsol[getNumCols()] is an array of values for the primal variables.
00441      These values are copied to memory owned by the solver interface object
00442      or the solver.  They will be returned as the result of getColSolution()
00443      until changed by another call to setColSolution() or by a call to any
00444      solver routine.  Whether the solver makes use of the solution in any
00445      way is solver-dependent.
00446    */
00447    virtual void setColSolution(const double *colsol) {
00448       data_->setPrimalSol(colsol);
00449    }
00450 
00451 
00462    virtual void setRowPrice(const double * rowprice) {
00463       CoinAssertHint(0, "Sorry, not implemented yet.");
00464    }
00465 
00466    //-------------------------------------------------------------------------
00470    virtual void setContinuous(int index) {
00471       CoinAssertHint(0, "Sorry, not implemented yet.");
00472    }
00473 
00475    virtual void setInteger(int index) {
00476       CoinAssertHint(0, "Sorry, not implemented yet.");
00477    }
00478 
00482    //-------------------------------------------------------------------------
00483     
00484    //-------------------------------------------------------------------------
00492    virtual void addCol(const CoinPackedVectorBase& vec,
00493                        const double collb, const double colub,   
00494                        const double obj) {
00495       CoinAssertHint(0, "Sorry, not implemented yet.");
00496    }
00497 
00504    virtual void deleteCols(const int num, const int * colIndices) {
00505       CoinAssertHint(0, "Sorry, not implemented yet.");
00506    }
00507     
00509    virtual void addRow(const CoinPackedVectorBase& vec,
00510                        const double rowlb, const double rowub) {
00511       CoinAssertHint(0, "Sorry, not implemented yet.");
00512    }
00513 
00515    virtual void addRow(const CoinPackedVectorBase& vec,
00516                        const char rowsen, const double rowrhs,   
00517                        const double rowrng) {
00518       CoinAssertHint(0, "Sorry, not implemented yet.");
00519    }
00520 
00526    virtual void deleteRows(const int num, const int * rowIndices) {
00527       CoinAssertHint(0, "Sorry, not implemented yet.");
00528    }
00529     
00530 
00531 
00532    //---------------------------------------------------------------------
00534    //TODO: ugh force both row/col format?
00535    void loadDataAndSolution(const CoinPackedMatrix & rowMatrix,
00536                             const CoinPackedMatrix & colMatrix,
00537                             const double           * collb, 
00538                             const double           * colub,   
00539                             const double           * obj,
00540                             const double           * rowlb, 
00541                             const double           * rowub,
00542                             const char             * colType,
00543                             const double           * primalSol,
00544                             const double             infinity){
00545       data_->setMatrixByRow(&rowMatrix);
00546       data_->setMatrixByCol(&colMatrix);      
00547       data_->setNrow(rowMatrix.getNumRows());
00548       data_->setNcol(rowMatrix.getNumCols());
00549       data_->setColLower(collb);
00550       data_->setColUpper(colub);
00551       data_->setRowLower(rowlb);
00552       data_->setRowUpper(rowub);
00553       data_->setObj(obj);
00554       data_->setColType(colType);
00555       data_->setPrimalSol(primalSol);
00556       data_->setInfinity(infinity);
00557       data_->initializeOtherData();
00558    }
00559 
00560 
00561 
00563 
00574    virtual void loadProblem(const CoinPackedMatrix & matrix,
00575                             const double * collb, 
00576                             const double * colub,   
00577                             const double * obj,
00578                             const double * rowlb, 
00579                             const double * rowub){
00580       CoinAssertHint(0, "Sorry, not implemented yet.");
00581    }
00582 
00583    //TODO: version that passes in rhs/ranges/sense and converts to bounds
00584                 
00594    virtual void assignProblem(CoinPackedMatrix*& matrix,
00595                               double*& collb, double*& colub, double*& obj,
00596                               double*& rowlb, double*& rowub) {
00597       CoinAssertHint(0, "Sorry, not implemented yet.");
00598    }
00599 
00612    virtual void loadProblem(const CoinPackedMatrix& matrix,
00613                             const double* collb, const double* colub,
00614                             const double* obj,
00615                             const char* rowsen, const double* rowrhs,   
00616                             const double* rowrng) {
00617       CoinAssertHint(0, "Sorry, not implemented yet.");
00618    }
00619 
00629    virtual void assignProblem(CoinPackedMatrix*& matrix,
00630                               double*& collb, double*& colub, double*& obj,
00631                               char*& rowsen, double*& rowrhs,
00632                               double*& rowrng) {
00633       CoinAssertHint(0, "Sorry, not implemented yet.");
00634    }
00635 
00638    virtual void loadProblem(const int numcols, const int numrows,
00639                             const CoinBigIndex * start, const int* index,
00640                             const double* value,
00641                             const double* collb, const double* colub,   
00642                             const double* obj,
00643                             const double* rowlb, const double* rowub) {
00644       CoinAssertHint(0, "Sorry, not implemented yet.");
00645    }
00646 
00649    virtual void loadProblem(const int numcols, const int numrows,
00650                             const CoinBigIndex * start, const int* index,
00651                             const double* value,
00652                             const double* collb, const double* colub,   
00653                             const double* obj,
00654                             const char* rowsen, const double* rowrhs,   
00655                             const double* rowrng) {
00656       CoinAssertHint(0, "Sorry, not implemented yet.");
00657    }
00658 
00665    virtual void writeMps(const char *filename,
00666                          const char *extension = "mps",
00667                          double objSense=0.0) const {
00668       CoinAssertHint(0, "Sorry, not implemented yet.");
00669    }
00670    
00671    //-----------------------------------------------------------------------
00672 
00674 
00675 
00676    OsiNullSolverInterface() :
00677       OsiSolverInterface(),
00678       data_(NULL)
00679    {
00680       data_ = new OsiData(OsiNullInfinity);
00681    }
00682    
00688    virtual OsiNullSolverInterface * clone(bool copyData = true) const {
00689       CoinAssertHint(0, "Sorry, not implemented yet.");
00690       return NULL;
00691    }
00692   
00694    OsiNullSolverInterface(const OsiNullSolverInterface &);
00695   
00697    OsiNullSolverInterface & operator=(const OsiNullSolverInterface& rhs);
00698   
00700    virtual ~OsiNullSolverInterface () {
00701       delete data_;
00702    }
00703 
00705 
00706    //------------------------------------------------------------------------
00707 
00708 protected:
00710 
00711 
00712    virtual void applyRowCut( const OsiRowCut & rc ) {
00713       CoinAssertHint(0, "OsiNull does not have a solver");
00714    }
00715 
00717    virtual void applyColCut( const OsiColCut & cc ) {
00718       CoinAssertHint(0, "OsiNull does not have a solver");
00719    }
00722    template <class T> inline T
00723    forceIntoRange(const T value, const T lower, const T upper) const {
00724       return value < lower ? lower : (value > upper ? upper : value);
00725    }
00727   
00728    //---------------------------------------------------------------------
00729 protected:
00730    OsiData * data_;
00731 };
00732 
00733 #endif

Generated on 5 Apr 2015 for Dip-All by  doxygen 1.6.1