- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

# /home/coin/svn-release/Smi-0.93.1/Smi/src/SmiSmpsIO.hpp

Go to the documentation of this file.

    00001 // Copyright (C) 2003, International Business Machines
    00002 // Corporation and others.  All Rights Reserved.
    00003
    00004 #ifndef SmiSmpsIO_HPP
    00005 #define SmiSmpsIO_HPP
    00006
    00007 #if defined(_MSC_VER)
    00008 // Turn off compiler warning about long names
    00009 #  pragma warning(disable:4786)
    00010 #endif
    00011
    00012 #include "CoinMpsIO.hpp"
    00013 #include "CoinFileIO.hpp"
    00014 #include "CoinFinite.hpp"
    00015 #include "SmiScnModel.hpp"
    00016 #include "SmiScnData.hpp"
    00017 #include "SmiScenarioTree.hpp"
    00018
    00019 #include <vector>
    00020 #include <map>
    00021 #include <string>
    00022
    00023 using namespace std;
    00024
    00025
    00026 // sections
    00027 enum SmiSectionType { SMI_NO_SECTION, SMI_NAME_SECTION,
    00028                                           SMI_ENDATA_SECTION,
    00029                                         SMI_EOF_SECTION,
    00030                                           SMI_TIME_SECTION,
    00031                                         SMI_SCENARIOS_SECTION,
    00032                                         SMI_INDEPENDENT_SECTION,
    00033                                           SMI_UNKNOWN_SECTION
    00034 };
    00035
    00036 enum SmiSmpsType { SMI_SC_CARD, SMI_BL_CARD, SMI_COLUMN_CARD, SMI_DISCRETE_DIST, SMI_SMPS_COMBINE_ADD,
    00037         SMI_SMPS_COMBINE_REPLACE, SMI_SMPS_COMBINE_UNKNOWN, SMI_UNKNOWN_MPS_TYPE,
    00038         SMI_TIME_UNORDERED_CORE_TYPE, SMI_TIME_ORDERED_CORE_TYPE
    00039 };
    00040
    00041 class SmiSmpsCardReader:
    00042 public CoinMpsCardReader
    00043 {
    00044 public:
    00045           SmiSectionType nextSmpsField (  );
    00046           SmiSectionType whichSmpsSection(){return smiSection_;}
    00047
    00048           SmiSmpsType whichSmpsType() {return smiSmpsType_;}
    00049
    00050           inline const char *periodName (  ) const {return periodName_;}
    00051           inline const char *scenarioNew (  ) const {return columnName_;}
    00052           inline const char *scenarioAnc (  ) const {return rowName_;}
    00053
    00054           inline double getProb(){ return prob_;}
    00055
    00056           inline void setCoreCombineRule(SmiCoreCombineRule *r){combineRule_=r;combineRuleSet=true;}
    00057           inline SmiCoreCombineRule *getCoreCombineRule() { return combineRule_;}
    00058
    00061           SmiSmpsCardReader( CoinFileInput *input, CoinMpsIO * reader ):CoinMpsCardReader (input,reader ),
    00062                 combineRuleSet(false),prob_(0.0){}
    00063
    00064           ~SmiSmpsCardReader(){}
    00065 private:
    00067         char periodName_[COIN_MAX_FIELD_LENGTH];
    00068         float fvalue_;
    00069         SmiSectionType smiSection_;
    00070         SmiSmpsType smiSmpsType_;
    00071         SmiCoreCombineRule *combineRule_;
    00072         bool combineRuleSet;
    00073         double prob_;
    00074 };
    00075
    00076 class SmiSmpsIO:
    00077 public CoinMpsIO
    00078 {
    00079 public:
    00080         SmiCoreData * readTimeFile(SmiScnModel *smi,const char *c,const char *ext="time");
    00081         int readStochFile(SmiScnModel *smi,SmiCoreData *core, const char *c,const char *ext="stoch");
    00082
    00083         inline void setCoreCombineRule(SmiCoreCombineRule *r){combineRule_=r; combineRuleSet=true;}
    00084         inline SmiCoreCombineRule *getCoreCombineRule() { return combineRule_;}
    00085         inline int getNumStages(){ return nstag_;}
    00086         inline int *getColumnStages(){ return cstag_;}
    00087         inline int *getRowStages(){ return rstag_;}
    00088
    00089     inline void setSolverInfinity(double solverInf) { solverInf_ = solverInf; }
    00090     inline double getSolverInfinity() const { return solverInf_; }
    00091
    00092         void writeSmps(const char* filename, bool winFileExtensions = false, bool strictFormat = true);
    00093 public:
    00094         SmiSmpsIO():CoinMpsIO(),nstag_(0),cstag_(NULL),rstag_(NULL),solverInf_(COIN_DBL_MAX),iftime(false),ifstoch(false),smpsCardReader_(NULL),combineRule_(NULL),combineRuleSet(false),core(NULL),tree(NULL),periodMap_(),scenarioMap_() {}
    00095     SmiSmpsIO(SmiCoreData * core, SmiScenarioTree<SmiScnNode *> * smiTree):CoinMpsIO(),nstag_(0),cstag_(NULL),rstag_(NULL),solverInf_(COIN_DBL_MAX),iftime(false),ifstoch(false),smpsCardReader_(NULL),combineRule_(NULL),combineRuleSet(false),core(core),tree(smiTree),periodMap_(),scenarioMap_() {}
    00096
    00097     ~SmiSmpsIO(){delete [] cstag_;delete[] rstag_;delete smpsCardReader_;}
    00098 private:
    00107     void writeCoreFile(const char* filename, const char* extension, const bool strictFormat);
    00108
    00117     void writeTimeFile(const char* filename, const char* extension, const bool strictFormat);
    00118
    00126     void writeStochFile(const char* filename, const char* extension, const bool strictFormat);
    00127
    00131     void writeScenarioToStochFile(std::ostringstream& stream, SmiTreeNode<SmiScnNode *> * node, int scenario, bool strictFormat);
    00132
    00133     std::string getModProblemName(); // get the (probably modified) problem name
    00134
    00135         int nstag_;
    00136         int *cstag_;
    00137         int *rstag_;
    00138     double solverInf_;
    00139
    00140         bool iftime,ifstoch;
    00141         SmiSmpsCardReader *smpsCardReader_;
    00142         SmiCoreCombineRule *combineRule_;
    00143         bool combineRuleSet;
    00144
    00145         SmiCoreData * core;
    00146         SmiScenarioTree<SmiScnNode *> * tree;
    00147
    00148     typedef std::map<string,int> StringIntMap;
    00149     StringIntMap periodMap_;
    00150     StringIntMap scenarioMap_;
    00151
    00152 };
    00153
    00154
    00155
    00156
    00157
    00158
    00159
    00160
    00161
    00162 #endif //#define SmiSmpsIO_HPP