00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00027 #ifndef _DAG_DELTA_H_
00028 #define _DAG_DELTA_H_
00029
00030 #include <api_delta.h>
00031
00032 class dag_undelta : public undelta_base
00033 {
00034 private:
00035 typedef model::walker walker;
00036
00037 public:
00038 gptr<model>* old_model;
00039
00040 counted_ptr<model> rm_dag;
00041 std::vector<model::enhanced_edge> rm_e;
00042
00043 std::vector<walker> added_nodes;
00044 std::vector<walker> added_constraints;
00045 std::vector<walker> added_ghosts;
00046 std::vector<walker> added_vars;
00047
00048 std::map<unsigned int, interval> bounds_chgd;
00049
00050 bool is_full_undelta;
00051
00052 private:
00053 class __check_walkers
00054 {
00055 private:
00056 const std::vector<walker>& nr;
00057
00058 public:
00059 __check_walkers(const std::vector<walker>& __nr) : nr(__nr) {}
00060
00061 bool operator()(const walker& _w) const
00062 {
00063 std::vector<walker>::const_iterator __x(nr.begin()), __e(nr.end());
00064 for(; __x != __e; ++__x)
00065 if(_w == *__x)
00066 return false;
00067 return true;
00068 }
00069 };
00070
00071 public:
00072 dag_undelta(bool full=false) : undelta_base(),
00073 old_model(NULL),
00074 rm_dag(), rm_e(),
00075 added_nodes(), added_constraints(),
00076 added_ghosts(), added_vars(),
00077 bounds_chgd(), is_full_undelta(full)
00078 {}
00079
00080 dag_undelta(gptr<model>* __nc) : undelta_base(),
00081 old_model(__nc),
00082 rm_dag(), rm_e(),
00083 added_nodes(), added_constraints(),
00084 added_ghosts(), added_vars(),
00085 bounds_chgd(), is_full_undelta(true)
00086 {}
00087
00088 dag_undelta(const dag_undelta& _du) : undelta_base(_du),
00089 old_model(_du.old_model),
00090 rm_dag(_du.rm_dag), rm_e(_du.rm_e),
00091 added_nodes(_du.added_nodes),
00092 added_constraints(_du.added_constraints),
00093 added_ghosts(_du.added_ghosts),
00094 added_vars(_du.added_vars),
00095 bounds_chgd(_du.bounds_chgd),
00096 is_full_undelta(_du.is_full_undelta)
00097 {
00098 #if DEBUG_DELTA
00099 std::cerr << "Called dag_undelta copy constructor" << std::endl;
00100 #endif
00101 }
00102
00103 ~dag_undelta() { if(old_model) delete old_model; }
00104
00105 dag_undelta* new_copy() const { return new dag_undelta(*this); }
00106 void destroy_copy(dag_undelta* __d) { delete __d; }
00107
00108 bool unapply(work_node& x) const;
00109
00110 friend class dag_delta;
00111 };
00112
00113 class dag_delta : public delta_base
00114 {
00115 private:
00116 typedef model::walker walker;
00117
00118 public:
00119 counted_ptr<model> new_constraints;
00120
00121 std::vector<walker> rm_nodes;
00122
00123
00124 bool is_full_delta;
00125
00126
00127
00128 dag_delta(const std::string& __a, bool full=false) :
00129 delta_base(__a), new_constraints(),
00130 rm_nodes(), is_full_delta(full)
00131 {}
00132
00133 dag_delta(const std::string& __a, model* __nc, bool full=false) :
00134 delta_base(__a),
00135 new_constraints(__nc),
00136 rm_nodes(), is_full_delta(full)
00137 {}
00138
00139 dag_delta(const dag_delta& __d) : delta_base(__d),
00140 new_constraints(__d.new_constraints),
00141 rm_nodes(__d.rm_nodes),
00142 is_full_delta(__d.is_full_delta)
00143 {
00144 #if DEBUG_DELTA
00145 std::cerr << "Called dag_delta copy constructor" << std::endl;
00146 #endif
00147 }
00148
00149 ~dag_delta() {}
00150
00151 dag_delta* new_copy() const { return new dag_delta(*this); }
00152 void destroy_copy(dag_delta* __d) { delete __d; }
00153
00154 void add_new(model* __m) { new_constraints = __m; }
00155 void add_new(model& __m) { new_constraints = new model(__m); }
00156
00157 void remove(const walker& _nn) { rm_nodes.push_back(_nn); }
00158 void remove(const std::vector<walker>& _nn)
00159 { rm_nodes.insert(rm_nodes.end(), _nn.begin(), _nn.end()); }
00160
00161 private:
00162 void help_apply_p(work_node& x, model::walker& _x, model* nm) const;
00163 void help_apply_s(work_node& x, model* nm) const;
00164 void help_apply_c(work_node& x, model::walker& _x, model* nm) const;
00165 void help_apply_g(work_node& x, model* nm) const;
00166
00167 struct __docompare_nodes
00168 {
00169 bool operator() (const model::walker& _a, unsigned int _b) const
00170 {return _a->node_num < _b;}
00171 bool operator() (unsigned int _a, const model::walker& _b) const
00172 {return _a < _b->node_num;}
00173 };
00174
00175 class __check_nodes
00176 {
00177 private:
00178 const std::vector<walker>& nr;
00179
00180 public:
00181 __check_nodes(const std::vector<walker>& __nr) : nr(__nr) {}
00182
00183 bool operator()(const walker& _w) const
00184 {
00185 std::vector<walker>::const_iterator
00186 __x(lower_bound(nr.begin(), nr.end(),
00187 _w->node_num, __docompare_nodes()));
00188 if(__x != nr.end() && (*__x)->node_num == _w->node_num)
00189 return false;
00190 else
00191 return true;
00192 }
00193 };
00194
00195 public:
00196 bool apply(work_node& x, undelta_base*& _u) const;
00197
00198 friend class dag_undelta;
00199 };
00200
00201 #endif