00001
00002 #ifndef _angel_types_include_
00003 #define _angel_types_include_
00004
00005 #include <vector>
00006 #include <string>
00007 #include <algorithm>
00008 #include <iostream>
00009 #include <sstream>
00010
00011 #include "boost/graph/adjacency_list.hpp"
00012 #include "boost/graph/graph_traits.hpp"
00013 #include "boost/property_map.hpp"
00014
00015 #ifdef USEXAIFBOOSTER
00016 #include <map>
00017 #include <set>
00018 #include "xaifBooster/algorithms/CrossCountryInterface/inc/LinearizedComputationalGraph.hpp"
00019 #include "xaifBooster/algorithms/CrossCountryInterface/inc/JacobianAccumulationExpressionList.hpp"
00020 #include "xaifBooster/algorithms/CrossCountryInterface/inc/GraphCorrelations.hpp"
00021 #endif // USEXAIFBOOSTER
00022
00023 #include "angel_exceptions.hpp"
00024
00025
00026
00027
00028
00029 namespace angel {
00030
00032 enum vertex_type_t {independent,
00033 intermediate,
00034 dependent,
00035 dead_vertex,
00036 undefined_vertex
00037 };
00038
00039 enum Edge_Type_E { VARIABLE_EDGE,
00040 UNIT_EDGE,
00041 CONSTANT_EDGE };
00042
00043 struct EdgeType {
00044 enum { num = 129 };
00045 typedef boost::edge_property_tag kind;
00046 };
00047
00048
00049 typedef boost::property<boost::edge_weight_t, int> edge_weight_property;
00050 typedef boost::property<boost::edge_index_t, int, edge_weight_property> edge_index_weight_property;
00051 typedef boost::property<EdgeType, int, edge_index_weight_property> edge_type_index_weight_property;
00052
00054
00055
00056
00057 struct VertexVisited {
00058
00059 typedef boost::vertex_property_tag kind;
00060 };
00061
00062
00063 typedef boost::property<VertexVisited, bool> vertex_visited_property;
00064
00066 typedef boost::adjacency_list<boost::vecS,
00067 boost::vecS,
00068 boost::bidirectionalS,
00069 vertex_visited_property,
00070 edge_type_index_weight_property>
00071 pure_c_graph_t;
00072
00073
00074 class graph_package_t;
00075 class accu_graph_t;
00076 class edge_address_t;
00077
00079 class c_graph_t: public pure_c_graph_t {
00080 private:
00081 int X;
00082 public:
00084 typedef pure_c_graph_t pure_graph_t;
00086 typedef pure_c_graph_t::vertex_descriptor vertex_t;
00088 typedef pure_c_graph_t::edge_descriptor edge_t;
00090 typedef boost::graph_traits<pure_c_graph_t>::vertex_iterator vi_t;
00092 typedef boost::graph_traits<pure_c_graph_t>::edge_iterator ei_t;
00094 typedef boost::graph_traits<pure_c_graph_t>::in_edge_iterator iei_t;
00096 typedef boost::graph_traits<pure_c_graph_t>::out_edge_iterator oei_t;
00098 typedef boost::property_map<pure_c_graph_t, boost::edge_weight_t>::const_type const_ew_t;
00100 typedef boost::property_map<pure_c_graph_t, boost::edge_weight_t>::type ew_t;
00102 typedef boost::property_map<pure_c_graph_t, boost::edge_index_t>::const_type const_eind_t;
00104 typedef boost::property_map<pure_c_graph_t, boost::edge_index_t>::type eind_t;
00106 typedef boost::property_map<pure_c_graph_t, EdgeType>::const_type const_etype_t;
00108 typedef boost::property_map<pure_c_graph_t, EdgeType>::type etype_t;
00109
00110 int next_edge_number;
00111
00112 std::vector<vertex_t> dependents;
00113
00115 c_graph_t () :
00116 pure_c_graph_t (), X (0), next_edge_number (0) {}
00117
00123 c_graph_t (int V_, int X_, const std::vector<vertex_t>& deps) :
00124 pure_c_graph_t (V_), X (X_), next_edge_number (0), dependents (deps) {
00125
00126 #ifndef NDEBUG
00127
00128 THROW_EXCEPT_MACRO (X < 0 && X > V_, consistency_exception, "X inconsistent");
00129 for (size_t c= 0; c < dependents.size(); c++)
00130
00131 THROW_EXCEPT_MACRO (dependents[c] >= (vertex_t) V_, consistency_exception, "dependents inconsistent");
00132 #endif
00133 }
00134
00140 c_graph_t (int X_, int Z_, int Y_) :
00141 pure_c_graph_t (X_+Y_+Z_), X (X_), next_edge_number (0) {
00142
00143 vi_t vi, v_end;
00144 tie(vi, v_end)= vertices(*this);
00145 for (int c= 0; c < X_+Z_; c++, ++vi);
00146 for (; vi != v_end; ++vi)
00147 dependents.push_back (*vi);
00148 }
00149
00151 c_graph_t (const c_graph_t& _g) :
00152 pure_c_graph_t (_g), X (_g.X),
00153 next_edge_number (_g.next_edge_number), dependents (_g.dependents) {}
00154
00156 c_graph_t& operator= (const c_graph_t& _g) {
00157 clear_edges ();
00158 pure_c_graph_t::operator= (_g); X= _g.X;
00159 next_edge_number= _g.next_edge_number;
00160 dependents= _g.dependents;
00161 return *this; }
00162
00164 void swap (c_graph_t& _g) {
00165 pure_c_graph_t::swap (_g);
00166 std::swap (X, _g.X);
00167 std::swap (next_edge_number, _g.next_edge_number); dependents.swap (_g.dependents); }
00168
00169 int x () const {return X;}
00170 void x (int x) { X=x;}
00171 int y () const {return (int) dependents.size();}
00172 int v () const {return (int) num_vertices(*this);}
00173 int z () const {return v()-x()-y();}
00174
00176 enum vertex_type_t vertex_type (vertex_t ve) const {
00177 if (int (ve) >= v()) return undefined_vertex;
00178 if (ve < (vertex_t) X) return independent;
00179 if (std::find (dependents.begin(), dependents.end(), ve) != dependents.end()) return dependent;
00180 return in_degree (ve, *this) == 0 && out_degree (ve, *this) == 0 ? dead_vertex : intermediate; }
00181
00183 bool check () const;
00185 bool check_initial () const;
00187 void remove_dependents_with_successors ();
00188
00192 void clear_edges () {
00193 vi_t vi, v_end;
00194 for (tie (vi, v_end)= vertices (*this); vi != v_end; ++vi)
00195 clear_vertex (*vi, *this); }
00196
00198 void clear_graph ();
00199
00200 friend int read_graph_eliad (const std::string& file_name, c_graph_t& cg, bool retry);
00201 friend void stats2block (int inputs, int outputs, const std::vector<c_graph_t>& stats,
00202 c_graph_t& block);
00203 friend void block2loop (const c_graph_t& block, int loops,
00204 c_graph_t& loop);
00205 friend void unpack_graph (const graph_package_t& gp, c_graph_t& cg);
00206
00207 #ifdef USEXAIFBOOSTER
00208 friend void read_graph_xaif_booster (const xaifBoosterCrossCountryInterface::LinearizedComputationalGraph& xg,
00209 c_graph_t& cg,
00210 std::vector<const xaifBoosterCrossCountryInterface::LinearizedComputationalGraphVertex*>& av,
00211 std::vector<edge_address_t>& ev);
00212
00213 #endif // USEXAIFBOOSTER
00214
00215 };
00216
00218 bool operator== (const c_graph_t& g1, const c_graph_t& g2);
00219
00221 inline bool operator!= (const c_graph_t& g1, const c_graph_t& g2) {
00222 return !(g1 == g2); }
00223
00225 int overall_markowitz_degree (const c_graph_t& cg);
00226
00228 inline bool vertex_eliminatable (const c_graph_t& cg) {
00229 for (size_t c= 0; c < cg.dependents.size(); c++)
00230 if (out_degree (cg.dependents[c], cg) > 0) return false;
00231 return true;
00232 }
00233
00235 typedef std::pair<c_graph_t::edge_t,bool> edge_bool_t;
00236
00237
00238
00239
00240
00241
00242 typedef std::pair<int, int> ad_edge_t;
00243 typedef boost::property<boost::vertex_degree_t, int> vertex_degree_property;
00244 typedef boost::property<boost::vertex_name_t, ad_edge_t, vertex_degree_property> vertex_name_degree_property;
00245
00247 typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS,
00248 vertex_name_degree_property,
00249 boost::no_property> pure_line_graph_t;
00250
00257 class line_graph_t: public pure_line_graph_t {
00258 private:
00259 int X;
00260 bool cons_ok;
00261 public:
00263 typedef pure_line_graph_t pure_graph_t;
00265 typedef pure_line_graph_t::vertex_descriptor edge_t;
00267 typedef pure_line_graph_t::edge_descriptor face_t;
00269 typedef boost::graph_traits<pure_line_graph_t>::vertex_iterator ei_t;
00271 typedef boost::graph_traits<pure_line_graph_t>::edge_iterator fi_t;
00273 typedef boost::graph_traits<pure_line_graph_t>::in_edge_iterator ifi_t;
00275 typedef boost::graph_traits<pure_line_graph_t>::out_edge_iterator ofi_t;
00277 typedef boost::property_map<pure_line_graph_t, boost::vertex_degree_t>::const_type const_ed_t;
00279 typedef boost::property_map<pure_line_graph_t, boost::vertex_degree_t>::type ed_t;
00285 typedef boost::property_map<pure_line_graph_t, boost::vertex_name_t>::const_type const_evn_t;
00291 typedef boost::property_map<pure_line_graph_t, boost::vertex_name_t>::type evn_t;
00292
00293 std::vector<edge_t> dependents;
00294
00295 int x () const {return X;}
00296 int y () const {return dependents.size();}
00297 int v () const {return (int) num_vertices(*this);}
00298 int z () const {return v()-x()-y();}
00299
00300 const c_graph_t* cgp;
00301
00303 line_graph_t () : X (0), cons_ok (false), cgp (0) {}
00304
00310 line_graph_t (int V_, int X_, const std::vector<edge_t>& deps) :
00311 pure_line_graph_t (V_), X (X_), cons_ok (false), dependents (deps), cgp (0) {
00312
00313 #ifndef NDEBUG
00314
00315 THROW_EXCEPT_MACRO (X < 0 && X > V_, consistency_exception, "X inconsistent");
00316 for (size_t c= 0; c < dependents.size(); c++)
00317
00318 THROW_EXCEPT_MACRO (dependents[c] >= (edge_t) V_, consistency_exception, "dependents inconsistent");
00319 #endif
00320 }
00321
00323 line_graph_t (const c_graph_t& cg);
00324
00326 line_graph_t (const line_graph_t& _g) :
00327 pure_line_graph_t (_g), X (_g.X), cons_ok (_g.cons_ok),
00328 dependents (_g.dependents), cgp (_g.cgp) {}
00329
00331 ~line_graph_t () {clear_edges ();}
00332
00334 line_graph_t& operator= (const line_graph_t& _g) {
00335 clear_edges ();
00336 pure_line_graph_t::operator= (_g); X= _g.X; cons_ok= _g.cons_ok; cgp= _g.cgp;
00337 dependents= _g.dependents;
00338 return *this; }
00339
00343 void swap (line_graph_t& _g) {
00344 pure_line_graph_t::swap (_g);
00345 std::swap (X, _g.X); std::swap (cons_ok, _g.cons_ok); std::swap (cgp, _g.cgp);
00346 dependents.swap (_g.dependents); }
00347
00348
00350 enum vertex_type_t vertex_type (edge_t e) const {
00351 if (int (e) >= v()) return undefined_vertex;
00352 return in_degree (e, *this) == 0 ? (out_degree (e, *this) == 0 ? dead_vertex : independent)
00353 : (out_degree (e, *this) == 0 ? dependent : intermediate); }
00354
00356 void copy_properties (const line_graph_t& _g);
00357
00361 void clear_edges () {
00362 ei_t ei, e_end;
00363 for (tie (ei, e_end)= vertices (*this); ei != e_end; ++ei)
00364 clear_vertex (*ei, *this); }
00365
00367 void clear_graph ();
00368
00370 bool check () const;
00371
00373 bool is_tripartite () const;
00374
00375 friend int face_elimination (face_t face, int kr, line_graph_t& lg, accu_graph_t& ac);
00376 friend void unpack_graph (const graph_package_t& gp, line_graph_t& lg);
00377 };
00378
00386 template <typename Ad_graph_t>
00387 std::pair<typename Ad_graph_t::edge_descriptor, bool> inline
00388 edge (typename Ad_graph_t::vertex_descriptor u, typename Ad_graph_t::vertex_descriptor v,
00389 const Ad_graph_t& g) {
00390 if (u < num_vertices (g) && v < num_vertices (g))
00391 return boost::edge (u, v, (const Ad_graph_t&) g);
00392 else {
00393 typename Ad_graph_t::edge_descriptor e; return std::make_pair (e, false); }
00394 }
00395
00402 inline void edge_vertex_name (line_graph_t::edge_t e, const line_graph_t& lg,
00403 int& i, int& j) {
00404 line_graph_t::const_evn_t evn= get(boost::vertex_name, lg);
00405 i= evn[e].first; j= evn[e].second;
00406 }
00407
00408
00416 inline void face_vertex_name (line_graph_t::face_t f, const line_graph_t& lg,
00417 int& i, int& j, int& k) {
00418 line_graph_t::const_evn_t evn= get(boost::vertex_name, lg);
00419 line_graph_t::edge_t ij= source (f, lg), jk= target (f, lg);
00420 i= evn[ij].first, j= evn[ij].second, k= evn[jk].second;
00421 THROW_DEBUG_EXCEPT_MACRO (j != evn[jk].first, consistency_exception,
00422 "Adjacency corrupted in line graph");
00423 }
00424
00426 bool operator== (const line_graph_t& g1, const line_graph_t& g2);
00427
00429 inline bool operator!= (const line_graph_t& g1, const line_graph_t& g2) {
00430 return !(g1 == g2); }
00431
00433 int overall_markowitz_degree (const line_graph_t& lg);
00434
00440 int markowitz_degree (int j, const line_graph_t& lg);
00441
00442
00443
00444
00445
00446
00448 struct triplet_t {
00449 int i, j, k;
00450 triplet_t (int _i, int _j, int _k): i (_i), j (_j), k (_k) {}
00451 triplet_t (): i (-1), j (-1), k (-1) {}
00452 };
00453
00455 inline std::ostream& operator<< (std::ostream& stream, const triplet_t& t) {
00456 return stream << "(" << t.i << ", " << t.j << ", " << t.k << ")"; }
00457
00458
00459
00460
00461
00462
00463 template <typename Ad_graph_t>
00464 class predecessor_t {
00465 public:
00466 typedef typename Ad_graph_t::vertex_descriptor vd_t;
00467 typedef typename Ad_graph_t::edge_descriptor ed_t;
00468 typedef typename boost::graph_traits<Ad_graph_t>::vertex_iterator vi_t;
00469 typedef typename boost::graph_traits<Ad_graph_t>::edge_iterator gei_t;
00470 typedef typename boost::graph_traits<Ad_graph_t>::in_edge_iterator ei_t;
00471 typedef typename boost::graph_traits<Ad_graph_t>::out_edge_iterator rei_t;
00472 typedef typename boost::graph_traits<Ad_graph_t>::degree_size_type ds_t;
00473 private:
00474 std::vector<vd_t> independents;
00475 public:
00476 const Ad_graph_t& adg;
00477
00478 predecessor_t (const Ad_graph_t& _adg) : adg (_adg) {
00479 vi_t vi, v_end;
00480 tie (vi, v_end)= vertices (adg);
00481 for (int c= 0; c < adg.x(); c++, vi++)
00482 independents.push_back(*vi);
00483 }
00484
00485 ds_t degree (vd_t v) const {return in_degree (v, adg); }
00486
00487 std::pair<ei_t, ei_t> edges (vd_t v) const {return in_edges (v, adg); }
00488
00489 vd_t neighbor (ed_t e) const {return source (e, adg); }
00490
00491 vd_t neighbor (ei_t ei) const {return source (*ei, adg); }
00492
00493 ds_t rdegree (vd_t v) const {return out_degree (v, adg); }
00494
00495 std::pair<rei_t, rei_t> redges (vd_t v) const {return out_edges (v, adg); }
00496
00497 vd_t rneighbor (ed_t e) const {return target (e, adg); }
00498
00499 vd_t rneighbor (rei_t rei) const {return target (*rei, adg); }
00500
00501 const std::vector<vd_t>& first () const {return adg.dependents; }
00502
00503 const std::vector<vd_t>& last () const {return independents; }
00504
00505 void clear_vertices (const std::vector<vd_t>& vv) {
00506 for (size_t c= 0; c < vv.size(); c++)
00507 clear_vertex (vv[c], (Ad_graph_t&) adg); }
00508 };
00509
00510
00511 template <typename Ad_graph_t>
00512 class successor_t {
00513 public:
00514 typedef typename Ad_graph_t::vertex_descriptor vd_t;
00515 typedef typename Ad_graph_t::edge_descriptor ed_t;
00516 typedef typename boost::graph_traits<Ad_graph_t>::vertex_iterator vi_t;
00517 typedef typename boost::graph_traits<Ad_graph_t>::edge_iterator gei_t;
00518 typedef typename boost::graph_traits<Ad_graph_t>::out_edge_iterator ei_t;
00519 typedef typename boost::graph_traits<Ad_graph_t>::in_edge_iterator rei_t;
00520 typedef typename boost::graph_traits<Ad_graph_t>::degree_size_type ds_t;
00521 private:
00522 std::vector<vd_t> independents;
00523 public:
00524 const Ad_graph_t& adg;
00525
00526 successor_t (const Ad_graph_t& _adg) : adg (_adg) {
00527 vi_t vi, v_end;
00528 tie (vi, v_end)= vertices (adg);
00529 for (int c= 0; c < adg.x(); c++, vi++)
00530 independents.push_back(*vi);
00531 }
00532
00533 ds_t degree (vd_t v) const {return out_degree (v, adg); }
00534
00535 std::pair<ei_t, ei_t> edges (vd_t v) const {return out_edges (v, adg); }
00536
00537 vd_t neighbor (ed_t e) const {return target (e, adg); }
00538
00539 vd_t neighbor (ei_t ei) const {return target (*ei, adg); }
00540
00541 ds_t rdegree (vd_t v) const {return in_degree (v, adg); }
00542
00543 std::pair<rei_t, rei_t> redges (vd_t v) const {return in_edges (v, adg); }
00544
00545 vd_t rneighbor (ed_t e) const {return source (e, adg); }
00546
00547 vd_t rneighbor (rei_t rei) const {return source (*rei, adg); }
00548
00549 const std::vector<vd_t>& first () const {return independents; }
00550
00551 const std::vector<vd_t>& last () const {return adg.dependents; }
00552
00553 void clear_vertices (const std::vector<vd_t>& vv) {
00554 for (size_t c= 0; c < vv.size(); c++)
00555 clear_vertex (vv[c], (Ad_graph_t&) adg); }
00556 };
00557
00558
00559
00560
00561
00562
00563
00564
00565
00567 struct edge_elim_t {
00568 c_graph_t::edge_t edge;
00569 bool front;
00570 };
00571
00574 struct edge_pair_elim_t {
00575 c_graph_t::vertex_t i, j;
00576 bool front;
00577 };
00578
00580 inline std::ostream& operator<< (std::ostream& stream, const edge_pair_elim_t& ee) {
00581 return stream << "((" << ee.i << ", " << ee.j << "), " << ee.front << ")"; }
00582
00585 struct edge_ij_elim_t {
00586 int i, j;
00587 bool front;
00588 edge_ij_elim_t (int _i, int _j, bool _front) : i(_i), j(_j), front(_front) {}
00589 edge_ij_elim_t () : i(0), j(0), front(false) {}
00590 };
00591
00593 inline std::ostream& operator<< (std::ostream& stream, const edge_ij_elim_t& ee) {
00594 return stream << "((" << ee.i << ", " << ee.j << "), " << ee.front << ")"; }
00595
00598 typedef std::vector<edge_elim_t> edge_elim_seq_t;
00599
00602 typedef std::vector<edge_pair_elim_t> edge_pair_elim_seq_t;
00603
00606 typedef std::vector<edge_ij_elim_t> edge_ij_elim_seq_t;
00607
00608
00609
00610 struct accu_exp_t {
00611 enum ref_kind_t {nothing, exp, lgn, isop};
00612 enum op_t {add, mult};
00613 union ref_t {
00614 line_graph_t::edge_t node;
00615 int exp_nr;
00616 op_t op; };
00617
00618 ref_t ref;
00619 ref_kind_t ref_kind;
00620
00621 void set_exp (int _exp_nr) {ref_kind= exp; ref.exp_nr= _exp_nr; }
00622 void set_node (line_graph_t::edge_t _node) {ref_kind= lgn; ref.node= _node; }
00623 void set_op (op_t _op) {ref_kind= isop; ref.op= _op; }
00624
00625
00626
00627
00628 };
00629
00630 inline std::ostream& operator<< (std::ostream& stream, const accu_exp_t& exp) {
00631 switch (exp.ref_kind) {
00632 case accu_exp_t::nothing: stream << "nothing"; break;
00633 case accu_exp_t::exp: stream << "expression #" << exp.ref.exp_nr; break;
00634 case accu_exp_t::lgn: stream << "line_graph_node #" << exp.ref.node; break;
00635 case accu_exp_t::isop: stream << "op " << (exp.ref.op == accu_exp_t::add ? "add" : "mult"); }
00636 return stream; }
00637
00638 typedef boost::property<boost::vertex_name_t, accu_exp_t> accu_exp_property;
00639
00640 typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS,
00641 accu_exp_property,
00642 boost::no_property> pure_accu_exp_graph_t;
00643
00644 class accu_exp_graph_t : public pure_accu_exp_graph_t {
00645 int X;
00646 public:
00647 void set_graph (line_graph_t::edge_t e_out, line_graph_t::edge_t e1,
00648 line_graph_t::edge_t e2, std::vector<int> exp_nr);
00649 void set_graph (accu_exp_t::op_t op, line_graph_t::edge_t e1, line_graph_t::edge_t e2,
00650 std::vector<int> exp_nr);
00651 void set_graph (line_graph_t::edge_t edge);
00652 std::vector<pure_accu_exp_graph_t::vertex_descriptor> dependents;
00653 int x () const {return X; }
00654 int y () const {return int (dependents.size()); }
00655 int v () const {return (int) num_vertices(*this);}
00656 int z () const {return v()-x()-y();}
00657 };
00658
00659 struct accu_graph_t {
00660 const c_graph_t& cg;
00661 const line_graph_t& lg;
00662 std::vector<accu_exp_graph_t> accu_exp;
00663 std::vector<ad_edge_t> jacobi_entries;
00664 std::vector<int> exp_nr;
00665
00666 accu_graph_t (const c_graph_t& _cg, const line_graph_t& _lg) : cg (_cg), lg (_lg),
00667 exp_nr (lg.v(), -1) {}
00668
00669 void set_jacobi_entries ();
00670 };
00671
00672 #ifdef USEXAIFBOOSTER
00673 enum EdgeRefType_E {LCG_EDGE,
00674 JAE_VERT,
00675 UNDEFINED};
00676
00677 struct EdgeRef_t {
00678 c_graph_t::edge_t my_angelLCGedge;
00679 EdgeRefType_E my_type;
00680 const xaifBoosterCrossCountryInterface::LinearizedComputationalGraphEdge* my_LCG_edge_p;
00681 xaifBoosterCrossCountryInterface::JacobianAccumulationExpressionVertex* my_JAE_vertex_p;
00682
00683 EdgeRef_t (c_graph_t::edge_t _e,
00684 const xaifBoosterCrossCountryInterface::LinearizedComputationalGraphEdge* _LCGedge_p) :
00685 my_angelLCGedge(_e),
00686 my_type(LCG_EDGE),
00687 my_LCG_edge_p(_LCGedge_p),
00688 my_JAE_vertex_p(NULL) {}
00689
00690 EdgeRef_t (c_graph_t::edge_t _e,
00691 xaifBoosterCrossCountryInterface::JacobianAccumulationExpressionVertex* _JAEvert_p) :
00692 my_angelLCGedge(_e),
00693 my_type(JAE_VERT),
00694 my_LCG_edge_p(NULL),
00695 my_JAE_vertex_p(_JAEvert_p) {}
00696 };
00697
00698 struct edge_reroute_t {
00699 c_graph_t::edge_t e;
00700 c_graph_t::edge_t pivot_e;
00701 bool isPre;
00702
00703 mutable bool pivot_eliminatable;
00704 mutable bool increment_eliminatable;
00705
00706 mutable std::vector<c_graph_t::vertex_t> type3EdgeElimVector;
00707
00708 edge_reroute_t () {};
00709
00710 edge_reroute_t (const c_graph_t::edge_t _e,
00711 const c_graph_t::edge_t _pivot_e,
00712 bool _isPre) :
00713 e (_e),
00714 pivot_e (_pivot_e),
00715 isPre (_isPre),
00716 pivot_eliminatable (0),
00717 increment_eliminatable (0) { type3EdgeElimVector.clear(); }
00718 };
00719
00721
00725 class EdgeElim {
00726 public:
00727
00728 EdgeElim();
00729
00730 EdgeElim(const c_graph_t::edge_t& e,
00731 bool isFront,
00732 const c_graph_t& angelLCG);
00733
00734 EdgeElim(const edge_bool_t& be,
00735 const c_graph_t& angelLCG);
00736
00737 EdgeElim(const edge_ij_elim_t& eij);
00738
00739 std::string debug() const;
00740
00741 bool isFront() const;
00742
00743 unsigned int getSource() const;
00744
00745 unsigned int getTarget() const;
00746
00747 c_graph_t::edge_t getE(const c_graph_t& angelLCG) const;
00748
00749 edge_bool_t getBool(const c_graph_t& angelLCG) const;
00750
00752 unsigned int getCost(const c_graph_t& angelLCG) const;
00753
00754 private:
00755
00756 bool myIsFrontFlag;
00757 unsigned int mySource;
00758 unsigned int myTarget;
00759
00760 };
00761
00763
00767 class Rerouting {
00768 public:
00769
00770 Rerouting();
00771
00772 Rerouting(const c_graph_t::edge_t e,
00773 const c_graph_t::edge_t pivot_e,
00774 bool isPre,
00775 const c_graph_t& angelLCG);
00776
00777 Rerouting(const edge_reroute_t& er,
00778 const c_graph_t& angelLCG);
00779
00780 std::string debug() const;
00781
00782 bool isPre() const;
00783
00784 c_graph_t::edge_t getE(const c_graph_t& angelLCG) const;
00785
00786 c_graph_t::edge_t getPivotE(const c_graph_t& angelLCG) const;
00787
00788 edge_reroute_t getER(const c_graph_t& angelLCG) const;
00789
00790 unsigned int getI() const;
00791 unsigned int getJ() const;
00792 unsigned int getK() const;
00793
00794 bool operator==(const Rerouting& anotherRerouting) const;
00795
00796 private:
00797
00798 void init(const c_graph_t::edge_t& e,
00799 const c_graph_t::edge_t& pivot_e,
00800 bool isPre,
00801 const c_graph_t& angelLCG);
00802
00803 unsigned int i, j, k;
00804 bool pre;
00805
00806 };
00807
00809
00813 class Transformation {
00814 public:
00815
00816 Transformation(const EdgeElim& anEdgeElim);
00817
00818 Transformation(const edge_bool_t& be,
00819 const c_graph_t& angelLCG);
00820
00821 Transformation(const edge_ij_elim_t& an_ij_elim);
00822
00823 Transformation(const Rerouting& aRerouting);
00824
00825 Transformation(const edge_reroute_t& aRerouteElim,
00826 const c_graph_t& angelLCG);
00827
00828 std::string debug() const;
00829
00831 bool isRerouting() const;
00832
00833 const EdgeElim& getEdgeElim() const;
00834 const Rerouting& getRerouting() const;
00835
00836 private:
00837
00838 Transformation();
00839
00840 bool myIsReroutingFlag;
00841
00842 Rerouting myRerouting;
00843 EdgeElim myEdgeElim;
00844
00845 };
00846
00847 struct elimSeq_cost_t {
00848 std::vector<EdgeElim> edgeElimVector;
00849 unsigned int bestNumNontrivialEdges;
00850 unsigned int cost;
00851 unsigned int costAtBestEdgecount;
00852 unsigned int numIntermediatesAtBestEdgecount;
00853 unsigned int numIntermediatesWithoutUnitEdgeAtBestEdgecount;
00854 size_t lastDesiredElim;
00855 mutable bool revealedNewDependence;
00856
00857 elimSeq_cost_t (unsigned int _bestNumNontrivialEdges,
00858 unsigned int _cost,
00859 unsigned int _costAtBestEdgecount,
00860 unsigned int _numIntermediatesAtBestEdgecount,
00861 unsigned int _numIntermediatesWithoutUnitEdgeAtBestEdgecount,
00862 size_t _lastDesiredElim) :
00863 bestNumNontrivialEdges (_bestNumNontrivialEdges),
00864 cost (_cost),
00865 costAtBestEdgecount (_costAtBestEdgecount),
00866 numIntermediatesAtBestEdgecount (_numIntermediatesAtBestEdgecount),
00867 numIntermediatesWithoutUnitEdgeAtBestEdgecount (_numIntermediatesWithoutUnitEdgeAtBestEdgecount),
00868 lastDesiredElim (_lastDesiredElim),
00869 revealedNewDependence (false) {}
00870 };
00871
00872 struct transformationSeq_cost_t {
00873 std::vector<Transformation> transformationVector;
00874 unsigned int bestNumNontrivialEdges;
00875 unsigned int cost;
00876 unsigned int costAtBestEdgecount;
00877 unsigned int numIntermediatesAtBestEdgecount;
00878 unsigned int numIntermediatesWithoutUnitEdgeAtBestEdgecount;
00879 size_t lastDesiredTransformation;
00880 mutable bool revealedNewDependence;
00881
00882 transformationSeq_cost_t (unsigned int _bestNumNontrivialEdges,
00883 unsigned int _cost,
00884 unsigned int _costAtBestEdgecount,
00885 unsigned int _numIntermediatesAtBestEdgecount,
00886 unsigned int _numIntermediatesWithoutUnitEdgeAtBestEdgecount,
00887 size_t _lastDesiredTransformation) :
00888 bestNumNontrivialEdges (_bestNumNontrivialEdges),
00889 cost (_cost),
00890 costAtBestEdgecount (_costAtBestEdgecount),
00891 numIntermediatesAtBestEdgecount (_numIntermediatesAtBestEdgecount),
00892 numIntermediatesWithoutUnitEdgeAtBestEdgecount (_numIntermediatesWithoutUnitEdgeAtBestEdgecount),
00893 lastDesiredTransformation (_lastDesiredTransformation),
00894 revealedNewDependence (false) {}
00895 };
00896
00897 typedef std::pair<unsigned int,unsigned int> uint_pair_t;
00898 typedef std::set<c_graph_t::vertex_t> vertex_set_t;
00899 typedef std::map< uint_pair_t, vertex_set_t > refillDependenceMap_t;
00900
00901 #endif // USEXAIFBOOSTER
00902
00903 }
00904
00905
00912 #endif // _angel_types_include_
00913