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

- File List
- File Members

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

Go to the documentation of this file.

    00001 // Copyright (C) 2003, International Business Machines
    00002 // Corporation and others.  All Rights Reserved.
    00003 #ifndef SmiDiscreteRV_H
    00004 #define SmiDiscreteRV_H
    00005
    00015 #include "CoinPragma.hpp"
    00016 #include "SmiScnData.hpp"
    00017 #include "SmiLinearData.hpp"
    00018
    00019 #include <vector>
    00020
    00021 //forward declarations
    00022 class SmiDiscreteRV;
    00023
    00024 class SmiDiscreteDistribution
    00025 {
    00026         friend void SmiDiscreteUnitTest();
    00027 public:
    00029         void addDiscreteRV(SmiDiscreteRV *s)
    00030         { smiDiscrete_.push_back(s); }
    00031
    00033         SmiDiscreteRV * getDiscreteRV(int i) {return smiDiscrete_[i];}
    00034
    00036         int getNumRV() { return (int)smiDiscrete_.size(); }
    00037
    00039         SmiCoreData *getCore(){ return core_; }
    00040
    00042         inline void setCombineWithCoreRule(SmiCoreCombineRule *r){
    00043                         combineRule_ = r;
    00044         }
    00045
    00047         inline SmiCoreCombineRule *getCombineWithCoreRule() { return combineRule_;}
    00048
    00049
    00051         SmiDiscreteDistribution(SmiCoreData *c, SmiCoreCombineRule *r=SmiCoreCombineReplace::Instance())
    00052         {
    00053                 core_=c;
    00054                 this->setCombineWithCoreRule(r);
    00055         }
    00056
    00057         ~SmiDiscreteDistribution();
    00058
    00059 private:
    00060         SmiDiscreteDistribution(){core_=NULL;}
    00061         SmiCoreData *core_;
    00062         std::vector<SmiDiscreteRV *> smiDiscrete_;
    00063         SmiCoreCombineRule *combineRule_;
    00064
    00065
    00066 };
    00067
    00068
    00069 class SmiDiscreteEvent : public SmiLinearData
    00070 {
    00071         friend void SmiDiscreteUnitTest();
    00072 public:
    00073         inline void setEventProb(double p) {prob_ = p;}
    00074         inline const double getEventProb () { return prob_; }
    00075         SmiDiscreteEvent(SmiLinearData d, double p):SmiLinearData(d),prob_(p){}
    00076         ~SmiDiscreteEvent(){}
    00077 private:
    00078         double prob_;
    00079 };
    00080
    00081
    00082 class SmiDiscreteRV
    00083 {
    00084         friend void SmiDiscreteUnitTest();
    00085 public:
    00086         void addEvent(CoinPackedMatrix &matrix,
    00087                                 CoinPackedVector &dclo, CoinPackedVector &dcup,
    00088                                 CoinPackedVector &dobj,
    00089                                 CoinPackedVector &drlo, CoinPackedVector &drup, double prob)
    00090         {
    00091                 SmiLinearData d(matrix,dclo,dcup,dobj,drlo,drup);
    00092                 SmiDiscreteEvent *e = new SmiDiscreteEvent(d,prob);
    00093                 events_.push_back(e);
    00094                 prob_+=prob;
    00095         }
    00096         void addEvent(OsiSolverInterface &osi, double prob)
    00097         {
    00098                 SmiLinearData d(osi);
    00099                 SmiDiscreteEvent *e = new SmiDiscreteEvent(d,prob);
    00100                 events_.push_back(e);
    00101                 prob_+=prob;
    00102         }
    00103
    00104         inline const CoinPackedMatrix &getEventMatrix(int i)   {return events_[i]->getMatrix(); }
    00105         inline const CoinPackedVector &getEventColLower(int i) {return events_[i]->getColLower();}
    00106         inline const CoinPackedVector &getEventColUpper(int i) {return events_[i]->getColUpper();}
    00107         inline const CoinPackedVector &getEventObjective(int i){return events_[i]->getObjective();}
    00108         inline const CoinPackedVector &getEventRowLower(int i) {return events_[i]->getRowLower();}
    00109         inline const CoinPackedVector &getEventRowUpper(int i) {return events_[i]->getRowUpper();}
    00110         double getEventProb(int i) {
    00111         //      return events_[i]->getEventProb()/prob_;
    00112                         return events_[i]->getEventProb();
    00113         }
    00114         inline size_t getNumEvents() { return events_.size(); }
    00115         inline int getStage() {return stg_;}
    00116         inline void setStage(int p) {stg_=p;}
    00117         SmiDiscreteRV(){prob_=0.0; stg_=-1;}
    00118         SmiDiscreteRV(int p) {prob_=0.0; stg_=p;}
    00119         ~SmiDiscreteRV(){
    00120                 for (size_t i=0; i<events_.size(); ++i)
    00121                         delete events_[i];
    00122         }
    00123 private:
    00124         std::vector<SmiDiscreteEvent *> events_;
    00125         SmiStageIndex  stg_;
    00126         double prob_;
    00127 };
    00128
    00129 void SmiDiscreteUnitTest();
    00130
    00131 #endif //SmiDiscreteRV_H
    00132