GamsModel.hpp

Go to the documentation of this file.
00001 // Copyright (C) GAMS Development 2006
00002 // All Rights Reserved.
00003 // This code is published under the Common Public License.
00004 //
00005 // $Id: GamsModel.hpp 56 2007-02-03 17:51:56Z stefan $
00006 //
00007 // Authors:  Michael Bussieck, Stefan Vigerske
00008 
00009 #ifndef __GAMSMODEL_HPP__
00010 #define __GAMSMODEL_HPP__
00011 
00012 #include "GAMSlinksConfig.h"
00013 
00014 #if defined(_MSC_VER)
00015 // Turn off compiler warning about long names
00016 #  pragma warning(disable:4786)
00017 #endif
00018 
00019 extern "C" struct dictRec;
00020 extern "C" struct optRec; 
00021 
00025 class GamsModel  {
00026 public:
00027 
00030   enum  BasisStatus { 
00031     NonBasicLower = 0,
00032     NonBasicUpper,
00033     Basic,
00034     SuperBasic,
00035     LastBasisStatus 
00036   };
00037   
00040   enum VariableStatus {
00041                 VarNormal = 0,
00042                 VarNonOptimal,
00043                 VarInfeasible,
00044                 VarUnbounded,
00045                 VarLastStatus   
00046   };
00047 
00050   enum RowStatus {
00051                 RowNormal = 0,
00052                 RowNonOptimal,
00053                 RowInfeasible,
00054                 RowUnbounded,
00055                 RowLastStatus   
00056   };
00057   
00060   enum  SolverStatus { 
00061     SolverStatusNotSet = 0,
00062     NormalCompletion = 1,
00063     IterationInterrupt,
00064     ResourceInterrupt,
00065     TerminatedBySolver,
00066     EvaluationErrorLimit,
00067     CapabilityProblems,
00068     LicensingProblems,
00069     UserInterrupt,
00070     ErrorSetupFailure,
00071     ErrorSolverFailure,
00072     ErrorInternalSolverError,
00073     SolveProcessingSkipped,
00074     ErrorSystemFailure,
00075     LastSolverStatus 
00076   }; 
00077 
00080   enum  ModelStatus { 
00081     ModelStatusNotSet = 0,
00082     Optimal,
00083     LocallyOptimal,
00084     Unbounded,
00085     Infeasible,
00086     LocallyInfeasible,
00087     IntermediateInfeasible,
00088     IntermediateNonoptimal,
00089     IntegerSolution,
00090     IntermediateNonInteger,
00091     IntegerInfeasible,
00092     LicensingProblemNoSolution,
00093     ErrorUnknown,
00094     ErrorNoSolution,
00095     NoSolutionReturned,
00096     SolvedUnique,
00097     Solved,
00098     SolvedSingular,
00099     UnboundedNoSolution,
00100     InfeasibleNoSolution,
00101     LastModelStatus 
00102   };
00103   
00106   enum PrintMask {
00107         LogMask = 0x1,
00108         StatusMask = 0x2,
00109         AllMask = LogMask|StatusMask,
00110         LastPrintMask
00111   };
00112   
00113 
00119   GamsModel(const char *cntrfile, const double SolverMInf=0, const double SolverPInf=0);
00120 
00123   ~GamsModel();
00124 
00134   void PrintOut(PrintMask mask, const char *msg);
00135   
00138   int getSysOut(); 
00145   void TimerStart();
00148   double SecondsSinceStart();
00154         const char* getSystemDir();
00155         
00160   inline int nCols() const  { return nCols_; }
00163   inline int nDCols() const { return nDCols_; }
00166   inline int nSOS1() const  { return nSOS1_; }
00169   inline int nSOS2() const  { return nSOS2_; }
00172   inline int nRows() const  { return nRows_; }
00175   inline int nNnz()  const  { return nNnz_; }
00176 
00179   inline double *ColLb()    { return ColLb_; }
00182   inline double *ColUb()    { return ColUb_; }
00185   inline int    *ColDisc()  { return ColDisc_; }
00193   inline int    *SOSIndicator() { return SOSIndicator_; }
00200         char          *ColName(int colnr, char *buffer, int bufLen);
00201 
00210   inline char   *RowSense() { return RowSense_; }
00213   inline double *RowRhs()   { return RowRhs_; }
00220         char          *RowName(int rownr, char *buffer, int bufLen);
00221 
00224   inline double *ObjCoef()  { return ObjCoef_; }
00227   inline double ObjConstant()  { return ObjRhs_; }
00231   inline double ObjSense() const { return ObjSense_; } 
00232 
00235   inline int    *matStart()  { return matStart_; }
00238   inline int    *matRowIdx() { return matRowIdx_; }
00241   inline double *matValue()  { return matValue_; }
00247   int matSqueezeZeros();
00254   ModelStatus getModelStatus();
00257   SolverStatus getSolverStatus();
00258 
00263   void setStatus(const SolverStatus& newSolverStatus, 
00264                  const ModelStatus& newModelStatus);
00265 
00269   inline void setIterUsed(const int IterUsed) { IterUsed_ = IterUsed; }
00273   inline void setResUsed(const double ResUsed) { ResUsed_ = ResUsed; }
00277   inline void setObjVal(const double ObjVal) { ObjVal_ = ObjVal; }
00280   inline double getObjVal() { return ObjVal_; }
00283   inline double getResUsed() { return ResUsed_; }
00284 
00287   inline double *ColLevel()     { return ColLevel_; }
00290   inline double *ColMargin()    { return ColMargin_; }
00293   inline int    *ColBasis()     { return ColBasis_; }
00297   inline int    *ColIndicator() { return ColIndicator_; }
00298 
00301   inline double *RowLevel()     { return RowLevel_; }
00304   inline double *RowMargin()    { return RowMargin_; }
00307   inline int    *RowBasis()     { return RowBasis_; }
00311   inline int    *RowIndicator() { return RowIndicator_; }
00312 
00318   void setSolution(const double *ColLevel=0, const double *ColMargin=0, 
00319                    const int *ColBasis=0, const int *ColIndicator=0,
00320                    const double *RowLevel=0, const double *RowMargin=0, 
00321                    const int *RowBasis=0, const int *RowIndicator=0);
00328   double getResLim();
00331   int    getIterLim(); // Iteration limit for model run
00334   int    getNodeLim();
00340   int    getGamsInteger(int nr);
00347   int    getGamsInteger(int intnr, int bitnr);
00350   double getOptCA();   
00353   double getOptCR();   
00356   double getCutOff();
00357 
00361         const char* getOptionfile();
00362 
00368         bool ReadOptionsDefinitions(const char* solvername); 
00371         bool ReadOptionsFile(); 
00372 
00377         bool optDefined(const char *optname);
00378 //      bool optDefinedRecent(const char *optname);
00379         
00383         inline bool optGetBool(const char* optname) { return optGetInteger(optname); }
00387         int optGetInteger(const char *optname);
00391         double optGetDouble(const char *optname);
00396         char* optGetString(const char *optname, char *buffer);
00397         
00402         inline void optSetBool(const char *optname, bool bval) { optSetInteger(optname, bval ? 1 : 0); }
00407         void optSetInteger(const char *optname, int ival);
00412         void optSetDouble(const char *optname, double dval);
00417         void optSetString(const char *optname, char *sval);
00420 private:
00421   int nCols_;  // # columns
00422   int nDCols_; // # discrete columns
00423   int nSOS1_;  // # SOS type 1
00424   int nSOS2_;  // # SOS type 2
00425   int nRows_;  // # rows
00426   int nNnz_;   // # non zeros
00427 
00428   double startTime_; // Start time
00429 
00430   double *ColLb_;   // lower bound for columns
00431   double *ColUb_;   // upper bound for columns
00432   int    *ColDisc_; // list 0..nDCols_-1 for column indicies of discrete columns
00433   int    *ColStat_; // Column basis status
00434   int    *SOSIndicator_;  // indicator for SOS of type 1 and 2
00435 
00436   char   *RowSense_; // sense of row
00437   double *RowRhs_;   // rhs
00438   int    *RowStat_;  // Row basis status
00439 
00440   double ObjSense_; // objective sense 1=min, -1=max
00441   double *ObjCoef_;  // Dense objective function
00442   double  ObjRhs_;   // constant in objective function
00443   double  zCoef_;    // coefficient of objective variable
00444   int     isReform_; // reformulated objective function
00445 
00446   int    *matStart_;  // matrix start of column
00447   int    *matRowIdx_; // matrix row index
00448   double *matValue_;  // matrix values
00449 
00450   double *RowLevel_;
00451   double *RowMargin_;
00452   int    *RowBasis_;
00453   int    *RowIndicator_;
00454 
00455   double *ColLevel_;
00456   double *ColMargin_;
00457   int    *ColBasis_;
00458   int    *ColIndicator_;
00459   
00460   void Allocate();
00461   void ReadMatrix();
00462 
00463   double ObjVal_;
00464   double ResUsed_;
00465   int    IterUsed_;
00466   int    DomUsed_;
00467 
00468   SolverStatus SolverStatus_;
00469   ModelStatus ModelStatus_;
00470 
00471   struct dictRec* dict; // handle for dictionary  
00472         char* ConstructName(char* buffer, int bufLen, int lSym, int* uelIndices, int nIndices);
00473 
00474         struct optRec* optionshandle; // handle for options
00475 };
00476 
00477 #endif // __GAMSMODEL_HPP__

Generated on Fri May 16 19:23:21 2008 for GAMSlinks by  doxygen 1.4.7