corenode_base.hpp
Go to the documentation of this file.
1 
20 #ifndef CORENODE_BASE_HPP
21 #define CORENODE_BASE_HPP
22 
23 
27 #include "flopc.hpp"
28 
29 namespace FlopSmiEx {
30 using namespace flopc;
31 using namespace std;
32 
33 
34 
36 class CoreNodeBase {
37 protected:
39 
48 
50 
55  static double const * p2varValues;
56 
59 
60 public:
62  CoreNodeBase(CoreNodeBase *p2pred, int nodeStage = -1)
63  : p2parent(p2pred), p2child(NULL), stage(nodeStage)
64  {
65  if (p2parent != NULL) {
66  assert (p2parent->p2child == NULL && "only one child per node in Core");
67  p2parent->p2child = this; // register with the parent
68  }
69  CoreNodeBase::p2activeNode = this; // point the static pointer to itself
70  }
71 
72  virtual ~CoreNodeBase() {}
73 
76  int stage;
77 
79 
84  vector<VariableRef const *> all_variables;
86  vector<MP_constraint *> all_constraints;
87  vector<int> constr_row_offsets;
88 
91  void set_var_values(double const *p2values) {
92  p2varValues = p2values;
93  }
94 
96 
98  if (p2parent != NULL) {
99  cerr << "Warning: get_obj_func called from a non-root node!" << endl;
100  }
101  make_obj_func_rec();
102  return objFuncRec;
103  }
104 
105 protected:
107 
111  class SP_variable : public MP_variable {
112  private:
114  int varIndx;
115  public:
117  MP_set const &s2 = MP_set::getEmpty())
118  : MP_variable(s1, s2), p2node(CoreNodeBase::p2activeNode),
119  varIndx(static_cast<int>(p2node->all_variables.size()))
120  {
121  #ifndef NDEBUG
122  cout << "Stage " << p2node->stage << ": adding SP_variable with "
123  << s1.size() * s2.size() << " element(s), starting at col "
124  << varIndx << endl;
125  #endif
126  for (int i1 = 0; i1 < s1.size(); i1++) {
127  for (int i2 = 0; i2 < s2.size(); i2++) {
128  p2node->all_variables.push_back(& this->operator()(i1,i2));
129  }
130  }
131  }
132 
134 
141  double value(int const i1 = 0, int const i2 = 0) const {
142  assert (CoreNodeBase::p2varValues != NULL
143  && "variable values must be set before they are accessed!");
144  return CoreNodeBase::p2varValues[varIndx + f(i1, i2)];
145  }
146  };
147 
149 
170  class SP_constraint : public MP_constraint {
171  private:
174  public:
175  SP_constraint (MP_set const &s1 = MP_set::getEmpty())
176  : MP_constraint(s1), p2node(CoreNodeBase::p2activeNode),
177  constrIndx(static_cast<int>(p2node->all_constraints.size()))
178  {
179  #ifndef NDEBUG
180  cout << "Stage " << p2node->stage << ": adding SP_constr. with "
181  << s1.size() << " element(s), starting at row " << constrIndx
182  << endl;
183  #endif
184  for (int i1 = 0; i1 < s1.size(); i1++) {
185  p2node->all_constraints.push_back(this);
186  p2node->constr_row_offsets.push_back(i1);
187  }
188  }
189  };
190 
192 
196  void make_obj_func_rec();
197 };
198 
199 
200 } // namespace FlopSmiEx
201 #endif
Problem-independent base class for an LP/MIP model in one node of a tree.
MP_expression objFuncRec
objective function in this node and below
vector< MP_constraint * > all_constraints
list of ref. to constraints
CoreNodeBase(CoreNodeBase *p2pred, int nodeStage=-1)
constructor
class for a stochastic (node-based) variable
vector< int > constr_row_offsets
list of row offsets
static MP_set & getEmpty()
gets the distinct &#39;empty&#39; MP_set.
Semantic representation of a linear constraint.
MP_expression & get_obj_func()
make and return the recursive objective function
void set_var_values(double const *p2values)
point a given pointer to the vector of scenario solution values
SP_variable(MP_set const &s1=MP_set::getEmpty(), MP_set const &s2=MP_set::getEmpty())
static CoreNodeBase * p2activeNode
static pointer to the current CoreNodeBase object
int varIndx
index of the 1st el. in the vector of node&#39;s variables
CoreNodeBase * p2node
pointer to the node the constr. belongs to
class for a stochastic (node-based) constraint
Representation of a set for indexing into some other construct.
Definition: MP_set.hpp:78
virtual ~CoreNodeBase()
destructor
Symantic representation of a variable.
Definition: MP_variable.hpp:75
double value(int const i1=0, int const i2=0) const
get the value of a given variable
MP_expression objFuncNode
objective function in this node
static double const * p2varValues
vector of scenario solution values, for use in SP_variable
CoreNodeBase * p2node
pointer to the node the var belongs to
CoreNodeBase * p2child
pointer to the node&#39;s child
Symbolic representation of a linear expression.
int stage
stage of the node (used only for reporting)
CoreNodeBase * p2parent
pointer to the node&#39;s parent
int size() const