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

- File List
- File Members

# /home/coin/svn-release/Smi-0.93.1/Smi/flopcpp_examples/scen-tree_struct.hpp

Go to the documentation of this file.

    00001
    00014 #ifndef SCENTREE_STRUCT_HPP
    00015 #define SCENTREE_STRUCT_HPP
    00016
    00017 #include <iostream>
    00018 #include <vector>
    00019 #include <cassert>
    00020
    00021 namespace FlopSmiEx {
    00022 using std::vector;
    00023 using std::cout;
    00024 using std::cerr;
    00025 using std::endl;
    00026
    00028 class ScenTreeStruct {
    00029 protected:
    00030         int nmbScens;
    00031         vector<int> leaves;
    00032
    00033 public:
    00034         int nmbStages;
    00035
    00037         ScenTreeStruct(int const nScens, int const nStages = 0)
    00038         : nmbScens(nScens), leaves(nScens, -1), nmbStages(nStages)
    00039         {}
    00041         virtual ~ScenTreeStruct() {}
    00042
    00044
    00047         virtual int get_parent_node(int n) const = 0;
    00048
    00050         int get_nmb_stages() const { return nmbStages; }
    00051
    00053         int get_nmb_scens() const { return static_cast<int>(leaves.size()); }
    00054
    00056         virtual double get_scen_prob(int const sc) const = 0;
    00057
    00059         virtual int const * get_scen_nodes(int const sc) = 0;
    00060
    00062         inline int const * get_core_scen() { return get_scen_nodes(0); }
    00063
    00065
    00074         virtual int const * get_next_scen(int &scen, int &parentScen,
    00075                                           int &branchStage, double &prob) = 0;
    00076 };
    00077
    00078
    00080 class BinTreeStruct : public ScenTreeStruct {
    00081 protected:
    00082         int * scenNodeNmb;
    00083         int nextScen;
    00084         double scenProb;
    00085
    00088         int set_scen_nodes(int const sc);
    00089
    00090 public:
    00092
    00095         BinTreeStruct(int const T);
    00096
    00097         ~BinTreeStruct(){
    00098                 delete[] scenNodeNmb;
    00099         }
    00100
    00101         int get_parent_node(int n) const {
    00102                 return (n-1) / 2;    // This gives: get_parent_node(0) = 0
    00103         }
    00104
    00105         double get_scen_prob(int const sc) const { return scenProb; }
    00106
    00107         int const * get_scen_nodes(int const sc) {
    00108                 set_scen_nodes(sc);
    00109                 return scenNodeNmb;
    00110         }
    00111
    00112         int const * get_next_scen(int &scen, int &parentScen,
    00113                                   int &branchStage, double &prob);
    00114 };
    00115
    00116
    00118 class TwoStageTree : public ScenTreeStruct {
    00119 protected:
    00120         int nmbScens;
    00121         vector<int> leaves;
    00122         vector<double> probs;
    00123         int scenNodeNmb[2];
    00124         int nextScen;
    00125
    00128         int set_scen_nodes(int const sc) {
    00129                 scenNodeNmb[1] = 1 + sc; // scenNodeNmb[0] == 0, the root
    00130                 return 1;
    00131         }
    00132
    00133 public:
    00134         int nmbStages;
    00135
    00137         TwoStageTree(int const nScens);
    00138
    00140          ~TwoStageTree() {}
    00141
    00143         int get_parent_node(int n) const { return 0; }
    00144
    00146         void set_scen_prob(double * const pr);
    00147
    00149         double get_scen_prob(int const sc) const { return probs[sc]; }
    00150
    00152         int const * get_scen_nodes(int const sc) {
    00153                 set_scen_nodes(sc);
    00154                 return scenNodeNmb;
    00155         }
    00156
    00158
    00167         int const * get_next_scen(int &scen, int &parentScen,
    00168                                   int &branchStage, double &prob);
    00169 };
    00170
    00171
    00172 } // namespace FlopSmiEx
    00173 #endif