SmiDiscreteDistribution.hpp
Go to the documentation of this file.
1 // Copyright (C) 2003, International Business Machines
2 // Corporation and others. All Rights Reserved.
3 #ifndef SmiDiscreteRV_H
4 #define SmiDiscreteRV_H
5 
15 #include "CoinPragma.hpp"
16 #include "SmiScnData.hpp"
17 #include "SmiLinearData.hpp"
18 
19 #include <vector>
20 
21 //forward declarations
22 class SmiDiscreteRV;
23 
25 {
26  friend void SmiDiscreteUnitTest();
27 public:
30  { smiDiscrete_.push_back(s); }
31 
34 
36  int getNumRV() { return (int)smiDiscrete_.size(); }
37 
39  SmiCoreData *getCore(){ return core_; }
40 
43  combineRule_ = r;
44  }
45 
48 
49 
52  {
53  core_=c;
54  this->setCombineWithCoreRule(r);
55  }
56 
58 
59 private:
62  std::vector<SmiDiscreteRV *> smiDiscrete_;
64 
65 
66 };
67 
68 
70 {
71  friend void SmiDiscreteUnitTest();
72 public:
73  inline void setEventProb(double p) {prob_ = p;}
74  inline const double getEventProb () { return prob_; }
77 private:
78  double prob_;
79 };
80 
81 
83 {
84  friend void SmiDiscreteUnitTest();
85 public:
86  void addEvent(CoinPackedMatrix &matrix,
88  CoinPackedVector &dobj,
89  CoinPackedVector &drlo, CoinPackedVector &drup, double prob);
90  void addEvent(OsiSolverInterface &osi, double prob)
91  {
92  SmiLinearData d(osi);
93  SmiDiscreteEvent *e = new SmiDiscreteEvent(d,prob);
94  events_.push_back(e);
95  prob_+=prob;
96  }
97 
98  inline const CoinPackedMatrix &getEventMatrix(int i) {return events_[i]->getMatrix(); }
99  inline const CoinPackedVector &getEventColLower(int i) {return events_[i]->getColLower();}
100  inline const CoinPackedVector &getEventColUpper(int i) {return events_[i]->getColUpper();}
101  inline const CoinPackedVector &getEventObjective(int i){return events_[i]->getObjective();}
102  inline const CoinPackedVector &getEventRowLower(int i) {return events_[i]->getRowLower();}
103  inline const CoinPackedVector &getEventRowUpper(int i) {return events_[i]->getRowUpper();}
104  double getEventProb(int i) {
105  // return events_[i]->getEventProb()/prob_;
106  return events_[i]->getEventProb();
107  }
108  inline size_t getNumEvents() { return events_.size(); }
109  inline int getStage() {return stg_;}
110  inline void setStage(int p) {stg_=p;}
112  SmiDiscreteRV(int p) {prob_=0.0; stg_=p;}
114  for (size_t i=0; i<events_.size(); ++i)
115  delete events_[i];
116  }
117 private:
118  std::vector<SmiDiscreteEvent *> events_;
120  double prob_;
121 };
122 
123 void SmiDiscreteUnitTest();
124 
125 #endif //SmiDiscreteRV_H
126 
SmiDiscreteRV * getDiscreteRV(int i)
get discrete RV
const CoinPackedMatrix & getEventMatrix(int i)
SmiCoreCombineRule * getCombineWithCoreRule()
get combine rule
const CoinPackedVector & getEventRowLower(int i)
static SmiCoreCombineReplace * Instance()
friend void SmiDiscreteUnitTest()
std::vector< SmiDiscreteRV * > smiDiscrete_
Sparse Matrix Base Class.
std::vector< SmiDiscreteEvent * > events_
friend void SmiDiscreteUnitTest()
const CoinPackedVector & getEventObjective(int i)
void setCombineWithCoreRule(SmiCoreCombineRule *r)
set combine rule
void addDiscreteRV(SmiDiscreteRV *s)
add discrete RV
SmiCoreCombineRule * combineRule_
Abstract Base Class for describing an interface to a solver.
int SmiStageIndex
Definition: SmiScnData.hpp:23
core_
constructor requires core data and combine rule
void addEvent(OsiSolverInterface &osi, double prob)
This deals with combining Core and Stochastic data.
void addEvent(CoinPackedMatrix &matrix, CoinPackedVector &dclo, CoinPackedVector &dcup, CoinPackedVector &dobj, CoinPackedVector &drlo, CoinPackedVector &drup, double prob)
const CoinPackedVector & getEventColUpper(int i)
Sparse Vector.
void SmiDiscreteUnitTest()
const CoinPackedVector & getEventRowUpper(int i)
friend void SmiDiscreteUnitTest()
const CoinPackedVector & getEventColLower(int i)
int getNumRV()
get number of RV
SmiDiscreteEvent(SmiLinearData d, double p)
SmiCoreData * getCore()
get core model